Search in sources :

Example 6 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMConditionalExpression method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    DSubTree Tcond = new DOMExpression(expression.getExpression(), visitor).handle();
    DSubTree Tthen = new DOMExpression(expression.getThenExpression(), visitor).handle();
    DSubTree Telse = new DOMExpression(expression.getElseExpression(), visitor).handle();
    boolean branch = (Tcond.isValid() && Tthen.isValid()) || (Tcond.isValid() && Telse.isValid()) || (Tthen.isValid() && Telse.isValid());
    if (branch)
        tree.addNode(new DBranch(Tcond.getNodesAsCalls(), Tthen.getNodes(), Telse.getNodes()));
    else {
        // only one of these will add nodes, the rest will add nothing
        tree.addNodes(Tcond.getNodes());
        tree.addNodes(Tthen.getNodes());
        tree.addNodes(Telse.getNodes());
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) DBranch(edu.rice.cs.caper.bayou.core.dsl.DBranch)

Example 7 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMEnhancedForStatement method handle.

/* TODO: handle this properly, by creating a call to Iterator.hasNext() and next() in a loop */
@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    DSubTree Texpr = new DOMExpression(statement.getExpression(), visitor).handle();
    DSubTree Tbody = new DOMStatement(statement.getBody(), visitor).handle();
    tree.addNodes(Texpr.getNodes());
    tree.addNodes(Tbody.getNodes());
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree)

Example 8 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMForStatement method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    for (Object o : statement.initializers()) {
        DSubTree init = new DOMExpression((Expression) o, visitor).handle();
        tree.addNodes(init.getNodes());
    }
    DSubTree cond = new DOMExpression(statement.getExpression(), visitor).handle();
    DSubTree body = new DOMStatement(statement.getBody(), visitor).handle();
    for (Object o : statement.updaters()) {
        DSubTree update = new DOMExpression((Expression) o, visitor).handle();
        // updaters are part of body
        body.addNodes(update.getNodes());
    }
    boolean loop = cond.isValid();
    if (loop)
        tree.addNode(new DLoop(cond.getNodesAsCalls(), body.getNodes()));
    else {
        // only one of these will add nodes
        tree.addNodes(cond.getNodes());
        tree.addNodes(body.getNodes());
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) Expression(org.eclipse.jdt.core.dom.Expression) DLoop(edu.rice.cs.caper.bayou.core.dsl.DLoop)

Example 9 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMIfStatement method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    DSubTree Tcond = new DOMExpression(statement.getExpression(), visitor).handle();
    DSubTree Tthen = new DOMStatement(statement.getThenStatement(), visitor).handle();
    DSubTree Telse = new DOMStatement(statement.getElseStatement(), visitor).handle();
    boolean branch = (Tcond.isValid() && Tthen.isValid()) || (Tcond.isValid() && Telse.isValid()) || (Tthen.isValid() && Telse.isValid());
    if (branch)
        tree.addNode(new DBranch(Tcond.getNodesAsCalls(), Tthen.getNodes(), Telse.getNodes()));
    else {
        // only one of these will add nodes, the rest will add nothing
        tree.addNodes(Tcond.getNodes());
        tree.addNodes(Tthen.getNodes());
        tree.addNodes(Telse.getNodes());
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) DBranch(edu.rice.cs.caper.bayou.core.dsl.DBranch)

Example 10 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMMethodInvocation method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    // add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
    DSubTree Texp = new DOMExpression(invocation.getExpression(), visitor).handle();
    tree.addNodes(Texp.getNodes());
    // evaluate arguments first
    for (Object o : invocation.arguments()) {
        DSubTree Targ = new DOMExpression((Expression) o, visitor).handle();
        tree.addNodes(Targ.getNodes());
    }
    IMethodBinding binding = invocation.resolveMethodBinding();
    // check if the binding is of a generic type that involves user-defined types
    if (binding != null) {
        ITypeBinding cls = binding.getDeclaringClass();
        boolean userType = false;
        if (cls != null && cls.isParameterizedType())
            for (int i = 0; i < cls.getTypeArguments().length; i++) userType |= !cls.getTypeArguments()[i].getQualifiedName().startsWith("java.") && !cls.getTypeArguments()[i].getQualifiedName().startsWith("javax.");
        if (// get to the generic declaration
        userType || cls == null)
            while (binding != null && binding.getMethodDeclaration() != binding) binding = binding.getMethodDeclaration();
    }
    MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding, visitor);
    if (localMethod != null) {
        Stack<MethodDeclaration> callStack = visitor.callStack;
        if (!callStack.contains(localMethod)) {
            callStack.push(localMethod);
            DSubTree Tmethod = new DOMMethodDeclaration(localMethod, visitor).handle();
            callStack.pop();
            tree.addNodes(Tmethod.getNodes());
        }
    } else if (Utils.isRelevantCall(binding, visitor)) {
        try {
            tree.addNode(new DAPICall(binding, visitor.getLineNumber(invocation)));
        } catch (DAPICall.InvalidAPICallException e) {
        // continue without adding the node
        }
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) DAPICall(edu.rice.cs.caper.bayou.core.dsl.DAPICall)

Aggregations

DSubTree (edu.rice.cs.caper.bayou.core.dsl.DSubTree)26 ArrayList (java.util.ArrayList)7 DAPICall (edu.rice.cs.caper.bayou.core.dsl.DAPICall)5 DBranch (edu.rice.cs.caper.bayou.core.dsl.DBranch)3 DLoop (edu.rice.cs.caper.bayou.core.dsl.DLoop)3 Sequence (edu.rice.cs.caper.bayou.core.dsl.Sequence)3 DASTNode (edu.rice.cs.caper.bayou.core.dsl.DASTNode)2 HashSet (java.util.HashSet)2 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)2 Multiset (com.google.common.collect.Multiset)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DExcept (edu.rice.cs.caper.bayou.core.dsl.DExcept)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1