Пример #1
0
 @Test
 public void getLine() {
   CompilationUnitTree tree = createTree("class A {\n" + "A a = new A() {};" + "\n}");
   ClassTree classTree = (ClassTree) tree.types().get(0);
   assertThat(((JavaTree) classTree).getLine()).isEqualTo(1);
   // get line of anonymous class
   NewClassTree newClassTree =
       (NewClassTree) ((VariableTree) classTree.members().get(0)).initializer();
   assertThat(((JavaTree) newClassTree.classBody()).getLine()).isEqualTo(2);
 }
Пример #2
0
 @Override
 public void visitNode(Tree tree) {
   NewClassTree newClassTree = (NewClassTree) tree;
   TypeTree newTypeTree = newClassTree.identifier();
   if (newClassTree.classBody() == null && isParameterizedType(newTypeTree)) {
     TypeTree type = getTypeFromExpression(tree.parent());
     if (type != null && isParameterizedType(type)) {
       reportIssue(
           ((ParameterizedTypeTree) newTypeTree).typeArguments(),
           "Replace the type specification in this constructor call with the diamond operator (\"<>\")."
               + JavaVersionHelper.java7CompatibilityMessage(context.getJavaVersion()));
     }
   }
 }