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