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

The following examples show how to use spoon.reflect.code.CtStatement#setParent() . 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: InsertBeforeOp.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {
		ctst.insertBefore((CtStatement) fix);
		fix.setParent(parentBlock);
		successful = true;
		operation.setSuccessfulyApplied(successful);
		StatementSupporter.updateBlockImplicitly(parentBlock, true);
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;

}
 
Example 2
Source File: InsertAfterOp.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {

	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;

	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {
		ctst.insertAfter((CtStatement) fix);
		fix.setParent(parentBlock);
		successful = true;
		operation.setSuccessfulyApplied(successful);
		StatementSupporter.updateBlockImplicitly(parentBlock, true);
	} else {
		log.error("Operation not applied. Parent null");
	}
	return successful;
}
 
Example 3
Source File: ReplaceOp.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {

		try {
			ctst.replace((CtStatement) fix);
			fix.setParent(parentBlock);
			successful = true;
			operation.setSuccessfulyApplied(successful);
		} catch (Exception ex) {
			log.error("Error applying an operation, exception: " + ex.getMessage());
			operation.setExceptionAtApplied(ex);
			operation.setSuccessfulyApplied(false);
		}
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;
}
 
Example 4
Source File: NullPreconditionOperator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {

		try {
			ctst.replace((CtStatement) fix);
			fix.setParent(parentBlock);
			successful = true;
			operation.setSuccessfulyApplied(successful);
		} catch (Exception ex) {
			log.error("Error applying an operation, exception: " + ex.getMessage());
			operation.setExceptionAtApplied(ex);
			operation.setSuccessfulyApplied(false);
		}
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;
}
 
Example 5
Source File: NullPreconditionOperatorMI.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {

		try {
			ctst.replace((CtStatement) fix);
			fix.setParent(parentBlock);
			successful = true;
			operation.setSuccessfulyApplied(successful);
		} catch (Exception ex) {
			log.error("Error applying an operation, exception: " + ex.getMessage());
			operation.setExceptionAtApplied(ex);
			operation.setSuccessfulyApplied(false);
		}
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;
}
 
Example 6
Source File: NullPreconditionWithExpressionOperator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {

		try {
			ctst.replace((CtStatement) fix);
			fix.setParent(parentBlock);
			successful = true;
			operation.setSuccessfulyApplied(successful);
		} catch (Exception ex) {
			log.error("Error applying an operation, exception: " + ex.getMessage());
			operation.setExceptionAtApplied(ex);
			operation.setSuccessfulyApplied(false);
		}
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;
}
 
Example 7
Source File: StatamentTransformer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static boolean doReplaceStatement(OperatorInstance operation) {
	StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation;
	boolean successful = false;
	CtStatement ctst = (CtStatement) operation.getOriginal();
	CtStatement fix = (CtStatement) operation.getModified();

	CtBlock parentBlock = stmtoperator.getParentBlock();

	if (parentBlock != null) {

		try {
			ctst.replace((CtStatement) fix);
			fix.setParent(parentBlock);
			successful = true;
			operation.setSuccessfulyApplied(successful);
		} catch (Exception ex) {
			log.error("Error applying an operation, exception: " + ex.getMessage());
			operation.setExceptionAtApplied(ex);
			operation.setSuccessfulyApplied(false);
		}
	} else {
		log.error("Operation not applied. Parent null ");
	}
	return successful;
}
 
Example 8
Source File: SingleUnWrapIfOperator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean applyModification() {

	CtStatement stmtinsideThenCloned = getBlock(ifToRemove.getThenStatement()).clone();

	stmtinsideThenCloned.setParent(null);
	MutationSupporter.clearPosition(stmtinsideThenCloned);

	CtStatement original = (CtStatement) MetaGenerator.geOriginalElement(ifToRemove);
	this.setParentBlock(original.getParent(CtBlock.class));

	super.setOriginal(original);
	super.setModified(stmtinsideThenCloned);

	return super.applyModification();
}