Search in sources :

Example 81 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class PyJavaPackageType method resolveMember.

@Override
public List<? extends RatedResolveResult> resolveMember(@NotNull String name, @Nullable PyExpression location, @NotNull AccessDirection direction, @NotNull PyResolveContext resolveContext) {
    Project project = myPackage.getProject();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    String childName = myPackage.getQualifiedName() + "." + name;
    GlobalSearchScope scope = getScope(project);
    ResolveResultList result = new ResolveResultList();
    final PsiClass[] classes = facade.findClasses(childName, scope);
    for (PsiClass aClass : classes) {
        result.poke(aClass, RatedResolveResult.RATE_NORMAL);
    }
    final PsiPackage psiPackage = facade.findPackage(childName);
    if (psiPackage != null) {
        result.poke(psiPackage, RatedResolveResult.RATE_NORMAL);
    }
    return result;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage)

Example 82 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-plugins by JetBrains.

the class BasePackageParser method getPackageReferences.

protected static PsiReference[] getPackageReferences(PsiElement psiElement) {
    String packageName = psiElement.getText();
    if (StringUtil.isEmptyOrSpaces(packageName)) {
        return PsiReference.EMPTY_ARRAY;
    }
    int offset = 0;
    if (packageName.charAt(0) == '!') {
        packageName = packageName.substring(1);
        offset = 1;
    }
    int size = packageName.length() - 1;
    if (packageName.charAt(size) == '?') {
        packageName = packageName.substring(0, size);
    }
    PackageReferenceSet refSet = new PackageReferenceSet(packageName, psiElement, offset) {

        @Override
        public Collection<PsiPackage> resolvePackageName(@Nullable PsiPackage context, String packageName) {
            if (context == null)
                return Collections.emptyList();
            String unwrappedPackageName = packageName.replaceAll("\\s+", "");
            return ContainerUtil.filter(context.getSubPackages(), pkg -> unwrappedPackageName.equals(pkg.getName()));
        }
    };
    return refSet.getReferences().toArray(new PsiPackageReference[0]);
}
Also used : PackageReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-plugins by JetBrains.

the class StrutsConstantValueReference method getVariants.

