use of com.intellij.psi.search.PsiNonJavaFileReferenceProcessor in project intellij-community by JetBrains.
the class ExtensionPointLocator method isRegisteredExtension.
public static boolean isRegisteredExtension(@NotNull PsiClass psiClass) {
String name = psiClass.getQualifiedName();
if (name == null)
return false;
Project project = psiClass.getProject();
GlobalSearchScope scope = getCandidatesScope(project);
return !PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {
@Override
public boolean process(PsiFile file, int startOffset, int endOffset) {
PsiElement at = file.findElementAt(startOffset);
String tokenText = at instanceof XmlToken ? at.getText() : null;
if (!StringUtil.equals(name, tokenText))
return true;
XmlTag tag = PsiTreeUtil.getParentOfType(at, XmlTag.class);
if (tag == null)
return true;
DomElement dom = DomUtil.getDomElement(tag);
return !(dom instanceof Extension && ((Extension) dom).getExtensionPoint() != null);
}
}, scope);
}
use of com.intellij.psi.search.PsiNonJavaFileReferenceProcessor in project intellij-community by JetBrains.
the class UnusedDeclarationInspectionBase method runInspection.
@Override
public void runInspection(@NotNull final AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
globalContext.getRefManager().iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull final RefEntity refEntity) {
if (refEntity instanceof RefElementImpl) {
final RefElementImpl refElement = (RefElementImpl) refEntity;
if (!refElement.isSuspicious())
return;
PsiFile file = refElement.getContainingFile();
if (file == null)
return;
final boolean isSuppressed = refElement.isSuppressed(getShortName(), ALTERNATIVE_ID);
if (isSuppressed || !((GlobalInspectionContextBase) globalContext).isToCheckFile(file, UnusedDeclarationInspectionBase.this)) {
if (isSuppressed || !scope.contains(file)) {
getEntryPointsManager(globalContext).addEntryPoint(refElement, false);
}
}
}
}
});
if (isAddNonJavaUsedEnabled()) {
checkForReachableRefs(globalContext);
final StrictUnreferencedFilter strictUnreferencedFilter = new StrictUnreferencedFilter(this, globalContext);
ProgressManager.getInstance().runProcess(new Runnable() {
@Override
public void run() {
final RefManager refManager = globalContext.getRefManager();
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(refManager.getProject());
refManager.iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull final RefEntity refEntity) {
if (refEntity instanceof RefClass && strictUnreferencedFilter.accepts((RefClass) refEntity)) {
findExternalClassReferences((RefClass) refEntity);
} else if (refEntity instanceof RefMethod) {
RefMethod refMethod = (RefMethod) refEntity;
if (refMethod.isConstructor() && strictUnreferencedFilter.accepts(refMethod)) {
findExternalClassReferences(refMethod.getOwnerClass());
}
}
}
private void findExternalClassReferences(final RefClass refElement) {
final PsiClass psiClass = refElement.getElement();
String qualifiedName = psiClass != null ? psiClass.getQualifiedName() : null;
if (qualifiedName != null) {
final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(globalContext.getProject());
final PsiNonJavaFileReferenceProcessor processor = (file, startOffset, endOffset) -> {
getEntryPointsManager(globalContext).addEntryPoint(refElement, false);
return false;
};
final DelegatingGlobalSearchScope globalSearchScope = new DelegatingGlobalSearchScope(projectScope) {
@Override
public boolean contains(@NotNull VirtualFile file) {
return file.getFileType() != JavaFileType.INSTANCE && super.contains(file);
}
};
if (helper.processUsagesInNonJavaFiles(qualifiedName, processor, globalSearchScope)) {
final PsiReference reference = ReferencesSearch.search(psiClass, globalSearchScope).findFirst();
if (reference != null) {
getEntryPointsManager(globalContext).addEntryPoint(refElement, false);
for (PsiMethod method : psiClass.getMethods()) {
final RefElement refMethod = refManager.getReference(method);
if (refMethod != null) {
getEntryPointsManager(globalContext).addEntryPoint(refMethod, false);
}
}
}
}
}
}
});
}
}, null);
}
myProcessedSuspicious = new HashSet<>();
myPhase = 1;
}
use of com.intellij.psi.search.PsiNonJavaFileReferenceProcessor in project intellij-community by JetBrains.
the class TestNGRelatedFilesProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
if (psiClass != null) {
final Project project = psiClass.getProject();
while (psiClass != null && TestNGUtil.hasTest(psiClass) && PsiClassUtil.isRunnableClass(psiClass, true)) {
final String qName = psiClass.getQualifiedName();
if (qName != null) {
final String packageQName = ((PsiJavaFile) psiClass.getContainingFile()).getPackageName();
final String packageName = StringUtil.getShortName(packageQName);
final String[] names;
if (packageQName.length() > 0) {
final String pName = packageName.length() > 0 ? packageName : packageQName;
names = new String[] { qName, pName };
} else {
names = new String[] { qName };
}
final List<PsiElement> tags = new ArrayList<>();
for (final String name : names) {
PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {
public boolean process(final PsiFile file, final int startOffset, final int endOffset) {
final PsiReference referenceAt = file.findReferenceAt(startOffset);
if (referenceAt != null) {
if (packageQName.endsWith(name)) {
//special package tag required
final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class);
if (tag == null || !tag.getName().equals("package")) {
return true;
}
final XmlAttribute attribute = tag.getAttribute("name");
if (attribute == null)
return true;
final String value = attribute.getValue();
if (value == null)
return true;
if (!(value.equals(StringUtil.getQualifiedName(packageQName, "*")) || value.equals(packageQName)))
return true;
}
tags.add(referenceAt.getElement());
}
return true;
}
}, new TestNGSearchScope(project));
}
if (!tags.isEmpty()) {
return GotoRelatedItem.createItems(tags, "TestNG");
}
}
psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
}
}
return Collections.emptyList();
}
use of com.intellij.psi.search.PsiNonJavaFileReferenceProcessor in project intellij-community by JetBrains.
the class ExtensionPointLocator method findExtensionPointCandidates.
private static void findExtensionPointCandidates(PsiClass psiClass, final List<ExtensionPointCandidate> list) {
String name = psiClass.getQualifiedName();
if (name == null)
return;
Project project = psiClass.getProject();
GlobalSearchScope scope = getCandidatesScope(project);
PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {
@Override
public boolean process(PsiFile file, int startOffset, int endOffset) {
PsiElement element = file.findElementAt(startOffset);
processExtensionPointCandidate(element, list);
return true;
}
}, scope);
}
Aggregations