use of com.perl5.lang.perl.psi.impl.PerlSubCallElement in project Perl5-IDEA by Camelcade.
the class PerlMooseAttributeHandler method createMojoAttributes.
@NotNull
private List<PerlDelegatingLightNamedElement<?>> createMojoAttributes(@NotNull PerlSubCallElement subCallElement, @NotNull Pair<List<PsiElement>, List<PsiElement>> lists) {
List<PsiElement> arguments = lists.second.subList(1, lists.second.size());
PsiElement argument = ContainerUtil.getFirstItem(arguments);
PerlSubExpr subExpr = ObjectUtils.tryCast(argument, PerlSubExpr.class);
List<PerlDelegatingLightNamedElement<?>> result = new ArrayList<>();
String namespaceName = PerlPackageUtil.getContextNamespaceName(subCallElement);
for (PsiElement identifier : lists.first) {
AtomicNotNullLazyValue<PerlValue> valueProvider = AtomicNotNullLazyValue.createValue(() -> PerlSmartGetterValue.create(subExpr != null ? PerlResolveUtil.computeReturnValueFromControlFlow(subExpr) : argument != null ? PerlValuesManager.from(argument) : PerlScalarValue.create(namespaceName)));
PerlLightMethodDefinitionElement<PerlSubCallElement> newMethod = new PerlLightMethodDefinitionElement<>(subCallElement, ElementManipulators.getValueText(identifier), LIGHT_METHOD_DEFINITION, identifier, namespaceName, Arrays.asList(PerlSubArgument.self(), PerlSubArgument.optionalScalar(PerlSubArgument.NEW_VALUE_VALUE)), PerlSubAnnotations.tryToFindAnnotations(identifier, subCallElement.getParent()), valueProvider, subExpr == null ? null : subExpr.getBlock());
result.add(newMethod);
}
return result;
}
use of com.perl5.lang.perl.psi.impl.PerlSubCallElement in project Perl5-IDEA by Camelcade.
the class PerlHandleCompletionProvider method isApplicable.
private boolean isApplicable(@NotNull PsiElement position) {
PerlSubCallElement subCallElement = PsiTreeUtil.getParentOfType(position, PerlSubCallElement.class);
if (subCallElement == null) {
return true;
}
PsiPerlMethod method = subCallElement.getMethod();
if (method == null || method.hasExplicitNamespace()) {
return true;
}
PerlSubNameElement subNameElement = method.getSubNameElement();
if (subNameElement == null) {
return true;
}
return !AUTO_VIVIFICATION_SUBS.contains(subNameElement.getName());
}
use of com.perl5.lang.perl.psi.impl.PerlSubCallElement in project Perl5-IDEA by Camelcade.
the class PerlClassAccessorHandler method computeLightElementsFromPsi.
@Override
@NotNull
public List<? extends PerlDelegatingLightNamedElement<?>> computeLightElementsFromPsi(@NotNull PerlSubCallElement psiElement) {
String packageName = PerlPackageUtil.getContextNamespaceName(psiElement);
if (StringUtil.isEmpty(packageName)) {
return Collections.emptyList();
}
List<PsiElement> listElements = psiElement.getCallArgumentsList();
if (listElements.isEmpty()) {
return Collections.emptyList();
}
List<PerlDelegatingLightNamedElement<?>> result = new ArrayList<>();
for (PsiElement listElement : listElements) {
if (!psiElement.isAcceptableIdentifierElement(listElement)) {
continue;
}
String baseName = ElementManipulators.getValueText(listElement);
PerlSubAnnotations subAnnotations = PerlSubAnnotations.computeForLightElement(psiElement, listElement);
for (Function<String, String> computation : getNamesComputations(psiElement)) {
result.add(new PerlClassAccessorMethod(psiElement, baseName, computation, CLASS_ACCESSOR_METHOD, listElement, packageName, subAnnotations));
}
}
return result;
}
use of com.perl5.lang.perl.psi.impl.PerlSubCallElement in project Perl5-IDEA by Camelcade.
the class PerlAttributeGrouper method group.
@Override
@NotNull
public Collection<Group> group(@NotNull AbstractTreeNode<?> parent, @NotNull Collection<TreeElement> children) {
if (children.isEmpty() || parent instanceof GroupWrapper && ((GroupWrapper) parent).getValue() instanceof AttributeGroup) {
return Collections.emptyList();
}
Map<PerlSubCallElement, AttributeGroup> groupMap = FactoryMap.create(AttributeGroup::new);
for (TreeElement childTreeElement : children) {
if (!(childTreeElement instanceof PerlStructureViewElement)) {
continue;
}
Object value = ((PerlStructureViewElement) childTreeElement).getValue();
if (!(value instanceof PerlLightMethodDefinitionElement<?>)) {
continue;
}
PsiElement delegate = ((PerlLightMethodDefinitionElement<?>) value).getDelegate();
if (!PerlMooseAttributeHandler.isMooseAttributeWrapper(delegate)) {
continue;
}
assert delegate instanceof PerlSubCallElement;
groupMap.get(delegate).addChild(childTreeElement);
}
return new ArrayList<>(groupMap.values());
}
use of com.perl5.lang.perl.psi.impl.PerlSubCallElement in project Perl5-IDEA by Camelcade.
the class PerlIndentProcessor method getNodeIndent.
@NotNull
public Indent getNodeIndent(@NotNull ASTNode node) {
IElementType nodeType = node.getElementType();
ASTNode parent = node.getTreeParent();
ASTNode grandParent = parent != null ? parent.getTreeParent() : null;
IElementType parentNodeType = parent != null ? parent.getElementType() : null;
IElementType grandParentNodeType = grandParent != null ? grandParent.getElementType() : null;
ASTNode prevSibling = FormatterUtil.getPreviousNonWhitespaceSibling(node);
IElementType prevSiblingElementType = prevSibling != null ? prevSibling.getElementType() : null;
ASTNode nextSibling = FormatterUtil.getNextNonWhitespaceSibling(node);
IElementType nextSiblingElementType = nextSibling != null ? nextSibling.getElementType() : null;
boolean isFirst = prevSibling == null;
boolean isLast = nextSibling == null;
if (parentNodeType == ATTRIBUTES) {
return Indent.getContinuationIndent();
}
if (PerlFormattingTokenSets.FOR_ELEMENTS_TOKENSET.contains(nodeType)) {
return Indent.getContinuationIndent();
}
if (isFirst && BLOCK_OPENERS.contains(nodeType) || isLast && BLOCK_CLOSERS.contains(nodeType)) {
return Indent.getNoneIndent();
}
if (VARIABLE_DECLARATIONS.contains(parentNodeType) && (nodeType == LEFT_PAREN || nodeType == RIGHT_PAREN)) {
return Indent.getNoneIndent();
}
boolean forceFirstIndent = false;
if (HEREDOC_BODIES_TOKENSET.contains(nodeType)) {
PsiElement psi = node.getPsi();
assert psi instanceof PerlHeredocElementImpl;
if (!((PerlHeredocElementImpl) psi).isIndentable()) {
return Indent.getAbsoluteNoneIndent();
}
forceFirstIndent = true;
}
if (getAbsoluteUnindentableTokens().contains(nodeType)) {
return Indent.getAbsoluteNoneIndent();
}
if ((BLOCK_LIKE_CONTAINERS.contains(nodeType) || nodeType == SUB_EXPR) && PerlFormattingTokenSets.MULTI_PARAM_BLOCK_CONTAINERS.contains(parentNodeType)) {
return Indent.getNoneIndent();
}
if (parent == null || grandParent == null && nodeType != HEREDOC_END_INDENTABLE && !HEREDOC_BODIES_TOKENSET.contains(nodeType)) {
return Indent.getNoneIndent();
}
if (getUnindentableTokens().contains(nodeType) || (nodeType instanceof PerlPolyNamedElementType && !(node.getPsi() instanceof PerlSubCallElement) && nodeType != USE_STATEMENT && nodeType != NO_STATEMENT)) {
return Indent.getNoneIndent();
}
if (parentNodeType == STRING_LIST && (nodeType == QUOTE_SINGLE_OPEN || nodeType == QUOTE_SINGLE_CLOSE)) {
return Indent.getNoneIndent();
}
if (nodeType == STRING_BARE && parentNodeType == STRING_LIST) {
return Indent.getContinuationIndent();
}
// defined by parent
if (getUnindentableContainers().contains(parentNodeType)) {
// a little magic for sub attributes
if (parentNodeType == SUB_DEFINITION) {
if (nodeType == COLON && nextSiblingElementType == ATTRIBUTE || nodeType == ATTRIBUTE && prevSiblingElementType != COLON) {
return Indent.getContinuationIndent();
}
}
return Indent.getNoneIndent();
}
if (PerlFormattingTokenSets.COMMA_LIKE_SEQUENCES.contains(parentNodeType)) {
return grandParentNodeType == STATEMENT ? Indent.getContinuationWithoutFirstIndent() : Indent.getContinuationIndent();
}
if (parentNodeType == CALL_ARGUMENTS) {
return Indent.getContinuationIndent();
}
if (getBlockLikeContainers().contains(parentNodeType)) {
return Indent.getNormalIndent();
}
return forceFirstIndent ? Indent.getContinuationIndent() : Indent.getContinuationWithoutFirstIndent();
}
Aggregations