public ClsFieldImpl(@NotNull PsiFieldStub stub) { super(stub); myType = new AtomicNotNullLazyValue<PsiTypeElement>() { @NotNull @Override protected PsiTypeElement compute() { PsiFieldStub stub = getStub(); String typeText = TypeInfo.createTypeText(stub.getType(false)); assert typeText != null : stub; return new ClsTypeElementImpl(ClsFieldImpl.this, typeText, ClsTypeElementImpl.VARIANCE_NONE); } }; myInitializer = new VolatileNullableLazyValue<PsiExpression>() { @Nullable @Override protected PsiExpression compute() { String initializerText = getStub().getInitializerText(); return initializerText != null && !Comparing.equal(PsiFieldStub.INITIALIZER_TOO_LONG, initializerText) ? ClsParsingUtil.createExpressionFromText(initializerText, getManager(), ClsFieldImpl.this) : null; } }; }
@Override @NotNull public PsiType getType() { final PsiFieldStub stub = getStub(); if (stub != null) { PsiType type = SoftReference.dereference(myCachedType); if (type != null) return type; String typeText = TypeInfo.createTypeText(stub.getType(true)); try { type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); myCachedType = new SoftReference<PsiType>(type); return type; } catch (IncorrectOperationException e) { LOG.error(e); return null; } } myCachedType = null; return JavaSharedImplUtil.getType(getTypeElement(), getNameIdentifier()); }
@Override public PsiDocComment getDocComment(){ final PsiFieldStub stub = getStub(); if (stub != null && !stub.hasDocComment()) return null; CompositeElement treeElement = getNode(); if (getTypeElement() != null) { PsiElement element = treeElement.findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT); return element instanceof PsiDocComment ? (PsiDocComment)element : null; } else { ASTNode prevField = treeElement.getTreePrev(); while(prevField.getElementType() != JavaElementType.FIELD){ prevField = prevField.getTreePrev(); } return ((PsiField)SourceTreeToPsiMap.treeElementToPsi(prevField)).getDocComment(); } }
@Override @Nullable public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if(isSet(access, Opcodes.ACC_SYNTHETIC)) { return null; } if(name == null) { return null; } byte flags = PsiFieldStubImpl.packFlags(isSet(access, Opcodes.ACC_ENUM), isSet(access, Opcodes.ACC_DEPRECATED), false, false); TypeInfo type = fieldType(desc, signature); String initializer = constToString(value, type.text, false, myMapping); PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags); PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access)); return new FieldAnnotationCollectingVisitor(modList, myMapping); }
public static boolean isStaticNonPrivateMember(@NotNull StubElement<?> stub) { StubElement<PsiModifierList> type = stub.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST); if(!(type instanceof PsiModifierListStub)) { return false; } int mask = ((PsiModifierListStub) type).getModifiersMask(); if(ModifierFlags.hasModifierProperty(PsiModifier.PRIVATE, mask)) { return false; } if(ModifierFlags.hasModifierProperty(PsiModifier.STATIC, mask)) { return true; } return stub instanceof PsiFieldStub && stub.getStubType() == JavaElementType.ENUM_CONSTANT || stub.getParentStub() instanceof PsiClassStub && ((PsiClassStub) stub.getParentStub()).isInterface(); }
public PsiExpression getDetachedInitializer() { final PsiFieldStub stub = getGreenStub(); PsiExpression initializer; if(stub == null) { initializer = getInitializer(); } else { String initializerText = stub.getInitializerText(); if(StringUtil.isEmpty(initializerText) || PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText) || PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) { initializer = getInitializer(); } else { PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade(); initializer = parserFacade.createExpressionFromText(initializerText, this); ((LightVirtualFile) initializer.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false); } } return initializer; }
@Override public PsiDocComment getDocComment() { final PsiFieldStub stub = getGreenStub(); if(stub != null && !stub.hasDocComment()) { return null; } CompositeElement treeElement = getNode(); if(getTypeElement() != null) { PsiElement element = treeElement.findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT); return element instanceof PsiDocComment ? (PsiDocComment) element : null; } else { ASTNode prevField = treeElement.getTreePrev(); while(prevField.getElementType() != JavaElementType.FIELD) { prevField = prevField.getTreePrev(); } return ((PsiField) SourceTreeToPsiMap.treeElementToPsi(prevField)).getDocComment(); } }
@Override @NotNull public String getName() { final PsiFieldStub stub = getStub(); if (stub != null) { return stub.getName(); } return getNameIdentifier().getText(); }
@Override public boolean isDeprecated() { final PsiFieldStub stub = getStub(); if (stub != null) { return stub.isDeprecated(); } PsiDocComment docComment = getDocComment(); return docComment != null && docComment.findTagByName("deprecated") != null || getModifierList().findAnnotation("java.lang.Deprecated") != null; }
@Override public boolean hasInitializer() { PsiFieldStub stub = getStub(); if (stub != null) { return stub.getInitializerText() != null; } return getInitializer() != null; }
@Override public boolean isDeprecated() { final PsiFieldStub stub = getStub(); if (stub != null) { return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this); } return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this); }
public ClsFieldImpl(@NotNull PsiFieldStub stub) { super(stub); myTypeElement = new AtomicNotNullLazyValue<PsiTypeElement>() { @NotNull @Override protected PsiTypeElement compute() { PsiFieldStub stub = getStub(); String typeText = TypeInfo.createTypeText(stub.getType(false)); assert typeText != null : stub; return new ClsTypeElementImpl(ClsFieldImpl.this, typeText, ClsTypeElementImpl.VARIANCE_NONE); } }; myInitializer = new VolatileNullableLazyValue<PsiExpression>() { @Nullable @Override protected PsiExpression compute() { String initializerText = getStub().getInitializerText(); return initializerText != null && !Comparing.equal(PsiFieldStub.INITIALIZER_TOO_LONG, initializerText) ? ClsParsingUtil.createExpressionFromText(initializerText, getManager(), ClsFieldImpl.this) : null; } }; }
@Override @NotNull public String getName() { final PsiFieldStub stub = getStub(); if(stub != null) { return stub.getName(); } return getNameIdentifier().getText(); }
@Override public boolean isDeprecated() { final PsiFieldStub stub = getStub(); if(stub != null) { return stub.isDeprecated(); } PsiDocComment docComment = getDocComment(); return docComment != null && docComment.findTagByName("deprecated") != null || getModifierList().findAnnotation("java.lang.Deprecated") != null; }
@Override @NotNull public String getName() { final PsiFieldStub stub = getGreenStub(); if(stub != null) { return stub.getName(); } return getNameIdentifier().getText(); }
@Override public boolean hasInitializer() { PsiFieldStub stub = getGreenStub(); if(stub != null) { return stub.getInitializerText() != null; } return getInitializer() != null; }
@Override public boolean isDeprecated() { final PsiFieldStub stub = getGreenStub(); if(stub != null) { return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this); } return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this); }
public ClsEnumConstantImpl(@NotNull PsiFieldStub stub) { super(stub); }
public PsiEnumConstantImpl(final PsiFieldStub stub) { super(stub, JavaStubElementTypes.ENUM_CONSTANT); }
public PsiFieldImpl(final PsiFieldStub stub) { this(stub, JavaStubElementTypes.FIELD); }
protected PsiFieldImpl(final PsiFieldStub stub, final IStubElementType type) { super(stub, type); }
@Nullable private Object _computeConstantValue(Set<PsiVariable> visitedVars) { Object cachedInitializerValue = myCachedInitializerValue; if (cachedInitializerValue != null && !(cachedInitializerValue instanceof PsiExpression)){ return cachedInitializerValue; } PsiType type = getType(); // javac rejects all non primitive and non String constants, although JLS states constants "variables whose initializers are constant expressions" if (!(type instanceof PsiPrimitiveType) && !type.equalsToText("java.lang.String")) return null; PsiExpression initializer; if (cachedInitializerValue != null) { initializer = (PsiExpression)cachedInitializerValue; } else{ final PsiFieldStub stub = getStub(); if (stub == null) { initializer = getInitializer(); if (initializer == null) return null; } else{ String initializerText = stub.getInitializerText(); if (StringUtil.isEmpty(initializerText)) return null; if (PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText)) return null; if (PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) { getNode(); return computeConstantValue(visitedVars); } final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade(); initializer = parserFacade.createExpressionFromText(initializerText, this); } } Object result = PsiConstantEvaluationHelperImpl.computeCastTo(initializer, type, visitedVars); if (initializer instanceof PsiLiteralExpression){ myCachedInitializerValue = result; } else{ myCachedInitializerValue = initializer; } return result; }
@Nullable private Object _computeConstantValue(Set<PsiVariable> visitedVars) { Object cachedInitializerValue = myCachedInitializerValue; if (cachedInitializerValue != null && !(cachedInitializerValue instanceof PsiExpression)){ return cachedInitializerValue; } PsiType type = getType(); // javac rejects all non primitive and non String constants, although JLS states constants "variables whose initializers are constant expressions" if (!(type instanceof PsiPrimitiveType) && !type.equalsToText("java.lang.String")) return null; PsiExpression initializer; if (cachedInitializerValue != null) { initializer = (PsiExpression)cachedInitializerValue; } else{ final PsiFieldStub stub = getStub(); if (stub == null) { initializer = getInitializer(); if (initializer == null) return null; } else{ String initializerText = stub.getInitializerText(); if (initializerText == null) return null; if (PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText)) return null; if (PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) { getNode(); return computeConstantValue(visitedVars); } final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade(); initializer = parserFacade.createExpressionFromText(initializerText, this); } } Object result = PsiConstantEvaluationHelperImpl.computeCastTo(initializer, type, visitedVars); if (initializer instanceof PsiLiteralExpression){ myCachedInitializerValue = result; } else{ myCachedInitializerValue = initializer; } return result; }