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;
}
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;
}
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;
}
});
}
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);
}
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);
}
Aggregations