use of org.whole.lang.visitors.AbstractVisitor in project whole by wholeplatform.
the class CoreOperationsDeployer method deploy.
public void deploy(ReflectionFactory platform) {
platform.addOperationFactory(EditorsLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new EditorsArtifactsGeneratorVisitor((ArtifactsGeneratorOperation) operation);
}
});
platform.addOperationFactory(GrammarsLanguageKit.URI, ContentAssistOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GrammarsContentAssistVisitor();
}
});
platform.addOperationFactory(GrammarsLanguageKit.URI, ValidatorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GrammarsValidatorVisitor();
}
});
if (!ReflectionFactory.getLanguageKit(GrammarsLanguageKit.URI, false, null).hasVisitor(InterpreterOperation.ID))
platform.addOperationFactory(GrammarsLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
if (stage == 0)
return new GrammarsInterpreterVisitor();
else
return null;
}
});
platform.addPersistenceKit("org.whole.lang.grammars.GrammarEditor", GrammarsPersistenceKit.instance());
platform.addPersistenceKit("org.whole.lang.objectivec.ObjectiveCEditor", ObjectiveCPersistenceKit.instance());
platform.addPersistenceKit("org.whole.lang.mediawiki.MediaWikiEditor", MediaWikiPersistenceKit.instance());
platform.addOperationFactory(TemplatesLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new AbstractVisitor() {
public void visit(IEntity entity) {
BehaviorUtils.apply("whole:org.whole.lang.templates:TemplatesSemantics#toJava", entity, getBindings());
}
};
}
});
platform.addOperationFactory(PojoLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new PojoArtifactsGeneratorVisitor((ArtifactsGeneratorOperation) operation);
}
});
platform.addOperationFactory(FramesLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
if (stage == 0)
return new FramesInterpreterVisitor();
else
return null;
}
});
// TODO test
// ReflectLibrary.deploy();
new ReflectLibraryDeployer().deploy(platform);
new ViewDerivationLibraryDeployer().deploy(platform);
}
use of org.whole.lang.visitors.AbstractVisitor in project whole by wholeplatform.
the class GenericMatcherFactory method rewrite.
public IVisitor rewrite(final IEntity oldPattern, final IEntity newPattern, final boolean includeAdjacents) {
return new AbstractVisitor() {
public void visit(IEntity entity) {
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
if (!Matcher.match(oldPattern, entity, bindings))
throw new VisitException();
IEntity rewritePattern = EntityUtils.clone(newPattern);
if (!entity.wGetParent().wSet(entity, rewritePattern))
throw new VisitException();
Matcher.substitute(rewritePattern, bindings, includeAdjacents);
}
};
}
use of org.whole.lang.visitors.AbstractVisitor in project whole by wholeplatform.
the class GenericMatcherFactory method match.
public IVisitor match(final IEntity pattern) {
return new AbstractVisitor() {
public void visit(IEntity entity) {
if (!Matcher.match(pattern, entity))
throw new VisitException();
}
public void toString(StringBuilder sb) {
sb.append("match(");
// TODO startOf
sb.append(pattern);
sb.append(")");
}
};
}
use of org.whole.lang.visitors.AbstractVisitor in project whole by wholeplatform.
the class GenericMatcherFactory method hasKindMatcher.
public IVisitor hasKindMatcher(final EntityKinds kind) {
return new AbstractVisitor() {
public void visit(IEntity entity) {
if (!kind.equals(entity.wGetEntityKind()))
throw new VisitException();
}
public void toString(StringBuilder sb) {
sb.append("hasKind(");
sb.append(kind);
sb.append(")");
}
};
}
use of org.whole.lang.visitors.AbstractVisitor in project whole by wholeplatform.
the class DefaultValueFactory method setUniqueDefault.
public static void setUniqueDefault(IEntity entity) {
final String defaultPrefix = entity.wStringValue();
entity.wAddRequestEventHandler(new IdentityRequestEventHandler() {
int max = 0;
void updateMax(int value) {
if (value > max)
max = value;
}
public String notifyRequested(final IEntity source, FeatureDescriptor feature, String value) {
if (value.equals(defaultPrefix)) {
final EntityDescriptor<?> sourceDescriptor = source.wGetEntityDescriptor();
final EntityDescriptor<?> parentDescriptor = source.wGetParent().wGetEntityDescriptor();
GenericTraversalFactory.instance.topDown(new AbstractVisitor() {
public void visit(IEntity entity) {
if (entity == source)
return;
if (sourceDescriptor.equals(entity.wGetEntityDescriptor()) && parentDescriptor.equals(entity.wGetParent().wGetEntityDescriptor())) {
String strValue = entity.wStringValue();
if (strValue.startsWith(defaultPrefix)) {
try {
int value = Integer.parseInt(strValue.substring(defaultPrefix.length()));
updateMax(value);
} catch (NumberFormatException e) {
} catch (IndexOutOfBoundsException e) {
}
}
}
}
}, false).visit(EntityUtils.getCompoundRoot(source));
source.wSetValue(value = defaultPrefix + ++max);
source.wRemoveRequestEventHandler(this);
}
return value;
}
});
}
Aggregations