Package japa.parser.ast.body

Examples of japa.parser.ast.body.TypeDeclaration


    @Test
    public void testGetTypeFromStringWhenFileContainsThatType()
            throws Exception {
        // Set up
        final JavaType mockTargetType = mock(JavaType.class);
        final TypeDeclaration mockTypeDeclaration = mock(TypeDeclaration.class);
        final ClassOrInterfaceTypeDetails mockClassOrInterfaceTypeDetails = mock(ClassOrInterfaceTypeDetails.class);
        final JavaParserClassOrInterfaceTypeDetailsBuilder mockBuilder = mock(JavaParserClassOrInterfaceTypeDetailsBuilder.class);
        when(mockBuilder.build()).thenReturn(mockClassOrInterfaceTypeDetails);

        mockStatic(JavaParserUtils.class);
View Full Code Here


        return testPackageName;
    }

    public static String findTestJavaFileName(CompilationUnit sourceCU, File javaFile, String testDir) {

        TypeDeclaration typeDeclaration = findTargetTypeDeclaration(sourceCU, javaFile);
        String className = typeDeclaration.getName();
        String testJavaFileName = PackageUtils.getTestJavaSourceName(testDir, findTestPackageName(sourceCU)
                , className + Consts.TEST_SUFFIX);
        return testJavaFileName;
    }
View Full Code Here

    }

    public static TypeDeclaration findTargetTypeDeclaration(CompilationUnit sourceCU, File javaFile) {
        List typeList = sourceCU.getTypes();
        String sourceFileName = javaFile.getName();
        TypeDeclaration targetTypeDeclaration = null;
        for (Object type : typeList) {
            TypeDeclaration typeDeclaration = (TypeDeclaration) type;
            String className = typeDeclaration.getName();
            if (sourceFileName.equals(className + Consts.JAVA_SUFFIX)) {
                targetTypeDeclaration = typeDeclaration;
                break;
            }
        }
View Full Code Here

    @Override
    public CompilationUnitBuilder createCU() {

        String testPackageName = JavaParserUtils.findTestPackageName(sourceCU);
        TypeDeclaration typeDeclaration = JavaParserUtils.findTargetTypeDeclaration(sourceCU, javaFile);

        CompilationUnitBuilder compilationUnitBuilder = new CompilationUnitBuilder();
        compilationUnitBuilder.buildComment(FileComments.GENERATOR_COMMENT);

        List<MethodDeclaration> methodDeclarations = MembersFilter.findMethodsFrom(typeDeclaration);
        String className = typeDeclaration.getName();
        ClassTypeBuilder classTypeBuilder = new ClassTypeBuilder(className + Consts.TEST_SUFFIX);
        compilationUnitBuilder.buildComment(FileComments.GENERATOR_COMMENT);
        compilationUnitBuilder.buildPackage(testPackageName);
        //process import
        compilationUnitBuilder.buildImports(null);
View Full Code Here

    @Override
    public CompilationUnitBuilder createCU() {
        CompilationUnitBuilder compilationUnitBuilder = new CompilationUnitBuilder();
        compilationUnitBuilder.buildComment(FileComments.GENERATOR_COMMENT);
        TypeDeclaration typeDeclaration = JavaParserUtils.findTargetTypeDeclaration(sourceCU, javaFile);
        List<MethodDeclaration> methodDeclarations = MembersFilter.findMethodsFrom(typeDeclaration);
        String className = typeDeclaration.getName();
        ClassTypeBuilder classTypeBuilder = new ClassTypeBuilder(className + Consts.TEST_SUFFIX);

        List<Comment> existComments = testCU.getComments();
        compilationUnitBuilder.addComments(existComments);
        PackageDeclaration existPackageDeclaration = testCU.getPackage();
View Full Code Here

    final public CompilationUnit CompilationUnit() throws ParseException {
        PackageDeclaration pakage = null;
        List imports = null;
        ImportDeclaration in = null;
        List types = null;
        TypeDeclaration tn = null;
        int line = -1;
        int column = 0;
        if (jj_2_1(2147483647)) {
            pakage = PackageDeclaration();
            line = pakage.getBeginLine();
            column = pakage.getBeginColumn();
        } else {
            ;
        }
        label_1: while (true) {
            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case IMPORT:
                    ;
                    break;
                default:
                    jj_la1[0] = jj_gen;
                    break label_1;
            }
            in = ImportDeclaration();
            if (line == -1) {
                line = in.getBeginLine();
                column = in.getBeginColumn();
            }
            imports = add(imports, in);
        }
        label_2: while (true) {
            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case ABSTRACT:
                case CLASS:
                case ENUM:
                case FINAL:
                case INTERFACE:
                case NATIVE:
                case PRIVATE:
                case PROTECTED:
                case PUBLIC:
                case STATIC:
                case STRICTFP:
                case SYNCHRONIZED:
                case TRANSIENT:
                case VOLATILE:
                case SEMICOLON:
                case AT:
                    ;
                    break;
                default:
                    jj_la1[1] = jj_gen;
                    break label_2;
            }
            tn = TypeDeclaration();
            if (line == -1) {
                line = tn.getBeginLine();
                column = tn.getBeginColumn();
            }
            types = add(types, tn);
        }
        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case 0:
View Full Code Here

/*
* Declaration syntax follows.
*/
    final public TypeDeclaration TypeDeclaration() throws ParseException {
        Modifier modifier;
        TypeDeclaration ret;
        pushJavadoc();
        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case SEMICOLON:
                jj_consume_token(SEMICOLON);
                ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn, popJavadoc());
View Full Code Here

  }

  public ClassOrInterfaceDeclaration assertDeclaration() {
    List<TypeDeclaration> decls = assertCompilationUnit().getTypes();
    AbstractTestCase.assertEquals(1, decls.size());
    TypeDeclaration decl = decls.get(0);
    return AbstractTestCase.assertInstanceOf(ClassOrInterfaceDeclaration.class, decl);
  }
View Full Code Here

    return r;
  }

  @Override
  public Node visit(TypeDeclarationStmt _n, Object _arg) {
    TypeDeclaration typeDecl = cloneNodes(_n.getTypeDeclaration(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);

    TypeDeclarationStmt r = new TypeDeclarationStmt(
        _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
        typeDecl
View Full Code Here

TOP

Related Classes of japa.parser.ast.body.TypeDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.