Search in sources :

Example 51 with IVisitor

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

the class AbstractByLanguageOperation method initVisitor.

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

Example 52 with IVisitor

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

the class AbstractByLanguageOperation method setVisitor.

@Override
public IVisitor setVisitor(IEntity entity, int absoluteStage, IVisitor visitor) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    String languageUri = languageKit.getURI();
    IVisitor oldVisitor = hasVisitor(languageUri) ? 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 53 with IVisitor

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

the class CommonsLanguageDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addLanguageKit(new CommonsLanguageKit());
    platform.addOperationFactory(CommonsLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new CommonsGenericBuilderAdapter((ICommonsBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new CommonsSpecificBuilderAdapter(strategy, entityContext);
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, ContentAssistOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new CommonsContentAssistVisitor();
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new CommonsInterpreterVisitor();
            else
                return null;
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, DynamicCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new CommonsDynamicCompilerVisitor();
            else
                return null;
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new CommonsPrettyPrinterVisitor((PrettyPrinterOperation) operation);
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, FindDeclarationOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return null;
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, FindDeclarationsOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return null;
        }
    });
    platform.addOperationFactory(CommonsLanguageKit.URI, IOperation.ANY_ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new CommonsInterpreterVisitor();
            else
                return null;
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) PrettyPrinterOperation(org.whole.lang.operations.PrettyPrinterOperation) CommonsContentAssistVisitor(org.whole.lang.commons.visitors.CommonsContentAssistVisitor) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) CommonsGenericBuilderAdapter(org.whole.lang.commons.builders.CommonsGenericBuilderAdapter) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder) CommonsPrettyPrinterVisitor(org.whole.lang.commons.visitors.CommonsPrettyPrinterVisitor) CommonsDynamicCompilerVisitor(org.whole.lang.commons.visitors.CommonsDynamicCompilerVisitor) CommonsInterpreterVisitor(org.whole.lang.commons.visitors.CommonsInterpreterVisitor) CommonsSpecificBuilderAdapter(org.whole.lang.commons.builders.CommonsSpecificBuilderAdapter)

Example 54 with IVisitor

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

the class GenericNormalizer method removeResolversFromComposites.

public static void removeResolversFromComposites(final boolean removeEmptyComposites, IEntity entity) {
    IVisitor visitor = GenericTraversalFactory.instance.downUp(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            beforeRemovingResolvers(entity);
        }
    }, new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (removeEmptyComposites)
                afterRemovingResolvers(entity);
        }
    }, false);
    visitor.visit(entity);
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) IEntity(org.whole.lang.model.IEntity) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor)

Example 55 with IVisitor

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

the class BehaviorUtils method evaluatePredicate.

// TODO ? fail on not boolean; != Queries predicate
public static boolean evaluatePredicate(IEntity predicate, int relativeStage, IBindingManager bm) {
    IEntity selfEntity = bm.wIsSet("self") ? bm.wGet("self") : NullEntity.instance;
    IEntity result = evaluate(predicate, relativeStage, bm);
    if (result == null || !EntityUtils.isData(result))
        return false;
    Object resultValue = result.wGetValue();
    return IVisitor.class.isInstance(resultValue) ? Matcher.match((IVisitor) resultValue, selfEntity) : EntityUtils.safeBooleanValue(result, false);
}
Also used : IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor)

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