use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
IElementType elementType = PsiUtilCore.getElementType(element);
if (elementType == NYI_STATEMENT) {
holder.createInfoAnnotation(element, "Unimplemented statement").setTextAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
} else if (element instanceof PerlGlobVariable && ((PerlGlobVariable) element).isBuiltIn()) {
holder.createInfoAnnotation(element, null).setTextAttributes(PERL_GLOB_BUILTIN);
} else if (element instanceof PerlVariable && ((PerlVariable) element).isBuiltIn()) {
holder.createInfoAnnotation(element, null).setTextAttributes(VARIABLE_KEYS_MAP.get(element.getClass()));
} else if (elementType == LABEL_DECLARATION || elementType == LABEL_EXPR) {
holder.createInfoAnnotation(element.getFirstChild(), null).setTextAttributes(PerlSyntaxHighlighter.PERL_LABEL);
} else if (elementType == PACKAGE) {
assert element instanceof PerlNamespaceElement;
PerlNamespaceElement namespaceElement = (PerlNamespaceElement) element;
PsiElement parent = namespaceElement.getParent();
if (parent instanceof PerlNamespaceDefinitionWithIdentifier) {
decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION, false);
} else {
if (namespaceElement.isPragma()) {
decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_PRAGMA, false);
} else if (namespaceElement.isBuiltin()) {
decorateElement(namespaceElement, holder, PerlSyntaxHighlighter.PERL_PACKAGE_CORE, false);
}
}
} else if (element instanceof PerlPolyNamedElement) {
TextAttributesKey subAttribute = PerlSyntaxHighlighter.PERL_SUB_DEFINITION;
if (elementType == PerlConstantsWrapperElementType.CONSTANT_WRAPPER) {
// fixme some interface?
subAttribute = PerlSyntaxHighlighter.PERL_CONSTANT;
}
for (PerlDelegatingLightNamedElement lightNamedElement : ((PerlPolyNamedElement) element).getLightElements()) {
TextAttributesKey currentKey = lightNamedElement instanceof PerlSubDefinition ? subAttribute : PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION;
PsiElement navigationElement = lightNamedElement.getNavigationElement();
holder.createInfoAnnotation(ElementManipulators.getValueTextRange(navigationElement).shiftRight(lightNamedElement.getTextOffset()), null).setEnforcedTextAttributes(adjustTextAttributes(currentScheme.getAttributes(currentKey), false));
}
} else if (// instanceof PerlSubNameElement
elementType == SUB_NAME) {
PsiElement parent = element.getParent();
if (parent instanceof PsiPerlSubDeclaration) {
holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_SUB_DECLARATION);
} else if (parent instanceof PerlSubDefinitionElement) {
if ("AUTOLOAD".equals(((PerlSubNameElement) element).getName())) {
holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_AUTOLOAD);
} else {
holder.createInfoAnnotation(element, null).setTextAttributes(PerlSyntaxHighlighter.PERL_SUB_DEFINITION);
}
} else if (parent instanceof PerlMethod) {
// fixme don't we need to take multiple references here?
PsiElement grandParent = parent.getParent();
PerlNamespaceElement methodNamespace = ((PerlMethod) parent).getNamespaceElement();
if (// / not ...->method fixme shouldn't we use isObjectMethod here?
!(grandParent instanceof PsiPerlNestedCall) && // no explicit NS or it's core
(methodNamespace == null || methodNamespace.isCORE()) && ((PerlSubNameElement) element).isBuiltIn()) {
decorateElement(element, holder, PerlSyntaxHighlighter.PERL_SUB_BUILTIN);
} else {
PsiReference reference = element.getReference();
if (reference instanceof PerlSubReference) {
((PerlSubReference) reference).multiResolve(false);
if (((PerlSubReference) reference).isConstant()) {
holder.createInfoAnnotation(element, "Constant").setTextAttributes(PerlSyntaxHighlighter.PERL_CONSTANT);
} else if (((PerlSubReference) reference).isAutoloaded()) {
holder.createInfoAnnotation(element, "Auto-loaded sub").setTextAttributes(PerlSyntaxHighlighter.PERL_AUTOLOAD);
} else if (((PerlSubReference) reference).isXSub()) {
holder.createInfoAnnotation(element, "XSub").setTextAttributes(PerlSyntaxHighlighter.PERL_XSUB);
}
}
}
}
}
}
use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlVariableNameCompletionProvider method fillWithImportedVariables.
private void fillWithImportedVariables(@NotNull PsiElement variableNameElement, @NotNull CompletionResultSet resultSet) {
PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(variableNameElement);
if (namespaceContainer == null) {
return;
}
String packageName = namespaceContainer.getPackageName();
if (// incomplete package definition
StringUtil.isEmpty(packageName)) {
return;
}
PerlNamespaceEntityProcessor<PerlExportDescriptor> processor = null;
PsiElement perlVariable = variableNameElement.getParent();
if (perlVariable instanceof PsiPerlScalarVariable) {
processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {
@Override
public boolean process(String namespaceName, PerlExportDescriptor entity) {
LookupElementBuilder lookupElement = null;
if (entity.isScalar()) {
lookupElement = PerlVariableCompletionUtil.getScalarLookupElement(entity.getImportedName());
} else if (entity.isArray()) {
lookupElement = PerlVariableCompletionUtil.getArrayElementLookupElement(entity.getImportedName());
} else if (entity.isHash()) {
lookupElement = PerlVariableCompletionUtil.getHashElementLookupElement(entity.getImportedName());
}
if (lookupElement != null) {
resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
}
return true;
}
};
} else if (perlVariable instanceof PsiPerlArrayVariable || perlVariable instanceof PsiPerlArrayIndexVariable) {
processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {
@Override
public boolean process(String namespaceName, PerlExportDescriptor entity) {
LookupElementBuilder lookupElement = null;
if (entity.isArray()) {
lookupElement = PerlVariableCompletionUtil.getArrayLookupElement(entity.getImportedName());
} else if (entity.isHash()) {
lookupElement = PerlVariableCompletionUtil.getHashSliceLookupElement(entity.getImportedName());
}
if (lookupElement != null) {
resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
}
return true;
}
};
} else if (perlVariable instanceof PsiPerlHashVariable) {
processor = new PerlNamespaceEntityProcessor<PerlExportDescriptor>() {
@Override
public boolean process(String namespaceName, PerlExportDescriptor entity) {
LookupElementBuilder lookupElement = null;
if (entity.isHash()) {
lookupElement = PerlVariableCompletionUtil.getHashLookupElement(entity.getImportedName());
}
if (lookupElement != null) {
resultSet.addElement(lookupElement.withTypeText(entity.getRealPackage(), true));
}
return true;
}
};
}
if (processor != null) {
PerlUtil.processImportedEntities(namespaceContainer, processor);
}
}
use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlVariableCompletionUtil method fillWithBuiltInVariables.
public static void fillWithBuiltInVariables(@NotNull PsiElement variableNameElement, @NotNull CompletionResultSet resultSet) {
PsiElement perlVariable = variableNameElement.getParent();
PerlBuiltInVariablesService perlBuiltInVariablesService = PerlBuiltInVariablesService.getInstance(variableNameElement.getProject());
if (perlVariable instanceof PsiPerlScalarVariable) {
perlBuiltInVariablesService.processScalars((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getScalarLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
perlBuiltInVariablesService.processArrays((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getArrayElementLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
perlBuiltInVariablesService.processHashes((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getHashElementLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
} else if (perlVariable instanceof PsiPerlArrayVariable) {
perlBuiltInVariablesService.processArrays((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getArrayLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
// noinspection ConstantConditions
resultSet.addElement(getArraySliceLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
perlBuiltInVariablesService.processHashes((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getHashSliceLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
} else if (perlVariable instanceof PsiPerlArrayIndexVariable) {
perlBuiltInVariablesService.processArrays((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getArrayLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
} else if (perlVariable instanceof PsiPerlHashVariable) {
perlBuiltInVariablesService.processHashes((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getHashLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
} else if (perlVariable instanceof PsiPerlGlobVariable) {
perlBuiltInVariablesService.processGlobs((element, state) -> {
// noinspection ConstantConditions
resultSet.addElement(getGlobLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
return true;
});
}
}
use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class PerlVariableCompletionUtil method fillWithLExicalVariables.
public static void fillWithLExicalVariables(@NotNull PsiElement variableNameElement, @NotNull final CompletionResultSet resultSet) {
final PsiElement perlVariable = variableNameElement.getParent();
PsiScopeProcessor processor = (element, state) -> {
if (element instanceof PerlVariableDeclarationElement) {
PerlVariableDeclarationElement variable = (PerlVariableDeclarationElement) element;
PsiElement declarationStatement = PsiTreeUtil.getParentOfType(variable, PerlStatement.class);
if (PsiTreeUtil.isAncestor(declarationStatement, perlVariable, false)) {
return true;
}
if (perlVariable instanceof PsiPerlScalarVariable) {
String variableName = variable.getName();
if (variableName != null) {
if (variable.getActualType() == PerlVariableType.SCALAR) {
resultSet.addElement(setLexical(getScalarLookupElement(variableName)));
} else if (variable.getActualType() == PerlVariableType.ARRAY) {
resultSet.addElement(setLexical(getArrayElementLookupElement(variableName)));
} else if (variable.getActualType() == PerlVariableType.HASH) {
resultSet.addElement(setLexical(getHashElementLookupElement(variableName)));
}
}
} else if (perlVariable instanceof PsiPerlArrayVariable) {
String variableName = variable.getName();
if (variableName != null) {
if (variable.getActualType() == PerlVariableType.ARRAY) {
resultSet.addElement(setLexical(getArrayLookupElement(variableName)));
resultSet.addElement(setLexical(getArraySliceLookupElement(variableName)));
} else if (variable.getActualType() == PerlVariableType.HASH) {
resultSet.addElement(setLexical(getHashSliceLookupElement(variableName)));
}
}
} else if (perlVariable instanceof PsiPerlArrayIndexVariable) {
String variableName = variable.getName();
if (variableName != null) {
if (variable.getActualType() == PerlVariableType.ARRAY) {
resultSet.addElement(setLexical(getArrayLookupElement(variableName)));
}
}
} else if (perlVariable instanceof PsiPerlHashVariable) {
String variableName = variable.getName();
if (variableName != null) {
if (variable.getActualType() == PerlVariableType.HASH) {
resultSet.addElement(setLexical(getHashLookupElement(variableName)));
}
}
}
}
return true;
};
PerlResolveUtil.treeWalkUp(variableNameElement, processor);
PerlBuiltInVariablesService.getInstance(variableNameElement.getProject()).processVariables(processor);
}
use of com.perl5.lang.perl.psi.PerlVariable in project Perl5-IDEA by Camelcade.
the class HTMLMasonArgsBlockImpl method getArgumentsListHeavy.
@NotNull
protected List<PerlSubArgument> getArgumentsListHeavy() {
List<PerlSubArgument> result = new ArrayList<>();
PsiElement run = getFirstChild();
while (run != null) {
if (run instanceof PerlVariableDeclarationElement) {
PerlVariable variable = ((PerlVariableDeclarationElement) run).getVariable();
if (variable != null) {
PsiElement nextSibling = PerlPsiUtil.getNextSignificantSibling(run);
result.add(PerlSubArgument.create(variable.getActualType(), variable.getName(), nextSibling != null && nextSibling.getNode().getElementType() == FAT_COMMA));
}
}
run = run.getNextSibling();
}
return result;
}
Aggregations