use of org.whole.lang.misc.factories.MiscEntityFactory in project whole by wholeplatform.
the class PojoUtilsTest method getCompilationUnits.
public static Misc getCompilationUnits(Class<?>... classes) {
MiscEntityFactory mef = MiscEntityFactory.instance;
Misc misc = mef.createMisc(0);
for (int i = 0; i < classes.length; i++) {
JavaClassTemplateFactory javaSourceTemplateFactory = new JavaClassTemplateFactory(classes[i]);
CompilationUnit compilationUnit = javaSourceTemplateFactory.create();
Any stageUpFragment = CommonsEntityAdapterFactory.createStageUpFragment(MiscEntityDescriptorEnum.Any, compilationUnit);
misc.wAdd(stageUpFragment);
}
return misc;
}
use of org.whole.lang.misc.factories.MiscEntityFactory in project whole by wholeplatform.
the class PojoUtilsTest method getCompilationUnits.
public static Misc getCompilationUnits(ITypeRoot... typeRoots) {
MiscEntityFactory mef = MiscEntityFactory.instance;
Misc misc = mef.createMisc(0);
for (int i = 0; i < typeRoots.length; i++) {
JavaSourceTemplateFactory javaSourceTemplateFactory = new JavaSourceTemplateFactory(typeRoots[i]);
CompilationUnit compilationUnit = javaSourceTemplateFactory.create();
Any stageUpFragment = CommonsEntityAdapterFactory.createStageUpFragment(MiscEntityDescriptorEnum.Any, compilationUnit);
misc.wAdd(stageUpFragment);
}
return misc;
}
use of org.whole.lang.misc.factories.MiscEntityFactory in project whole by wholeplatform.
the class WizardPojoModelImportPage1 method getCompilationUnits.
public static Misc getCompilationUnits(List<ITypeRoot> elements) {
Map<String, List<String>> map = new HashMap<String, List<String>>();
MiscEntityFactory mef = MiscEntityFactory.instance;
Misc misc = mef.createMisc(0);
elements = new ArrayList<ITypeRoot>(elements);
Iterator<ITypeRoot> iterator = elements.iterator();
while (iterator.hasNext()) {
ITypeRoot typeRoot = iterator.next();
IType type = typeRoot.findPrimaryType();
try {
boolean isMember = type.isMember();
boolean isAnonymous = type.isAnonymous();
if (isMember || isAnonymous)
iterator.remove();
if (!isMember || type.getElementName().contains("Impl"))
continue;
} catch (JavaModelException e) {
}
String declaringTypeName = type.getDeclaringType().getFullyQualifiedName();
List<String> memeberTypes = map.get(declaringTypeName);
if (memeberTypes == null)
map.put(declaringTypeName, memeberTypes = new ArrayList<String>());
memeberTypes.add(typeRoot.findPrimaryType().getElementName());
}
for (ITypeRoot typeRoot : elements) {
Class<?> clazz;
try {
clazz = Class.forName(typeRoot.findPrimaryType().getFullyQualifiedName(), false, JDTUtils.createClassLoader(typeRoot.getJavaProject(), true));
if (clazz.getAnnotation(Deprecated.class) != null)
continue;
} catch (ClassNotFoundException e) {
continue;
}
JavaSourceTemplateFactory templateFactory = new JavaSourceTemplateFactory(typeRoot) {
@Override
protected void init(String sourceAttachment, String className, IJavaProject javaProject) {
// FIXME implement import inlining
super.init(/* ensure reflection is used */
null, className, javaProject);
if (clazz.getAnnotation(Deprecated.class) != null)
;
}
};
templateFactory.useCanonicalNames(false);
CompilationUnit compilationUnit = templateFactory.create();
String compilationUnitName = typeRoot.findPrimaryType().getFullyQualifiedName();
if (map.containsKey(compilationUnitName)) {
List<String> memberNames = map.get(compilationUnitName);
BodyDeclarations bodyDeclarations = compilationUnit.getTypes().get(0).getBodyDeclarations();
IEntityIterator<TypeDeclaration> entityIterator = IteratorFactory.<TypeDeclaration>childMatcherIterator().withPattern(JavaEntityDescriptorEnum.TypeDeclaration);
entityIterator.reset(bodyDeclarations);
while (entityIterator.hasNext()) if (!memberNames.contains(entityIterator.next().getName().getValue()))
entityIterator.remove();
}
Any stageUpFragment = CommonsEntityAdapterFactory.createStageUpFragment(MiscEntityDescriptorEnum.Any, compilationUnit);
misc.wAdd(stageUpFragment);
}
return misc;
}
use of org.whole.lang.misc.factories.MiscEntityFactory in project whole by wholeplatform.
the class IteratorFactoryTest method testAncestorOrSelfIteratorRemoveSet.
@Test
public void testAncestorOrSelfIteratorRemoveSet() {
Grammar g = new TestXmlGrammar().create();
MiscEntityFactory mef = MiscEntityFactory.instance(RegistryConfigurations.RESOLVER);
Any any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, g);
Misc innerMisc = mef.createMisc(any);
any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, innerMisc);
Misc outerMisc = mef.createMisc(any);
Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
i.reset(r);
IEntity next = null;
while (i.hasNext()) {
next = i.next();
if (Matcher.match(MiscEntityDescriptorEnum.Misc, next))
break;
}
assertSame(innerMisc, next);
i.set(EntityUtils.clone(any));
assertEquals(1, outerMisc.wSize());
Rule r2 = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
assertTrue(Matcher.match(r, r2));
assertNotSame(r, r2);
i.remove();
assertEquals(0, outerMisc.wSize());
i.reset(r2);
while (i.hasNext()) {
next = i.next();
if (i.hasNext())
i.remove();
}
assertFalse(EntityUtils.hasParent(next));
}
Aggregations