use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method calculateDifferenceAIsEmpty.
@Test
public void calculateDifferenceAIsEmpty() {
Node n1 = new FieldDeclaration();
Node n2 = new MethodDeclaration();
LexicalDifferenceCalculator.CalculatedSyntaxModel a = new LexicalDifferenceCalculator.CalculatedSyntaxModel(Collections.emptyList());
LexicalDifferenceCalculator.CalculatedSyntaxModel b = new LexicalDifferenceCalculator.CalculatedSyntaxModel(Arrays.asList(new CsmToken(GeneratedJavaParserConstants.LPAREN), new CsmChild(n1), new CsmToken(GeneratedJavaParserConstants.RPAREN), new CsmChild(n2)));
Difference diff = Difference.calculate(a, b);
assertEquals(4, diff.getElements().size());
assertEquals(added(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(0));
assertEquals(added(new CsmChild(n1)), diff.getElements().get(1));
assertEquals(added(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(2));
assertEquals(added(new CsmChild(n2)), diff.getElements().get(3));
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method annotationDeclarationModifiersExampleModified.
@Test
public void annotationDeclarationModifiersExampleModified() throws IOException {
considerExample("AnnotationDeclaration_Example1_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.MODIFIERS, EnumSet.noneOf(Modifier.class), EnumSet.of(Modifier.PUBLIC));
csm.removeIndentationElements();
int i = 0;
assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
assertEquals(i, csm.elements.size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method annotationDeclaratioJavadocExampleOriginal.
@Test
public void annotationDeclaratioJavadocExampleOriginal() throws IOException {
considerExample("AnnotationDeclaration_Example3_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
csm.removeIndentationElements();
int i = 0;
assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
assertEquals(i, csm.elements.size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method annotationDeclarationModifiersExampleOriginal.
@Test
public void annotationDeclarationModifiersExampleOriginal() throws IOException {
considerExample("AnnotationDeclaration_Example1_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
csm.removeIndentationElements();
int i = 0;
assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
assertEquals(i, csm.elements.size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method calculateDifferenceBIsEmpty.
@Test
public void calculateDifferenceBIsEmpty() {
Node n1 = new FieldDeclaration();
Node n2 = new MethodDeclaration();
LexicalDifferenceCalculator.CalculatedSyntaxModel a = new LexicalDifferenceCalculator.CalculatedSyntaxModel(Arrays.asList(new CsmToken(GeneratedJavaParserConstants.LPAREN), new CsmChild(n1), new CsmToken(GeneratedJavaParserConstants.RPAREN), new CsmChild(n2)));
LexicalDifferenceCalculator.CalculatedSyntaxModel b = new LexicalDifferenceCalculator.CalculatedSyntaxModel(Collections.emptyList());
Difference diff = Difference.calculate(a, b);
assertEquals(4, diff.getElements().size());
assertEquals(removed(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(0));
assertEquals(removed(new CsmChild(n1)), diff.getElements().get(1));
assertEquals(removed(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(2));
assertEquals(removed(new CsmChild(n2)), diff.getElements().get(3));
}
Aggregations