ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclaration { @Override public boolean isLocal() { if (!isLocalComputed) { Node current = getParent(); while (current != null) { if (current instanceof ASTAnyTypeDeclaration) { isLocal = false; break; } else if (current instanceof ASTMethodOrConstructorDeclaration || current instanceof ASTInitializer) { isLocal = true; break; } current = current.getParent(); } if (current == null) { isLocal = false; } isLocalComputed = true; } return isLocal; } @InternalApi @Deprecated  ASTClassOrInterfaceDeclaration(int id); @InternalApi @Deprecated  ASTClassOrInterfaceDeclaration(JavaParser p, int id); @Override boolean isFindBoundary(); @Override Object jjtAccept(JavaParserVisitor visitor, Object data); @Override boolean isPackagePrivate(); @Override boolean isLocal(); boolean isInterface(); @InternalApi @Deprecated void setInterface(); @Override TypeKind getTypeKind(); @Override List<ASTAnyTypeBodyDeclaration> getDeclarations(); ASTClassOrInterfaceType getSuperClassTypeNode(); List<ASTClassOrInterfaceType> getSuperInterfacesTypeNodes(); @Experimental List<ASTClassOrInterfaceType> getPermittedSubclasses(); @Experimental boolean isSealed(); @Experimental boolean isNonSealed();  }
@Test public void testLocalInMethod() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(LOCAL_CLASS_IN_METHOD); assertTrue(classes.size() == 2); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertTrue("Local class false-negative", classes.get(1).isLocal()); }
@Test public void testLocalInInitializer() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(LOCAL_CLASS_IN_INITIALIZER); assertTrue(classes.size() == 2); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertTrue("Local class false-negative", classes.get(1).isLocal()); }
@Test public void testLocalAbstractClass() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(LOCAL_CLASS_WITH_MODIFIERS); assertTrue(classes.size() == 2); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertTrue("Local class false-negative", classes.get(1).isLocal()); assertTrue("Local class should preserve its modifiers", classes.get(1).isAbstract()); }
@Test public void testLocalClassWithMixedModifiers() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(LOCAL_CLASS_WITH_MIXED_MODIFIER_ANNOTATIONS); assertTrue(classes.size() == 2); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertTrue("Local class false-negative", classes.get(1).isLocal()); assertTrue("Local class should preserve its modifiers", classes.get(1).isFinal()); }
@Test public void testNestedClassIsNotLocal() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(NESTED_CLASS_IS_NOT_LOCAL); assertTrue(classes.size() == 2); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertFalse("Local class false-positive", classes.get(1).isLocal()); }
@Test public void testLocalChildrenAreNotAlwaysLocal() { List<ASTClassOrInterfaceDeclaration> classes = getClassDecls(LOCAL_CHILDREN_ARE_NOT_ALWAYS_LOCAL); assertTrue(classes.size() == 4); assertFalse("Local class false-positive", classes.get(0).isLocal()); assertTrue("Local class false-negative", classes.get(1).isLocal()); assertFalse("Local class false-positive", classes.get(2).isLocal()); assertTrue("Local class false-negative", classes.get(3).isLocal()); }