Search in sources :

Example 1 with AbstractVisitor

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);
}
Also used : IOperation(org.whole.lang.operations.IOperation) AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) EditorsArtifactsGeneratorVisitor(org.whole.lang.editors.visitors.EditorsArtifactsGeneratorVisitor) GrammarsInterpreterVisitor(org.whole.lang.grammars.visitors.GrammarsInterpreterVisitor) IVisitor(org.whole.lang.visitors.IVisitor) IEntity(org.whole.lang.model.IEntity) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) FramesInterpreterVisitor(org.whole.lang.frames.visitors.FramesInterpreterVisitor) GrammarsContentAssistVisitor(org.whole.lang.grammars.visitors.GrammarsContentAssistVisitor) PojoArtifactsGeneratorVisitor(org.whole.lang.pojo.visitors.PojoArtifactsGeneratorVisitor) ReflectLibraryDeployer(org.whole.lang.ReflectLibraryDeployer) ArtifactsGeneratorOperation(org.whole.lang.operations.ArtifactsGeneratorOperation) ViewDerivationLibraryDeployer(org.whole.lang.ViewDerivationLibraryDeployer) GrammarsValidatorVisitor(org.whole.lang.grammars.visitors.GrammarsValidatorVisitor)

Example 2 with AbstractVisitor

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);
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 3 with AbstractVisitor

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(")");
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 4 with AbstractVisitor

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(")");
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 5 with AbstractVisitor

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;
        }
    });
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor)

Aggregations

IEntity (org.whole.lang.model.IEntity)6 AbstractVisitor (org.whole.lang.visitors.AbstractVisitor)6 VisitException (org.whole.lang.visitors.VisitException)4 ReflectLibraryDeployer (org.whole.lang.ReflectLibraryDeployer)1 ViewDerivationLibraryDeployer (org.whole.lang.ViewDerivationLibraryDeployer)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 EditorsArtifactsGeneratorVisitor (org.whole.lang.editors.visitors.EditorsArtifactsGeneratorVisitor)1 FramesInterpreterVisitor (org.whole.lang.frames.visitors.FramesInterpreterVisitor)1 GrammarsContentAssistVisitor (org.whole.lang.grammars.visitors.GrammarsContentAssistVisitor)1 GrammarsInterpreterVisitor (org.whole.lang.grammars.visitors.GrammarsInterpreterVisitor)1 GrammarsValidatorVisitor (org.whole.lang.grammars.visitors.GrammarsValidatorVisitor)1 ArtifactsGeneratorOperation (org.whole.lang.operations.ArtifactsGeneratorOperation)1 IOperation (org.whole.lang.operations.IOperation)1 PojoArtifactsGeneratorVisitor (org.whole.lang.pojo.visitors.PojoArtifactsGeneratorVisitor)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 IVisitor (org.whole.lang.visitors.IVisitor)1 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)1