Search in sources :

Example 11 with ClassDeclaration

use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateWithTwoNestedSelectQueries.

@Test
public void testSelectTemplateWithTwoNestedSelectQueries() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithTwoNestedSelectQueries");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        BodyDeclarations bodyDeclarations = t.getBodyDeclarations();
        MethodDeclaration md = (MethodDeclaration) bodyDeclarations.wGet(bodyDeclarations.wSize() - 1);
        assertEquals(bodyDeclarations.wSize() - 1, md.getBody().wSize());
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) MethodDeclaration(org.whole.lang.java.model.MethodDeclaration) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) BodyDeclarations(org.whole.lang.java.model.BodyDeclarations) Test(org.junit.Test)

Example 12 with ClassDeclaration

use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateWithNestedEmptyQuery.

@Test
public void testSelectTemplateWithNestedEmptyQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedEmptyQuery");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        assertEquals(2, t.getBodyDeclarations().wSize());
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 13 with ClassDeclaration

use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.

the class JDTTransformerVisitor method visit.

public boolean visit(TypeDeclaration node) {
    // FIXME workaround for type nesting
    org.whole.lang.java.model.Type type = this.type;
    org.whole.lang.java.model.Name name = this.name;
    org.whole.lang.java.model.TypeParameter typeParameter = this.typeParameter;
    org.whole.lang.java.model.Parameters params = this.params;
    org.whole.lang.java.model.Types thrownExceptions = this.thrownExceptions;
    org.whole.lang.java.model.SingleVariableDeclaration varDecl = this.varDecl;
    org.whole.lang.java.model.Block block = this.block;
    org.whole.lang.java.model.Statement stm = this.stm;
    org.whole.lang.java.model.Expression exp = this.exp;
    org.whole.lang.java.model.VariableDeclarationFragment varFrag = this.varFrag;
    org.whole.lang.java.model.CatchClauses catchClauses = this.catchClauses;
    org.whole.lang.java.model.AnonymousClassDeclaration anonymousClassDeclaration = this.anonymousClassDeclaration;
    env().wEnterScope();
    if (node.isInterface()) {
        InterfaceDeclaration interfaceDecl;
        appendBodyDeclaration(interfaceDecl = lf.create(JavaEntityDescriptorEnum.InterfaceDeclaration));
        if (acceptChild(node.getJavadoc()))
            interfaceDecl.setJavadoc(this.javadoc);
        Iterator<?> j = node.typeParameters().iterator();
        while (j.hasNext()) {
            ((ASTNode) j.next()).accept(this);
            interfaceDecl.getTypeParameters().wAdd(this.typeParameter);
        }
        List<?> modifiers = node.modifiers();
        if (!modifiers.isEmpty()) {
            interfaceDecl.setModifiers(lf.create(JavaEntityDescriptorEnum.ExtendedModifiers));
            setExtendedModifiers(interfaceDecl.getModifiers(), modifiers);
        }
        if (acceptChild(node.getName()))
            interfaceDecl.setName((org.whole.lang.java.model.SimpleName) this.name);
        Iterator<?> i = node.superInterfaceTypes().iterator();
        while (i.hasNext()) {
            ((ASTNode) i.next()).accept(this);
            interfaceDecl.getSuperInterfaceTypes().wAdd(this.type);
        }
        org.whole.lang.java.model.BodyDeclarations bodyDecl = lf.createBodyDeclarations();
        interfaceDecl.setBodyDeclarations(bodyDecl);
        env().wDef("typeDeclarationsContainer", bodyDecl);
        acceptChildren(node.bodyDeclarations());
    } else {
        ClassDeclaration classDecl;
        appendBodyDeclaration(classDecl = lf.create(JavaEntityDescriptorEnum.ClassDeclaration));
        if (acceptChild(node.getJavadoc()))
            classDecl.setJavadoc(this.javadoc);
        Iterator<?> j = node.typeParameters().iterator();
        while (j.hasNext()) {
            ((ASTNode) j.next()).accept(this);
            classDecl.getTypeParameters().wAdd(this.typeParameter);
        }
        List<?> modifiers = node.modifiers();
        if (!modifiers.isEmpty()) {
            classDecl.setModifiers(lf.create(JavaEntityDescriptorEnum.ExtendedModifiers));
            setExtendedModifiers(classDecl.getModifiers(), modifiers);
        }
        if (acceptChild(node.getName()))
            classDecl.setName((org.whole.lang.java.model.SimpleName) this.name);
        if (acceptChild(node.getSuperclassType()))
            classDecl.setSuperclassType(this.type);
        Iterator<?> i = node.superInterfaceTypes().iterator();
        while (i.hasNext()) {
            ((ASTNode) i.next()).accept(this);
            classDecl.getSuperInterfaceTypes().wAdd(this.type);
        }
        org.whole.lang.java.model.BodyDeclarations bodyDecl = lf.createBodyDeclarations();
        classDecl.setBodyDeclarations(bodyDecl);
        env().wDef("typeDeclarationsContainer", bodyDecl);
        acceptChildren(node.bodyDeclarations());
    }
    env().wExitScope();
    // FIXME workaround for type nesting
    this.anonymousClassDeclaration = anonymousClassDeclaration;
    this.type = type;
    this.name = name;
    this.typeParameter = typeParameter;
    this.params = params;
    this.thrownExceptions = thrownExceptions;
    this.varDecl = varDecl;
    this.block = block;
    this.stm = stm;
    this.exp = exp;
    this.varFrag = varFrag;
    this.catchClauses = catchClauses;
    return false;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) InterfaceDeclaration(org.whole.lang.java.model.InterfaceDeclaration) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Type(org.whole.lang.java.model.Type)

