Package japa.parser.ast.body

Examples of japa.parser.ast.body.ClassOrInterfaceDeclaration


    public static void main(String[] args) {
        CompilationUnit cu = new CompilationUnit();
        //set the package
        cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("cn.shenyanchao.javaparser.test")));
        //create the type declaration
        ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "HelloWorld");
        ASTHelper.addTypeDeclaration(cu, type);
        //create a method
        MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
        method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
        ASTHelper.addMember(type, method);
View Full Code Here


public class ClassTypeBuilder {

    private ClassOrInterfaceDeclaration type = null;

    public ClassTypeBuilder(String clazzName) {
        type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, clazzName);
    }
View Full Code Here

        return Boolean.TRUE;
    }

    public Boolean visit(ClassOrInterfaceDeclaration n1, Node arg) {
        ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg;

        // javadoc are checked at CompilationUnit

        if (n1.getModifiers() != n2.getModifiers()) {
            return Boolean.FALSE;
        }

        if (n1.isInterface() != n2.isInterface()) {
            return Boolean.FALSE;
        }

        if (!objEquals(n1.getName(), n2.getName())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getExtends(), n2.getExtends())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getImplements(), n2.getImplements())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getMembers(), n2.getMembers())) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }
View Full Code Here

                ;
        }
        members = ClassOrInterfaceBody(isInterface);
        {
            if (true) {
                return new ClassOrInterfaceDeclaration(line, column, token.endLine, token.endColumn, popJavadoc(), modifier.modifiers, modifier.annotations, isInterface, name, typePar, extList, impList, members);
            }
        }
        throw new Error("Missing return statement in function");
    }
View Full Code Here

* Classes inside block stametents can only be abstract or final. The semantic must check it.
*/
    final public Statement BlockStatement() throws ParseException {
        Statement ret;
        Expression expr;
        ClassOrInterfaceDeclaration typeDecl;
        Modifier modifier;
        if (jj_2_36(2147483647)) {
            pushJavadoc();
            modifier = Modifiers();
            typeDecl = ClassOrInterfaceDeclaration(modifier);
            ret = new TypeDeclarationStmt(typeDecl.getBeginLine(), typeDecl.getBeginColumn(), token.endLine, token.endColumn, typeDecl);
        } else if (jj_2_37(2147483647)) {
            expr = VariableDeclarationExpression();
            jj_consume_token(SEMICOLON);
            ret = new ExpressionStmt(expr.getBeginLine(), expr.getBeginColumn(), token.endLine, token.endColumn, expr);
        } else {
View Full Code Here

    for (ImportDeclaration d : baseImports) {
      imports.add(d.getName().toString());
    }

    // create the type declaration
    ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, true, informerInfos.getInformerName());
    type.setExtends(Arrays.asList(new ClassOrInterfaceType(Informer.class.getSimpleName() + "<" + informerInfos.className + ">")));
    type.setJavaDoc(new JavadocComment("\n" + "Informer for {@link " + informerInfos.className + "}\n" + "@author InformerMojos\n"));
    ASTHelper.addTypeDeclaration(cu, type);
    for (PropertyInfos infos : informerInfos.properties) {
      // create a method
      MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "get" + Utils.uppercaseFirst(infos.name));
      String informerTypeFor = InformerTypeFinder.getInformerTypeFor(resolvedInformers, qualifiedEnums, imports, infos);
View Full Code Here

    for (ImportDeclaration d : baseImports) {
      imports.add(d.getName().toString());
    }

    // create the type declaration
    ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, true, informerInfos.getInformerName());
    type.setExtends(Arrays.asList(new ClassOrInterfaceType(Informer.class.getSimpleName() + "<" + informerInfos.className + ">")));
    type.setJavaDoc(new JavadocComment("\n" + "Informer for {@link " + informerInfos.className + "}\n" + "@author InformerMojos\n"));
    List<AnnotationExpr> annotations = new LinkedList<AnnotationExpr>();
    // Constructing generated annotation value
    List<MemberValuePair> parameters = new LinkedList<MemberValuePair>();
    parameters.add(new MemberValuePair("date", new StringLiteralExpr(
            javax.xml.bind.DatatypeConverter.printDateTime(GregorianCalendar.getInstance()))));
    parameters.add(new MemberValuePair("comments", new StringLiteralExpr("generated by gaedo-informer-generator")));
    List<Expression> values = new LinkedList<Expression>();
    values.add(new StringLiteralExpr(informerInfos.getQualifiedClassName()));
    parameters.add(new MemberValuePair("value",
            new ArrayInitializerExpr(values)));
    NormalAnnotationExpr generated = new NormalAnnotationExpr(ASTHelper.createNameExpr(Generated.class.getName()), parameters);
    type.setAnnotations(annotations);
    ASTHelper.addTypeDeclaration(cu, type);
    for (PropertyInfos infos : informerInfos.properties) {
      // create a method
      MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "get" + Utils.uppercaseFirst(infos.name));
      String informerTypeFor = InformerTypeFinder.getInformerTypeFor(resolvedInformers, qualifiedEnums, imports, infos);
View Full Code Here

    CompilerAssert<File, File> helper = incrementalCompiler("metamodel.param");
    helper.assertCompile();

    // Remove @Param
    JavaFile file = helper.assertJavaSource("metamodel.param.A");
    ClassOrInterfaceDeclaration bean = file.assertDeclaration();
    MethodDeclaration index = null;
    for (BodyDeclaration decl : bean.getMembers()) {
      if (decl instanceof MethodDeclaration) {
        index = (MethodDeclaration)decl;
      }
    }
    Parameter param = index.getParameters().get(0);
View Full Code Here

    mm.getQueue().clear();
    Tools.serialize(unserialize, ser);

    //
    JavaFile file = helper.assertJavaSource("metamodel.controller.A");
    ClassOrInterfaceDeclaration a = file.assertDeclaration();
    MethodDeclaration decl = (MethodDeclaration)a.getMembers().get(0);
    decl.getAnnotations().get(0).setName(ASTHelper.createNameExpr(Action.class.getName()));
    file.assertSave();

    //
    helper.assertCompile();
View Full Code Here

    mm.getQueue().clear();
    Tools.serialize(unserialize, ser);

    //
    JavaFile file = helper.assertJavaSource("metamodel.controller.A");
    ClassOrInterfaceDeclaration a = file.assertDeclaration();
    MethodDeclaration decl = (MethodDeclaration)a.getMembers().get(0);
    decl.getAnnotations().clear();
    file.assertSave();

    //
    helper.assertCompile();
View Full Code Here

TOP

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

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.