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;
}
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());
}
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)));
}
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;
}
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))));
}
Aggregations