Search in sources :

Example 1 with JavaClassReferenceProvider

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider in project intellij-community by JetBrains.

the class TestNGSuiteReferenceContributor method registerReferenceProviders.

public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(ourTestClassPattern, new JavaClassReferenceProvider());
    registrar.registerReferenceProvider(ourListenerClassPattern, new JavaClassReferenceProvider());
    final JavaClassReferenceProvider methodSelectorProvider = new JavaClassReferenceProvider();
    methodSelectorProvider.setOption(JavaClassReferenceProvider.EXTEND_CLASS_NAMES, new String[] { "org.testng.IMethodSelector" });
    registrar.registerReferenceProvider(ourMethodSelectorPattern, methodSelectorProvider);
    registrar.registerReferenceProvider(ourSuiteFilePattern, new PathListReferenceProvider() {

        @Override
        protected boolean disableNonSlashedPaths() {
            return false;
        }
    });
}
Also used : JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) PathListReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.PathListReferenceProvider)

Example 2 with JavaClassReferenceProvider

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider in project intellij-community by JetBrains.

the class FormReferenceProvider method processReferences.

private static void processReferences(final PsiPlainTextFile file, final PsiReferenceProcessor processor) {
    final Project project = file.getProject();
    final XmlTag rootTag = ApplicationManager.getApplication().runReadAction(new Computable<XmlTag>() {

        public XmlTag compute() {
            final XmlFile xmlFile = (XmlFile) PsiFileFactory.getInstance(project).createFileFromText("a.xml", XmlFileType.INSTANCE, file.getViewProvider().getContents());
            return xmlFile.getRootTag();
        }
    });
    if (rootTag == null || !Utils.FORM_NAMESPACE.equals(rootTag.getNamespace())) {
        return;
    }
    @NonNls final String name = rootTag.getName();
    if (!"form".equals(name)) {
        return;
    }
    PsiReference classReference = null;
    final XmlAttribute classToBind = rootTag.getAttribute("bind-to-class", null);
    if (classToBind != null) {
        // reference to class
        final XmlAttributeValue valueElement = classToBind.getValueElement();
        if (valueElement == null) {
            return;
        }
        final String className = valueElement.getValue().replace('$', '.');
        final PsiReference[] referencesByString = new JavaClassReferenceProvider().getReferencesByString(className, file, valueElement.getTextRange().getStartOffset() + 1);
        if (referencesByString.length < 1) {
            // There are no references there
            return;
        }
        for (PsiReference aReferencesByString : referencesByString) {
            processor.execute(aReferencesByString);
        }
        classReference = referencesByString[referencesByString.length - 1];
    }
    final PsiReference finalClassReference = classReference;
    ApplicationManager.getApplication().runReadAction(() -> processReferences(rootTag, finalClassReference, file, processor));
}
Also used : Project(com.intellij.openapi.project.Project) NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)

Example 3 with JavaClassReferenceProvider

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider in project intellij-community by JetBrains.

the class PsiClassConverter method createReferences.

@NotNull
public PsiReference[] createReferences(GenericDomValue<PsiClass> genericDomValue, PsiElement element, ConvertContext context) {
    ExtendClass extendClass = genericDomValue.getAnnotation(ExtendClass.class);
    final JavaClassReferenceProvider provider = createClassReferenceProvider(genericDomValue, context, extendClass);
    return provider.getReferencesByElement(element);
}
Also used : JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JavaClassReferenceProvider

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider in project intellij-community by JetBrains.

the class ExtendsClassChecker method checkExtendsClassInReferences.

public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
    if (!isPsiClassType(element)) {
        return Collections.emptyList();
    }
    final Object valueObject = element.getValue();
    if (!(valueObject instanceof PsiClass))
        return Collections.emptyList();
    final XmlElement valueElement = DomUtil.getValueElement(element);
    if (valueElement == null)
        return Collections.emptyList();
    final PsiReference[] references = ourProvider.getReferencesByElement(valueElement, new ProcessingContext());
    for (PsiReference reference : references) {
        if (reference instanceof JavaClassReference) {
            final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference) reference).getProvider();
            final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES.getValue(((JavaClassReferenceProvider) psiReferenceProvider).getOptions()) : null;
            if (value != null && value.length != 0) {
                for (String className : value) {
                    final List<DomElementProblemDescriptor> problemDescriptors = checkExtendClass(element, ((PsiClass) valueObject), className, false, false, true, false, true, true, holder);
                    if (!problemDescriptors.isEmpty()) {
                        return problemDescriptors;
                    }
                }
            }
        }
    }
    return Collections.emptyList();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) XmlElement(com.intellij.psi.xml.XmlElement)

Example 5 with JavaClassReferenceProvider

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider in project intellij-community by JetBrains.

the class ClassReferenceParser method getReferences.

@NotNull
@Override
public PsiReference[] getReferences(@NotNull HeaderValuePart headerValuePart) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(headerValuePart);
    JavaClassReferenceProvider provider;
    if (module != null) {
        provider = new JavaClassReferenceProvider() {

            @Override
            public GlobalSearchScope getScope(Project project) {
                return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
            }
        };
    } else {
        provider = new JavaClassReferenceProvider();
    }
    return provider.getReferencesByElement(headerValuePart);
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JavaClassReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)11 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 TextRange (com.intellij.openapi.util.TextRange)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XmlTag (com.intellij.psi.xml.XmlTag)2 NonNls (org.jetbrains.annotations.NonNls)2 ASTNode (com.intellij.lang.ASTNode)1 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 PsiType (com.intellij.psi.PsiType)1 JavaClassReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference)1 JavaClassReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet)1 PathListReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.PathListReferenceProvider)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlFile (com.intellij.psi.xml.XmlFile)1 ProcessingContext (com.intellij.util.ProcessingContext)1