Search in sources :

Example 1 with PsiMethodStub

use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.

the class PsiClassImpl method getContextStub.

@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;
}
Also used : PsiClassInitializerStub(com.intellij.psi.impl.java.stubs.PsiClassInitializerStub) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) StubElement(com.intellij.psi.stubs.StubElement) PsiClassStub(com.intellij.psi.impl.java.stubs.PsiClassStub) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiMethodStub

use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.

the class PsiMethodImpl method getName.

@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>";
}
Also used : PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiMethodStub

use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.

the class PsiMethodImpl method getReturnType.

@Override
public PsiType getReturnType() {
    if (isConstructor())
        return null;
    PsiMethodStub stub = getStub();
    if (stub != null) {
        PsiType type = SoftReference.dereference(myCachedType);
        if (type == null) {
            String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false));
            assert typeText != null : stub;
            type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this);
            type = JavaSharedImplUtil.applyAnnotations(type, getModifierList());
            myCachedType = new SoftReference<>(type);
        }
        return type;
    }
    myCachedType = null;
    PsiTypeElement typeElement = getReturnTypeElement();
    return typeElement != null ? JavaSharedImplUtil.getType(typeElement, getParameterList()) : null;
}
Also used : PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub)

Example 4 with PsiMethodStub

use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.

the class PsiAnnotationMethodImpl method getDefaultValue.

@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<>(value);
        return value;
    }
    myCachedDefaultValue = null;
    final ASTNode node = getNode().findChildByRole(ChildRole.ANNOTATION_DEFAULT_VALUE);
    if (node == null)
        return null;
    return (PsiAnnotationMemberValue) node.getPsi();
}
Also used : PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) ASTNode(com.intellij.lang.ASTNode)

Example 5 with PsiMethodStub

use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.

the class GrTraitUtil method doCollectCompiledTraitMethods.

private static void doCollectCompiledTraitMethods(final ClsClassImpl trait, final Collection<PsiMethod> result) {
    for (PsiMethod method : trait.getMethods()) {
        if (AnnotationUtil.isAnnotated(method, GROOVY_TRAIT_IMPLEMENTED, false)) {
            result.add(method);
        }
    }
    VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
    if (traitFile == null)
        return;
    VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitMethodsFileIndex.HELPER_SUFFIX);
    if (helperFile == null)
        return;
    int key = FileBasedIndex.getFileId(helperFile);
    List<PsiJavaFileStub> values = FileBasedIndex.getInstance().getValues(GroovyTraitMethodsFileIndex.INDEX_ID, key, trait.getResolveScope());
    values.forEach(root -> ((PsiJavaFileStubImpl) root).setPsi((PsiJavaFile) trait.getContainingFile()));
    values.stream().map(root -> root.getChildrenStubs().get(0).getChildrenStubs()).<StubElement>flatMap(Collection::stream).filter(stub -> stub instanceof PsiMethodStub).forEach(stub -> result.add(createTraitMethodFromCompiledHelperMethod(((PsiMethodStub) stub).getPsi(), trait)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) ABSTRACT(com.intellij.psi.PsiModifier.ABSTRACT) ContainerUtil(com.intellij.util.containers.ContainerUtil) GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) GrAnnotationUtil(org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil) Map(java.util.Map) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Logger(com.intellij.openapi.diagnostic.Logger) GROOVY_TRAIT(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiJavaFileStubImpl(com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl) GROOVY_TRAIT_IMPLEMENTED(org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_TRAIT_IMPLEMENTED) Collection(java.util.Collection) TraitFieldDescriptor(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex.TraitFieldDescriptor) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) GroovyTraitFieldsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitFieldsFileIndex) List(java.util.List) GroovyTraitMethodsFileIndex(org.jetbrains.plugins.groovy.lang.resolve.GroovyTraitMethodsFileIndex) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) com.intellij.psi(com.intellij.psi) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) GrModifierFlags(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierFlags) Ref(com.intellij.openapi.util.Ref) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) PsiMethodStub(com.intellij.psi.impl.java.stubs.PsiMethodStub) Collection(java.util.Collection) StubElement(com.intellij.psi.stubs.StubElement) PsiJavaFileStub(com.intellij.psi.impl.java.stubs.PsiJavaFileStub)

Aggregations

PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)5 StubElement (com.intellij.psi.stubs.StubElement)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)1 ASTNode (com.intellij.lang.ASTNode)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 com.intellij.psi (com.intellij.psi)1 ABSTRACT (com.intellij.psi.PsiModifier.ABSTRACT)1 ClsClassImpl (com.intellij.psi.impl.compiled.ClsClassImpl)1 PsiClassInitializerStub (com.intellij.psi.impl.java.stubs.PsiClassInitializerStub)1 PsiClassStub (com.intellij.psi.impl.java.stubs.PsiClassStub)1 PsiJavaFileStub (com.intellij.psi.impl.java.stubs.PsiJavaFileStub)1 PsiJavaFileStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl)1 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)1 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)1 InheritanceUtil (com.intellij.psi.util.InheritanceUtil)1 PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)1