/** * Writes a statement. */ public void writeStatement(CtStatement statement) { try (Writable _context = prettyPrinter.getContext().modify().setStatement(statement)) { prettyPrinter.scan(statement); } }
List<CtStatement> st = forLoop.getForInit(); if (!st.isEmpty()) { try (Writable _context = context.modify().isFirstForVariable(true)) { scan(st.get(0)); try (Writable _context = context.modify().isNextForVariable(true)) { for (int i = 1; i < st.size(); i++) { printer.writeSeparator(",").writeSpace();
@Override public <T> void visitCtFieldReference(CtFieldReference<T> reference) { boolean isStatic = "class".equals(reference.getSimpleName()) || !"super".equals(reference.getSimpleName()) && reference.isStatic(); boolean printType = true; if (reference.isFinal() && reference.isStatic()) { CtTypeReference<?> declTypeRef = reference.getDeclaringType(); if (declTypeRef.isAnonymous()) { //never print anonymous class ref printType = false; } else { if (context.isInCurrentScope(declTypeRef)) { //do not printType if we are in scope of that type printType = false; } } } if (isStatic && printType && !context.ignoreStaticAccess()) { try (Writable _context = context.modify().ignoreGenerics(true)) { scan(reference.getDeclaringType()); } printer.writeSeparator("."); } if ("class".equals(reference.getSimpleName())) { printer.writeKeyword("class"); } else { printer.writeIdentifier(reference.getSimpleName()); } }
@Override public <T> void visitCtAnnotationFieldAccess(CtAnnotationFieldAccess<T> annotationFieldAccess) { enterCtExpression(annotationFieldAccess); try (Writable _context = context.modify()) { if (annotationFieldAccess.getTarget() != null) { scan(annotationFieldAccess.getTarget()); printer.writeSeparator("."); _context.ignoreStaticAccess(true); } _context.ignoreGenerics(true); scan(annotationFieldAccess.getVariable()); printer.writeSeparator("(").writeSeparator(")"); } exitCtExpression(annotationFieldAccess); }
obj -> writeAnnotationElement(factory, obj)); } else if (value instanceof Enum) { try (Writable c = prettyPrinter.getContext().modify().ignoreGenerics(true)) { prettyPrinter.scan(factory.Type().createReference(((Enum<?>) value).getDeclaringClass()));
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)); }
try (Writable _context = context.modify().skipArray(true)) { scan(ref);
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { enterCtExpression(operator); scan(operator.getLeftHandOperand()); printer.writeSpace(); printer.writeOperator(OperatorHelper.getOperatorText(operator.getKind())); printer.writeSpace(); try (Writable _context = context.modify()) { if (operator.getKind() == BinaryOperatorKind.INSTANCEOF) { _context.forceWildcardGenerics(true); } scan(operator.getRightHandOperand()); } exitCtExpression(operator); }
@Override public <T, E extends CtExpression<?>> void visitCtExecutableReferenceExpression(CtExecutableReferenceExpression<T, E> expression) { enterCtExpression(expression); try (Writable _context = context.modify()) { if (expression.getExecutable().isStatic()) { _context.ignoreGenerics(true); } scan(expression.getTarget()); } printer.writeSeparator("::"); if (expression.getExecutable().isConstructor()) { printer.writeKeyword("new"); } else { printer.writeIdentifier(expression.getExecutable().getSimpleName()); } exitCtExpression(expression); }
printer.writeSpace(); try (Writable _context = context.modify().ignoreGenerics(false)) { scan(m.getType());
private <T> void printCtFieldAccess(CtFieldAccess<T> f) { enterCtExpression(f); try (Writable _context = context.modify()) { if ((f.getVariable().isStatic() || "class".equals(f.getVariable().getSimpleName())) && f.getTarget() instanceof CtTypeAccess) { _context.ignoreGenerics(true);
try (Writable _context = context.modify()) { if (invocation.getTarget() instanceof CtTypeAccess) { _context.ignoreGenerics(true);