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

项目:intellij-ce-playground    文件:ClsMethodImpl.java   
public ClsMethodImpl(final PsiMethodStub stub) {
  super(stub);

  myReturnType = isConstructor() ? null : new AtomicNotNullLazyValue<PsiTypeElement>() {
    @NotNull
    @Override
    protected PsiTypeElement compute() {
      PsiMethodStub stub = getStub();
      String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false));
      assert typeText != null : stub;
      return new ClsTypeElementImpl(ClsMethodImpl.this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
    }
  };

  final String text = getStub().getDefaultValueText();
  myDefaultValue = StringUtil.isEmptyOrSpaces(text) ? null : new AtomicNotNullLazyValue<PsiAnnotationMemberValue>() {
    @NotNull
    @Override
    protected PsiAnnotationMemberValue compute() {
      return ClsParsingUtil.createMemberValueFromText(text, getManager(), ClsMethodImpl.this);
    }
  };
}
项目:intellij-ce-playground    文件:PsiAnnotationMethodImpl.java   
@Override
public PsiAnnotationMemberValue getDefaultValue() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    final String text = stub.getDefaultValueText();
    if (StringUtil.isEmpty(text)) return null;

    PsiAnnotationMemberValue value = SoftReference.dereference(myCachedDefaultValue);
    if (value != null) {
      return value;
    }

    value = JavaPsiFacade.getElementFactory(getProject()).createAnnotationFromText("@Foo(" + text + ")", this).findAttributeValue(null);
    myCachedDefaultValue = new SoftReference<PsiAnnotationMemberValue>(value);
    return value;
  }

  myCachedDefaultValue = null;

  final ASTNode node = getNode().findChildByRole(ChildRole.ANNOTATION_DEFAULT_VALUE);
  if (node == null) return null;
  return (PsiAnnotationMemberValue)node.getPsi();
}
项目:intellij-ce-playground    文件:ClsPsiTest.java   
public void testAnnotationMethods() {
  PsiMethod[] methods = getFile("Annotation").getClasses()[0].getMethods();
  assertNotNull(((PsiAnnotationMethod)methods[0]).getDefaultValue());

  methods = getFile("Annotation2").getClasses()[0].getMethods();
  for (PsiMethod method : methods) {
    assertTrue(String.valueOf(method), method instanceof PsiAnnotationMethod);
    try {
      PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod)method).getDefaultValue();
      assertTrue(String.valueOf(defaultValue), defaultValue instanceof PsiBinaryExpression);
      PsiPrimitiveType type = method.getName().startsWith("f") ? PsiType.FLOAT : PsiType.DOUBLE;
      assertEquals(type, ((PsiBinaryExpression)defaultValue).getType());
    }
    catch (Exception e) {
      String valueText = ((PsiMethodStub)((StubBasedPsiElement)method).getStub()).getDefaultValueText();
      fail("Unable to compute default value of method " + method + " from text '" + valueText + "': " + e.getMessage());
    }
  }
}
项目:tools-idea    文件:ClsMethodImpl.java   
public ClsMethodImpl(final PsiMethodStub stub) {
  super(stub);

  myReturnType = isConstructor() ? null : new AtomicNotNullLazyValue<PsiTypeElement>() {
    @NotNull
    @Override
    protected PsiTypeElement compute() {
      PsiMethodStub stub = getStub();
      String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false));
      assert typeText != null : stub;
      return new ClsTypeElementImpl(ClsMethodImpl.this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
    }
  };

  final String text = getStub().getDefaultValueText();
  myDefaultValue = StringUtil.isEmptyOrSpaces(text) ? null : new AtomicNotNullLazyValue<PsiAnnotationMemberValue>() {
    @NotNull
    @Override
    protected PsiAnnotationMemberValue compute() {
      return ClsParsingUtil.createMemberValueFromText(text, getManager(), ClsMethodImpl.this);
    }
  };
}
项目:consulo-java    文件:StubBuildingVisitor.java   
private MethodAnnotationCollectingVisitor(PsiMethodStub owner,
        PsiModifierListStub modList,
        int ignoreCount,
        int paramIgnoreCount,
        int paramCount,
        PsiParameterStubImpl[] paramStubs,
        Function<String, String> mapping)
{
    super(ASM_API);
    myOwner = owner;
    myModList = modList;
    myIgnoreCount = ignoreCount;
    myParamIgnoreCount = paramIgnoreCount;
    myParamCount = paramCount;
    myParamStubs = paramStubs;
    myMapping = mapping;
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
@NotNull
public String getName()
{
    final String name;
    final PsiMethodStub stub = getGreenStub();
    if(stub != null)
    {
        name = stub.getName();
    }
    else
    {
        final PsiIdentifier nameIdentifier = getNameIdentifier();
        name = nameIdentifier == null ? null : nameIdentifier.getText();
    }

    return name != null ? name : "<unnamed>";
}
项目:consulo-java    文件:PsiClassImpl.java   
@Nullable
private StubElement getContextStub()
{
    PsiClassStub<?> stub = getStub();
    if(stub == null)
    {
        return null;
    }

    // if AST is not loaded, then we only can need context to resolve supertype references
    // this can be done by stubs unless there are local/anonymous classes referencing other local classes
    StubElement parent = stub.getParentStub();
    if(parent instanceof PsiClassInitializerStub || parent instanceof PsiMethodStub)
    {
        if(parent.getChildrenByType(JavaStubElementTypes.CLASS, PsiElement.ARRAY_FACTORY).length <= 1)
        {
            parent = parent.getParentStub();
        }
    }
    return parent instanceof PsiClassStub ? parent : null;
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
@NotNull
public String getName() {
  final String name;
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    name = stub.getName();
  }
  else {
    final PsiIdentifier nameIdentifier = getNameIdentifier();
    name = nameIdentifier == null ? null : nameIdentifier.getText();
  }

  return name != null ? name : "<unnamed>";
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public PsiType getReturnType() {
  if (isConstructor()) return null;

  final PsiMethodStub stub = getStub();
  if (stub != null) {
    PsiType type = SoftReference.dereference(myCachedType);
    if (type != null) return type;

    final String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(true));
    if (typeText == null) return null;

    try {
      type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeFromText(typeText, this);
      myCachedType = new SoftReference<PsiType>(type);
      return type;
    }
    catch (IncorrectOperationException e) {
      LOG.error("stub: " + stub + "; method: " + getText(), e);
      return null;
    }
  }

  myCachedType = null;
  PsiTypeElement typeElement = getReturnTypeElement();
  if (typeElement == null) return null;
  PsiParameterList parameterList = getParameterList();
  return JavaSharedImplUtil.getType(typeElement, parameterList);
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public boolean isDeprecated() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
  }

  return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public PsiDocComment getDocComment() {
  final PsiMethodStub stub = getStub();
  if (stub != null && !stub.hasDocComment()) return null;

  return (PsiDocComment)getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public boolean isConstructor() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isConstructor();
  }

  return getNode().findChildByRole(ChildRole.TYPE) == null;
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
@Override
public boolean isVarArgs() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isVarArgs();
  }

  return PsiImplUtil.isVarArgs(this);
}
项目:tools-idea    文件:PsiMethodImpl.java   
@Override
@NotNull
public String getName() {
  final String name;
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    name = stub.getName();
  }
  else {
    final PsiIdentifier nameIdentifier = getNameIdentifier();
    name = nameIdentifier == null ? null : nameIdentifier.getText();
  }

  return name != null ? name : "<unnamed>";
}
项目:tools-idea    文件:PsiMethodImpl.java   
@Override
public boolean isDeprecated() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
  }

  return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:tools-idea    文件:PsiMethodImpl.java   
