use of lombok.ToString in project lombok by rzwitserloot.
the class HandleToString method generateToString.
public void generateToString(JavacNode typeNode, JavacNode source, List<String> excludes, List<String> includes, boolean includeFieldNames, Boolean callSuper, boolean whineIfExists, FieldAccess fieldAccess) {
boolean notAClass = true;
if (typeNode.get() instanceof JCClassDecl) {
long flags = ((JCClassDecl) typeNode.get()).mods.flags;
notAClass = (flags & (Flags.INTERFACE | Flags.ANNOTATION)) != 0;
}
if (callSuper == null) {
try {
callSuper = ((Boolean) ToString.class.getMethod("callSuper").getDefaultValue()).booleanValue();
} catch (Exception ignore) {
}
}
if (notAClass) {
source.addError("@ToString is only supported on a class or enum.");
return;
}
ListBuffer<JavacNode> nodesForToString = new ListBuffer<JavacNode>();
if (includes != null) {
for (JavacNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD)
continue;
JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
if (includes.contains(fieldDecl.name.toString()))
nodesForToString.append(child);
}
} else {
for (JavacNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD)
continue;
JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
// Skip static fields.
if ((fieldDecl.mods.flags & Flags.STATIC) != 0)
continue;
// Skip excluded fields.
if (excludes != null && excludes.contains(fieldDecl.name.toString()))
continue;
// Skip fields that start with $.
if (fieldDecl.name.toString().startsWith("$"))
continue;
nodesForToString.append(child);
}
}
switch(methodExists("toString", typeNode, 0)) {
case NOT_EXISTS:
JCMethodDecl method = createToString(typeNode, nodesForToString.toList(), includeFieldNames, callSuper, fieldAccess, source.get());
injectMethod(typeNode, method);
break;
case EXISTS_BY_LOMBOK:
break;
default:
case EXISTS_BY_USER:
if (whineIfExists) {
source.addWarning("Not generating toString(): A method with that name already exists");
}
break;
}
}
use of lombok.ToString in project lombok by rzwitserloot.
the class HandleToString method generateToString.
public void generateToString(EclipseNode typeNode, EclipseNode errorNode, List<String> excludes, List<String> includes, boolean includeFieldNames, Boolean callSuper, boolean whineIfExists, FieldAccess fieldAccess) {
TypeDeclaration typeDecl = null;
if (typeNode.get() instanceof TypeDeclaration)
typeDecl = (TypeDeclaration) typeNode.get();
int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0;
if (typeDecl == null || notAClass) {
errorNode.addError("@ToString is only supported on a class or enum.");
}
if (callSuper == null) {
try {
callSuper = ((Boolean) ToString.class.getMethod("callSuper").getDefaultValue()).booleanValue();
} catch (Exception ignore) {
}
}
List<EclipseNode> nodesForToString = new ArrayList<EclipseNode>();
if (includes != null) {
for (EclipseNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD)
continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
if (includes.contains(new String(fieldDecl.name)))
nodesForToString.add(child);
}
} else {
for (EclipseNode child : typeNode.down()) {
if (child.getKind() != Kind.FIELD)
continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
if (!filterField(fieldDecl))
continue;
// Skip excluded fields.
if (excludes != null && excludes.contains(new String(fieldDecl.name)))
continue;
nodesForToString.add(child);
}
}
switch(methodExists("toString", typeNode, 0)) {
case NOT_EXISTS:
MethodDeclaration toString = createToString(typeNode, nodesForToString, includeFieldNames, callSuper, errorNode.get(), fieldAccess);
injectMethod(typeNode, toString);
break;
case EXISTS_BY_LOMBOK:
break;
default:
case EXISTS_BY_USER:
if (whineIfExists) {
errorNode.addWarning("Not generating toString(): A method with that name already exists");
}
}
}
use of lombok.ToString in project incubator-gobblin by apache.
the class MySqlBufferedInserter method createPrepareStatementStr.
@Override
protected String createPrepareStatementStr(int batchSize) {
final String VALUE_FORMAT = "(%s)";
StringBuilder sb = new StringBuilder(this.insertStmtPrefix);
String values = String.format(VALUE_FORMAT, JOINER_ON_COMMA.useForNull("?").join(new String[this.columnNames.size()]));
sb.append(values);
for (int i = 1; i < batchSize; i++) {
sb.append(',').append(values);
}
return sb.append(';').toString();
}
use of lombok.ToString in project incubator-gobblin by apache.
the class TeradataBufferedInserter method createPrepareStatementStr.
@Override
protected String createPrepareStatementStr(int batchSize) {
final String VALUE_FORMAT = "(%s)";
StringBuilder sb = new StringBuilder(this.insertStmtPrefix);
String values = String.format(VALUE_FORMAT, JOINER_ON_COMMA.useForNull("?").join(new String[this.columnNames.size()]));
sb.append(values);
return sb.append(';').toString();
}
use of lombok.ToString in project jcabi-github by jcabi.
the class MkIssueEvents method create.
/**
* Creates a new issue event.
* This has no equivalent in GitHub's public API, since GitHub generates
* events automatically in response to some other API calls.
* @param type Type of event
* @param issue ID number of issue the event is regarding
* @param login Username of actor who caused the event
* @param label Label added or removed
* @return The newly created issue event
* @throws IOException If there is any I/O problem
* @todo #1063:30min Make it possible to set the "assignee" field for
* "assigned"/"unassigned" events. Make it possible to set the
* "milestone" field for "milestoned"/"demilestoned" events. Make it
* possible to set the "rename" field for "renamed" events. Make it
* possible to set the "commit_id" field for events related to commits.
* See https://developer.github.com/v3/issues/events/ for details.
* @checkstyle ParameterNumberCheck (4 lines)
*/
public Event create(final String type, final int issue, final String login, final Optional<String> label) throws IOException {
final String created = new Github.Time().toString();
this.storage.lock();
final int number;
try {
number = 1 + this.storage.xml().xpath(String.format("%s/issue-event/number/text()", this.xpath())).size();
Directives directives = new Directives().xpath(this.xpath()).add("issue-event").add("issue").set(Integer.toString(issue)).up().add("number").set(Integer.toString(number)).up().add("event").set(type).up().add("created_at").set(created).up().add("login").set(login).up();
if (label.isPresent()) {
directives = directives.add("label").set(label.get()).up();
}
this.storage.apply(directives);
} finally {
this.storage.unlock();
}
Logger.info(MkEvent.class, "issue event #%d of type %s created in %s for issue #%d by %s", number, type, this.self, issue, login);
return this.get(number);
}
Aggregations