Search in sources :

Example 1 with Path

use of org.whole.lang.queries.model.Path in project whole by wholeplatform.

the class GrammarsContentAssistVisitor method calculateNonTerminalValues.

public static Set<String> calculateNonTerminalValues(IEntity e) {
    Grammar grammar = Matcher.findAncestor(Grammar, e);
    if (grammar != null) {
        Set<String> names = new HashSet<String>();
        IEntity parent = e.wGetParent();
        ILanguageKit languageKit = getLanguageKitIfExists(grammar);
        if (languageKit != null) {
            if (!grammar.getLexicalStructure().equals(parent.wGetParent()))
                names.addAll(languageKit.getEntityDescriptorEnum().names());
            if (!parent.wGetFeatureDescriptor(e).equals(name)) {
                QueriesEntityFactory qef = QueriesEntityFactory.instance;
                Path allTokenNames = qef.createPath(qef.createSequence(qef.createFeatureStep("lexicalStructure"), qef.createFeatureStep("phraseStructure")), qef.createChildStep(), qef.createFilter(qef.createFeatureStep("name"), qef.createKindTest(KindTestEnum.IMPL)));
                for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(allTokenNames, grammar)) names.add(nt.getValue());
            }
        } else {
            AbstractPatternFilterIterator<NonTerminal> i = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(NonTerminal);
            i.reset(grammar);
            for (NonTerminal nt : i) if (EntityUtils.isNotResolver(nt))
                names.add(nt.getValue());
        }
        return names;
    }
    return Collections.emptySet();
}
Also used : Path(org.whole.lang.queries.model.Path) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) NonTerminal(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Grammar(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar) Grammar(org.whole.lang.grammars.model.Grammar) ILanguageKit(org.whole.lang.reflect.ILanguageKit) HashSet(java.util.HashSet)

Example 2 with Path

use of org.whole.lang.queries.model.Path in project whole by wholeplatform.

the class PojoNormalizerVisitor method createDefaultTypeInParameters.

public static void createDefaultTypeInParameters(Library entity, IBindingManager bindings) {
    Path findAllParametersWithoutType = (Path) PojoTemplateManager.instance().create("findAllParametersWithoutType");
    Path findParameterType = (Path) PojoTemplateManager.instance().create("findPropertyType");
    bindings.wEnterScope();
    for (Parameter parameter : BehaviorUtils.<Parameter>compileAndLazyEvaluate(findAllParametersWithoutType, entity, bindings)) {
        PojoDeclaration pojo = (PojoDeclaration) bindings.wGet("pojo");
        Type type = BehaviorUtils.<Type>evaluateFirstResult(findParameterType, pojo, bindings);
        if (type != null)
            parameter.setType(EntityUtils.clone(type));
        else
            throw new IllegalArgumentException("Missing " + bindings.wStringValue("name") + " property in " + pojo.getName().wStringValue() + " pojo declaration");
    }
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) Type(org.whole.lang.pojo.model.Type) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Parameter(org.whole.lang.pojo.model.Parameter)

Example 3 with Path

use of org.whole.lang.queries.model.Path in project whole by wholeplatform.

the class PojoNormalizerVisitor method resolveTemplateNameCollisionsInDeclarations.

public static void resolveTemplateNameCollisionsInDeclarations(Library entity, IBindingManager bindings, FreshNameGenerator entityNameGenerator) {
    Path findAllProductDeclarationsWithTemplateName = (Path) PojoTemplateManager.instance().create("findAllProductDeclarationsWithTemplateName");
    bindings.wEnterScope();
    for (ProductDeclaration declaration : BehaviorUtils.<ProductDeclaration>compileAndLazyEvaluate(findAllProductDeclarationsWithTemplateName, entity, bindings)) {
        Template template = declaration.getTemplate();
        template.wSetValue(entityNameGenerator.nextFreshName(StringUtils.toSimpleName(template.wStringValue())));
    }
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) ProductDeclaration(org.whole.lang.pojo.model.ProductDeclaration) Template(org.whole.lang.pojo.model.Template)

Example 4 with Path

use of org.whole.lang.queries.model.Path in project whole by wholeplatform.

the class PojoNormalizerVisitor method createDefaultTemplateInDeclarations.

public static void createDefaultTemplateInDeclarations(Library entity, IBindingManager bindings, FreshNameGenerator entityNameGenerator) {
    PojoEntityFactory pef = PojoEntityFactory.instance;
    Path findAllProductDeclarationsWithEmptyTemplate = (Path) PojoTemplateManager.instance().create("findAllProductDeclarationsWithEmptyTemplate");
    bindings.wEnterScope();
    for (ProductDeclaration declaration : BehaviorUtils.<ProductDeclaration>compileAndLazyEvaluate(findAllProductDeclarationsWithEmptyTemplate, entity, bindings)) {
        String name = StringUtils.toSimpleName(bindings.wStringValue("name"));
        declaration.setTemplate(pef.createName(entityNameGenerator.nextFreshName(name)));
    }
    bindings.wExitScope();
}
Also used : PojoEntityFactory(org.whole.lang.pojo.factories.PojoEntityFactory) Path(org.whole.lang.queries.model.Path) ProductDeclaration(org.whole.lang.pojo.model.ProductDeclaration)

Example 5 with Path

use of org.whole.lang.queries.model.Path in project whole by wholeplatform.

the class PojoNormalizerVisitor method addMappingDataTypes.

public static void addMappingDataTypes(Library entity, IBindingManager bindings, FreshNameGenerator entityNameGenerator) {
    Path findNonPrimitiveTypes = (Path) PojoTemplateManager.instance().create("findAllPropertyTypes");
    bindings.wEnterScope();
    for (Type type : BehaviorUtils.<Type>compileAndLazyEvaluate(findNonPrimitiveTypes, entity, bindings)) addMappingDataType(type, entity, bindings, entityNameGenerator);
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) Type(org.whole.lang.pojo.model.Type) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType)

Aggregations

Path (org.whole.lang.queries.model.Path)10 IEntity (org.whole.lang.model.IEntity)4 Test (org.junit.Test)2 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)2 ArrayType (org.whole.lang.pojo.model.ArrayType)2 CollectionType (org.whole.lang.pojo.model.CollectionType)2 MapType (org.whole.lang.pojo.model.MapType)2 Name (org.whole.lang.pojo.model.Name)2 Parameter (org.whole.lang.pojo.model.Parameter)2 PojoDeclaration (org.whole.lang.pojo.model.PojoDeclaration)2 PrimitiveType (org.whole.lang.pojo.model.PrimitiveType)2 ProductDeclaration (org.whole.lang.pojo.model.ProductDeclaration)2 ReferenceType (org.whole.lang.pojo.model.ReferenceType)2 Type (org.whole.lang.pojo.model.Type)2 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)2 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)2 Document (org.whole.lang.xml.model.Document)2 HashSet (java.util.HashSet)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 Grammar (org.whole.lang.grammars.model.Grammar)1