@NotNull
@SuppressWarnings({ "unchecked" })
public Object[] getVariants() {
    if (elementConverterPair == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final Converter converter = elementConverterPair.second;
    if (!(converter instanceof ResolvingConverter)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final ResolvingConverter resolvingConverter = (ResolvingConverter) converter;
    // merge "normal" + additional variants
    final DomElement paramValueElement = elementConverterPair.first;
    final ConvertContext convertContext = ConvertContextFactory.createConvertContext(paramValueElement);
    // wrap explicitly for empty list
    final Collection converterVariants = new ArrayList(resolvingConverter.getVariants(convertContext));
    final Collection variants;
    if (!converterVariants.isEmpty() && converterVariants.iterator().next() instanceof DomElement) {
        variants = Arrays.asList(ElementPresentationManager.getInstance().createVariants(converterVariants));
    } else {
        variants = converterVariants;
    }
    variants.addAll(resolvingConverter.getAdditionalVariants(convertContext));
    // add custom created references
    if (resolvingConverter instanceof CustomReferenceConverter) {
        final PsiReference[] references = ((CustomReferenceConverter) resolvingConverter).createReferences((GenericDomValue) paramValueElement, myElement, convertContext);
        for (final PsiReference customReference : references) {
            if (customReference instanceof JavaClassReference) {
                JavaClassReference javaClassReference = (JavaClassReference) customReference;
                String[] names = javaClassReference.getExtendClassNames();
                PsiElement context = javaClassReference.getCompletionContext();
                if (names != null && context instanceof PsiPackage) {
                    javaClassReference.processSubclassVariants((PsiPackage) context, names, element -> variants.add(element));
                    continue;
                }
            }
            Collections.addAll(variants, customReference.getVariants());
        }
    }
    return ArrayUtil.toObjectArray(variants);
}
Also used : JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) PsiReference(com.intellij.psi.PsiReference) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with PsiPackage

use of com.intellij.psi.PsiPackage in project oxy-template-support-plugin by mutant-industries.

the class InnerJsReferenceExpressionResolver method getResultsFromProcessor.

/**
 *  !!    TEMP CODE -  https://youtrack.jetbrains.com/issue/IDEA-138078    !!
 *
 * duplicated code to {@link NashornJSReferenceExpressionResolver#getResultsFromProcessor(WalkUpResolveProcessor)}
 *  - {@link super#resolveInPsiClass(PsiClass, boolean)} will one day (hopefully) be protected
 */
// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
protected ResolveResult[] getResultsFromProcessor(WalkUpResolveProcessor processor) {
    List<JSTaggedResolveResult> taggedResolveResults = processor.getTaggedResolveResults();
    if (taggedResolveResults.isEmpty() || (taggedResolveResults.get(0)).hasTag(JSTaggedResolveResult.ResolveResultTag.PARTIAL)) {
        Module module;
        if (JSSymbolUtil.isAccurateReferenceExpression(this.myRef)) {
            if (this.myQualifier instanceof JSReferenceExpression) {
                PsiElement qualifierResolve = ((JSReferenceExpression) this.myQualifier).resolve();
                if (qualifierResolve instanceof PsiClass) {
                    List<ResolveResult> results = this.resolveInPsiClass((PsiClass) qualifierResolve, true);
                    return results.isEmpty() ? ResolveResult.EMPTY_ARRAY : results.toArray(new ResolveResult[results.size()]);
                }
            }
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile);
            JSQualifiedName qualifiedName = JSSymbolUtil.getAccurateReferenceName(this.myRef);
            if (qualifiedName != null) {
                qualifiedName = ((JSQualifiedNameImpl) qualifiedName).withoutInnermostComponent("Packages");
            }
            if (qualifiedName != null) {
                String qName = qualifiedName.getQualifiedName();
                if (module != null) {
                    PsiClass aClass = psiFacade.findClass(qName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
                    if (aClass != null) {
                        return new ResolveResult[] { new JSResolveResult(aClass) };
                    }
                }
                PsiPackage aPackage = psiFacade.findPackage(qName);
                if (aPackage != null) {
                    return new ResolveResult[] { new JSResolveResult(aPackage) };
                }
            }
        }
        JSTypeInfo typeInfo = processor.getTypeInfo();
        if (!typeInfo.myContextLevels.isEmpty() && (module = ModuleUtilCore.findModuleForPsiElement(this.myContainingFile)) != null) {
            JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(this.myContainingFile.getProject());
            GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
            List<ResolveResult> javaResults = new SmartList();
            boolean contextResolvesToJavaClass = false;
            Iterator var9 = typeInfo.myContextLevels.iterator();
            while (var9.hasNext()) {
                JSContextLevel level = (JSContextLevel) var9.next();
                JSQualifiedName qualifiedName = level.myNamespace.getQualifiedName();
                if (level.myRelativeLevel == 0 && qualifiedName != null) {
                    PsiClass aClass = psiFacade.findClass(qualifiedName.getQualifiedName(), scope);
                    if (aClass != null) {
                        contextResolvesToJavaClass = true;
                        List<ResolveResult> results = this.resolveInPsiClass(aClass, level.myNamespace.getJSContext() == JSContext.STATIC);
                        javaResults.addAll(results);
                    }
                }
            }
            if (contextResolvesToJavaClass) {
                return javaResults.toArray(ResolveResult.EMPTY_ARRAY);
            }
        }
    }
    return processor.getResults();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) JSTypeInfo(com.intellij.lang.javascript.psi.resolve.JSTypeInfo) PsiClass(com.intellij.psi.PsiClass) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiPackage(com.intellij.psi.PsiPackage) JSQualifiedName(com.intellij.lang.javascript.psi.JSQualifiedName) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Iterator(java.util.Iterator) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) JSContextLevel(com.intellij.lang.javascript.psi.resolve.JSContextLevel) PsiElement(com.intellij.psi.PsiElement)

