Java 类com.intellij.psi.impl.java.stubs.PsiFieldStub 实例源码

项目:intellij-ce-playground    文件:ClsFieldImpl.java   
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;
    }
  };
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@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());
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@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();
  }
}
项目:tools-idea    文件:ClsFieldImpl.java   
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;
    }
  };
}
项目:consulo-java    文件:StubBuildingVisitor.java   
@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);
}
项目:consulo-java    文件:RecordUtil.java   
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();
}
项目:consulo-java    文件:PsiFieldImpl.java   
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;
}
项目:consulo-java    文件:PsiFieldImpl.java   
@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();
    }
}
项目:intellij-ce-playground    文件:PsiEnumConstantImpl.java   
@Override
@NotNull
public String getName() {
  final PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getName();
  }
  return getNameIdentifier().getText();
}
项目:intellij-ce-playground    文件:PsiEnumConstantImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@Override
@NotNull
public String getName() {
  final PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getName();
  }
  return getNameIdentifier().getText();
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@Override
public boolean hasInitializer() {
  PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getInitializerText() != null;
  }

  return getInitializer() != null;
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@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);
}
项目:tools-idea    文件:PsiEnumConstantImpl.java   
@Override
@NotNull
public String getName() {
  final PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getName();
  }
  return getNameIdentifier().getText();
}
项目:tools-idea    文件:PsiEnumConstantImpl.java   
@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;
}
项目:tools-idea    文件:PsiFieldImpl.java   
@Override
@NotNull
public String getName() {
  final PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getName();
  }
  return getNameIdentifier().getText();
}
项目:tools-idea    文件:PsiFieldImpl.java   
@Override
public boolean hasInitializer() {
  PsiFieldStub stub = getStub();
  if (stub != null) {
    return stub.getInitializerText() != null;
  }

  return getInitializer() != null;
}
项目:tools-idea    文件:PsiFieldImpl.java   
@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);
}
项目:consulo-java    文件:ClsFieldImpl.java   
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;
        }
    };
}
项目:consulo-java    文件:PsiEnumConstantImpl.java   
@Override
@NotNull
public String getName()
{
    final PsiFieldStub stub = getStub();
    if(stub != null)
    {
        return stub.getName();
    }
    return getNameIdentifier().getText();
}
项目:consulo-java    文件:PsiEnumConstantImpl.java   
@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;
}
项目:consulo-java    文件:PsiFieldImpl.java   
@Override
@NotNull
public String getName()
{
    final PsiFieldStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.getName();
    }
    return getNameIdentifier().getText();
}
项目:consulo-java    文件:PsiFieldImpl.java   
@Override
public boolean hasInitializer()
{
    PsiFieldStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.getInitializerText() != null;
    }

    return getInitializer() != null;
}
项目:consulo-java    文件:PsiFieldImpl.java   
@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);
}
项目:intellij-ce-playground    文件:ClsEnumConstantImpl.java   
public ClsEnumConstantImpl(@NotNull PsiFieldStub stub) {
  super(stub);
}
项目:intellij-ce-playground    文件:PsiEnumConstantImpl.java   
public PsiEnumConstantImpl(final PsiFieldStub stub) {
  super(stub, JavaStubElementTypes.ENUM_CONSTANT);
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
public PsiFieldImpl(final PsiFieldStub stub) {
  this(stub, JavaStubElementTypes.FIELD);
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
protected PsiFieldImpl(final PsiFieldStub stub, final IStubElementType type) {
  super(stub, type);
}
项目:intellij-ce-playground    文件:PsiFieldImpl.java   
@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;
}
项目:tools-idea    文件:ClsEnumConstantImpl.java   
public ClsEnumConstantImpl(@NotNull PsiFieldStub stub) {
  super(stub);
}
项目:tools-idea    文件:PsiEnumConstantImpl.java   
public PsiEnumConstantImpl(final PsiFieldStub stub) {
  super(stub, JavaStubElementTypes.ENUM_CONSTANT);
}
项目:tools-idea    文件:PsiFieldImpl.java   
public PsiFieldImpl(final PsiFieldStub stub) {
  this(stub, JavaStubElementTypes.FIELD);
}
项目:tools-idea    文件:PsiFieldImpl.java   
protected PsiFieldImpl(final PsiFieldStub stub, final IStubElementType type) {
  super(stub, type);
}
项目:tools-idea    文件:PsiFieldImpl.java   
@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;
}
项目:consulo-java    文件:ClsEnumConstantImpl.java   
public ClsEnumConstantImpl(@NotNull PsiFieldStub stub) {
  super(stub);
}
项目:consulo-java    文件:PsiEnumConstantImpl.java   
public PsiEnumConstantImpl(final PsiFieldStub stub)
{
    super(stub, JavaStubElementTypes.ENUM_CONSTANT);
}
项目:consulo-java    文件:PsiFieldImpl.java   
public PsiFieldImpl(final PsiFieldStub stub)
{
    this(stub, JavaStubElementTypes.FIELD);
}
项目:consulo-java    文件:PsiFieldImpl.java   
protected PsiFieldImpl(final PsiFieldStub stub, final IStubElementType type)
{
    super(stub, type);
}