Search in sources :

Example 1 with ClsClassImpl

use of com.intellij.psi.impl.compiled.ClsClassImpl in project intellij-community by JetBrains.

the class JavaPsiImplementationHelperImpl method getClsFileNavigationElement.

@NotNull
@Override
public PsiElement getClsFileNavigationElement(PsiJavaFile clsFile) {
    PsiClass[] classes = clsFile.getClasses();
    if (classes.length == 0)
        return clsFile;
    String sourceFileName = ((ClsClassImpl) classes[0]).getSourceFileName();
    String packageName = clsFile.getPackageName();
    String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;
    ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(clsFile.getProject());
    for (OrderEntry orderEntry : index.getOrderEntriesForFile(clsFile.getContainingFile().getVirtualFile())) {
        if (!(orderEntry instanceof LibraryOrSdkOrderEntry))
            continue;
        for (VirtualFile root : orderEntry.getFiles(OrderRootType.SOURCES)) {
            VirtualFile source = root.findFileByRelativePath(relativePath);
            if (source != null && source.isValid()) {
                PsiFile psiSource = clsFile.getManager().findFile(source);
                if (psiSource instanceof PsiClassOwner) {
                    return psiSource;
                }
            }
        }
    }
    return clsFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ClsClassImpl

use of com.intellij.psi.impl.compiled.ClsClassImpl in project intellij-community by JetBrains.

the class ClassInheritorsTest method testClsAndSourcesDoNotMixUp.

public void testClsAndSourcesDoNotMixUp() {
    PsiClass numberClass = myFixture.getJavaFacade().findClass("java.lang.Number", GlobalSearchScope.allScope(getProject()));
    assertTrue(String.valueOf(numberClass), numberClass instanceof ClsClassImpl);
    PsiClass n2 = (PsiClass) numberClass.getNavigationElement();
    assertTrue(String.valueOf(n2), n2 instanceof PsiClassImpl);
    Collection<PsiClass> subClasses = DirectClassInheritorsSearch.search(n2, GlobalSearchScope.allScope(getProject())).findAll();
    List<String> fqn = subClasses.stream().map(PsiClass::getQualifiedName).sorted().collect(Collectors.toList());
    // no dups mean no Cls/Psi mixed
    assertEquals(fqn.toString(), fqn.size(), new HashSet<>(fqn).size());
    Collection<PsiClass> allSubClasses = ClassInheritorsSearch.search(n2, GlobalSearchScope.allScope(getProject()), true).findAll();
    List<String> allFqn = allSubClasses.stream().map(PsiClass::getQualifiedName).sorted().collect(Collectors.toList());
    assertEquals(allFqn.toString(), allFqn.size(), new HashSet<>(allFqn).size());
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiClassImpl(com.intellij.psi.impl.source.PsiClassImpl) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet)

Example 3 with ClsClassImpl

use of com.intellij.psi.impl.compiled.ClsClassImpl 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)

Example 4 with ClsClassImpl

use of com.intellij.psi.impl.compiled.ClsClassImpl in project intellij-community by JetBrains.

the class PositionManagerImpl method findPsiClassByName.

private PsiClass findPsiClassByName(String originalQName, @Nullable Consumer<ClsClassImpl> altClsProcessor) {
    PsiClass psiClass = null;
    // first check alternative jre if any
    Sdk alternativeJre = myDebugProcess.getSession().getAlternativeJre();
    if (alternativeJre != null) {
        psiClass = findClass(myDebugProcess.getProject(), originalQName, AlternativeJreClassFinder.getSearchScope(alternativeJre));
        if (psiClass instanceof ClsClassImpl && altClsProcessor != null) {
            //try to find sources
            altClsProcessor.accept((ClsClassImpl) psiClass);
        }
    }
    if (psiClass == null) {
        psiClass = findClass(myDebugProcess.getProject(), originalQName, myDebugProcess.getSearchScope());
    }
    return psiClass;
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) ClsClassImpl(com.intellij.psi.impl.compiled.ClsClassImpl)

Example 5 with ClsClassImpl

use of com.intellij.psi.impl.compiled.ClsClassImpl in project intellij-community by JetBrains.

the class GrTraitUtil method doCollectCompiledTraitFields.

private static void doCollectCompiledTraitFields(ClsClassImpl trait, Collection<GrField> result) {
    VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
    if (traitFile == null)
        return;
    VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitFieldsFileIndex.HELPER_SUFFIX);
    if (helperFile == null)
        return;
    int key = FileBasedIndex.getFileId(helperFile);
    final List<Collection<TraitFieldDescriptor>> values = FileBasedIndex.getInstance().getValues(GroovyTraitFieldsFileIndex.INDEX_ID, key, trait.getResolveScope());
    values.forEach(descriptors -> descriptors.forEach(descriptor -> result.add(createTraitField(descriptor, 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) Collection(java.util.Collection)

Aggregations

ClsClassImpl (com.intellij.psi.impl.compiled.ClsClassImpl)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Ref (com.intellij.openapi.util.Ref)2 com.intellij.psi (com.intellij.psi)2 ABSTRACT (com.intellij.psi.PsiModifier.ABSTRACT)2 PsiJavaFileStub (com.intellij.psi.impl.java.stubs.PsiJavaFileStub)2 PsiMethodStub (com.intellij.psi.impl.java.stubs.PsiMethodStub)2 PsiJavaFileStubImpl (com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl)2 StubElement (com.intellij.psi.stubs.StubElement)2 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)2 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)2 InheritanceUtil (com.intellij.psi.util.InheritanceUtil)2 PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)2 Collection (java.util.Collection)2 List (java.util.List)2