Example 14 with ClassDeclaration

use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.

the class MatcherTest method testMultipleTypesSubstitute.

@Test
public void testMultipleTypesSubstitute() {
    ClassDeclaration functionPattern = new FunctionPattern().create();
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    bindings.wDefValue("factName", "factorial");
    bindings.wDefValue("factArg", 5);
    Matcher.substitute(functionPattern, bindings, false);
    IEntity var1 = functionPattern.getBodyDeclarations().wGet(0).wGet(JavaFeatureDescriptorEnum.name);
    MethodInvocation methodInvocation = (MethodInvocation) functionPattern.getBodyDeclarations().wGet(1).wGet(JavaFeatureDescriptorEnum.body).wGet(0).wGet(JavaFeatureDescriptorEnum.expression).wGet(JavaFeatureDescriptorEnum.arguments).wGet(0);
    IEntity var2 = methodInvocation.getName();
    IEntity var3 = methodInvocation.getArguments().wGet(0);
    assertEquals("factorial", var1.wStringValue());
    assertEquals("factorial", var2.wStringValue());
    assertEquals(5, var3.wByteValue());
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) MethodInvocation(org.whole.lang.java.model.MethodInvocation) Test(org.junit.Test)

Example 15 with ClassDeclaration

use of org.whole.lang.java.model.ClassDeclaration in project whole by wholeplatform.

the class ClassDeclarationPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    ClassDeclaration classDeclaration = getModelEntity();
    ((ClassDeclarationFigure) getFigure()).hideTypeParameters(EntityUtils.isResolver(classDeclaration.getTypeParameters()));
    ((ClassDeclarationFigure) getFigure()).hideSuperclassType(EntityUtils.isResolver(classDeclaration.getSuperclassType()));
    ((ClassDeclarationFigure) getFigure()).hideSuperInterfaceTypes(EntityUtils.isResolver(classDeclaration.getSuperInterfaceTypes()));
    List<IEntity> list = new ArrayList<IEntity>(7);
    list.add(classDeclaration.getJavadoc());
    list.add(classDeclaration.getModifiers());
    list.add(classDeclaration.getName());
    list.add(classDeclaration.getTypeParameters());
    list.add(classDeclaration.getSuperclassType());
    list.add(classDeclaration.getSuperInterfaceTypes());
    list.add(classDeclaration.getBodyDeclarations());
    return list;
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ClassDeclarationFigure(org.whole.lang.java.ui.figures.ClassDeclarationFigure)

Aggregations

ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)15 Test (org.junit.Test)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 Model (org.whole.lang.models.model.Model)11 PathExpression (org.whole.lang.queries.model.PathExpression)11 ITemplateManager (org.whole.lang.templates.ITemplateManager)11 IEntity (org.whole.lang.model.IEntity)7 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelsModel (org.whole.lang.models.codebase.ModelsModel)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 SimpleEntity (org.whole.lang.models.model.SimpleEntity)2 ArrayList (java.util.ArrayList)1 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 BodyDeclarations (org.whole.lang.java.model.BodyDeclarations)1 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)1 IJavaEntity (org.whole.lang.java.model.IJavaEntity)1 InterfaceDeclaration (org.whole.lang.java.model.InterfaceDeclaration)1 MethodDeclaration (org.whole.lang.java.model.MethodDeclaration)1 MethodInvocation (org.whole.lang.java.model.MethodInvocation)1