Search in sources :

Example 1 with ResolvedFieldDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration in project javaparser by javaparser.

the class JavaParserClassDeclarationTest method testGetAllNonStaticFields.

@Test
public void testGetAllNonStaticFields() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    List<ResolvedFieldDeclaration> allFields = constructorDeclaration.getAllNonStaticFields();
    assertEquals(13, allFields.size());
    ResolvedFieldDeclaration fieldDeclaration = null;
    fieldDeclaration = allFields.get(0);
    assertEquals("modifiers", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(1);
    assertEquals("typeParameters", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(2);
    assertEquals("name", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(3);
    assertEquals("parameters", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(4);
    assertEquals("throws_", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(5);
    assertEquals("body", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(6);
    assertEquals("annotations", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(7);
    assertEquals("range", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(8);
    assertEquals("parentNode", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(9);
    assertEquals("childrenNodes", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(10);
    assertEquals("orphanComments", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(11);
    assertEquals("userData", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(12);
    assertEquals("comment", fieldDeclaration.getName());
}
Also used : ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 2 with ResolvedFieldDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration in project javaparser by javaparser.

the class JavaParserClassDeclarationTest method testGetAllStaticFields.

@Test
public void testGetAllStaticFields() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolverNewCode.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    List<ResolvedFieldDeclaration> allFields = constructorDeclaration.getAllStaticFields();
    assertEquals(3, allFields.size());
    ResolvedFieldDeclaration fieldDeclaration = null;
    fieldDeclaration = allFields.get(0);
    assertEquals("NODE_BY_BEGIN_POSITION", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(1);
    assertEquals("ABSOLUTE_BEGIN_LINE", fieldDeclaration.getName());
    fieldDeclaration = allFields.get(2);
    assertEquals("ABSOLUTE_END_LINE", fieldDeclaration.getName());
}
Also used : ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 3 with ResolvedFieldDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration in project javaparser by javaparser.

the class JavaParserInterfaceDeclarationTest method testGetFieldForExistingField.

// /
// / Test fields
// /
@Test
public void testGetFieldForExistingField() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    ResolvedFieldDeclaration ResolvedFieldDeclaration;
    // declared field
    ResolvedFieldDeclaration = constructorDeclaration.getField("modifiers");
    assertEquals("modifiers", ResolvedFieldDeclaration.getName());
    assertEquals("java.util.EnumSet", ResolvedFieldDeclaration.getType().asReferenceType().getQualifiedName());
    assertEquals(AccessSpecifier.PRIVATE, ResolvedFieldDeclaration.accessSpecifier());
    assertEquals(false, ResolvedFieldDeclaration.isStatic());
    // inherited field
    ResolvedFieldDeclaration = constructorDeclaration.getField("annotations");
    assertEquals("annotations", ResolvedFieldDeclaration.getName());
    assertEquals("java.util.List", ResolvedFieldDeclaration.getType().asReferenceType().getQualifiedName());
    assertEquals(AccessSpecifier.PRIVATE, ResolvedFieldDeclaration.accessSpecifier());
}
Also used : ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 4 with ResolvedFieldDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration in project javaparser by javaparser.

the class JavaParserInterfaceDeclarationTest method testGetAllFields.

@Test
public void testGetAllFields() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    List<ResolvedFieldDeclaration> allFields = constructorDeclaration.getAllFields();
    assertEquals(16, allFields.size());
    ResolvedFieldDeclaration ResolvedFieldDeclaration;
    ResolvedFieldDeclaration = allFields.get(0);
    assertEquals("modifiers", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(1);
    assertEquals("typeParameters", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(2);
    assertEquals("name", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(3);
    assertEquals("parameters", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(4);
    assertEquals("throws_", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(5);
    assertEquals("body", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(6);
    assertEquals("annotations", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(7);
    assertEquals("NODE_BY_BEGIN_POSITION", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(8);
    assertEquals("range", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(9);
    assertEquals("parentNode", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(10);
    assertEquals("childrenNodes", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(11);
    assertEquals("orphanComments", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(12);
    assertEquals("userData", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(13);
    assertEquals("comment", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(14);
    assertEquals("ABSOLUTE_BEGIN_LINE", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(15);
    assertEquals("ABSOLUTE_END_LINE", ResolvedFieldDeclaration.getName());
}
Also used : ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Example 5 with ResolvedFieldDeclaration

use of com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration in project javaparser by javaparser.

the class JavaParserInterfaceDeclarationTest method testGetAllStaticFields.

@Test
public void testGetAllStaticFields() {
    JavaParserClassDeclaration constructorDeclaration = (JavaParserClassDeclaration) typeSolver.solveType("com.github.javaparser.ast.body.ConstructorDeclaration");
    List<ResolvedFieldDeclaration> allFields = constructorDeclaration.getAllStaticFields();
    assertEquals(3, allFields.size());
    ResolvedFieldDeclaration ResolvedFieldDeclaration;
    ResolvedFieldDeclaration = allFields.get(0);
    assertEquals("NODE_BY_BEGIN_POSITION", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(1);
    assertEquals("ABSOLUTE_BEGIN_LINE", ResolvedFieldDeclaration.getName());
    ResolvedFieldDeclaration = allFields.get(2);
    assertEquals("ABSOLUTE_END_LINE", ResolvedFieldDeclaration.getName());
}
Also used : ResolvedFieldDeclaration(com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration) AbstractTest(com.github.javaparser.symbolsolver.AbstractTest) Test(org.junit.Test)

Aggregations

ResolvedFieldDeclaration (com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration)10 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)10 Test (org.junit.Test)10