Java Code Examples for spoon.reflect.code.CtStatement#equals()

The following examples show how to use spoon.reflect.code.CtStatement#equals() . 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 File: NopolProcessor.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isToBeProcessed(CtStatement statement) {
    if (statement.getPosition() instanceof NoSourcePosition || target.getPosition() instanceof NoSourcePosition) {
        return false;
    }
    return target.getPosition().getSourceStart() == statement.getPosition().getSourceStart() && target.getPosition().getSourceEnd() == statement.getPosition().getSourceEnd() && statement.equals(target);
}
 
Example 2
Source File: OriginalFeatureExtractor.java    From coming with 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 3
Source File: ExtendedFeatureExtractor.java    From coming with 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 File: StatementSupporter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static boolean remove(CtBlock parentBlock, CtStatement fixStatement, int pos) {

		CtStatement s = parentBlock.getStatement(pos);
		// To be sure that the position has the element we
		// want to remove
		if (fixStatement.equals(s)) {
			parentBlock.getStatements().remove(pos);
			return true;
		} else {
			System.out.println("\n fx: " + fixStatement + "\n" + (s));
			throw new IllegalStateException("Undo: Not valid fix position");
		}
	}