Java Code Examples for spoon.reflect.code.CtStatementList

The following examples show how to use spoon.reflect.code.CtStatementList. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: nopol   Source File: SpoonStatementLibrary.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static boolean isLastStatementOfMethod(CtStatement statement) {
    CtElement statementParent = statement.getParent();
    if (!isStatementList(statementParent)) {
        return isLastStatementOfMethod((CtStatement) statementParent);
    }
    CtStatementList block = (CtStatementList) statementParent;
    if (isLastStatementOf(block, statement)) {
        CtElement blockParent = block.getParent();
        if (isStatement(blockParent)) {
            return isLastStatementOfMethod((CtStatement) blockParent);
        } else {
            return isMethod(blockParent);
        }
    }
    return false;
}
 
Example 2
Source Project: coming   Source File: ExtendedRepairGenerator.java    License: MIT License 6 votes vote down vote up
private Set<CtElement> fuzzyLocator(CtElement statement) {
    Set<CtElement> locations = new HashSet<>();
    if (statement instanceof CtMethod || statement instanceof CtClass || statement instanceof CtIf || statement instanceof CtStatementList) {
        locations.add(statement);
    } else {
        // "int a;" is not CtStatement?
        CtElement parent = statement.getParent();
        if (parent != null) {
            List<CtElement> statements = parent.getElements(new TypeFilter<>(CtElement.class));
            if (parent instanceof CtStatement) {
                statements = statements.subList(1, statements.size());
            }
            int idx = statements.indexOf(statement);
            if (idx >= 0) {
                if (idx > 0)
                    locations.add(statements.get(idx - 1));
                locations.add(statements.get(idx));
                if (idx < statements.size() - 1)
                    locations.add(statements.get(idx + 1));
            }
        }
    }
    return locations;
}
 
Example 3
Source Project: coming   Source File: OriginalFeatureExtractor.java    License: MIT License 5 votes vote down vote up
private void getNearbyStmts(Repair repair, List<CtElement> stmtsF, List<CtElement> stmtsL) {
    final int LOOKUP_DIS = 3;
    CtElement srcElem = repair.srcElem;
    CtElement parent = srcElem.getParent();
    if (parent instanceof CtStatementList) {
        CtStatementList CS = (CtStatementList) parent;
        List<CtStatement> tmp = new ArrayList<>();
        int idx = 0;
        boolean found = false;
        for (CtStatement stmt: CS.getStatements()) {
            if (stmt.equals(srcElem)) {
                found = true;
                idx = tmp.size();
            }
            tmp.add(stmt);
        }
        assert(found);
        int s = 0;
        if (idx > LOOKUP_DIS)
            s = idx - LOOKUP_DIS;
        int e = tmp.size();
        if (idx + LOOKUP_DIS + 1 < tmp.size())
            e = idx + LOOKUP_DIS + 1;
        boolean above = true;
        for (int i = s; i < e; i++) {
            if (!tmp.get(i).equals(srcElem)) {
                if (above)
                    stmtsF.add(tmp.get(i));
                else
                    stmtsL.add(tmp.get(i));
            }
            if (tmp.get(i).equals(srcElem))
                above = false;
        }
    }
    if (!repair.isReplace)
        stmtsL.add(srcElem);
}
 
Example 4
Source Project: coming   Source File: ExtendedFeatureExtractor.java    License: MIT License 5 votes vote down vote up
private void getNearbyStmts(Repair repair, List<CtElement> stmtsF, List<CtElement> stmtsL) {
    final int LOOKUP_DIS = 3;
    CtElement srcElem = repair.srcElem;
    CtElement parent = srcElem.getParent();
    if (parent instanceof CtStatementList) {
        CtStatementList CS = (CtStatementList) parent;
        List<CtStatement> tmp = new ArrayList<>();
        int idx = 0;
        boolean found = false;
        for (CtStatement stmt: CS.getStatements()) {
            if (stmt.equals(srcElem)) {
                found = true;
                idx = tmp.size();
            }
            tmp.add(stmt);
        }
        assert(found);
        int s = 0;
        if (idx > LOOKUP_DIS)
            s = idx - LOOKUP_DIS;
        int e = tmp.size();
        if (idx + LOOKUP_DIS + 1 < tmp.size())
            e = idx + LOOKUP_DIS + 1;
        boolean above = true;
        for (int i = s; i < e; i++) {
            if (tmp.get(i).equals(srcElem)) {
                if (above)
                    stmtsF.add(tmp.get(i));
                else
                    stmtsL.add(tmp.get(i));
            }
            if (tmp.get(i).equals(srcElem))
                above = false;
        }
    }
    if (!repair.isReplace)
        stmtsL.add(srcElem);
}
 
Example 5
Source Project: coming   Source File: ExtendedRepairGenerator.java    License: MIT License 5 votes vote down vote up
private boolean isTainted(CtStatement S) {
    if (S == null) return false;
    if (area.contains(S))
        return true;
    // why Prophet does not need the second condition ?
    if (S instanceof CtStatementList && compound_counter.containsKey(S)) {
        CtStatementList CS = (CtStatementList) S;
        return compound_counter.get(CS) >= 2 || (compound_counter.get(CS) == 1 && CS.getStatements().size() == 1);
    } else {
        return false;
    }
}
 
Example 6
Source Project: gumtree-spoon-ast-diff   Source File: TreeScanner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ignore some element from the AST
 * 
 * @param element
 * @return
 */
private boolean isToIgnore(CtElement element) {
	if (element instanceof CtStatementList && !(element instanceof CtCase)) {
		if (element.getRoleInParent() == CtRole.ELSE || element.getRoleInParent() == CtRole.THEN) {
			return false;
		}
		return true;
	}

	if (element instanceof CtReference && element.getRoleInParent() == CtRole.SUPER_TYPE) {
		return false;
	}

	return element.isImplicit() || element instanceof CtReference;
}
 
Example 7
Source Project: nopol   Source File: SpoonStatementLibrary.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static boolean isLastStatementOf(CtStatementList block, CtStatement statement) {
    List<CtStatement> statements = block.getStatements();
    CtStatement lastStatement = MetaList.last(statements);
    return lastStatement == statement;
}