use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMPrefixExpression method handle.
@Override
public DSubTree handle() {
DSubTree sub = new DOMExpression(expression.getOperand(), visitor).handle();
if (expression.getOperator() == PrefixExpression.Operator.NOT && sub.getNodes().size() == 1) {
// encode the ! predicate into the API call name
DAPICall call = (DAPICall) sub.getNodes().get(0);
call.setNotPredicate();
}
return sub;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMSynchronizedStatement method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
DSubTree Texpr = new DOMExpression(statement.getExpression(), visitor).handle();
DSubTree Tbody = new DOMBlock(statement.getBody(), visitor).handle();
tree.addNodes(Texpr.getNodes());
tree.addNodes(Tbody.getNodes());
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMTryStatement method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// restriction: considering only the first catch clause
DSubTree Ttry = new DOMBlock(statement.getBody(), visitor).handle();
DSubTree Tcatch;
if (!statement.catchClauses().isEmpty())
Tcatch = new DOMCatchClause((CatchClause) statement.catchClauses().get(0), visitor).handle();
else
Tcatch = new DSubTree();
DSubTree Tfinally = new DOMBlock(statement.getFinally(), visitor).handle();
boolean except = Ttry.isValid() && Tcatch.isValid();
if (except)
tree.addNode(new DExcept(Ttry.getNodes(), Tcatch.getNodes()));
else {
// only one of these will add nodes
tree.addNodes(Ttry.getNodes());
tree.addNodes(Tcatch.getNodes());
}
tree.addNodes(Tfinally.getNodes());
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMVariableDeclarationExpression method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
for (Object o : expression.fragments()) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) o;
DSubTree t = new DOMVariableDeclarationFragment(fragment, visitor).handle();
tree.addNodes(t.getNodes());
}
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class Visitor method visit.
@Override
public boolean visit(TypeDeclaration clazz) {
if (clazz.isInterface())
return false;
List<TypeDeclaration> classes = new ArrayList<>();
classes.addAll(Arrays.asList(clazz.getTypes()));
classes.add(clazz);
for (TypeDeclaration cls : classes) allMethods.addAll(Arrays.asList(cls.getMethods()));
List<MethodDeclaration> constructors = allMethods.stream().filter(m -> m.isConstructor()).collect(Collectors.toList());
List<MethodDeclaration> publicMethods = allMethods.stream().filter(m -> !m.isConstructor() && Modifier.isPublic(m.getModifiers())).collect(Collectors.toList());
List<String> skeletons = new ArrayList<>();
List<Multiset<Integer>> cfg3_bfs = new ArrayList<>();
List<Multiset<Integer>> cfg4_bfs = new ArrayList<>();
List<Multiset<Integer>> cfg3_dfs = new ArrayList<>();
List<Multiset<Integer>> cfg4_dfs = new ArrayList<>();
for (MethodDeclaration m : allMethods) {
DecoratedSkeletonFeature skeleton = new DecoratedSkeletonFeature(m);
skeletons.add(skeleton.toString());
CFGFeature cfg = new CFGFeature(m);
cfg3_bfs.add(cfg.gen_subgraph(3, true));
cfg4_bfs.add(cfg.gen_subgraph(4, true));
cfg3_dfs.add(cfg.gen_subgraph(3, false));
cfg4_dfs.add(cfg.gen_subgraph(4, false));
}
Set<Pair<DSubTree, String>> astsWithJavadoc = new HashSet<>();
if (!constructors.isEmpty() && !publicMethods.isEmpty()) {
for (MethodDeclaration c : constructors) for (MethodDeclaration m : publicMethods) {
String javadoc = Utils.getJavadoc(m, options.JAVADOC_TYPE);
callStack.push(c);
DSubTree ast = new DOMMethodDeclaration(c, this).handle();
callStack.push(m);
ast.addNodes(new DOMMethodDeclaration(m, this).handle().getNodes());
callStack.pop();
callStack.pop();
if (ast.isValid())
astsWithJavadoc.add(new ImmutablePair<>(ast, javadoc));
}
} else if (!constructors.isEmpty()) {
// no public methods, only constructor
for (MethodDeclaration c : constructors) {
String javadoc = Utils.getJavadoc(c, options.JAVADOC_TYPE);
callStack.push(c);
DSubTree ast = new DOMMethodDeclaration(c, this).handle();
callStack.pop();
if (ast.isValid())
astsWithJavadoc.add(new ImmutablePair<>(ast, javadoc));
}
} else if (!publicMethods.isEmpty()) {
// no constructors, methods executed typically through Android callbacks
for (MethodDeclaration m : publicMethods) {
String javadoc = Utils.getJavadoc(m, options.JAVADOC_TYPE);
callStack.push(m);
DSubTree ast = new DOMMethodDeclaration(m, this).handle();
callStack.pop();
if (ast.isValid())
astsWithJavadoc.add(new ImmutablePair<>(ast, javadoc));
}
}
for (Pair<DSubTree, String> astDoc : astsWithJavadoc) {
List<Sequence> sequences = new ArrayList<>();
sequences.add(new Sequence());
try {
astDoc.getLeft().updateSequences(sequences, options.MAX_SEQS, options.MAX_SEQ_LENGTH);
List<Sequence> uniqSequences = new ArrayList<>(new HashSet<>(sequences));
if (okToPrintAST(uniqSequences))
addToJson(astDoc.getLeft(), uniqSequences, astDoc.getRight(), skeletons, cfg3_bfs, cfg4_bfs, cfg3_dfs, cfg4_dfs);
} catch (DASTNode.TooManySequencesException e) {
System.err.println("Too many sequences from AST");
} catch (DASTNode.TooLongSequenceException e) {
System.err.println("Too long sequence from AST");
}
}
return false;
}
Aggregations