LocalScope extends AbstractJavaScope { @Override public Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence) { JavaNameOccurrence javaOccurrence = (JavaNameOccurrence) occurrence; Set<NameDeclaration> declarations = findVariableHere(javaOccurrence); if (!declarations.isEmpty() && !javaOccurrence.isThisOrSuper()) { for (NameDeclaration decl : declarations) { List<NameOccurrence> nameOccurrences = getVariableDeclarations().get(decl); nameOccurrences.add(javaOccurrence); Node n = javaOccurrence.getLocation(); if (n instanceof ASTName) { ((ASTName) n).setNameDeclaration(decl); } } } return declarations; }  Map<VariableNameDeclaration, List<NameOccurrence>> getVariableDeclarations(); @Override Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence); @Override void addDeclaration(NameDeclaration nameDecl); @Override Set<NameDeclaration> findVariableHere(JavaNameOccurrence occurrence); @Override String toString();  }
@Test public void testNameWithThisOrSuperIsNotFlaggedAsUnused() { LocalScope scope = new LocalScope(); ASTName name = new ASTName(1); name.setImage("foo"); ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2); prefix.setUsesThisModifier(); name.jjtAddChild(prefix, 1); JavaNameOccurrence occ = new JavaNameOccurrence(name, "foo"); scope.addNameOccurrence(occ); assertFalse(scope.getDeclarations().keySet().iterator().hasNext()); }
@Test public void testNameWithSuperIsNotFlaggedAsUnused() { LocalScope scope = new LocalScope(); ASTName name = new ASTName(1); name.setImage("foo"); ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2); prefix.setUsesSuperModifier(); name.jjtAddChild(prefix, 1); JavaNameOccurrence occ = new JavaNameOccurrence(name, "foo"); scope.addNameOccurrence(occ); assertFalse(scope.getDeclarations().keySet().iterator().hasNext()); }