use of spoon.reflect.visitor.PrintingContext.Writable in project spoon by INRIA.
the class DefaultJavaPrettyPrinter method visitCtFieldReference.
@Override
public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
boolean isStatic = reference.getSimpleName().equals("class") || !reference.getSimpleName().equals("super") && 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 (reference.getSimpleName().equals("class")) {
printer.writeKeyword("class");
} else {
printer.writeIdentifier(reference.getSimpleName());
}
}
use of spoon.reflect.visitor.PrintingContext.Writable in project spoon by INRIA.
the class ElementPrinterHelper method writeAnnotationElement.
/**
* Writes an annotation element.
*/
public void writeAnnotationElement(Factory factory, Object value) {
if (value instanceof CtTypeAccess) {
prettyPrinter.scan((CtTypeAccess) value);
printer.writeSeparator(".").writeKeyword("class");
} else if (value instanceof CtFieldReference) {
prettyPrinter.scan(((CtFieldReference<?>) value).getDeclaringType());
printer.writeSeparator(".").writeIdentifier(((CtFieldReference<?>) value).getSimpleName());
} else if (value instanceof CtElement) {
prettyPrinter.scan((CtElement) value);
} else if (value instanceof String) {
printer.writeLiteral("\"" + LiteralHelper.getStringLiteral((String) value, true) + "\"");
} else if (value instanceof Collection) {
try (ListPrinter lp = createListPrinter(false, "{", false, true, ",", false, false, "}")) {
for (Object obj : (Collection<?>) value) {
lp.printSeparatorIfAppropriate();
writeAnnotationElement(factory, obj);
}
}
} else if (value instanceof Object[]) {
try (ListPrinter lp = createListPrinter(false, "{", false, true, ",", false, false, "}")) {
for (Object obj : (Object[]) value) {
lp.printSeparatorIfAppropriate();
writeAnnotationElement(factory, obj);
}
}
} else if (value instanceof Enum) {
try (Writable c = prettyPrinter.getContext().modify().ignoreGenerics(true)) {
prettyPrinter.scan(factory.Type().createReference(((Enum<?>) value).getDeclaringClass()));
}
printer.writeSeparator(".");
printer.writeIdentifier(value.toString());
} else {
// it probably prints, boolean, number, ...
printer.writeLiteral(value.toString());
}
}
Aggregations