use of com.perl5.lang.perl.psi.properties.PerlIdentifierOwner in project Perl5-IDEA by Camelcade.
the class PerlStructureViewElement method getChildren.
@NotNull
@Override
public TreeElement[] getChildren() {
List<TreeElement> result = new ArrayList<>();
Set<String> implementedMethods = new HashSet<>();
if (myElement instanceof PerlFile) {
FileViewProvider viewProvider = ((PerlFile) myElement).getViewProvider();
PsiFile podFile = viewProvider.getPsi(PodLanguage.INSTANCE);
if (podFile != null && podFile.getChildren().length > 1) {
result.add(new PodStructureViewElement(podFile));
}
Language targetLanguage = null;
for (Language language : viewProvider.getLanguages()) {
if (language == PerlLanguage.INSTANCE) {
targetLanguage = language;
break;
} else if (targetLanguage == null && language.isKindOf(PerlLanguage.INSTANCE)) {
targetLanguage = language;
}
}
if (targetLanguage != null) {
viewProvider.getPsi(targetLanguage).accept(new PerlRecursiveVisitor() {
@Override
public void visitNamespaceDefinitionElement(@NotNull PerlNamespaceDefinitionElement o) {
result.add(new PerlNamespaceStructureViewElement(o));
super.visitNamespaceDefinitionElement(o);
}
});
}
}
if (myElement instanceof PerlNamespaceDefinitionElement) {
// global variables
for (PerlVariableDeclarationElement child : PsiTreeUtil.findChildrenOfType(myElement, PerlVariableDeclarationElement.class)) {
if (child.isGlobalDeclaration() && myElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) {
result.add(new PerlVariableDeclarationStructureViewElement(child));
}
}
Project project = myElement.getProject();
GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
// imported scalars
for (PerlExportDescriptor exportDescritptor : ((PerlNamespaceDefinitionElement) myElement).getImportedScalarDescriptors()) {
String canonicalName = exportDescritptor.getTargetCanonicalName();
Collection<PerlVariableDeclarationElement> variables = PerlScalarUtil.getGlobalScalarDefinitions(project, canonicalName);
for (PerlVariableDeclarationElement variable : variables) {
result.add(new PerlVariableDeclarationStructureViewElement(variable).setImported(exportDescritptor));
}
// globs
Collection<PsiPerlGlobVariable> items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName, projectScope);
if (items.isEmpty()) {
items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName);
}
for (PerlGlobVariable item : items) {
result.add(new PerlGlobStructureViewElement(item).setImported(exportDescritptor));
}
}
// imported arrays
for (PerlExportDescriptor exportDescritptor : ((PerlNamespaceDefinitionElement) myElement).getImportedArrayDescriptors()) {
String canonicalName = exportDescritptor.getTargetCanonicalName();
Collection<PerlVariableDeclarationElement> variables = PerlArrayUtil.getGlobalArrayDefinitions(project, canonicalName);
for (PerlVariableDeclarationElement variable : variables) {
result.add(new PerlVariableDeclarationStructureViewElement(variable).setImported(exportDescritptor));
}
// globs
Collection<PsiPerlGlobVariable> items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName, projectScope);
if (items.isEmpty()) {
items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName);
}
for (PerlGlobVariable item : items) {
result.add(new PerlGlobStructureViewElement(item).setImported(exportDescritptor));
}
}
// imported hashes
for (PerlExportDescriptor exportDescritptor : ((PerlNamespaceDefinitionElement) myElement).getImportedHashDescriptors()) {
String canonicalName = exportDescritptor.getTargetCanonicalName();
Collection<PerlVariableDeclarationElement> variables = PerlHashUtil.getGlobalHashDefinitions(project, canonicalName);
for (PerlVariableDeclarationElement variable : variables) {
result.add(new PerlVariableDeclarationStructureViewElement(variable).setImported(exportDescritptor));
}
// globs
Collection<PsiPerlGlobVariable> items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName, projectScope);
if (items.isEmpty()) {
items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName);
}
for (PerlGlobVariable item : items) {
result.add(new PerlGlobStructureViewElement(item).setImported(exportDescritptor));
}
}
// Imported subs
for (PerlExportDescriptor exportDescritptor : ((PerlNamespaceDefinitionElement) myElement).getImportedSubsDescriptors()) {
String canonicalName = exportDescritptor.getTargetCanonicalName();
// declarations
Collection<PerlSubDeclarationElement> subDeclarations = PerlSubUtil.getSubDeclarations(project, canonicalName, projectScope);
if (subDeclarations.isEmpty()) {
subDeclarations = PerlSubUtil.getSubDeclarations(project, canonicalName);
}
for (PerlSubDeclarationElement item : subDeclarations) {
result.add(new PerlSubStructureViewElement(item).setImported(exportDescritptor));
}
// definitions
Collection<PerlSubDefinitionElement> subDefinitions = PerlSubUtil.getSubDefinitions(project, canonicalName, projectScope);
if (subDefinitions.isEmpty()) {
subDefinitions = PerlSubUtil.getSubDefinitions(project, canonicalName);
}
for (PerlSubDefinitionElement item : subDefinitions) {
result.add(new PerlSubStructureViewElement(item).setImported(exportDescritptor));
}
// globs
Collection<PsiPerlGlobVariable> items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName, projectScope);
if (items.isEmpty()) {
items = PerlGlobUtil.getGlobsDefinitions(project, canonicalName);
}
for (PerlGlobVariable item : items) {
result.add(new PerlGlobStructureViewElement(item).setImported(exportDescritptor));
}
}
myElement.accept(new PerlRecursiveVisitor() {
@Override
public void visitPerlSubDefinitionElement(@NotNull PerlSubDefinitionElement child) {
if (myElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) {
implementedMethods.add(child.getName());
result.add(new PerlSubStructureViewElement(child));
}
super.visitPerlSubDefinitionElement(child);
}
@Override
public void visitSubDeclarationElement(@NotNull PerlSubDeclarationElement child) {
if (myElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) {
result.add(new PerlSubStructureViewElement(child));
}
super.visitSubDeclarationElement(child);
}
@Override
public void visitGlobVariable(@NotNull PsiPerlGlobVariable child) {
if (child.isLeftSideOfAssignment() && myElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) {
implementedMethods.add(child.getName());
result.add(new PerlGlobStructureViewElement(child));
}
super.visitGlobVariable(child);
}
});
}
// inherited elements
if (myElement instanceof PerlNamespaceDefinitionWithIdentifier) {
List<TreeElement> inheritedResult = new ArrayList<>();
String packageName = ((PerlNamespaceDefinitionElement) myElement).getPackageName();
if (packageName != null) {
for (PsiElement element : PerlMro.getVariants(myElement, packageName, true)) {
if (element instanceof PerlIdentifierOwner && !implementedMethods.contains(((PerlIdentifierOwner) element).getName())) {
if (element instanceof PerlLightConstantDefinitionElement) {
inheritedResult.add(new PerlSubStructureViewElement((PerlSubDefinitionElement) element).setInherited());
} else if (element instanceof PerlSubDefinitionElement) {
inheritedResult.add(new PerlSubStructureViewElement((PerlSubDefinitionElement) element).setInherited());
} else if (element instanceof PerlSubDeclarationElement) {
inheritedResult.add(new PerlSubStructureViewElement((PerlSubDeclarationElement) element).setInherited());
} else if (element instanceof PerlGlobVariable && ((PerlGlobVariable) element).isLeftSideOfAssignment() && ((PerlGlobVariable) element).getName() != null) {
inheritedResult.add(new PerlGlobStructureViewElement((PerlGlobVariable) element).setInherited());
}
}
}
}
if (!inheritedResult.isEmpty()) {
result.addAll(0, inheritedResult);
}
}
return result.toArray(new TreeElement[result.size()]);
}
use of com.perl5.lang.perl.psi.properties.PerlIdentifierOwner in project Perl5-IDEA by Camelcade.
the class PerlSubReferenceSimple method getResolveResults.
@NotNull
public List<ResolveResult> getResolveResults(List<PsiElement> relatedItems) {
List<ResolveResult> result = new ArrayList<>();
resetFlags();
for (PsiElement element : relatedItems) {
if (!isAutoloaded() && element instanceof PerlIdentifierOwner && PerlSubUtil.SUB_AUTOLOAD.equals(((PerlIdentifierOwner) element).getName())) {
setAutoloaded();
}
if (!isConstant() && element instanceof PerlLightConstantDefinitionElement) {
setConstant();
}
if (!isDeclared() && element instanceof PerlSubDeclarationElement) {
setDeclared();
}
if (!isDefined() && element instanceof PerlSubDefinitionElement) {
setDefined();
}
if (!isXSub() && element instanceof PerlSubElement && ((PerlSubElement) element).isXSub()) {
setXSub();
}
if (!isAliased() && element instanceof PerlGlobVariable) {
setAliased();
}
result.add(new PsiElementResolveResult(element));
}
return result;
}
Aggregations