private static boolean isOperatorEquals(@Nullable PsiElement l, @Nullable PsiElement r) { if (l == null || r == null) return false; ASTNode lNode = l.getNode(); ASTNode rNode = r.getNode(); return lNode instanceof LeafElement && lNode.getElementType().equals(rNode.getElementType()); }
public static PsiElement createElement(ASTNode node) { IElementType type = node.getElementType(); if (type == TAG) { return new EExTagImpl(node); } throw new AssertionError("Unknown element type: " + type); } }
private static boolean isProhibited(@NotNull GoCompositeElement o, @Nullable GoCompositeElement qualifier) { ASTNode next = FormatterUtil.getNextNonWhitespaceSibling(o.getNode()); boolean isDot = next != null && next.getElementType() == GoTypes.DOT; return isDot || qualifier != null; } }
public static boolean onStatementBeginning(@NotNull PsiElement psiElement) { PsiElement prevLeaf = prevVisibleLeafOrNewLine(psiElement); if (prevLeaf == null) { return false; } if (prevLeaf instanceof PsiWhiteSpace) { return true; } IElementType type = prevLeaf.getNode().getElementType(); return type == GoTypes.SEMICOLON || type == GoTypes.LBRACE || type == GoTypes.RBRACE || type == GoTypes.COLON; }
@Override public String toString() { return getNode().getElementType().toString(); } }
@Override public String toString() { return getNode().getElementType().toString(); }
@NotNull private static Indent indentIfNotBrace(@NotNull ASTNode child) { return BRACES_TOKEN_SET.contains(child.getElementType()) ? Indent.getNoneIndent() : Indent.getNormalIndent(); }
@Override protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) { IElementType type = node.getElementType(); if (type == GoParserDefinition.LINE_COMMENT || type == GoParserDefinition.MULTILINE_COMMENT) { return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS; } if (type == GoTypes.BLOCK && CodeFoldingSettings.getInstance().COLLAPSE_METHODS) { ASTNode parent = node.getTreeParent(); return parent != null && parent.getPsi() instanceof GoFunctionOrMethodDeclaration; } return CodeFoldingSettings.getInstance().COLLAPSE_IMPORTS && node.getElementType() == GoTypes.IMPORT_LIST; } }
@Override public boolean process(@NotNull PsiElement o) { IElementType type = o.getNode().getElementType(); if (GoParserDefinition.COMMENTS.contains(type) || GoParserDefinition.WHITESPACES.contains(type)) { return true; } myIsLineBreakpointAvailable = true; return false; }
private boolean oneLinerUnmatchedCallBody(@NotNull ASTNode container) { ASTNode containerParent = container.getTreeParent(); boolean oneLiner = false; if (containerParent.getElementType() == ACCESS_EXPRESSION) { ASTNode accessExpressionParent = containerParent.getTreeParent(); if (KEYWORD_PAIR_TOKEN_SET.contains(accessExpressionParent.getElementType())) { oneLiner = oneLinerKeywordPair(accessExpressionParent); } } return oneLiner; }
@Override public boolean process(@NotNull PsiElement element) { IElementType type = element.getNode().getElementType(); myIsLineBreakpointAvailable = !(type instanceof PsiWhiteSpace) && !element.getNode().getText().isEmpty(); return true; }
@NotNull private GoFormattingBlock buildSubBlock(@NotNull ASTNode child, @Nullable Alignment alignment) { if (child.getPsi() instanceof GoType && child.getTreeParent().getElementType() == FIELD_DECLARATION) { alignment = getUserData(TYPE_ALIGNMENT_INSIDE_STRUCT); } Indent indent = calcIndent(child); return new GoFormattingBlock(child, alignment, indent, null, mySettings, mySpacingBuilder); }
@Override public String toString() { return getNode().getElementType().toString(); }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { WriteCommandAction.runWriteCommandAction(project, () -> { PsiElement element = ObjectUtils.tryCast(descriptor.getStartElement(), myClazz); if (element != null && (myElementType == null || element.getNode().getElementType() == myElementType)) { element.delete(); } }); } }
@Override public boolean shouldCreateStub(ASTNode node) { return super.shouldCreateStub(node) && node.getElementType() == GoTypes.VAR_SPEC && PsiTreeUtil.getParentOfType(node.getPsi(), GoFunctionOrMethodDeclaration.class) == null; }
@Override protected boolean isInContext(@NotNull PsiElement element) { if (element.getNode().getElementType() == GoTypes.IDENTIFIER) { if (isInsideFieldTypeDeclaration(element)) { return true; } if (isInsideFieldTypeDeclaration(prevVisibleLeafOrNewLine(element))) { return true; } } return false; }
@Nullable @Override public Info getInfo(PsiElement e) { if (e != null && e.getNode().getElementType() == GoTypes.IDENTIFIER) { PsiElement parent = e.getParent(); PsiFile file = e.getContainingFile(); if (GoRunUtil.isMainGoFile(file) && parent instanceof GoFunctionDeclaration) { if (GoConstants.MAIN.equals(((GoFunctionDeclaration)parent).getName())) { return new Info(AllIcons.RunConfigurations.TestState.Run, TOOLTIP_PROVIDER, ExecutorAction.getActions(0)); } } } return null; } }
@Override public boolean isPublic() { T stub = getStub(); if (stub != null && stub.isPublic()) { return true; } PsiElement firstChild = getFirstChild(); return firstChild.getNode().getElementType() == BallerinaTypes.PUBLIC; }
private static void deleteImportSpec(@Nullable GoImportSpec importSpec) { GoImportDeclaration importDeclaration = PsiTreeUtil.getParentOfType(importSpec, GoImportDeclaration.class); if (importSpec != null && importDeclaration != null) { PsiElement startElementToDelete = importSpec; PsiElement endElementToDelete = importSpec; if (importDeclaration.getImportSpecList().size() == 1) { startElementToDelete = importDeclaration; endElementToDelete = importDeclaration; PsiElement nextSibling = endElementToDelete.getNextSibling(); if (nextSibling != null && nextSibling.getNode().getElementType() == GoTypes.SEMICOLON) { endElementToDelete = nextSibling; } } // todo: delete after proper formatter implementation PsiElement nextSibling = endElementToDelete.getNextSibling(); if (nextSibling instanceof PsiWhiteSpace && nextSibling.textContains('\n')) { endElementToDelete = nextSibling; } startElementToDelete.getParent().deleteChildRange(startElementToDelete, endElementToDelete); } }
@NotNull private Indent calcIndent(@NotNull ASTNode child) { IElementType parentType = myNode.getElementType(); IElementType type = child.getElementType(); if (type == SWITCH_START) return Indent.getNoneIndent(); if (parentType == BLOCK && type == SELECT_STATEMENT) return Indent.getNoneIndent(); if (parentType == SELECT_STATEMENT && type == RBRACE) return Indent.getNormalIndent(); if (parentType == ARGUMENT_LIST && type != LPAREN && type != RPAREN) return Indent.getNormalIndent(); if ((parentType == EXPR_CASE_CLAUSE || parentType == TYPE_CASE_CLAUSE) && (type == CASE || type == DEFAULT)) return Indent.getNoneIndent(); if (BLOCKS_TOKEN_SET.contains(parentType)) return indentIfNotBrace(child); if (parentType == IMPORT_DECLARATION) return indentOfMultipleDeclarationChild(type, IMPORT_SPEC); if (parentType == CONST_DECLARATION) return indentOfMultipleDeclarationChild(type, CONST_SPEC); if (parentType == VAR_DECLARATION) return indentOfMultipleDeclarationChild(type, VAR_SPEC); if (parentType == TYPE_DECLARATION) return indentOfMultipleDeclarationChild(type, TYPE_SPEC); if (parentType == COMM_CLAUSE && child.getPsi() instanceof GoStatement) return Indent.getNormalIndent(); if (child.getPsi() instanceof GoExpression) return Indent.getContinuationWithoutFirstIndent(); return Indent.getNoneIndent(); }