private boolean shouldSetBracket(CtExpression<?> e) { if (!e.getTypeCasts().isEmpty()) { return true; } try { if ((e.getParent() instanceof CtBinaryOperator) || (e.getParent() instanceof CtUnaryOperator)) { return (e instanceof CtTargetedExpression) || (e instanceof CtAssignment) || (e instanceof CtConditional) || (e instanceof CtUnaryOperator) || e instanceof CtBinaryOperator; } if (e.getParent() instanceof CtTargetedExpression) { return (e instanceof CtBinaryOperator) || (e instanceof CtAssignment) || (e instanceof CtConditional) || (e instanceof CtUnaryOperator); } } catch (ParentNotInitializedException ex) { // nothing we accept not to have a parent } return false; }
/** * Gets the index of a one-dimension array (helper). */ @SuppressWarnings("unchecked") public static Integer getIndex(CtExpression<?> e) { if (e.getParent() instanceof CtArrayAccess) { CtExpression<Integer> indexExpression = ((CtArrayAccess<?, CtExpression<Integer>>) e.getParent()).getIndexExpression(); return ((CtLiteral<Integer>) indexExpression).getValue(); } return null; }
/** * Check if the target expression is a static final field initialized in a static anonymous block. */ private <T> boolean isInitializeStaticFinalField(CtExpression<T> targetExp) { final CtElement parent; final CtAnonymousExecutable anonymousParent; try { parent = targetExp.getParent(); anonymousParent = targetExp.getParent(CtAnonymousExecutable.class); } catch (ParentNotInitializedException e) { return false; } return parent instanceof CtFieldWrite && targetExp.equals(((CtFieldWrite) parent).getTarget()) && anonymousParent != null && ((CtFieldWrite) parent).getVariable() != null && ((CtFieldWrite) parent).getVariable().getModifiers().contains(ModifierKind.STATIC) && ((CtFieldWrite) parent).getVariable().getModifiers().contains(ModifierKind.FINAL); }
private boolean shouldSetBracket(CtExpression<?> e) { if (e.getTypeCasts().size() != 0) { return true; } try { if ((e.getParent() instanceof CtBinaryOperator) || (e.getParent() instanceof CtUnaryOperator)) { return (e instanceof CtTargetedExpression) || (e instanceof CtAssignment) || (e instanceof CtConditional) || (e instanceof CtUnaryOperator); } if (e.getParent() instanceof CtTargetedExpression) { return (e instanceof CtBinaryOperator) || (e instanceof CtAssignment) || (e instanceof CtConditional); } } catch (ParentNotInitializedException ex) { // nothing we accept not to have a parent } return false; }
/** * Gets the index of a one-dimension array (helper). */ @SuppressWarnings("unchecked") public static Integer getIndex(CtExpression<?> e) { if (e.getParent() instanceof CtArrayAccess) { CtExpression<Integer> indexExpression = ((CtArrayAccess<?, CtExpression<Integer>>) e.getParent()).getIndexExpression(); return ((CtLiteral<Integer>) indexExpression).getValue(); } return null; }
private CtStatement getFirstStatement(CtExpression ctElement) { CtElement ctParent = ctElement.getParent(); while (!(ctParent instanceof CtStatement) && ctParent != null) { ctParent = ctParent.getParent(); } if (ctParent == null) { return null; } return (CtStatement) ctParent; }
return false; if (element.getParent() instanceof CtInvocation) { // the element is an argument of a method call final CtInvocation<?> parent = (CtInvocation<?>) element.getParent(); if (TestFramework.get().isAssert(parent) || element.equals(parent.getTarget())) { return false; if (element.getParent() instanceof CtLocalVariable && element instanceof CtLiteral<?>) {// the element is a defaultExpression final CtTypedElement<?> parent = element.getParent(CtTypedElement.class); return !parent.getType().isPrimitive();// the expected type is not primitive
@Override public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) { boolean successful = false; CtExpression rightTerm = null, leftTerm = null; try { CtExpression ctst = (CtExpression) operation.getOriginal(); CtExpression fix = (CtExpression) operation.getModified(); ctst.replace((CtExpression) fix); successful = true; operation.setSuccessfulyApplied((successful)); log.debug(" applied: " + ctst.getParent().toString()); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } return true; }
private List<Ingredient> computeIngredientsFromExpressionExplansion(ModificationPoint modificationPoint, CtExpression previousExpression, List<IngredientFromDyna> ingredientsDynamoth, BinaryOperatorKind operatorKind2) { List<Ingredient> ingredientsNewBinaryExpressions = new ArrayList(); for (IngredientFromDyna ingredientFromDyna : ingredientsDynamoth) { CtBinaryOperator binaryOperator = new CtBinaryOperatorImpl<>(); binaryOperator.setKind(operatorKind2); CtExpression previousExpressionCloned = previousExpression.clone(); MutationSupporter.clearPosition(previousExpressionCloned); binaryOperator.setLeftHandOperand(previousExpressionCloned); CtExpression newRightExpression = MutationSupporter.getFactory() .createCodeSnippetExpression(ingredientFromDyna.getDynmothExpression().toString()); binaryOperator.setRightHandOperand(newRightExpression); // binaryOperator.setFactory(MutationSupporter.getFactory()); binaryOperator.setParent(previousExpression.getParent()); Ingredient newIngredientExtended = new Ingredient(binaryOperator); newIngredientExtended.setDerivedFrom(previousExpression); ingredientsNewBinaryExpressions.add(newIngredientExtended); } return ingredientsNewBinaryExpressions; }
CtType<?> target = expToChange.getParent(CtType.class); Set<ModifierKind> modifiers = new HashSet<>(); modifiers.add(ModifierKind.PRIVATE);