use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlDocUtil method getPerlVarDoc.
@Nullable
public static PsiElement getPerlVarDoc(PerlVariable variable) {
final Project project = variable.getProject();
PerlVariableType actualType = variable.getActualType();
String variableName = variable.getName();
if (actualType != null && StringUtil.isNotEmpty(variableName)) {
String text = actualType.getSigil() + variableName;
if (myVariablesRedirections.containsKey(text)) {
return resolveDocLink(myVariablesRedirections.get(text), variable);
}
if (variable.isBuiltIn()) {
PodDocumentPattern pattern = PodDocumentPattern.itemPattern(text);
if (text.matches("\\$[123456789]")) {
pattern.setItemPattern("$<digits>");
}
return searchPodElementInFile(project, PodSearchHelper.PERL_VAR_FILE_NAME, pattern);
}
}
return null;
}
use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlElementFactory method createDereference.
public static PsiElement createDereference(Project project) {
PerlFileImpl file = createFile(project, "$a->{bla};");
PerlVariable variable = PsiTreeUtil.findChildOfType(file, PerlVariable.class);
assert variable != null : "While creating dereference";
return variable.getNextSibling();
}
use of com.perl5.lang.perl.psi.PerlVariable 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.PerlVariable 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.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlBuiltinVariableRedeclarationInspection method checkDeclaration.
public void checkDeclaration(ProblemsHolder holder, PerlVariableDeclarationElement variableDeclarationWrapper) {
PerlVariable variable = variableDeclarationWrapper.getVariable();
PsiElement declarationContainer = variableDeclarationWrapper.getParent();
if (variable != null && PerlBuiltInVariablesService.getInstance(variableDeclarationWrapper.getProject()).getVariableDeclaration(variable.getActualType(), variable.getName()) != null && !(declarationContainer instanceof PsiPerlVariableDeclarationLocal)) {
registerProblem(holder, variable, PerlBundle.message("perl.inspection.builtin.shadowing"));
}
}
Aggregations