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));
}
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);
}
Aggregations