Search in sources :

Example 1 with IVisitor

use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.

the class GenOperationsDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    // from java (legacy)
    platform.addOperationFactory(JavaLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new JavaJavaModelGeneratorVisitor();
            else
                return new JavaJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
        }
    });
    // from artifacts (core)
    platform.addOperationFactory(ArtifactsLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new ArtifactsJavaModelGeneratorVisitor();
            else
                return new ArtifactsJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
        }
    });
    platform.addOperationFactory(ArtifactsLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            // if (stage == 0)
            IBindingManager args = operation.getOperationEnvironment();
            if (args.wIsSet("resourceKind") && ResourceKindEnum.FILE_SYSTEM.equals(((ResourceKind) args.wGet("resourceKind")).getValue()))
                return new ResourceArtifactsGeneratorVisitor();
            else
                return new WorkspaceArtifactsGeneratorVisitor();
        }
    });
    // from editors (core)
    // platform.addOperationFactory(EditorsLanguageKit.URI, JavaCompilerOperation.ID,
    // new IVisitorFactory() {
    // public IVisitor create(IOperation operation, int stage) {
    // if (stage == 0)
    // return new EditorsJavaModelGeneratorVisitor();
    // else
    // return new EditorsJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
    // }
    // });
    // misc (core)
    platform.addOperationFactory(MiscLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new MiscTraverseAllVisitor();
            else
                return new MiscJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
        }
    });
    // from models (core)
    platform.addOperationFactory(ModelsLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new ModelsJavaModelGeneratorVisitor();
            else
                return new ModelsJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
        }
    });
    platform.addOperationFactory(GrammarsLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new GrammarsJavaModelGeneratorVisitor();
        }
    });
    // from pojo (core.op)
    platform.addOperationFactory(PojoLanguageKit.URI, JavaCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new PojoJavaModelGeneratorVisitor();
            else
                return new PojoJavaStoreGeneratorVisitor(((JavaCompilerOperation) operation).getGenerator().javaStoreBuilder(), true);
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) ModelsJavaModelGeneratorVisitor(org.whole.lang.visitors.ModelsJavaModelGeneratorVisitor) PojoJavaModelGeneratorVisitor(org.whole.lang.visitors.PojoJavaModelGeneratorVisitor) IVisitor(org.whole.lang.visitors.IVisitor) ResourceArtifactsGeneratorVisitor(org.whole.lang.artifacts.visitors.ResourceArtifactsGeneratorVisitor) GrammarsJavaModelGeneratorVisitor(org.whole.lang.visitors.GrammarsJavaModelGeneratorVisitor) JavaCompilerOperation(org.whole.lang.operations.JavaCompilerOperation) MiscTraverseAllVisitor(org.whole.lang.misc.visitors.MiscTraverseAllVisitor) MiscJavaStoreGeneratorVisitor(org.whole.lang.visitors.MiscJavaStoreGeneratorVisitor) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) JavaJavaStoreGeneratorVisitor(org.whole.lang.visitors.JavaJavaStoreGeneratorVisitor) ArtifactsJavaModelGeneratorVisitor(org.whole.lang.visitors.ArtifactsJavaModelGeneratorVisitor) WorkspaceArtifactsGeneratorVisitor(org.whole.lang.visitors.WorkspaceArtifactsGeneratorVisitor) JavaJavaModelGeneratorVisitor(org.whole.lang.visitors.JavaJavaModelGeneratorVisitor) IBindingManager(org.whole.lang.bindings.IBindingManager) PojoJavaStoreGeneratorVisitor(org.whole.lang.visitors.PojoJavaStoreGeneratorVisitor) ModelsJavaStoreGeneratorVisitor(org.whole.lang.visitors.ModelsJavaStoreGeneratorVisitor) ArtifactsJavaStoreGeneratorVisitor(org.whole.lang.visitors.ArtifactsJavaStoreGeneratorVisitor)

Example 2 with IVisitor

use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.

the class JavaStoreBuilder method addSubtree.

// NB devono essere 3 addSubtree
public Expression addSubtree(IVisitor visitor, SameStageFragment fragment, String type) {
    int parentNestingSize = initNestingSize();
    IVisitor v = ((AbstractOperation) visitor.getOperation()).getVisitor(fragment.wGetRoot(), visitor.getOperation().getStage());
    v.visit(fragment.wGetRoot());
    MethodInvocation callExp2 = newFactoryInvocation(v, "makeRootEntity");
    callExp2.arguments().add(getExpression());
    MethodInvocation callExp = newFactoryInvocation(visitor, "create" + type);
    callExp.arguments().add(callExp2);
    return addSubtree(parentNestingSize, type, callExp);
}
Also used : AbstractOperation(org.whole.lang.operations.AbstractOperation) IVisitor(org.whole.lang.visitors.IVisitor) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation)

Example 3 with IVisitor

use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.

the class JavaStoreBuilder method addSubtree.

public Expression addSubtree(IVisitor visitor, StageUpFragment fragment, String type) {
    int parentNestingSize = initNestingSize();
    IVisitor v = ((AbstractOperation) visitor.getOperation()).getVisitor(fragment.wGetRoot(), 1);
    v.visit(fragment.wGetRoot());
    MethodInvocation callExp2 = newFactoryInvocation(v, "makeRootEntity");
    callExp2.arguments().add(getExpression());
    MethodInvocation callExp = newFactoryInvocation(visitor, "create" + type);
    callExp.arguments().add(callExp2);
    return addSubtree(parentNestingSize, type, callExp);
}
Also used : AbstractOperation(org.whole.lang.operations.AbstractOperation) IVisitor(org.whole.lang.visitors.IVisitor) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation)

Example 4 with IVisitor

use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.

the class AbstractOperation method setVisitor.

// TODO test and change into liftVisitor
public IVisitor setVisitor(IEntity entity, int absoluteStage, IVisitor visitor) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    IVisitor oldVisitor = languageKit.hasVisitor(this) ? getVisitor(entity, absoluteStage) : null;
    int normalizedStage = absoluteStage <= 0 ? 0 : 1;
    String uri = ReflectionFactory.getLanguageKit(entity).getURI();
    IVisitor[] stagedVisitors = stagedVisitorsMap.get(uri);
    if (stagedVisitors == null)
        stagedVisitorsMap.put(uri, stagedVisitors = new IVisitor[2]);
    stagedVisitors[normalizedStage] = visitor;
    return oldVisitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 5 with IVisitor

use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.

the class AbstractOperation method initVisitor.

protected IVisitor initVisitor(IEntity entity, int normalizedStage) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    IVisitor visitor = null;
    if (languageKit.hasVisitor(this))
        visitor = languageKit.getVisitor(this, normalizedStage);
    if (visitor == null)
        visitor = getDefaultVisitor(entity, normalizedStage);
    return visitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

IVisitor (org.whole.lang.visitors.IVisitor)63 IOperation (org.whole.lang.operations.IOperation)34 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)34 IBuilder (org.whole.lang.builders.IBuilder)20 IBuilderFactory (org.whole.lang.builders.IBuilderFactory)20 IEntityContext (org.whole.lang.contexts.IEntityContext)20 PrettyPrinterOperation (org.whole.lang.operations.PrettyPrinterOperation)13 IEntity (org.whole.lang.model.IEntity)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 Test (org.junit.Test)2 ITransactionScope (org.whole.lang.bindings.ITransactionScope)2 GenericMatcherFactory (org.whole.lang.matchers.GenericMatcherFactory)2 AbstractOperation (org.whole.lang.operations.AbstractOperation)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 VisitException (org.whole.lang.visitors.VisitException)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1