Search in sources :

Example 1 with ArrayType

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);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test)

Example 2 with ArrayType

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);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) Test(org.junit.Test)

Example 3 with ArrayType

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);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) Test(org.junit.Test)

Example 4 with ArrayType

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);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) SimpleName(com.github.javaparser.ast.expr.SimpleName) Parameter(com.github.javaparser.ast.body.Parameter) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 5 with ArrayType

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());
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) CsmChild(com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild) Test(org.junit.Test)

Aggregations

ArrayType (com.github.javaparser.ast.type.ArrayType)6 Test (org.junit.Test)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 Parameter (com.github.javaparser.ast.body.Parameter)2 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)2 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 CsmToken (com.github.javaparser.printer.concretesyntaxmodel.CsmToken)1 CsmChild (com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild)1