aboutsummaryrefslogtreecommitdiff
path: root/javaparser-core/src/main
diff options
context:
space:
mode:
authorlucamolteni <volothamp@gmail.com>2017-09-28 14:26:18 +0200
committerlucamolteni <volothamp@gmail.com>2017-09-28 14:26:18 +0200
commit63281f2730e8af78f2630d0d42f6e7158c3c554b (patch)
tree27be077f83fedd53260aa2cb3dba0c901bdd71f3 /javaparser-core/src/main
parentb6d023198354d6f758d175a0f99dc55e676fe6bf (diff)
downloadjavaparser-63281f2730e8af78f2630d0d42f6e7158c3c554b.tar.gz
Create new overload of NodeWithMembers::addField to allow user to create a field with an initializer expression
Diffstat (limited to 'javaparser-core/src/main')
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java
index e51c8adbf..6db806a99 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java
@@ -25,6 +25,7 @@ import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.ast.type.VoidType;
@@ -112,6 +113,21 @@ public interface NodeWithMembers<N extends Node> {
}
/**
+ * Add a field to this
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @param initializer the initializer of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addField(Type type, String name, Expression initializer, Modifier... modifiers) {
+ FieldDeclaration declaration = addField(type, name, modifiers);
+ declaration.getVariables().iterator().next().setInitializer(initializer);
+ return declaration;
+ }
+
+ /**
* Add a private field to this
*
* @param typeClass the type of the field