Search in sources :

Example 26 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class EntityDescriptorEnumBuilder method addSimpleEntity.

// public void addSupertypes(String eType, String name, Set<String> supertypes) {
// if (supertypes.size()>1) {//!supertypes.isEmpty()) {
// ExpressionStatement expStm = etypeExpressionMap.get(eType);
// Expression edExp = expStm.getExpression();
// 
// MethodInvocation nfd = newMethodInvocation("withSupertypes");
// expStm.setExpression(nfd);
// nfd.setExpression(edExp); // after unparenting edExp
// 
// for (String sType : supertypes)
// if (!sType.equals(name))
// nfd.arguments().add(ast.newSimpleName(sType+"_ord"));
// }
// }
@SuppressWarnings("unchecked")
public void addSimpleEntity(String eName, String name, String eType, Set<String> modifiers, Set<String> allSubtypes) {
    String eName_Ord = eName + "_ord";
    String oldType = entities.put(eName, eType);
    if (oldType == null) {
        // public static final int [eName_ord] = [nextOrdinal];
        FieldDeclaration fieldDecl = newFieldDeclaration("int", eName_Ord, newLiteral(nextOrdinal));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal++, fieldDecl);
        // public static final EntityDescriptor<eName> [eName] = (EntityDescriptor<eName>) instance.valueOf([eName_ord]);
        fieldDecl = newFieldDeclaration(newParameterizedType(EntityDescriptor.class.getName(), eName), newVariableDeclarationFragment(eName, newCastExpression(newParameterizedType(EntityDescriptor.class.getName(), eName), newMethodInvocation("instance", "valueOf", ast.newSimpleName(eName_Ord)))));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal * 2, fieldDecl);
    } else if (oldType.equals(eType))
        return;
    // putSimpleEntity([eName_ord], "[eName]", [eType].class);
    MethodInvocation callExp = newMethodInvocation("putSimpleEntity");
    callExp.arguments().add(ast.newSimpleName(eName_Ord));
    callExp.arguments().add(newLiteral(name));
    if (!eName.equals(name))
        callExp.arguments().add(newLiteral(eName));
    callExp.arguments().add(newTypeLiteral(eType));
    callExp.arguments().add(newLiteral(modifiers != null && modifiers.contains("ABSTRACT")));
    if (!allSubtypes.isEmpty())
        for (String type : allSubtypes) if (!type.equals(name))
            callExp.arguments().add(ast.newSimpleName(type + "_ord"));
    ExpressionStatement expStm = newExpressionStatement(callExp);
    initEntityDescriptors.getBody().statements().add(expStm);
    etypeExpressionMap.put(eType, expStm);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 27 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class CommandFactory method addOverSimpleConstraints.

protected synchronized void addOverSimpleConstraints(final Object[][] dndRules) {
    EnablerPredicateFactory pf = getEnablerPredicateFactory();
    List<IPartRequestHandler> cloneList = new ArrayList<IPartRequestHandler>(dndRules.length);
    List<IPartRequestHandler> shareList = new ArrayList<IPartRequestHandler>(dndRules.length);
    for (Object[] dndRule : dndRules) {
        EntityDescriptor<?> dndED = (EntityDescriptor<?>) dndRule[0];
        EntityDescriptor<?> targetED = (EntityDescriptor<?>) dndRule[1];
        IFeatureTransformer featureTransformer = (IFeatureTransformer) dndRule[2];
        boolean isExecutable = (Boolean) dndRule[3];
        cloneList.add(new PartRequestHandler(pf.dndSingleOver(dndED, targetED), isExecutable ? new ReplaceChildCommandFactory(CLONE(featureTransformer)) : unexecutableFeature));
        shareList.add(new PartRequestHandler(pf.dndSingleOver(dndED, targetED), isExecutable ? new ReplaceChildCommandFactory(SHARE(featureTransformer)) : unexecutableFeature));
    }
    addHandlers(PartRequest.CLONE_CHILD, cloneList);
    addHandlers(PartRequest.SHARE_CHILD, shareList);
}
Also used : EnablerPredicateFactory(org.whole.lang.ui.actions.EnablerPredicateFactory) ArrayList(java.util.ArrayList) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor)

Example 28 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class DefaultUITemplate method applyPalette.

public void applyPalette(IPaletteBuilder builder) {
    builder.Drawer_(languageKit.getName());
    EntityDescriptorEnum entityTypes = languageKit.getEntityDescriptorEnum();
    for (Iterator i = entityTypes.values().iterator(); i.hasNext(); ) {
        EntityDescriptor<?> ed = (EntityDescriptor<?>) i.next();
        if (ed.isAbstract())
            continue;
        if (contains(connectionDescriptors, ed))
            builder.Connection(ed);
        else
            builder.Template(ed);
    }
    builder._Drawer();
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) Iterator(java.util.Iterator)

Example 29 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class DataTypesGrammarsDataTypeParser method deploy.

public static void deploy(String grammarURI) {
    Grammar grammar = GrammarsRegistry.instance().getGrammar(grammarURI);
    ILanguageKit lk = ReflectionFactory.getLanguageKit(GrammarsUtils.getLanguageURI(grammar), false, null);
    EntityDescriptor<?> ed = lk.getEntityDescriptorEnum().valueOf("DateLiteral");
    Map<EntityDescriptor<?>, IDataTypeParser> strategies = new HashMap<EntityDescriptor<?>, IDataTypeParser>();
    strategies.put(ed, new DataTypesGrammarsDataTypeParser());
    install(lk, strategies);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) HashMap(java.util.HashMap) Grammar(org.whole.lang.grammars.model.Grammar) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)29 IEntity (org.whole.lang.model.IEntity)13 ArrayList (java.util.ArrayList)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)7 HashMap (java.util.HashMap)5 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)5 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)4 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)4 Actions (org.whole.lang.actions.model.Actions)3 GroupAction (org.whole.lang.actions.model.GroupAction)3 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IAction (org.eclipse.jface.action.IAction)2 Test (org.junit.Test)2 Database (org.whole.lang.rdb.model.Database)2