@Nullable private static List<String> down(@NotNull PsiElement qualifier) { List<String> nameList = null; if (qualifier instanceof Call) { nameList = down((Call) qualifier); } else if (qualifier instanceof ElixirAccessExpression) { nameList = down(qualifier.getChildren()); } else if (qualifier instanceof QualifiableAlias) { nameList = down((QualifiableAlias) qualifier); } return nameList; }
private void visitDeclaration (PsiElement o) { if (o.getChildren().length == 0 && GoDocumentationProvider.getCommentsForElement(o instanceof GoImportDeclaration && o.getPrevSibling() == null ? o.getParent() : o).isEmpty() && PsiTreeUtil.findChildrenOfType(o, PsiComment.class).isEmpty()) { holder.registerProblem(o, "Empty declaration <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new GoDeleteQuickFix(QUICK_FIX_NAME, o.getClass())); } } };
private static void foldTypes(@Nullable PsiElement e, @NotNull List<FoldingDescriptor> result) { if (e instanceof GoStructType) { if (((GoStructType)e).getFieldDeclarationList().isEmpty()) return; fold(e, ((GoStructType)e).getLbrace(), ((GoStructType)e).getRbrace(), "{...}", result); } if (e instanceof GoInterfaceType) { if (e.getChildren().length == 0) return; fold(e, ((GoInterfaceType)e).getLbrace(), ((GoInterfaceType)e).getRbrace(), "{...}", result); } }
private Set<String> typeTypeParameterNameSet(PsiElement psiElement) { Set<String> typeParameterNameSet; if (psiElement instanceof ElixirAccessExpression) { typeParameterNameSet = typeTypeParameterNameSet(psiElement.getChildren()); } else if (psiElement instanceof ElixirAlias) { /* Assume bare aliases are incorrectly capitalized type parameters, say from someone's that used to generics in Java. See https://github.com/KronicDeth/intellij-elixir/issues/694 */ typeParameterNameSet = typeTypeParameterNameSet((ElixirAlias) psiElement); } else if (psiElement instanceof ElixirTuple) { typeParameterNameSet = typeTypeParameterNameSet((ElixirTuple) psiElement); } else if (psiElement instanceof ElixirUnmatchedUnqualifiedNoArgumentsCall) { typeParameterNameSet = Collections.singleton(psiElement.getText()); } else { error("Cannot extract type type parameter name set", psiElement); typeParameterNameSet = Collections.emptySet(); } return typeParameterNameSet; }
PsiElement[] children = element.getChildren(); PsiElement[] children = element.getChildren(); PsiElement[] grandParentChildren = grandParent.getChildren();
public static boolean is(ElixirAtom atom) { boolean field = false; PsiElement parent = atom.getParent(); if (parent instanceof ElixirAccessExpression && parent.getChildren().length == 1) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof ElixirList) { PsiElement greatGrandParent = grandParent.getParent(); if (greatGrandParent instanceof ElixirAccessExpression && greatGrandParent.getChildren().length == 1) { PsiElement greatGreatGrandParent = greatGrandParent.getParent(); if (greatGreatGrandParent instanceof ElixirNoParenthesesOneArgument) { PsiElement greatGreatGreatGrandParent = greatGreatGrandParent.getParent(); if (greatGreatGreatGrandParent instanceof Call) { Call greatGreatGreatGrandParentCall = (Call) greatGreatGreatGrandParent; field = Structure.is(greatGreatGreatGrandParentCall); } } } } } return field; }
) { PsiElement noParenthesesOneArgument = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument(); PsiElement[] grandChildren = noParenthesesOneArgument.getChildren(); PsiElement[] greatGrandChildren = grandChild.getChildren();
private Set<String> specificationTypeParameterNameSet(@NotNull PsiElement psiElement) { Set<String> parameterNameSet; if (psiElement instanceof ElixirAccessExpression || psiElement instanceof ElixirKeywords || psiElement instanceof ElixirList || psiElement instanceof ElixirNoParenthesesKeywords) { parameterNameSet = specificationTypeParameterNameSet(psiElement.getChildren()); } else if (psiElement instanceof ElixirKeywordPair) { parameterNameSet = specificationTypeParameterNameSet((ElixirKeywordPair) psiElement); } else if (psiElement instanceof Type) { parameterNameSet = specificationTypeParameterNameSet((Type) psiElement); } else if (psiElement instanceof ElixirNoParenthesesKeywordPair) { parameterNameSet = specificationTypeParameterNameSet((ElixirNoParenthesesKeywordPair) psiElement); } else if (psiElement instanceof UnqualifiedNoArgumentsCall) { parameterNameSet = specificationTypeParameterNameSet((UnqualifiedNoArgumentsCall) psiElement); } else if (psiElement instanceof UnqualifiedNoParenthesesCall) { parameterNameSet = specificationTypeParameterNameSet((UnqualifiedNoParenthesesCall) psiElement); } else { error("Cannot extract specification type parameter name set", psiElement); parameterNameSet = Collections.emptySet(); } return parameterNameSet; }
psiElement instanceof ElixirTuple) { highlightTypesAndTypeTypeParameterDeclarations( psiElement.getChildren(), typeParameterNameSet, annotationHolder,
isCollapsedByDefault = ElixirFoldingSettings.getInstance().isReplaceModuleAttributesWithValues(); } else { PsiElement[] children = element.getChildren();
psiElement instanceof ElixirNoParenthesesKeywords) { highlightTypesAndSpecificationTypeParameterDeclarations( psiElement.getChildren(), typeParameterNameSet, annotationHolder,
/** * Return element range which contains TextRange(start, end) of top level elements * common parent of elements is straight parent for each element */ @Nullable private static Couple<PsiElement> getTopmostElementRange(@NotNull Couple<PsiElement> elementRange, @NotNull PsiElement commonParent) { if (elementRange.first == null || elementRange.second == null) return null; int start = elementRange.first.getTextOffset(); int end = elementRange.second.getTextRange().getEndOffset(); TextRange range = commonParent.getTextRange(); PsiElement[] children = commonParent.getChildren(); if (commonParent.isEquivalentTo(elementRange.first) || commonParent.isEquivalentTo(elementRange.second) || range.getStartOffset() == start && (children.length == 0 || children[0].getTextRange().getStartOffset() > start) || range.getEndOffset() == end && (children.length == 0 || children[children.length - 1].getTextRange().getEndOffset() < end)) { return Couple.of(commonParent, commonParent); } PsiElement startElement = elementRange.first; PsiElement endElement = elementRange.second; for (PsiElement element : children) { range = element.getTextRange(); if (range.contains(start) && !range.contains(end)) { startElement = element; } if (range.contains(end - 1) && !range.contains(start - 1)) { endElement = element; } } return startElement.getParent().isEquivalentTo(endElement.getParent()) ? Couple.of(startElement, endElement) : null; }
@NotNull final AnnotationHolder annotationHolder) { PsiElement noParenthesesOneArgument = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument(); PsiElement[] grandChildren = noParenthesesOneArgument.getChildren();
public List<PsiElement> getChildrenOfArrayObject(final PsiElement psiElement) { return Arrays.stream(psiElement.getChildren()) .filter(child -> child instanceof JsonArray || child instanceof YAMLSequence) .map(el -> Arrays.asList(el.getChildren())) .flatMap(Collection::stream) .collect(Collectors.toList()); }
TextAttributesKey leftMostFunctionArgumentsTextAttributesKey) { PsiElement noParenthesesOneArgument = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument(); PsiElement[] grandChildren = noParenthesesOneArgument.getChildren();
public boolean isLastChild(@NotNull PsiElement psiElement) { final Optional<PsiElement> lastChildOfParent = Optional.ofNullable(psiElement.getParent()) .map(PsiElement::getParent) .map(PsiElement::getParent) .map(el -> el.getChildren()[el.getChildren().length - 1]); final Optional<PsiElement> child = Optional.of(psiElement).map(PsiElement::getParent).map(PsiElement::getParent); return lastChildOfParent.equals(child); }
PsiElement[] children = commonParent.getChildren(); if (range.equalsToRange(start, end) || range.getStartOffset() == start && (children.length == 0 || children[0].getTextRange().getStartOffset() > start) ||
element instanceof ElixirStabBody || element instanceof ElixirTuple) { keepProcessing = execute(element.getChildren(), state); } else if (element instanceof ElixirContainerAssociationOperation) { keepProcessing = execute((ElixirContainerAssociationOperation) element, state);
psiElement instanceof ElixirTuple) { highlightTypesAndTypeParameterUsages( psiElement.getChildren(), typeParameterNameSet, annotationHolder,
@Override public boolean isUniqueArrayStringValue(final String value, final PsiElement psiElement) { return Optional.ofNullable(psiElement.getParent()) .map(PsiElement::getParent) .filter(el -> el instanceof JsonArray) .map(el -> Arrays.asList(el.getChildren())) .map(children -> children.stream().filter(c -> c instanceof JsonLiteral)) .map(childrenStream -> childrenStream.map(JsonLiteral.class::cast)) .map( childrenStream -> childrenStream.noneMatch( jsonLiteral -> value.equals(StringUtils.removeAllQuotes(jsonLiteral.getText())))) .orElse(true); }