Search in sources :

Example 16 with PropertyMetaModel

use of com.github.javaparser.metamodel.PropertyMetaModel in project javaparser by javaparser.

the class PropertyGenerator method generateNode.

@Override
protected void generateNode(BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
    for (PropertyMetaModel property : nodeMetaModel.getDeclaredPropertyMetaModels()) {
        generateGetter(nodeMetaModel, nodeCoid, property);
        generateSetter(nodeMetaModel, nodeCoid, property);
    }
    nodeMetaModel.getDerivedPropertyMetaModels().forEach(p -> derivedProperties.put(p.getName(), p));
}
Also used : PropertyMetaModel(com.github.javaparser.metamodel.PropertyMetaModel)

Example 17 with PropertyMetaModel

use of com.github.javaparser.metamodel.PropertyMetaModel in project javaparser by javaparser.

the class ReplaceMethodGenerator method generateNode.

@Override
protected void generateNode(BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
    MethodDeclaration replaceNodeMethod = (MethodDeclaration) parseBodyDeclaration("public boolean replace(Node node, Node replacementNode) {}");
    nodeCu.addImport(Node.class);
    nodeMetaModel.getSuperNodeMetaModel().ifPresent(s -> annotateOverridden(replaceNodeMethod));
    final BlockStmt body = replaceNodeMethod.getBody().get();
    body.addStatement("if (node == null) return false;");
    for (PropertyMetaModel property : nodeMetaModel.getDeclaredPropertyMetaModels()) {
        if (!property.isNode()) {
            continue;
        }
        String check;
        if (property.isNodeList()) {
            check = nodeListCheck(property);
        } else {
            check = attributeCheck(property, property.getSetterMethodName());
        }
        if (property.isOptional()) {
            check = f("if (%s != null) { %s }", property.getName(), check);
        }
        body.addStatement(check);
    }
    if (nodeMetaModel.getSuperNodeMetaModel().isPresent()) {
        body.addStatement("return super.replace(node, replacementNode);");
    } else {
        body.addStatement("return false;");
    }
    addOrReplaceWhenSameSignature(nodeCoid, replaceNodeMethod);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) PropertyMetaModel(com.github.javaparser.metamodel.PropertyMetaModel)

Aggregations

PropertyMetaModel (com.github.javaparser.metamodel.PropertyMetaModel)17 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)12 SeparatedItemStringBuilder (com.github.javaparser.utils.SeparatedItemStringBuilder)5 Node (com.github.javaparser.ast.Node)4 NodeList (com.github.javaparser.ast.NodeList)4 NodeMetaModel (com.github.javaparser.metamodel.NodeMetaModel)4 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 ArrayList (java.util.ArrayList)2 TokenRange (com.github.javaparser.TokenRange)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 VisitorGenerator (com.github.javaparser.generator.VisitorGenerator)1 BaseNodeMetaModel (com.github.javaparser.metamodel.BaseNodeMetaModel)1 CodeGenerationUtils.f (com.github.javaparser.utils.CodeGenerationUtils.f)1 SourceRoot (com.github.javaparser.utils.SourceRoot)1 Arrays (java.util.Arrays)1 List (java.util.List)1