@Override public boolean visit(SimpleName node) { VariableDeclaration decl = getVariableDeclaration(node); if (decl == null) return super.visit(node); IVariableBinding binding = decl.resolveBinding(); if (binding == null) return super.visit(node); boolean keysEqual = fKey.equals(binding.getKey()); boolean rangeInSet = fRanges.contains(new Region(node.getStartPosition(), node.getLength())); if (keysEqual && !rangeInSet) fProblemNodes.add(node); if (!keysEqual && rangeInSet) fProblemNodes.add(node); /* * if (!keyEquals && !rangeInSet) * ok, different local variable. * * if (keyEquals && rangeInSet) * ok, renamed local variable & has been renamed. */ return super.visit(node); }
private boolean isInRemoved(SimpleName ref, int[] removedStartsEnds) { int start = ref.getStartPosition(); int end = start + ref.getLength(); for (int index = 0; index < removedStartsEnds.length; index += 2) { if (start >= removedStartsEnds[index] && end <= removedStartsEnds[index + 1]) return true; } return false; }
/* * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SimpleName) */ public boolean visit(SimpleName node) { fToken.update(node); for (int i = 0, n = fJobSemanticHighlightings.length; i < n; i++) { SemanticHighlighting semanticHighlighting = fJobSemanticHighlightings[i]; if (fJobHighlightings[i].isEnabled() && semanticHighlighting.consumes(fToken)) { int offset = node.getStartPosition(); int length = node.getLength(); if (offset > -1 && length > 0) addPosition(offset, length, fJobHighlightings[i]); break; } } fToken.clear(); return false; }
@SuppressWarnings("rawtypes") @Override public boolean visit(MethodInvocation node) { SimpleName methodName = node.getName(); List args = node.arguments(); Expression expression = node.getExpression(); Map<String, Integer> scopeBindings = getNodeScopes().get(node); String target = getTarget(expression); String targetType = translateTargetToType(target, scopeBindings); // Add only if you could guess the type of target, else ignore. // TODO: In case of a method in super type, this will still infer it as in "this". if (!targetType.isEmpty()) { List<String> argTypes = translateArgsToTypes(args, scopeBindings); if (!methodStack.empty()) { MethodDeclaration currentMethod = methodStack.peek(); MethodDecl methodDecl = getMethodDecl(currentMethod); List<MethodInvokRef> invoks = methodInvoks.get(methodDecl); if (invoks == null) { invoks = new ArrayList<>(); methodInvoks.put(methodDecl, invoks); } MethodInvokRef methodInvokRef = new MethodInvokRef( methodName.toString(), targetType, target, args.size(), node.getName().getStartPosition(), argTypes, methodName.getLength(), false, getReturnType(node)); invoks.add(methodInvokRef); } } return true; }