use of org.eclipse.jdt.core.dom.SimpleName in project AutoRefactor by JnRouvignac.
the class ASTHelper method isSameVariable.
/**
* Returns whether the two provided nodes represent the same variable.
*
* @param node1 the first node to compare
* @param node2 the second node to compare
* @return true if the two provided nodes represent the same variable, false otherwise
*/
public static boolean isSameVariable(ASTNode node1, ASTNode node2) {
node1 = removeParentheses(node1);
node2 = removeParentheses(node2);
if (node1 == null || node2 == null) {
return false;
}
switch(node1.getNodeType()) {
case THIS_EXPRESSION:
return node2.getNodeType() == THIS_EXPRESSION;
case SIMPLE_NAME:
final SimpleName sn = (SimpleName) node1;
switch(node2.getNodeType()) {
case QUALIFIED_NAME:
return isSameVariable(sn, (QualifiedName) node2);
case FIELD_ACCESS:
return isSameVariable(sn, (FieldAccess) node2);
}
break;
case QUALIFIED_NAME:
final QualifiedName qn = (QualifiedName) node1;
switch(node2.getNodeType()) {
case SIMPLE_NAME:
return isSameVariable((SimpleName) node2, qn);
case QUALIFIED_NAME:
return isSameVariable(qn, (QualifiedName) node2);
case FIELD_ACCESS:
return isSameVariable(qn, (FieldAccess) node2);
}
break;
case FIELD_ACCESS:
final FieldAccess fa = (FieldAccess) node1;
switch(node2.getNodeType()) {
case SIMPLE_NAME:
return isSameVariable((SimpleName) node2, fa);
case QUALIFIED_NAME:
return isSameVariable((QualifiedName) node2, fa);
case FIELD_ACCESS:
return isSameVariable(fa, (FieldAccess) node2);
}
}
return areVariableBindingsEqual(node1, node2);
}
use of org.eclipse.jdt.core.dom.SimpleName in project eclipse.jdt.ls by eclipse.
the class CodeScopeBuilder method visit.
@Override
public boolean visit(MethodInvocation node) {
Expression receiver = node.getExpression();
if (receiver == null) {
SimpleName name = node.getName();
if (fIgnoreBinding == null || !Bindings.equals(fIgnoreBinding, name.resolveBinding())) {
node.getName().accept(this);
}
} else {
receiver.accept(this);
}
accept(node.arguments());
return false;
}
use of org.eclipse.jdt.core.dom.SimpleName in project eclipse.jdt.ls by eclipse.
the class JdtASTMatcher method match.
@Override
public boolean match(SimpleName node, Object other) {
boolean isomorphic = super.match(node, other);
if (!isomorphic || !(other instanceof SimpleName)) {
return false;
}
SimpleName name = (SimpleName) other;
IBinding nodeBinding = node.resolveBinding();
IBinding otherBinding = name.resolveBinding();
if (nodeBinding == null) {
if (otherBinding != null) {
return false;
}
} else {
if (nodeBinding != otherBinding) {
return false;
}
}
if (node.resolveTypeBinding() != name.resolveTypeBinding()) {
return false;
}
return true;
}
use of org.eclipse.jdt.core.dom.SimpleName in project eclipse.jdt.ls by eclipse.
the class LinkedNodeFinder method findByProblems.
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
ArrayList<SimpleName> res = new ArrayList<>();
ASTNode astRoot = parent.getRoot();
if (!(astRoot instanceof CompilationUnit)) {
return null;
}
IProblem[] problems = ((CompilationUnit) astRoot).getProblems();
int nameNodeKind = getNameNodeProblemKind(problems, nameNode);
if (nameNodeKind == 0) {
// no problem on node
return null;
}
int bodyStart = parent.getStartPosition();
int bodyEnd = bodyStart + parent.getLength();
String name = nameNode.getIdentifier();
for (int i = 0; i < problems.length; i++) {
IProblem curr = problems[i];
int probStart = curr.getSourceStart();
int probEnd = curr.getSourceEnd() + 1;
if (probStart > bodyStart && probEnd < bodyEnd) {
int currKind = getProblemKind(curr);
if ((nameNodeKind & currKind) != 0) {
ASTNode node = NodeFinder.perform(parent, probStart, (probEnd - probStart));
if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
res.add((SimpleName) node);
}
}
}
}
return res.toArray(new SimpleName[res.size()]);
}
use of org.eclipse.jdt.core.dom.SimpleName in project eclipse.jdt.ls by eclipse.
the class RenameNodeCorrectionProposal method addEdits.
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
// build a full AST
CompilationUnit unit = CoreASTProvider.getInstance().getAST(getCompilationUnit(), CoreASTProvider.WAIT_YES, null);
ASTNode name = NodeFinder.perform(unit, fOffset, fLength);
if (name instanceof SimpleName) {
SimpleName[] names = LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
if (names != null) {
for (int i = 0; i < names.length; i++) {
SimpleName curr = names[i];
root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
}
return;
}
}
root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
Aggregations