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); } }; }
@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(); }
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()); } } }
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; }
@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>"; }
@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; }
@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>"; }
@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); }
@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); }
@Override public PsiDocComment getDocComment() { final PsiMethodStub stub = getStub(); if (stub != null && !stub.hasDocComment()) return null; return (PsiDocComment)getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT); }
@Override public boolean isConstructor() { final PsiMethodStub stub = getStub(); if (stub != null) { return stub.isConstructor(); } return getNode().findChildByRole(ChildRole.TYPE) == null; }
@Override public boolean isVarArgs() { final PsiMethodStub stub = getStub(); if (stub != null) { return stub.isVarArgs(); } return PsiImplUtil.isVarArgs(this); }
@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"))); }
@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); }
@Override public PsiDocComment getDocComment() { final PsiMethodStub stub = getGreenStub(); if(stub != null && !stub.hasDocComment()) { return null; } return (PsiDocComment) getNode().findChildByRoleAsPsiElement(ChildRole.DOC_COMMENT); }
@Override public boolean isConstructor() { final PsiMethodStub stub = getGreenStub(); if(stub != null) { return stub.isConstructor(); } return getNode().findChildByRole(ChildRole.TYPE) == null; }
@Override public boolean isVarArgs() { final PsiMethodStub stub = getGreenStub(); if(stub != null) { return stub.isVarArgs(); } return PsiImplUtil.isVarArgs(this); }
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(); } }; }
public PsiAnnotationMethodImpl(final PsiMethodStub stub) { super(stub, JavaStubElementTypes.ANNOTATION_METHOD); }
public PsiMethodImpl(final PsiMethodStub stub) { this(stub, JavaStubElementTypes.METHOD); }
protected PsiMethodImpl(final PsiMethodStub stub, final IStubElementType type) { super(stub, type); }
public PsiMethodWithRobotName(PsiMethodStub stub) { super(stub); }
public PsiMethodWithRobotName(PsiMethodStub stub, PsiMethod delegate) { super(stub); this.delegate = delegate; }
protected PsiMethodWithRobotName(PsiMethodStub stub, IStubElementType type) { super(stub, type); }