private static boolean hasProperEquals(MethodTree methodTree) { Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.lookupSymbols(EQUALS).stream().anyMatch(EQUALS_MATCHER::matches); }
private static boolean hasProperEquals(MethodTree methodTree) { Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.lookupSymbols(EQUALS).stream().anyMatch(EQUALS_MATCHER::matches); }
private static boolean isIteratorNextMethod(Symbol.MethodSymbol symbol) { return "next".equals(symbol.name()) && symbol.parameterTypes().isEmpty() && isIterator(symbol.enclosingClass()); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree constructor = (MethodTree) tree; Symbol.TypeSymbol owner = constructor.symbol().enclosingClass(); Set<Symbol> staticFields = owner.memberSymbols().stream() .filter(Symbol::isVariableSymbol) .filter(Symbol::isStatic) .collect(Collectors.toSet()); StaticFieldUpdateVisitor visitor = new StaticFieldUpdateVisitor(staticFields); constructor.block().accept(visitor); visitor.assignedStaticFields().forEach(identifierTree -> { Symbol staticField = identifierTree.symbol(); reportIssue(identifierTree, "Remove this assignment of \"" + staticField.name() + "\".", Collections.singletonList(new JavaFileScannerContext.Location("", staticField.declaration())), null); }); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); String className = enclosingClass.type().fullyQualifiedName(); MethodMatcher writeObjectMatcher = SerializableContract.writeObjectMatcher(className); if (writeObjectMatcher.matches(methodTree) && hasModifier(methodTree.modifiers(), SYNCHRONIZED)) { SynchronizationVisitor visitor = new SynchronizationVisitor(methodTree); enclosingClass.declaration().accept(visitor); if (!visitor.moreThanSingleLock) { reportIssue(ModifiersUtils.getModifier(methodTree.modifiers(), SYNCHRONIZED), "Remove this \"synchronized\" keyword."); } } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree constructor = (MethodTree) tree; Symbol.TypeSymbol owner = constructor.symbol().enclosingClass(); Set<Symbol> staticFields = owner.memberSymbols().stream() .filter(Symbol::isVariableSymbol) .filter(Symbol::isStatic) .collect(Collectors.toSet()); StaticFieldUpdateVisitor visitor = new StaticFieldUpdateVisitor(staticFields); constructor.block().accept(visitor); visitor.assignedStaticFields().forEach(identifierTree -> { Symbol staticField = identifierTree.symbol(); reportIssue(identifierTree, "Remove this assignment of \"" + staticField.name() + "\".", Collections.singletonList(new JavaFileScannerContext.Location("", staticField.declaration())), null); }); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); String className = enclosingClass.type().fullyQualifiedName(); MethodMatcher writeObjectMatcher = SerializableContract.writeObjectMatcher(className); if (writeObjectMatcher.matches(methodTree) && hasModifier(methodTree.modifiers(), SYNCHRONIZED)) { SynchronizationVisitor visitor = new SynchronizationVisitor(methodTree); enclosingClass.declaration().accept(visitor); if (!visitor.moreThanSingleLock) { reportIssue(ModifiersUtils.getModifier(methodTree.modifiers(), SYNCHRONIZED), "Remove this \"synchronized\" keyword."); } } }
private static boolean isIteratorNextMethod(Symbol.MethodSymbol symbol) { return "next".equals(symbol.name()) && symbol.parameterTypes().isEmpty() && isIterator(symbol.enclosingClass()); }
private boolean isIteratorNextMethod(Symbol.MethodSymbol symbol) { return "next".equals(symbol.name()) && symbol.parameterTypes().isEmpty() && isIterator(symbol.enclosingClass()); }
private static boolean isDesignedForExtension(MethodTree tree) { if (tree.symbol().enclosingClass().isFinal()) { // methods of final class can not be overridden, because the class can not be extended return false; } ModifiersTree modifiers = tree.modifiers(); return ModifiersUtils.hasModifier(modifiers, Modifier.DEFAULT) || (!ModifiersUtils.hasModifier(modifiers, Modifier.PRIVATE) && isEmptyOrThrowStatement(tree.block())); }
public boolean matches(MethodTree methodTree) { MethodSymbol symbol = methodTree.symbol(); Symbol.TypeSymbol enclosingClass = symbol.enclosingClass(); return enclosingClass != null && matches(symbol, enclosingClass.type()); }
public boolean matches(MethodTree methodTree) { MethodSymbol symbol = methodTree.symbol(); Symbol.TypeSymbol enclosingClass = symbol.enclosingClass(); return enclosingClass != null && matches(symbol, enclosingClass.type()); }
private static boolean isDesignedForExtension(MethodTree tree) { if (tree.symbol().enclosingClass().isFinal()) { // methods of final class can not be overridden, because the class can not be extended return false; } ModifiersTree modifiers = tree.modifiers(); return ModifiersUtils.hasModifier(modifiers, Modifier.DEFAULT) || (!ModifiersUtils.hasModifier(modifiers, Modifier.PRIVATE) && isEmptyOrThrowStatement(tree.block())); }
private static boolean isUnitTest(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); while (symbol != null) { if (symbol.metadata().isAnnotatedWith("org.junit.Test")) { return true; } symbol = symbol.overriddenSymbol(); } Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.type().isSubtypeOf("junit.framework.TestCase") && methodTree.simpleName().name().startsWith("test"); }
private static boolean isUnitTest(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); while (symbol != null) { if (symbol.metadata().isAnnotatedWith("org.junit.Test")) { return true; } symbol = symbol.overriddenSymbol(); } Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.type().isSubtypeOf("junit.framework.TestCase") && methodTree.simpleName().name().startsWith("test"); }