@Test void testOperatorMissingError() throws IOException { String code = "package test; public class ErrorTest { " + "void method() { int x = y z } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[z]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testOperatorMissingError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testMissingParenthesisError() throws IOException { String code = "package test; public class ErrorTest { " + "void f() {String s = new String; } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[new String()]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testMissingParenthesisError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testMissingClassError() throws IOException { String code = "package Test; clas ErrorTest { " + "void f() {String s = new String(); } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[, clas]", "[]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testMissingClassError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testSwitchError() throws IOException { String code = "package test; public class ErrorTest { " + "int numDays; void m1(int i) { switchh {i} { case 1: " + "numDays = 31; break; } } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[switchh]", "[i]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testSwitchError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testMethodError() throws IOException { String code = "package Test; class ErrorTest { " + "static final void f) {String s = new String(); } }"; CompilationUnitTree cut = cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[\nstatic final void f();]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(normalize(getErroneousTreeValues(node).toString())); return null; } }.scan(cut, null); assertEquals("testMethodError: The Erroneous tree " + "error value: " + values + " does not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testOperatorMissingError() throws IOException { String code = "package test; public class ErrorTest { " + "void method() { int x = y z } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[z]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testSwitchError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testMissingParenthesisError() throws IOException { String code = "package test; public class ErrorTest { " + "void f() {String s = new String; } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[new String()]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testSwitchError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Test void testMissingClassError() throws IOException { String code = "package Test; clas ErrorTest { " + "void f() {String s = new String(); } }"; CompilationUnitTree cut = getCompilationUnitTree(code); final List<String> values = new ArrayList<>(); final List<String> expectedValues = new ArrayList<>(Arrays.asList("[, clas]", "[]")); new TreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree node, Void p) { values.add(getErroneousTreeValues(node).toString()); return null; } }.scan(cut, null); assertEquals("testSwitchError: The Erroneous tree " + "error values: " + values + " do not match expected error values: " + expectedValues, values, expectedValues); }
@Override public Tree visitErroneous(ErroneousTree tree, Void p) { ErroneousTree n = make.Erroneous(tree.getErrorTrees()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Void visitErroneous(ErroneousTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); scan(tree.getErrorTrees(), below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
List<String> getErroneousTreeValues(ErroneousTree node) { List<String> values = new ArrayList<>(); if (node.getErrorTrees() != null) { for (Tree t : node.getErrorTrees()) { values.add(t.toString()); } } else { throw new RuntimeException("ERROR: No Erroneous tree " + "has been created."); } return values; }
public static Name createName(List<? extends ExpressionTree> names) { IdentifierTree identifier; List<CharSequence> identifierNameList = new ArrayList<>(); for (ExpressionTree current : names) { if (current instanceof ErroneousTree) { break; } identifier = ((IdentifierTree) current); identifierNameList.add(identifier.getName()); } return createNameFromString(String.join(DOT_SEPARATOR, identifierNameList),names); }
@Override public Void visitErroneous(ErroneousTree expected, Tree actual) { Optional<ErroneousTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } parallelScan(expected.getErrorTrees(), other.get().getErrorTrees()); return null; }