protected Printer space() { return space(true); }
protected Printer modifiersStringPrefix(ModifiableElement e, boolean addSpace) { List<Modifier> modifiers = e.getModifiers(); if (modifiers != null && !modifiers.isEmpty()) { implode(modifiers, " "); if (addSpace) { space(); } } return this; }
public void visitDefine(Define e) { append(indent, "#define ", e.getName()); space(e.getValue() != null).append(e.getValue()); }
public void visitAnnotation(Annotation e) { append("@", e.getAnnotationClass()); boolean first = true; boolean hasDefault = e.getDefaultArgument() != null; boolean hasNamed = !e.getNamedArguments().isEmpty(); if (hasDefault || hasNamed) { append("("); if (hasDefault) { if (hasNamed) append("value = "); append(e.getDefaultArgument()); first = false; } for (Map.Entry<String, Expression> entry : e.getNamedArguments().entrySet()) { if (!first) append(", "); append(entry.getKey(), " = ", entry.getValue()); first = false; } append(")"); } space(); }
protected void valueTypeAndStorageSuffix(StoredDeclarations e) { if (e.getValueType() instanceof FunctionSignature) { FunctionSignature sig = (FunctionSignature) e.getValueType(); if (sig.getFunction() != null) { Identifier name = sig.getFunction().getName(); if (name != null && e.declarators.size() == 1) { String stoName = e.declarators.get(0).resolveName(); if (name.equals(stoName) || stoName == null) { append(sig); return; } } } } append(e.getValueType()).space(!e.getDeclarators().isEmpty()).implode(e.getDeclarators(), ", "); }
public void visitVariablesDeclaration(VariablesDeclaration e) { formatComments(e, false, true, true); if (!e.getAnnotations().isEmpty()) { implode(e.getAnnotations(), "\n" + indent).append("\n", indent); } modifiersStringPrefix(e); valueTypeAndStorageSuffix(e); if (!(e.getParentElement() instanceof Catch)) { append(";"); } if (e.getCommentAfter() != null) { space().append(e.getCommentAfter()); } }
case StaticInit: implode(modifiers, " "); space(!modifiers.isEmpty()); append(e.getBody() == null ? ";" : e.getBody()); break; if (name != null && name.equals("operator") && e.getType() == Function.Type.CppMethod) { append(name); space(); implode(modifiers, " "); space(!modifiers.isEmpty()); append(valueType); } else { implode(modifiers, " "); space(!modifiers.isEmpty()); append(valueType); space(valueType != null); append(name); case ObjCMethod: append(modifiers.contains(ModifierType.Static) ? "+" : "-"); space(); if (valueType != null) { append("(", valueType, ")");
public void visitEnumItem(EnumItem e) { formatComments(e, false, true, true); append(e.getName()); if (!e.getArguments().isEmpty()) { if (e.getType() == Type.C) { append(" = ", e.getArguments().get(0)); } else { append("("); implode(e.getArguments(), ", "); append(")"); } } if (e.getBody() != null) { append(" {\n\t", indent); indent(); implode(e.getBody().getDeclarations(), "\n" + indent); deindent(); append("\n", indent, "}"); } space(e.getCommentAfter() != null).append(e.getCommentAfter()); }
space(e.getTag() != null).append("{\n"); indent(); append(indent);
public void visitDeclarator(Declarator e) { if (e.isParenthesized()) { append('('); } implode(e.getModifiers(), " ").space(!e.getModifiers().isEmpty()); if (e instanceof DirectDeclarator) { append(((DirectDeclarator) e).getName()); } else if (e instanceof PointerDeclarator) { PointerDeclarator d = (PointerDeclarator) e; append(d.getPointerStyle(), d.getTarget()); } else if (e instanceof FunctionDeclarator) { FunctionDeclarator d = (FunctionDeclarator) e; append(d.getTarget(), '(').implode(d.getArgs(), ", ").append(")"); } else if (e instanceof ArrayDeclarator) { ArrayDeclarator d = (ArrayDeclarator) e; append(d.getTarget(), '[').implode(d.getDimensions(), "][").append("]"); } if (e.isParenthesized()) { append(')'); } if (e.getBits() >= 0) { append(":", e.getBits()); } if (e.getDefaultValue() != null) { append(" = ", e.getDefaultValue()); } }
public void visitFunctionSignature(FunctionSignature e) { if (e.getFunction() == null) { return; } assert e.getFunction().getBody() == null; modifiersStringPrefix(e); append(e.getFunction().getValueType()).space(e.getFunction().getValueType() != null); if (e.getParentElement() instanceof TypeRef.Pointer) { append("("); modifiersStringPrefix(e.getFunction()); switch (e.getType()) { case CFunction: append("*"); break; case ObjCBlock: append("^"); break; } append(e.getFunction().getName()); append(")"); } else { append(e.getFunction().getName()); } append("("); implode(e.getFunction().getArgs(), ", "); append(")"); append(e.getModifiers().isEmpty() ? "" : " "); implode(e.getModifiers(), " "); }