use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement in project Perl5-IDEA by Camelcade.
the class PerlVariableDeclarationSearcher method processBuiltIns.
public boolean processBuiltIns() {
PerlVariableDeclarationElement variableDeclaration = PerlBuiltInVariablesService.getInstance(myVariable.getProject()).getVariableDeclaration(myVariableType, myName);
if (variableDeclaration == null) {
return true;
}
myResult = variableDeclaration;
return true;
}
use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement in project Perl5-IDEA by Camelcade.
the class PerlVariableReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement elementParent = myElement.getParent();
assert elementParent instanceof PerlVariable;
PerlVariable perlVariable = (PerlVariable) elementParent;
List<ResolveResult> result = new ArrayList<>();
PerlVariableDeclarationElement lexicalDeclaration = PerlResolveUtil.getLexicalDeclaration(perlVariable);
if (lexicalDeclaration == null || lexicalDeclaration.isGlobalDeclaration() && !(lexicalDeclaration instanceof PerlImplicitVariableDeclaration)) {
// not found explicit lexically visible declarations
// imports
PerlVariableType actualType = perlVariable.getActualType();
Project project = perlVariable.getProject();
PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(perlVariable);
if (// not true if LPE in TemplateToolkit
namespaceContainer != null) {
String variableName = perlVariable.getName();
if (actualType == PerlVariableType.SCALAR) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedScalarDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlScalarUtil.getGlobalScalarDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
} else if (actualType == PerlVariableType.ARRAY) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedArrayDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlArrayUtil.getGlobalArrayDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
} else if (actualType == PerlVariableType.HASH) {
for (PerlExportDescriptor importEntry : namespaceContainer.getImportedHashDescriptors()) {
if (importEntry.getImportedName().equals(variableName)) {
for (PerlVariableDeclarationElement targetVariable : PerlHashUtil.getGlobalHashDefinitions(project, importEntry.getTargetCanonicalName())) {
result.add(new PsiElementResolveResult(targetVariable));
}
}
}
}
}
// our variable declaration
for (PerlGlobVariable glob : perlVariable.getRelatedGlobs()) {
result.add(new PsiElementResolveResult(glob));
}
// globs
for (PerlVariableDeclarationElement globalDeclaration : perlVariable.getGlobalDeclarations()) {
result.add(new PsiElementResolveResult(globalDeclaration));
}
} else {
result.add(new PsiElementResolveResult(lexicalDeclaration));
}
return result.toArray(new ResolveResult[result.size()]);
}
use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement in project Perl5-IDEA by Camelcade.
the class PerlUseVarsQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
Collection<PerlVariableDeclarationElement> declarations = myVariablesProvider.getValue();
if (declarations.isEmpty()) {
startElement.delete();
return;
}
StringBuilder newCode = new StringBuilder("our");
if (declarations.size() > 1) {
newCode.append("(");
}
newCode.append(StringUtil.join(ContainerUtil.map(declarations, PsiElement::getText), ","));
if (declarations.size() > 1) {
newCode.append(")");
}
newCode.append(";");
PerlFileImpl fakeFile = PerlElementFactory.createFile(myStartElement.getProject(), newCode.toString());
PsiPerlStatement newElement = PsiTreeUtil.findChildOfType(fakeFile, PsiPerlStatement.class);
if (newElement != null) {
startElement.replace(newElement);
}
}
use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement in project Perl5-IDEA by Camelcade.
the class PerlUnresolvedVariableInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PerlVisitor() {
@Override
public void visitPerlVariable(@NotNull final PerlVariable variable) {
PsiElement parent = variable.getParent();
if (parent instanceof PerlVariableDeclarationElement || variable.isBuiltIn()) {
return;
}
PerlVariableNameElement variableNameElement = variable.getVariableNameElement();
if (variableNameElement != null) {
for (PsiReference reference : variableNameElement.getReferences()) {
if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length > 0 || reference.resolve() != null) {
return;
}
}
registerProblem(holder, variableNameElement, "Unable to find variable declaration.");
}
}
};
}
use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement in project Perl5-IDEA by Camelcade.
the class PerlGotoVariableContributor method getItemsByName.
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
if (name.length() > 0) {
Collection<PerlVariableDeclarationElement> result;
GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
char firstChar = name.charAt(0);
if (firstChar == '$') {
result = PerlScalarUtil.getGlobalScalarDefinitions(project, name.substring(1), scope);
} else if (firstChar == '@') {
result = PerlArrayUtil.getGlobalArrayDefinitions(project, name.substring(1), scope);
} else if (firstChar == '%') {
result = PerlHashUtil.getGlobalHashDefinitions(project, name.substring(1), scope);
} else if (firstChar == '*') {
Collection<PsiPerlGlobVariable> globResult = PerlGlobUtil.getGlobsDefinitions(project, name.substring(1), scope);
// noinspection SuspiciousToArrayCall
return globResult.toArray(new NavigationItem[globResult.size()]);
} else {
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
}
// noinspection SuspiciousToArrayCall
return result.toArray(new NavigationItem[result.size()]);
}
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
}
Aggregations