use of org.whole.gen.lang.LanguageGenerator in project whole by wholeplatform.
the class SimpleEntityImplBuilder method addField.
public void addField(String fType, String fName, String name, boolean isId, boolean isOptional, boolean isReference, boolean isShared, boolean isDerived) {
// if (StringUtils.isAmbiguous(fType))
if (!StringUtils.isPrimitiveOrString(fType))
addImportDeclaration(generator.modelPackage() + "." + fType);
if (isId) {
hashCodeMethodAddId(fType, fName);
equalsMethodAddId(fType, fName);
toStringMethodAddField(fType, fName);
}
// add field, getter and setter methods
addBodyDeclaration(newFieldDeclaration(fType, fName));
addBodyDeclaration(newGetterMethodWithNotification(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fType, fName, name));
addBodyDeclaration(newSetterMethodWithNotification(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fType, fName, name, isReference));
if (StringUtils.isPrimitiveOrString(fType))
return;
// add get(int index) case
if (getByIndexMethod().getBody().statements().size() == 0) {
SwitchStatement switchStm = newSwitchStatement(ast.newSimpleName("index"));
getByIndexMethod().getBody().statements().add(switchStm);
getByIndexSwitchStatements = switchStm.statements();
}
getByIndexSwitchStatements.add(newCaseStatement(newLiteral(featureIndex)));
getByIndexSwitchStatements.add(newReturnStatement(newMethodInvocation(newMethodInvocation(StringUtils.getterName(StringUtils.isJavaKeyword(name) ? name : fName)), "wGetAdaptee", newLiteral(false))));
// add set(int index, IEntity value) case
if (setByIndexMethod().getBody().statements().size() == 0) {
SwitchStatement switchStm = newSwitchStatement(ast.newSimpleName("index"));
setByIndexMethod().getBody().statements().add(switchStm);
setByIndexSwitchStatements = switchStm.statements();
}
setByIndexSwitchStatements.add(newCaseStatement(newLiteral(featureIndex)));
MethodInvocation callExp = newMethodInvocation(StringUtils.setterName(StringUtils.isJavaKeyword(name) ? name : fName), newMethodInvocation(ast.newSimpleName("value"), "wGetAdapter", newFieldAccess(((LanguageGenerator) generator).specificEntityDescriptorEnumName(), fType)));
setByIndexSwitchStatements.add(newExpressionStatement(callExp));
setByIndexSwitchStatements.add(ast.newBreakStatement());
featureIndex++;
if (isReference)
references++;
else
children++;
}
use of org.whole.gen.lang.LanguageGenerator in project whole by wholeplatform.
the class CompilationUnitBuilder method newGetterMethodWithGenericForward.
public MethodDeclaration newGetterMethodWithGenericForward(String featuresEnum, String fType, String fName, String name) {
MethodDeclaration method = ast.newMethodDeclaration();
method.setConstructor(false);
method.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
method.setReturnType2(newType(fType));
method.setName(ast.newSimpleName(StringUtils.getterName(fType, StringUtils.isJavaKeyword(name) ? name : fName)));
if (!isInterface) {
Block body = newBlock();
MethodInvocation callExp = newMethodInvocation("wGet");
callExp.arguments().add(newFieldAccess(featuresEnum, fName));
body.statements().add(newReturnStatement(newMethodInvocation(callExp, "wGetAdapter", newFieldAccess(((LanguageGenerator) generator).specificEntityDescriptorEnumName(), fType))));
method.setBody(body);
}
return method;
}
use of org.whole.gen.lang.LanguageGenerator in project whole by wholeplatform.
the class ModelContextBuilder method addFeature.
public void addFeature(String fType, String fName) {
if (features.add(fName)) {
// add getter
MethodDeclaration method = newMethodDeclaration(generator.specificModelContextName(), StringUtils.getterName(fType, fName));
MethodInvocation callExp = newMethodInvocation("wGet");
callExp.arguments().add(newFieldAccess(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fName));
method.getBody().statements().add(newReturnStatement(newCastExpression(generator.specificModelContextName(), callExp)));
addBodyDeclaration(method);
// add setter
method = newMethodDeclaration("void", StringUtils.setterName(fName));
method.parameters().add(newSingleVariableDeclaration(generator.specificModelContextName(), fName));
callExp = newMethodInvocation("wSet");
callExp.arguments().add(newFieldAccess(((LanguageGenerator) generator).specificFeatureDescriptorEnumName(), fName));
callExp.arguments().add(ast.newSimpleName(fName));
method.getBody().statements().add(newExpressionStatement(callExp));
addBodyDeclaration(method);
}
}
use of org.whole.gen.lang.LanguageGenerator in project whole by wholeplatform.
the class AbstractVisitorCompilationUnitBuilder method addFactoryMethod.
public MethodDeclaration addFactoryMethod(String factoryName, String[][] params) {
LanguageGenerator gen = (LanguageGenerator) generator;
String factoryType;
switch(params.length) {
case 1:
factoryType = generator.unaryVisitorName();
break;
case 2:
factoryType = generator.binaryVisitorName();
break;
case 3:
factoryType = generator.ternaryVisitorName();
break;
default:
factoryType = generator.visitorInterfaceName();
}
String visitorName = typeDec.getName().getFullyQualifiedName();
MethodDeclaration factoryMethod = gen.visitorFactoryBuilder().addFactoryMethod("", factoryType, factoryName, visitorName);
for (int i = 0; i < params.length; i++) {
factoryMethod.parameters().add(newSingleVariableDeclaration(generator.visitorInterfaceName(), params[i][1]));
MethodInvocation callExp = newMethodInvocation("ensureSpecific");
callExp.arguments().add(ast.newSimpleName(params[i][1]));
((ClassInstanceCreation) ((ReturnStatement) factoryMethod.getBody().statements().get(0)).getExpression()).arguments().add(callExp);
}
return factoryMethod;
}
Aggregations