use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.
the class JDTJavaSourcePersistenceKit method doReadModel.
@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
String fileStr = StringUtils.readAsString(pp.getInputStream(), pp.getEncoding());
IBindingManager bm = pp.getBindings();
ASTNode ast = null;
// TODO remove when parse/unparse are added
if (bm.wIsSet("parseFragments") && bm.wBooleanValue("parseFragments")) {
IJavaEntity entity = JDTTransformerVisitor.transform(fileStr, JDTUtils.parse(fileStr));
if (Matcher.matchImpl(JavaEntityDescriptorEnum.ClassDeclaration, entity))
bm.wDef("syntheticRoot", ((ClassDeclaration) entity).getBodyDeclarations());
else if (Matcher.matchImpl(JavaEntityDescriptorEnum.Block, entity))
bm.wDef("syntheticRoot", entity);
return entity;
} else {
if (bm.wIsSet("entityURI")) {
String entityURI = bm.wStringValue("entityURI");
if (ResourceUtils.hasFragmentPart(entityURI)) {
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(entityURI, true, bm);
if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Expression)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.EXPRESSION);
} else if (ed.equals(JavaEntityDescriptorEnum.Block)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.STATEMENTS);
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Statement)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.STATEMENTS);
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.BodyDeclaration)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.CLASS_BODY_DECLARATIONS);
} else if (ed.equals(JavaEntityDescriptorEnum.BodyDeclarations)) {
ast = JDTUtils.parseAs(fileStr, JAVA_FRAGMENT.CLASS_BODY_DECLARATIONS);
} else if (ed.equals(JavaEntityDescriptorEnum.CompilationUnit))
ast = JDTUtils.parseAsCompilationUnit(fileStr);
}
}
if (ast == null)
ast = JDTUtils.parse(fileStr);
IEntity result = JDTTransformerVisitor.transform(fileStr, ast);
if (bm.wIsSet("entityURI")) {
String entityURI = bm.wStringValue("entityURI");
if (ResourceUtils.hasFragmentPart(entityURI)) {
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(entityURI, true, bm);
if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Expression)) {
if (!result.wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
} else if (!ed.equals(JavaEntityDescriptorEnum.Block) && ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.Statement)) {
if (result.wSize() != 1 || !(result = result.wGet(0)).wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
} else if (ed.isLanguageSubtypeOf(JavaEntityDescriptorEnum.BodyDeclaration)) {
if (result.wSize() != 1 || !(result = result.wGet(0)).wGetEntityDescriptor().isLanguageSubtypeOf(ed))
throw new IllegalArgumentException("");
}
} else if (result.wGetEntityDescriptor().equals(JavaEntityDescriptorEnum.Block) && result.wSize() == 1)
result = result.wGet(0);
}
return result;
}
}
use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.
the class ControlQueriesTest method testDo1.
@Test
public void testDo1() {
Model model = new XmlModel().create();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("do1");
IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
assertTrue(result instanceof ClassDeclaration);
assertEquals("HelloWorld", ((ClassDeclaration) result).getName().getValue());
}
use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.
the class ControlQueriesTest method testIf2.
@Test
public void testIf2() {
Model model = new XmlModel().create();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("if2");
IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
assertTrue(result instanceof ClassDeclaration);
assertEquals(model.getName().getValue(), ((ClassDeclaration) result).getName().getValue());
}
use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.
the class ControlQueriesTest method testChoose4.
@Test
public void testChoose4() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose4");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model, bm);
while (iterator.hasNext()) {
IEntity result = iterator.next();
assertSame(result, bm.wGet("type"));
assertTrue(result instanceof ClassDeclaration);
ClassDeclaration classDecl = (ClassDeclaration) result;
IEntity decl = decls.wGet(i++);
String name = "", superClassName = "";
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
SimpleEntity simpleEntity = (SimpleEntity) decl;
name = simpleEntity.getName().wStringValue();
superClassName = "AbstractSimpleEntity";
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
CompositeEntity compositeEntity = (CompositeEntity) decl;
name = compositeEntity.getName().wStringValue();
superClassName = "AbstractCompositeEntity";
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
DataEntity dataEntity = (DataEntity) decl;
name = dataEntity.getName().wStringValue();
superClassName = "AbstractDataEntity";
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumEntity enumEntity = (EnumEntity) decl;
name = enumEntity.getName().wStringValue();
superClassName = "AbstractEnumEntity";
break;
}
assertEquals(name, classDecl.getName().wStringValue());
assertEquals(superClassName, classDecl.getSuperclassType().wStringValue());
}
}
use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.
the class ControlQueriesTest method testIf3.
@Test
public void testIf3() {
Model model = new XmlModel().create();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("if3");
IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
assertTrue(result instanceof ClassDeclaration);
assertEquals(StringUtils.toUpperCap(model.getName().getValue()), ((ClassDeclaration) result).getName().getValue());
}
Aggregations