Example 85 with PsiPackage

use of com.intellij.psi.PsiPackage in project oxy-template-support-plugin by mutant-industries.

the class InnerJsTypeEvaluator method checkForEachDefinition.

// -----------------------------------------------------------------------------------------------------------------
@Nullable
private static JSType checkForEachDefinition(@NotNull final PsiElement element) {
    PsiElement elementLocal = element;
    if (elementLocal.getParent() instanceof JSVarStatement) {
        elementLocal = elementLocal.getParent();
    }
    // repeat macro - var keyword is missing
    if (elementLocal instanceof PsiPackage || !(elementLocal.getFirstChild() instanceof JSVariable)) {
        return null;
    }
    PsiElement elementAt = elementLocal.getContainingFile().getViewProvider().findElementAt(elementLocal.getNode().getStartOffset(), OxyTemplate.INSTANCE);
    assert elementAt != null;
    MacroAttribute attribute = PsiTreeUtil.getParentOfType(elementAt, MacroAttribute.class);
    if (attribute == null || !MacroIndex.REPEAT_MACRO_VARIABLE_DEFINITION.equals(attribute.getMacroParamName().getText())) {
        return null;
    }
    MacroCall macroCall = PsiTreeUtil.getParentOfType(attribute, MacroCall.class);
    assert macroCall != null;
    for (MacroAttribute macroAttribute : macroCall.getMacroAttributeList()) {
        if (MacroIndex.REPEAT_MACRO_LIST_DEFINITION.equals(macroAttribute.getMacroParamName().getText())) {
            MacroParam macroParam;
            if ((macroParam = macroAttribute.getMacroParam()) == null) {
                return null;
            }
            PsiElement list = elementLocal.getContainingFile().getViewProvider().findElementAt(macroParam.getNode().getStartOffset() + macroParam.getTextLength() - 1, OxyTemplateInnerJs.INSTANCE);
            JSReferenceExpression statement = PsiTreeUtil.getParentOfType(list, JSReferenceExpression.class);
            if (statement != null) {
                JSSimpleTypeProcessor typeProcessor = new JSSimpleTypeProcessor();
                JSTypeEvaluator.evaluateTypes(statement, statement.getContainingFile(), typeProcessor);
                if (typeProcessor.getType() instanceof JSArrayTypeImpl) {
                    return ((JSArrayTypeImpl) typeProcessor.getType()).getType();
                }
            }
        }
    }
    return null;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSArrayTypeImpl(com.intellij.lang.javascript.psi.types.JSArrayTypeImpl) MacroAttribute(ool.intellij.plugin.psi.MacroAttribute) PsiPackage(com.intellij.psi.PsiPackage) JSSimpleTypeProcessor(com.intellij.lang.javascript.psi.resolve.JSSimpleTypeProcessor) JSVarStatement(com.intellij.lang.javascript.psi.JSVarStatement) JSVariable(com.intellij.lang.javascript.psi.JSVariable) PsiElement(com.intellij.psi.PsiElement) MacroCall(ool.intellij.plugin.psi.MacroCall) MacroParam(ool.intellij.plugin.psi.MacroParam) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)93 PsiDirectory (com.intellij.psi.PsiDirectory)24 PsiClass (com.intellij.psi.PsiClass)22 Module (com.intellij.openapi.module.Module)19 Project (com.intellij.openapi.project.Project)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 PsiFile (com.intellij.psi.PsiFile)12 PsiElement (com.intellij.psi.PsiElement)11 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 Nullable (org.jetbrains.annotations.Nullable)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 HashSet (java.util.HashSet)6 List (java.util.List)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 ArrayList (java.util.ArrayList)4