@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { if (child instanceof CtTypeAccess) { if (hasChildEqualsToType(ctConstructorCall)) { ctConstructorCall.getExecutable().setType(((CtTypeAccess) child).getAccessedType()); } else { ctConstructorCall.addActualTypeArgument(((CtTypeAccess) child).getAccessedType()); } return; } else if (child instanceof CtExpression) { if (hasChildEqualsToEnclosingInstance(ctConstructorCall)) { ctConstructorCall.setTarget((CtExpression<?>) child); } else { ctConstructorCall.addArgument((CtExpression<?>) child); } return; } super.visitCtConstructorCall(ctConstructorCall); }
@java.lang.Override public <T> void visitCtConstructorCall(final spoon.reflect.code.CtConstructorCall<T> ctConstructorCall) { spoon.reflect.code.CtConstructorCall<T> aCtConstructorCall = ctConstructorCall.getFactory().Core().createConstructorCall(); this.builder.copy(ctConstructorCall, aCtConstructorCall); aCtConstructorCall.setAnnotations(this.cloneHelper.clone(ctConstructorCall.getAnnotations())); aCtConstructorCall.setTypeCasts(this.cloneHelper.clone(ctConstructorCall.getTypeCasts())); aCtConstructorCall.setExecutable(this.cloneHelper.clone(ctConstructorCall.getExecutable())); aCtConstructorCall.setTarget(this.cloneHelper.clone(ctConstructorCall.getTarget())); aCtConstructorCall.setArguments(this.cloneHelper.clone(ctConstructorCall.getArguments())); aCtConstructorCall.setComments(this.cloneHelper.clone(ctConstructorCall.getComments())); this.cloneHelper.tailor(ctConstructorCall, aCtConstructorCall); this.other = aCtConstructorCall; }
private <T> void printConstructorCall(CtConstructorCall<T> ctConstructorCall) { try (Writable _context = context.modify()) { if (ctConstructorCall.getTarget() != null) { scan(ctConstructorCall.getTarget()); printer.writeSeparator("."); _context.ignoreEnclosingClass(true); } if (hasDeclaringTypeWithGenerics(ctConstructorCall.getType())) { _context.ignoreEnclosingClass(true); } printer.writeKeyword("new").writeSpace(); if (!ctConstructorCall.getActualTypeArguments().isEmpty()) { elementPrinterHelper.writeActualTypeArguments(ctConstructorCall); } scan(ctConstructorCall.getType()); } elementPrinterHelper.printList(ctConstructorCall.getArguments(), null, false, "(", false, false, ",", true, false, ")", exp -> scan(exp)); }
@java.lang.Override public <T> void visitCtConstructorCall(final spoon.reflect.code.CtConstructorCall<T> ctConstructorCall) { spoon.reflect.code.CtConstructorCall other = ((spoon.reflect.code.CtConstructorCall) (this.stack.peek())); enter(ctConstructorCall); biScan(spoon.reflect.path.CtRole.ANNOTATION, ctConstructorCall.getAnnotations(), other.getAnnotations()); biScan(spoon.reflect.path.CtRole.CAST, ctConstructorCall.getTypeCasts(), other.getTypeCasts()); biScan(spoon.reflect.path.CtRole.EXECUTABLE_REF, ctConstructorCall.getExecutable(), other.getExecutable()); biScan(spoon.reflect.path.CtRole.TARGET, ctConstructorCall.getTarget(), other.getTarget()); biScan(spoon.reflect.path.CtRole.ARGUMENT, ctConstructorCall.getArguments(), other.getArguments()); biScan(spoon.reflect.path.CtRole.COMMENT, ctConstructorCall.getComments(), other.getComments()); exit(ctConstructorCall); }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { enter(ctConstructorCall); scan(ctConstructorCall.getAnnotations()); scan(ctConstructorCall.getType()); scanReferences(ctConstructorCall.getTypeCasts()); scan(ctConstructorCall.getExecutable()); scan(ctConstructorCall.getTarget()); scan(ctConstructorCall.getArguments()); exit(ctConstructorCall); }
constructorCall.setType(references.getTypeReference(allocationExpression.type.resolvedType)); context.isGenericTypeExplicit = true; } else if (allocationExpression.expectedType() != null) { constructorCall.setType(references.getTypeReference(allocationExpression.expectedType())); constructorCall.setExecutable(references.getExecutableReference(allocationExpression.binding)); if (constructorCall.getExecutable() != null) { constructorCall.getExecutable().setType((CtTypeReference<Object>) constructorCall.getExecutable().getDeclaringType()); constructorCall.setActualTypeArguments(references.getBoundedTypesReferences(allocationExpression.genericTypeArguments()));
@Deprecated public static List<CtExpression> generateAllConstructionOf(CtTypeReference type) { CtConstructorCall<?> constructorCall = type.getFactory().createConstructorCall(); constructorCall.setType(type); if (type.getDeclaration() != null) { final List<CtConstructor<?>> constructors = type.getDeclaration() if (!constructors.isEmpty()) { final List<CtExpression> generatedConstructors = constructors.stream().map(ctConstructor -> { final CtConstructorCall<?> clone = constructorCall.clone(); ctConstructor.getParameters().forEach(parameter -> clone.addArgument(ValueCreator.generateRandomValue(parameter.getType(), 0)) ); return clone;
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); String type = ctConstructorCall.getType().getQualifiedName(); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); List<String> orig = resolveTypes(argumentlist); CtClass classname = parser.getClassMap().get(type); if(classname!=null) { Set<CtConstructor<T>> constructors=classname.getConstructors(); for(CtConstructor constructor:constructors) { List<CtParameter> paramlist=constructor.getParameters(); List<String> target=resolveParams(paramlist); transformOneMethod(orig,target,ctConstructorCall); } } else { List<Class[]> params = parser.fetchMethods(type, type); for (Class[] p : params) transformOneConstructor(orig, ctConstructorCall, p); } }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { if (ctConstructorCall.getExecutable() != null) { label = ctConstructorCall.getExecutable().getSignature(); } }
if (!constructors.isEmpty()) { CtConstructorCall<?> constructorCall = type.getFactory().createConstructorCall(); constructorCall.setType(type); final CtConstructor<?> selectedConstructor; if (depth > 3) { constructorCall.addArgument(ValueCreator.generateRandomValue(parameter.getType(), depth + 1)) ); return constructorCall;
@Override public <T> void visitCtEnumValue(CtEnumValue<T> enumValue) { elementPrinterHelper.visitCtNamedElement(enumValue, sourceCompilationUnit); elementPrinterHelper.writeComment(enumValue, CommentOffset.BEFORE); printer.writeIdentifier(enumValue.getSimpleName()); if (enumValue.getDefaultExpression() != null) { CtConstructorCall<?> constructorCall = (CtConstructorCall<?>) enumValue.getDefaultExpression(); if (!constructorCall.isImplicit()) { elementPrinterHelper.printList(constructorCall.getArguments(), null, false, "(", false, false, ",", true, false, ")", expr -> scan(expr)); } if (constructorCall instanceof CtNewClass) { scan(((CtNewClass<?>) constructorCall).getAnonymousClass()); } } }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); for (int i = 0; i < argumentlist.size(); i++) { @SuppressWarnings("rawtypes") CtExpression p = argumentlist.get(i); if (candidates.containsKey(p)) { argumentlist.set(i, candidates.get(p)); // ctConstructorCall.setArguments(argumentlist); saveSketchAndSynthesize(); argumentlist.set(i, p); resoreDiskFile(); // ctConstructorCall.setArguments(argumentlist); } } }
@Override public boolean visit(AllocationExpression allocationExpression, BlockScope scope) { CtConstructorCall constructorCall = factory.Core().createConstructorCall(); constructorCall.setExecutable(references.getExecutableReference(allocationExpression)); ASTPair first = this.context.stack.getFirst(); // in case of enum values the constructor call is often implicit if (first.element instanceof CtEnumValue) { if (allocationExpression.sourceEnd == first.node.sourceEnd) { constructorCall.setImplicit(true); } } context.enter(constructorCall, allocationExpression); return true; }
/** * Creates a constructor call. The correct constructor is inferred based on parameters * * @param type the decelerating type of the constructor * @param parameters the arguments of the constructor call * @param <T> the actual type of the decelerating type of the constructor if available * @return the constructor call */ public <T> CtConstructorCall<T> createConstructorCall(CtTypeReference<T> type, CtExpression<?>...parameters) { CtConstructorCall<T> constructorCall = factory.Core() .createConstructorCall(); CtExecutableReference<T> executableReference = factory.Core() .createExecutableReference(); executableReference.setType(type); executableReference.setDeclaringType(type == null ? type : type.clone()); executableReference.setSimpleName(CtExecutableReference.CONSTRUCTOR_NAME); List<CtTypeReference<?>> typeReferences = new ArrayList<>(); for (CtExpression<?> parameter : parameters) { typeReferences.add(parameter.getType()); } executableReference.setParameters(typeReferences); constructorCall.setArguments(Arrays.asList(parameters)); constructorCall.setExecutable(executableReference); return constructorCall; }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { if (this.jdtTreeBuilder.context.isArgument(ctConstructorCall) && child instanceof CtExpression) { ctConstructorCall.addArgument((CtExpression<?>) child); return; } super.visitCtConstructorCall(ctConstructorCall); }
private <T> boolean hasChildEqualsToEnclosingInstance(CtConstructorCall<T> ctConstructorCall) { if (!(jdtTreeBuilder.getContextBuilder().stack.peek().node instanceof QualifiedAllocationExpression)) { return false; } final QualifiedAllocationExpression parent = (QualifiedAllocationExpression) jdtTreeBuilder.getContextBuilder().stack.peek().node; // Enclosing instance is equals to the jdt child. return parent.enclosingInstance != null && getFinalExpressionFromCast(parent.enclosingInstance).equals(childJDT) // Enclosing instance not yet initialized. && !child.equals(ctConstructorCall.getTarget()); }
@Override public boolean visit(QualifiedAllocationExpression qualifiedAllocationExpression, BlockScope scope) { CtConstructorCall constructorCall; if (qualifiedAllocationExpression.anonymousType != null) { constructorCall = factory.Core().createNewClass(); } else { constructorCall = factory.Core().createConstructorCall(); } constructorCall.setExecutable(references.getExecutableReference(qualifiedAllocationExpression)); context.enter(constructorCall, qualifiedAllocationExpression); return true; }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { setResult(ctConstructorCall.getFactory().Core().clone(ctConstructorCall)); }
@Override public <T> void visitCtConstructorCall(final CtConstructorCall<T> ctConstructorCall) { enter(ctConstructorCall); scan(CtRole.ANNOTATION, ctConstructorCall.getAnnotations()); scan(CtRole.CAST, ctConstructorCall.getTypeCasts()); scan(CtRole.EXECUTABLE_REF, ctConstructorCall.getExecutable()); scan(CtRole.TARGET, ctConstructorCall.getTarget()); scan(CtRole.ARGUMENT, ctConstructorCall.getArguments()); scan(CtRole.COMMENT, ctConstructorCall.getComments()); exit(ctConstructorCall); }
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { if (ctConstructorCall.getExecutable() != null) { label = ctConstructorCall.getExecutable().getSignature(); } }