@Override public void collectElementsToIgnore(PsiElement element, Set<PsiElement> result) { PsiElement parent = element.getParent(); if (parent instanceof GoIfStatement) { result.add(parent); } }
@Override protected boolean isInContext(@NotNull PsiElement element) { return element instanceof GoStringLiteral && element.getParent() instanceof GoTag; } }
@Override protected boolean isInContext(@NotNull PsiElement element) { if (element instanceof PsiComment || element instanceof GoPackageClause) { return false; } return element instanceof GoFile || element.getParent() instanceof GoFile && !(element instanceof GoTopLevelDeclaration); } }
@Override protected boolean isInContext(@NotNull PsiElement element) { if (element instanceof PsiComment) { return false; } PsiElement parent = element.getParent(); if (parent instanceof PsiErrorElement || parent instanceof GoExpression) { parent = parent.getParent(); } return (parent instanceof GoStatement || parent instanceof GoLeftHandExprList || parent instanceof GoBlock) && onStatementBeginning(element); }
public GoDeleteRangeQuickFix(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String name) { super(startElement, endElement); if (!startElement.getParent().equals(endElement.getParent())) { LOG.error("Cannot delete range of elements with different parents"); } myName = name; }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { PsiElement parent = element.getParent(); return parent instanceof GoFunctionOrMethodDeclaration && ((GoFunctionOrMethodDeclaration)parent).getBlock() == null; }
@Override protected void collectAdditionalElements(@NotNull PsiElement element, @NotNull List<PsiElement> result) { element = PsiTreeUtil.getParentOfType(element, GoStatement.class, GoFunctionOrMethodDeclaration.class, GoFunctionLit.class); if (element != null) { result.add(element); PsiElement parent = element.getParent(); if (parent instanceof GoStatement) { result.add(parent); } } }
@Override @Nullable public TextRange surroundElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws IncorrectOperationException { PsiElement container = elements[0].getParent(); if (container == null) return null; return surroundStatements(project, container, elements); }
@Nullable public static PsiElement findAnchor(@NotNull List<PsiElement> occurrences, @Nullable PsiElement context) { PsiElement first = ContainerUtil.getFirstItem(occurrences); PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(first, GoStatement.class); while (statement != null && statement.getParent() != context) { statement = statement.getParent(); } return statement == null ? GoPsiImplUtil.getTopLevelDeclaration(first) : statement; }
@Contract("null,_->null") private static <T> T parent(@Nullable PsiElement of, @NotNull Class<T> parentClass) { return ObjectUtils.tryCast(of != null ? of.getParent() : null, parentClass); } }
@NotNull @Override public Access getExpressionAccess(@Nullable PsiElement e) { if (e instanceof GoFieldName) { return e.getParent() instanceof GoKey ? Access.Write : Access.Read; } GoReferenceExpression referenceExpression = PsiTreeUtil.getNonStrictParentOfType(e, GoReferenceExpression.class); return referenceExpression != null ? referenceExpression.getReadWriteAccess() : Access.Read; } }
@Nullable @Override public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement o) { if (myDaemonSettings.SHOW_METHOD_SEPARATORS && o instanceof GoTopLevelDeclaration && o.getParent() instanceof GoFile) { return LineMarkersPass.createMethodSeparatorLineMarker(findAnchorElement((GoTopLevelDeclaration)o), myColorsManager); } return null; }
@Nullable private static PsiElement getFirstCompositeElement(@Nullable PsiElement at) { if (at instanceof PsiComment || at instanceof LeafPsiElement && ((LeafPsiElement)at).getElementType() == GoTypes.STRING) return at; PsiElement result = at; while (result != null && (result instanceof PsiWhiteSpace || result.getNode().getChildren(null).length == 0)) { result = result.getParent(); } return result; }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element.isValid() && element instanceof GoConstDefinition) { PsiElement parent = element.getParent(); if (parent instanceof GoConstSpec) { ((GoConstSpec)parent).deleteDefinition((GoConstDefinition)element); } } } }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element.isValid() && element instanceof GoVarDefinition) { PsiElement parent = element.getParent(); if (parent instanceof GoVarSpec) { ((GoVarSpec)parent).deleteDefinition((GoVarDefinition)element); } } } }
public void extractNewLine(PsiElement from) { PsiElement newLine = GoElementFactory.createNewLine(from.getProject()); if (myIsEffective) { newLine = from.getParent().addBefore(newLine, from); } if (newLine != null) { addElementToExtract(newLine); } }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet set) { GoReferenceExpressionBase expression = PsiTreeUtil.getParentOfType(parameters.getPosition(), GoReferenceExpressionBase.class); PsiFile originalFile = parameters.getOriginalFile(); if (expression != null) { fillVariantsByReference(expression.getReference(), originalFile, set.withPrefixMatcher(createPrefixMatcher(set.getPrefixMatcher()))); } PsiElement parent = parameters.getPosition().getParent(); if (parent != null) { fillVariantsByReference(parent.getReference(), originalFile, set.withPrefixMatcher(createPrefixMatcher(set.getPrefixMatcher()))); } }