use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoMoveToStructInitializationIntention method addFieldDefinition.
private static void addFieldDefinition(@NotNull GoLiteralValue literalValue, @NotNull String name, @NotNull String value) {
Project project = literalValue.getProject();
PsiElement newField = GoElementFactory.createLiteralValueElement(project, name, value);
GoElement lastElement = getLastItem(literalValue.getElementList());
if (lastElement == null) {
literalValue.addAfter(newField, literalValue.getLbrace());
} else {
lastElement.add(GoElementFactory.createComma(project));
lastElement.add(newField);
}
}
use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoMoveToStructInitializationIntention method isAssignedInPreviousStatement.
private static boolean isAssignedInPreviousStatement(@NotNull GoExpression referenceExpression, @NotNull GoAssignmentStatement assignment) {
GoReferenceExpression rightExpression = unwrapParensAndCast(GoPsiImplUtil.getRightExpression(assignment, getTopmostExpression(referenceExpression)));
PsiElement resolve = rightExpression != null ? rightExpression.resolve() : null;
GoStatement previousElement = resolve != null ? PsiTreeUtil.getPrevSiblingOfType(assignment, GoStatement.class) : null;
return previousElement != null && exists(getLeftHandElements(previousElement), e -> isResolvedTo(e, resolve));
}
use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRecursiveCallMarkerProvider method collectSlowLineMarkers.
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
Set<Integer> lines = ContainerUtil.newHashSet();
for (PsiElement element : elements) {
if (element instanceof GoCallExpr) {
PsiElement resolve = GoPsiImplUtil.resolveCall((GoCallExpr) element);
if (resolve instanceof GoFunctionOrMethodDeclaration) {
if (isRecursiveCall(element, (GoFunctionOrMethodDeclaration) resolve)) {
PsiDocumentManager instance = PsiDocumentManager.getInstance(element.getProject());
Document document = instance.getDocument(element.getContainingFile());
int textOffset = element.getTextOffset();
if (document == null)
continue;
int lineNumber = document.getLineNumber(textOffset);
if (!lines.contains(lineNumber)) {
result.add(new RecursiveMethodCallMarkerInfo(element));
}
lines.add(lineNumber);
}
}
}
}
}
use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRecursiveVisitor method visitCompositeElement.
@Override
public void visitCompositeElement(@NotNull GoCompositeElement o) {
super.visitCompositeElement(o);
for (PsiElement psiElement : o.getChildren()) {
psiElement.accept(this);
ProgressIndicatorProvider.checkCanceled();
}
}
use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoExpressionUtil method identical.
public static boolean identical(@Nullable GoExpression left, @Nullable GoExpression right) {
if (left == right)
return true;
if (left == null || right == null)
return false;
GoExpression l = unwrap(left);
GoExpression r = unwrap(right);
if (l == null || r == null)
return false;
if (!l.getClass().equals(r.getClass()))
return false;
if (l instanceof GoBinaryExpr) {
GoBinaryExpr lBin = (GoBinaryExpr) l;
GoBinaryExpr rBin = (GoBinaryExpr) r;
return isOperatorEquals(lBin.getOperator(), rBin.getOperator()) && isChildrenExprEquals(lBin, rBin);
}
if (l instanceof GoUnaryExpr) {
GoUnaryExpr lUnary = (GoUnaryExpr) l;
GoUnaryExpr rUnary = (GoUnaryExpr) r;
return isOperatorEquals(lUnary.getOperator(), rUnary.getOperator()) && identical(lUnary.getExpression(), rUnary.getExpression());
}
if (l instanceof GoReferenceExpression) {
PsiElement resolve = ((GoReferenceExpression) l).resolve();
return resolve != null && resolve.isEquivalentTo(((GoReferenceExpression) r).resolve());
}
if (l instanceof GoIndexOrSliceExpr) {
GoIndexOrSliceExpr lSlice = (GoIndexOrSliceExpr) l;
GoIndexOrSliceExpr rSlice = (GoIndexOrSliceExpr) r;
return identical(lSlice.getExpression(), rSlice.getExpression()) && isIndicesIdentical(lSlice.getIndices(), rSlice.getIndices());
}
if (l instanceof GoStringLiteral) {
return Comparing.equal(((GoStringLiteral) l).getDecodedText(), ((GoStringLiteral) r).getDecodedText());
}
if (l instanceof GoLiteralTypeExpr) {
GoLiteralTypeExpr lLit = (GoLiteralTypeExpr) l;
GoLiteralTypeExpr rLit = (GoLiteralTypeExpr) r;
GoTypeReferenceExpression lExpr = lLit.getTypeReferenceExpression();
GoTypeReferenceExpression rExpr = rLit.getTypeReferenceExpression();
PsiElement lResolve = lExpr != null ? lExpr.resolve() : null;
return lResolve != null && rExpr != null && lResolve.equals(rExpr.resolve());
//todo: add || GoTypeUtil.identical(lLit.getType(), rLit.getType)
}
if (l instanceof GoLiteral) {
return l.textMatches(r);
}
if (l instanceof GoBuiltinCallExpr || l instanceof GoCallExpr) {
return false;
}
if (l instanceof GoCompositeLit) {
GoCompositeLit lLit = (GoCompositeLit) l;
GoCompositeLit rLit = (GoCompositeLit) r;
return identical(lLit.getLiteralValue(), rLit.getLiteralValue());
// todo: add && GoTypeUtil.identical
}
if (l instanceof GoTypeAssertionExpr) {
GoTypeAssertionExpr lAssertion = (GoTypeAssertionExpr) l;
GoTypeAssertionExpr rAssertion = (GoTypeAssertionExpr) r;
return identical(lAssertion.getExpression(), rAssertion.getExpression());
//todo: add && GoTypeUtil.identical(lAssertion.getType(), rAssertion.getType())
}
String lText = l.getText();
return lText != null && lText.equals(r.getText());
}
Aggregations