use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method methodDeclarationAddingParameter.
@Test
public void methodDeclarationAddingParameter() {
MethodDeclaration md = considerMd("public void foo(){}");
Parameter newParameter = new Parameter(new ArrayType(PrimitiveType.intType()), new SimpleName("foo"));
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(md);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterListAddition(md, ObservableProperty.PARAMETERS, 0, newParameter);
Difference diff = Difference.calculate(csmOriginal, csmChanged);
int i = 0;
assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getType())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getName())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.LPAREN)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.added(new CsmChild(newParameter)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.RPAREN)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmChild(md.getBody().get())), diff.getElements().get(i++));
assertEquals(i, diff.getElements().size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method annotationDeclarationExampleWithJavadocAdded.
@Test
public void annotationDeclarationExampleWithJavadocAdded() throws IOException {
considerExample("AnnotationDeclaration_Example3_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
JavadocComment comment = new JavadocComment("Cool this annotation!");
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.COMMENT, null, comment);
Difference diff = Difference.calculate(csmOriginal, csmChanged);
diff.removeIndentationElements();
int i = 0;
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++));
assertEquals(i, diff.getElements().size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method annotationDeclarationExampleWithModifierRemoved.
@Test
public void annotationDeclarationExampleWithModifierRemoved() throws IOException {
considerExample("AnnotationDeclaration_Example3_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.MODIFIERS, EnumSet.of(Modifier.PUBLIC), EnumSet.noneOf(Modifier.class));
Difference diff = Difference.calculate(csmOriginal, csmChanged);
diff.removeIndentationElements();
int i = 0;
assertEquals(removed(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++));
assertEquals(removed(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++));
assertEquals(i, diff.getElements().size());
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class DifferenceTest method compilationUnitExampleWithPackageSetDiff.
@Test
public void compilationUnitExampleWithPackageSetDiff() {
considerCode("class A {}");
CsmElement element = ConcreteSyntaxModel.forClass(cu.getClass());
PackageDeclaration packageDeclaration = new PackageDeclaration(new Name(new Name("foo"), "bar"));
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, cu);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, cu, ObservableProperty.PACKAGE_DECLARATION, null, packageDeclaration);
Difference diff = Difference.calculate(csmOriginal, csmChanged);
assertEquals(3, diff.getElements().size());
assertEquals(added(new CsmChild(packageDeclaration)), diff.getElements().get(0));
assertEquals(kept(new CsmChild(cu.getType(0))), diff.getElements().get(1));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(2));
}
use of com.github.javaparser.printer.concretesyntaxmodel.CsmToken in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method compilationUnitExampleWithPackageSet.
@Test
public void compilationUnitExampleWithPackageSet() {
considerCode("class A {}");
CsmElement element = ConcreteSyntaxModel.forClass(cu.getClass());
PackageDeclaration packageDeclaration = new PackageDeclaration(new Name(new Name("foo"), "bar"));
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, cu, ObservableProperty.PACKAGE_DECLARATION, null, packageDeclaration);
assertEquals(3, csmChanged.elements.size());
assertEquals(new LexicalDifferenceCalculator.CsmChild(packageDeclaration), csmChanged.elements.get(0));
assertEquals(new LexicalDifferenceCalculator.CsmChild(cu.getType(0)), csmChanged.elements.get(1));
assertEquals(new CsmToken(eolTokenKind()), csmChanged.elements.get(2));
}
Aggregations