use of com.github.javaparser.ast.type.ArrayType in project javaparser by javaparser.
the class TransformationsTest method exampleParam2.
@Test
public void exampleParam2() throws IOException {
considerExample("Example_param1_original");
MethodDeclaration md = (MethodDeclaration) cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
md.addParameter(new ArrayType(PrimitiveType.intType()), "p1");
md.addParameter("char", "p2");
assertTransformed("Example_param2", cu);
}
use of com.github.javaparser.ast.type.ArrayType in project javaparser by javaparser.
the class TransformationsTest method example7.
@Test
public void example7() throws IOException {
considerExample("Example7_original");
cu.getClassByName("A").get().getFieldByName("a").get().getVariable(0).setType(new ArrayType(PrimitiveType.intType()));
assertTransformed("Example7", cu);
}
use of com.github.javaparser.ast.type.ArrayType in project javaparser by javaparser.
the class TransformationsTest method example9.
@Test
public void example9() throws IOException {
considerExample("Example9_original");
FieldDeclaration fd = (FieldDeclaration) cu.getClassByName("A").get().getMember(0).asFieldDeclaration();
fd.addVariable(new VariableDeclarator(new ArrayType(PrimitiveType.intType()), "b"));
assertTransformed("Example9", cu);
}
use of com.github.javaparser.ast.type.ArrayType in project javaparser by javaparser.
the class ConstructorDeclarationTransformationsTest method replacingOnlyParameter.
@Test
public void replacingOnlyParameter() throws IOException {
ConstructorDeclaration cd = consider("public A(float f){}");
cd.getParameters().set(0, new Parameter(new ArrayType(PrimitiveType.intType()), new SimpleName("foo")));
assertTransformedToString("public A(int[] foo){}", cd);
}
use of com.github.javaparser.ast.type.ArrayType 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());
}
Aggregations