/** * Creates a local variable reference that points to an existing local * variable (strong referencing). */ public <T> CtLocalVariableReference<T> createLocalVariableReference(CtLocalVariable<T> localVariable) { CtLocalVariableReference<T> ref = factory.Core().createLocalVariableReference(); ref.setType(localVariable.getType() == null ? null : localVariable.getType().clone()); ref.setSimpleName(localVariable.getSimpleName()); ref.setParent(localVariable); return ref; }
public <T> void visitCtLocalVariable(final spoon.reflect.code.CtLocalVariable<T> localVariable) { spoon.reflect.code.CtLocalVariable other = ((spoon.reflect.code.CtLocalVariable) (this.stack.peek())); enter(localVariable); biScan(spoon.reflect.path.CtRole.ANNOTATION, localVariable.getAnnotations(), other.getAnnotations()); biScan(spoon.reflect.path.CtRole.TYPE, localVariable.getType(), other.getType()); biScan(spoon.reflect.path.CtRole.DEFAULT_EXPRESSION, localVariable.getDefaultExpression(), other.getDefaultExpression()); biScan(spoon.reflect.path.CtRole.COMMENT, localVariable.getComments(), other.getComments()); exit(localVariable); }
public <T> void visitCtLocalVariable(final CtLocalVariable<T> localVariable) { enter(localVariable); scan(CtRole.ANNOTATION, localVariable.getAnnotations()); scan(CtRole.TYPE, localVariable.getType()); scan(CtRole.DEFAULT_EXPRESSION, localVariable.getDefaultExpression()); scan(CtRole.COMMENT, localVariable.getComments()); exit(localVariable); }
@java.lang.Override public <T> void visitCtLocalVariable(final spoon.reflect.code.CtLocalVariable<T> localVariable) { replaceInListIfExist(localVariable.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(localVariable)); replaceElementIfExist(localVariable.getType(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypedElementTypeReplaceListener(localVariable)); replaceElementIfExist(localVariable.getDefaultExpression(), new spoon.support.visitor.replace.ReplacementVisitor.CtVariableDefaultExpressionReplaceListener(localVariable)); replaceInListIfExist(localVariable.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(localVariable)); }
public <T> void visitCtLocalVariable(final spoon.reflect.code.CtLocalVariable<T> localVariable) { spoon.reflect.code.CtLocalVariable<T> aCtLocalVariable = localVariable.getFactory().Core().createLocalVariable(); this.builder.copy(localVariable, aCtLocalVariable); aCtLocalVariable.setAnnotations(this.cloneHelper.clone(localVariable.getAnnotations())); aCtLocalVariable.setType(this.cloneHelper.clone(localVariable.getType())); aCtLocalVariable.setDefaultExpression(this.cloneHelper.clone(localVariable.getDefaultExpression())); aCtLocalVariable.setComments(this.cloneHelper.clone(localVariable.getComments())); this.cloneHelper.tailor(localVariable, aCtLocalVariable); this.other = aCtLocalVariable; }
@Override public <T> void visitCtLocalVariable(CtLocalVariable<T> localVariable) { enterCtStatement(localVariable); if (env.isPreserveLineNumbers()) { getPrinterHelper().adjustStartPosition(localVariable); } if (!context.isNextForVariable()) { elementPrinterHelper.writeModifiers(localVariable); if (localVariable.isInferred() && this.env.getComplianceLevel() >= 10) { getPrinterTokenWriter().writeKeyword("var"); } else { scan(localVariable.getType()); } printer.writeSpace(); } printer.writeIdentifier(localVariable.getSimpleName()); if (localVariable.getDefaultExpression() != null) { printer.writeSpace().writeOperator("=").writeSpace(); scan(localVariable.getDefaultExpression()); } exitCtStatement(localVariable); }
@Override public boolean matches(CtLocalVariable element) { return !element.getSimpleName().contains("DSPOT") && element.getParent() instanceof CtBlock && ValueCreatorHelper.canGenerateAValueForType(element.getType()); } }).stream()
@Override public Stream<CtMethod<?>> amplify(CtMethod<?> testMethod, int iteration) { List<CtLocalVariable<?>> existingObjects = getExistingObjects(testMethod); return existingObjects.stream() .flatMap(existingObject -> AmplifierHelper.findMethodsWithTargetType(existingObject.getType()).stream() .filter(ctMethod -> !MethodsHandler.isASupportedMethodName(ctMethod.getSimpleName()) || (MethodsHandler.isASupportedMethodName(ctMethod.getSimpleName()) && !ctMethod.getParameters().isEmpty()) ) .filter(ctMethod -> ctMethod.getParameters() .stream() .map(CtParameter::getType) .allMatch(ValueCreatorHelper::canGenerateAValueForType) ).map(methodToBeAdd -> AmplifierHelper.addInvocation(testMethod, methodToBeAdd, AmplifierHelper.createLocalVarRef(existingObject), existingObject, "_mg") ).map(amplifiedTestMethod -> { Counter.updateInputOf(amplifiedTestMethod, 1); return amplifiedTestMethod; } ) .collect(Collectors.toList()).stream() ); }
@SuppressWarnings("unchecked") @Override public Stream<CtMethod<?>> amplify(CtMethod<?> testMethod, int iteration) { return testMethod.getElements(new TypeFilter<CtLocalVariable>(CtLocalVariable.class) { @Override public boolean matches(CtLocalVariable element) { return !element.getSimpleName().contains("DSPOT") && element.getParent() instanceof CtBlock && ValueCreatorHelper.canGenerateAValueForType(element.getType()); } }).stream() .map(ctLocalVariable -> { final CtMethod clone = CloneHelper.cloneTestMethodForAmp(testMethod, "_replacement"); final CtLocalVariable localVariable = clone.getElements(new TypeFilter<>(CtLocalVariable.class)) .stream() .filter(ctLocalVariable1 -> ctLocalVariable1.equals(ctLocalVariable)) .findFirst() .get(); CtExpression<?> ctExpression = ValueCreator.generateRandomValue(ctLocalVariable.getType(), 0, localVariable.getAssignment()); localVariable.setAssignment(ctExpression); return clone; }); }
@Override public Stream<CtMethod<?>> amplify(CtMethod<?> method, int iteration) { List<CtLocalVariable<?>> existingObjects = getExistingObjects(method); final Stream<CtMethod<?>> gen_o1 = existingObjects.stream() // must use tmp variable because javac is confused .flatMap(localVariable -> ConstructorCreator.generateAllConstructionOf(localVariable.getType()).stream()) .map(ctExpression -> { final CtMethod<?> clone = CloneHelper.cloneTestMethodForAmp(method, "_sd"); clone.getBody().insertBegin( clone.getFactory().createLocalVariable( ctExpression.getType(), "__DSPOT_gen_o" + counterGenerateNewObject++, ctExpression ) ); return clone; } ); return gen_o1; }
Class<?> localVariableClass = ctLocalVariable.getType() .getActualClass();
Class<?> localVariableClass = ctLocalVariable.getType() .getActualClass();
/** * Creates a local variable reference that points to an existing local * variable (strong referencing). */ public <T> CtLocalVariableReference<T> createLocalVariableReference(CtLocalVariable<T> localVariable) { CtLocalVariableReference<T> ref = factory.Core().createLocalVariableReference(); ref.setType(localVariable.getType()); ref.setSimpleName(localVariable.getSimpleName()); ref.setDeclaration(localVariable); return ref; }
public <T> void visitCtLocalVariable(CtLocalVariable<T> localVariable) { enter(localVariable); scan(localVariable.getAnnotations()); scan(localVariable.getType()); scan(localVariable.getDefaultExpression()); exit(localVariable); }
public <T> DefaultJavaPrettyPrinter writeLocalVariable(CtLocalVariable<T> localVariable) { if (env.isPreserveLineNumbers()) { adjustPosition(localVariable); } if (!context.noTypeDecl) { writeModifiers(localVariable); scan(localVariable.getType()); write(" "); } write(localVariable.getSimpleName()); if (localVariable.getDefaultExpression() != null) { write(" = "); scan(localVariable.getDefaultExpression()); } return this; }