@Override
public boolean isConstructor() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isConstructor();
  }

  return getNode().findChildByRole(ChildRole.TYPE) == null;
}
项目:tools-idea    文件:PsiMethodImpl.java   
@Override
public boolean isVarArgs() {
  final PsiMethodStub stub = getStub();
  if (stub != null) {
    return stub.isVarArgs();
  }

  return PsiImplUtil.isVarArgs(this);
}
项目:consulo-java    文件:ClsMethodImpl.java   
public ClsMethodImpl(final PsiMethodStub stub)
{
    super(stub);

    myReturnType = isConstructor() ? null : new AtomicNotNullLazyValue<PsiTypeElement>()
    {
        @NotNull
        @Override
        protected PsiTypeElement compute()
        {
            PsiMethodStub stub = getStub();
            String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false));
            assert typeText != null : stub;
            return new ClsTypeElementImpl(ClsMethodImpl.this, typeText, ClsTypeElementImpl.VARIANCE_NONE);
        }
    };

    final String text = getStub().getDefaultValueText();
    myDefaultValue = StringUtil.isEmptyOrSpaces(text) ? null : new AtomicNotNullLazyValue<PsiAnnotationMemberValue>()
    {
        @NotNull
        @Override
        protected PsiAnnotationMemberValue compute()
        {
            return ClsParsingUtil.createMemberValueFromText(text, getManager(), ClsMethodImpl.this);
        }
    };
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
@NotNull
public PsiReferenceList getThrowsList()
{
    PsiReferenceList child = getStubOrPsiChild(JavaStubElementTypes.THROWS_LIST);
    if(child != null)
    {
        return child;
    }

    PsiMethodStub stub = getStub();
    Stream<String> children = stub != null ? stub.getChildrenStubs().stream().map(s -> s.getClass().getSimpleName() + " : " + s.getStubType()) : Stream.of(getChildren()).map(e -> e.getClass()
            .getSimpleName() + " : " + e.getNode().getElementType());
    throw new AssertionError("Missing throws list, file=" + getContainingFile() + " children:\n" + children.collect(Collectors.joining("\n")));
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
public boolean isDeprecated()
{
    final PsiMethodStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
    }

    return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
public PsiDocComment getDocComment()
{
    final PsiMethodStub stub = getGreenStub();
    if(stub != null && !stub.hasDocComment())
    {
        return null;
    }

    return (PsiDocComment) getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT);
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
public boolean isConstructor()
{
    final PsiMethodStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isConstructor();
    }

    return getNode().findChildByRole(ChildRole.TYPE) == null;
}
项目:consulo-java    文件:PsiMethodImpl.java   
@Override
public boolean isVarArgs()
{
    final PsiMethodStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isVarArgs();
    }

    return PsiImplUtil.isVarArgs(this);
}
项目:consulo-java    文件:MethodData.java   
public Supplier<PsiCodeBlock> methodBody(PsiMethodImpl method)
{
    return () ->
    {
        PsiMethodStub stub = method.getStub();
        if(stub != null)
        {
            return CachedValuesManager.getCachedValue(method, () -> new CachedValueProvider.Result<>(getDetachedBody(method), method));
        }
        else
        {
            return method.getBody();
        }
    };
}
项目:intellij-ce-playground    文件:PsiAnnotationMethodImpl.java   
public PsiAnnotationMethodImpl(final PsiMethodStub stub) {
  super(stub, JavaStubElementTypes.ANNOTATION_METHOD);
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
public PsiMethodImpl(final PsiMethodStub stub) {
  this(stub, JavaStubElementTypes.METHOD);
}
项目:intellij-ce-playground    文件:PsiMethodImpl.java   
protected PsiMethodImpl(final PsiMethodStub stub, final IStubElementType type) {
  super(stub, type);
}
项目:robot-intellij-plugin    文件:PsiMethodWithRobotName.java   
public PsiMethodWithRobotName(PsiMethodStub stub) {
    super(stub);
}
项目:robot-intellij-plugin    文件:PsiMethodWithRobotName.java   
public PsiMethodWithRobotName(PsiMethodStub stub, PsiMethod delegate) {
    super(stub);
    this.delegate = delegate;
}
项目:robot-intellij-plugin    文件:PsiMethodWithRobotName.java   
protected PsiMethodWithRobotName(PsiMethodStub stub, IStubElementType type) {
    super(stub, type);
}
项目:tools-idea    文件:PsiAnnotationMethodImpl.java   
public PsiAnnotationMethodImpl(final PsiMethodStub stub) {
  super(stub, JavaStubElementTypes.ANNOTATION_METHOD);
}
项目:tools-idea    文件:PsiMethodImpl.java   
public PsiMethodImpl(final PsiMethodStub stub) {
  this(stub, JavaStubElementTypes.METHOD);
}
项目:tools-idea    文件:PsiMethodImpl.java   
protected PsiMethodImpl(final PsiMethodStub stub, final IStubElementType type) {
  super(stub, type);
}
项目:consulo-java    文件:PsiAnnotationMethodImpl.java   
public PsiAnnotationMethodImpl(final PsiMethodStub stub) {
  super(stub, JavaStubElementTypes.ANNOTATION_METHOD);
}
项目:consulo-java    文件:PsiMethodImpl.java   
public PsiMethodImpl(final PsiMethodStub stub)
{
    this(stub, JavaStubElementTypes.METHOD);
}
项目:consulo-java    文件:PsiMethodImpl.java   
protected PsiMethodImpl(final PsiMethodStub stub, final IStubElementType type)
{
    super(stub, type);
}