aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-06 05:48:42 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-06 05:48:42 +0200
commit527b992a074c1c65727bc52c820d40340f074a6b (patch)
treedc18cc09150e6a0138737f30be36b2231b2178c2 /src/lombok/javac/handlers
parent8d4c5369ee7eff4020e892c7ca283ea0b1073638 (diff)
downloadlombok-527b992a074c1c65727bc52c820d40340f074a6b.tar.gz
lombok-527b992a074c1c65727bc52c820d40340f074a6b.tar.bz2
lombok-527b992a074c1c65727bc52c820d40340f074a6b.zip
Last massive documentation dump. All basic javadoc is now done, though especially the docs
on the lombok annotations in the lombok package need far more massaging. Also added a feature to HandleSynchronized to not auto-generate the locker fields if a specific name is provided (because, imagine you typoed those. You'd never find it!)
Diffstat (limited to 'src/lombok/javac/handlers')
-rw-r--r--src/lombok/javac/handlers/HandleCleanup.java24
-rw-r--r--src/lombok/javac/handlers/HandleData.java24
-rw-r--r--src/lombok/javac/handlers/HandleGetter.java36
-rw-r--r--src/lombok/javac/handlers/HandlePrintAST.java24
-rw-r--r--src/lombok/javac/handlers/HandleSetter.java36
-rw-r--r--src/lombok/javac/handlers/HandleSneakyThrows.java24
-rw-r--r--src/lombok/javac/handlers/HandleSynchronized.java34
-rw-r--r--src/lombok/javac/handlers/PKG.java80
8 files changed, 280 insertions, 2 deletions
diff --git a/src/lombok/javac/handlers/HandleCleanup.java b/src/lombok/javac/handlers/HandleCleanup.java
index 39f2c242..04ed2ed6 100644
--- a/src/lombok/javac/handlers/HandleCleanup.java
+++ b/src/lombok/javac/handlers/HandleCleanup.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import lombok.Cleanup;
@@ -26,6 +47,9 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
+/**
+ * Handles the <code>lombok.Cleanup</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
@Override public boolean handle(AnnotationValues<Cleanup> annotation, JCAnnotation ast, Node annotationNode) {
diff --git a/src/lombok/javac/handlers/HandleData.java b/src/lombok/javac/handlers/HandleData.java
index 5da08759..d3974c58 100644
--- a/src/lombok/javac/handlers/HandleData.java
+++ b/src/lombok/javac/handlers/HandleData.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import java.lang.reflect.Modifier;
@@ -37,6 +58,9 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
+/**
+ * Handles the <code>lombok.Data</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleData implements JavacAnnotationHandler<Data> {
@Override public boolean handle(AnnotationValues<Data> annotation, JCAnnotation ast, Node annotationNode) {
diff --git a/src/lombok/javac/handlers/HandleGetter.java b/src/lombok/javac/handlers/HandleGetter.java
index f66247ff..18e02a58 100644
--- a/src/lombok/javac/handlers/HandleGetter.java
+++ b/src/lombok/javac/handlers/HandleGetter.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import static lombok.javac.handlers.PKG.*;
@@ -24,8 +45,23 @@ import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
+/**
+ * Handles the <code>lombok.Getter</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleGetter implements JavacAnnotationHandler<Getter> {
+ /**
+ * Generates a getter on the stated field.
+ *
+ * Used by {@link HandleData}.
+ *
+ * The difference between this call and the handle method is as follows:
+ *
+ * If there is a <code>lombok.Getter</code> annotation on the field, it is used and the
+ * same rules apply (e.g. warning if the method already exists, stated access level applies).
+ * If not, the getter is still generated if it isn't already there, though there will not
+ * be a warning if its already there. The default access level is used.
+ */
public void generateGetterForField(Node fieldNode, DiagnosticPosition pos) {
AccessLevel level = AccessLevel.PUBLIC;
Node errorNode = fieldNode;
diff --git a/src/lombok/javac/handlers/HandlePrintAST.java b/src/lombok/javac/handlers/HandlePrintAST.java
index f2009c71..aa7b0ab9 100644
--- a/src/lombok/javac/handlers/HandlePrintAST.java
+++ b/src/lombok/javac/handlers/HandlePrintAST.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import java.io.File;
@@ -15,6 +36,9 @@ import lombok.javac.JavacASTVisitor;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacAST.Node;
+/**
+ * Handles the <code>lombok.core.PrintAST</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandlePrintAST implements JavacAnnotationHandler<PrintAST> {
@Override public boolean handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, Node annotationNode) {
diff --git a/src/lombok/javac/handlers/HandleSetter.java b/src/lombok/javac/handlers/HandleSetter.java
index 2b766db1..817d3011 100644
--- a/src/lombok/javac/handlers/HandleSetter.java
+++ b/src/lombok/javac/handlers/HandleSetter.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import static lombok.javac.handlers.PKG.*;
@@ -27,8 +48,23 @@ import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
+/**
+ * Handles the <code>lombok.Setter</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleSetter implements JavacAnnotationHandler<Setter> {
+ /**
+ * Generates a setter on the stated field.
+ *
+ * Used by {@link HandleData}.
+ *
+ * The difference between this call and the handle method is as follows:
+ *
+ * If there is a <code>lombok.Setter</code> annotation on the field, it is used and the
+ * same rules apply (e.g. warning if the method already exists, stated access level applies).
+ * If not, the setter is still generated if it isn't already there, though there will not
+ * be a warning if its already there. The default access level is used.
+ */
public void generateSetterForField(Node fieldNode, DiagnosticPosition pos) {
AccessLevel level = AccessLevel.PUBLIC;
Node errorNode = fieldNode;
diff --git a/src/lombok/javac/handlers/HandleSneakyThrows.java b/src/lombok/javac/handlers/HandleSneakyThrows.java
index b21468ee..4a4ab09b 100644
--- a/src/lombok/javac/handlers/HandleSneakyThrows.java
+++ b/src/lombok/javac/handlers/HandleSneakyThrows.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import static lombok.javac.handlers.PKG.chainDots;
@@ -24,6 +45,9 @@ import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
+/**
+ * Handles the <code>lombok.SneakyThrows</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleSneakyThrows implements JavacAnnotationHandler<SneakyThrows> {
@Override public boolean handle(AnnotationValues<SneakyThrows> annotation, JCAnnotation ast, Node annotationNode) {
diff --git a/src/lombok/javac/handlers/HandleSynchronized.java b/src/lombok/javac/handlers/HandleSynchronized.java
index 84508171..efc6daf0 100644
--- a/src/lombok/javac/handlers/HandleSynchronized.java
+++ b/src/lombok/javac/handlers/HandleSynchronized.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import static lombok.javac.handlers.PKG.*;
@@ -21,6 +42,9 @@ import lombok.core.AST.Kind;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacAST.Node;
+/**
+ * Handles the <code>lombok.Synchronized</code> annotation for javac.
+ */
@ProviderFor(JavacAnnotationHandler.class)
public class HandleSynchronized implements JavacAnnotationHandler<Synchronized> {
private static final String INSTANCE_LOCK_NAME = "$lock";
@@ -42,11 +66,19 @@ public class HandleSynchronized implements JavacAnnotationHandler<Synchronized>
}
boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
String lockName = annotation.getInstance().value();
- if ( lockName.length() == 0 ) lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ boolean autoMake = false;
+ if ( lockName.length() == 0 ) {
+ autoMake = true;
+ lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ }
TreeMaker maker = methodNode.getTreeMaker();
if ( fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS ) {
+ if ( !autoMake ) {
+ annotationNode.addError("The field " + new String(lockName) + " does not exist.");
+ return true;
+ }
JCExpression objectType = chainDots(maker, methodNode, "java", "lang", "Object");
//We use 'new Object[0];' because quite unlike 'new Object();', empty arrays *ARE* serializable!
JCNewArray newObjectArray = maker.NewArray(chainDots(maker, methodNode, "java", "lang", "Object"),
diff --git a/src/lombok/javac/handlers/PKG.java b/src/lombok/javac/handlers/PKG.java
index b7a02985..ef6b3eba 100644
--- a/src/lombok/javac/handlers/PKG.java
+++ b/src/lombok/javac/handlers/PKG.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.javac.handlers;
import java.lang.reflect.Modifier;
@@ -16,9 +37,17 @@ import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.javac.JavacAST;
+/**
+ * Container for static utility methods relevant to this package.
+ */
class PKG {
- private PKG() {}
+ private PKG() {
+ //Prevent instantiation
+ }
+ /**
+ * @return the likely getter name for the stated field. (e.g. private boolean foo; to isFoo).
+ */
static String toGetterName(JCVariableDecl field) {
CharSequence fieldName = field.name;
@@ -27,16 +56,26 @@ class PKG {
return TransformationsUtil.toGetterName(fieldName, isBoolean);
}
+ /**
+ * @return the likely setter name for the stated field. (e.g. private boolean foo; to setFoo).
+ */
static String toSetterName(JCVariableDecl field) {
CharSequence fieldName = field.name;
return TransformationsUtil.toSetterName(fieldName);
}
+ /** Serves as return value for the methods that check for the existence of fields and methods. */
enum MemberExistsResult {
NOT_EXISTS, EXISTS_BY_USER, EXISTS_BY_LOMBOK;
}
+ /**
+ * Checks if there is a field with the provided name.
+ *
+ * @param fieldName the field name to check for.
+ * @param node Any node that represents the Type (JCClassDecl) to check for, or any child node thereof.
+ */
static MemberExistsResult fieldExists(String fieldName, JavacAST.Node node) {
while ( node != null && !(node.get() instanceof JCClassDecl) ) {
node = node.up();
@@ -57,6 +96,13 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
+ /**
+ * Checks if there is a method with the provided name. In case of multiple methods (overloading), only
+ * the first method decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
+ *
+ * @param methodName the method name to check for.
+ * @param node Any node that represents the Type (JCClassDecl) to check for, or any child node thereof.
+ */
static MemberExistsResult methodExists(String methodName, JavacAST.Node node) {
while ( node != null && !(node.get() instanceof JCClassDecl) ) {
node = node.up();
@@ -77,6 +123,12 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
+ /**
+ * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
+ * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
+ *
+ * @param node Any node that represents the Type (JCClassDecl) to check for, or any child node thereof.
+ */
static MemberExistsResult constructorExists(JavacAST.Node node) {
while ( node != null && !(node.get() instanceof JCClassDecl) ) {
node = node.up();
@@ -98,6 +150,11 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
+ /**
+ * Turns an <code>AccessLevel<code> instance into the flag bit used by javac.
+ *
+ * @see java.lang.Modifier
+ */
static int toJavacModifier(AccessLevel accessLevel) {
switch ( accessLevel ) {
case MODULE:
@@ -113,6 +170,11 @@ class PKG {
}
}
+ /**
+ * Adds the given new field declaration to the provided type AST Node.
+ *
+ * Also takes care of updating the JavacAST.
+ */
static void injectField(JavacAST.Node typeNode, JCVariableDecl field) {
JCClassDecl type = (JCClassDecl) typeNode.get();
@@ -121,6 +183,12 @@ class PKG {
typeNode.add(field, Kind.FIELD).recursiveSetHandled();
}
+ /**
+ * Adds the given new method declaration to the provided type AST Node.
+ * Can also inject constructors.
+ *
+ * Also takes care of updating the JavacAST.
+ */
static void injectMethod(JavacAST.Node typeNode, JCMethodDecl method) {
JCClassDecl type = (JCClassDecl) typeNode.get();
@@ -154,6 +222,16 @@ class PKG {
return out;
}
+ /**
+ * In javac, dotted access of any kind, from <code>java.lang.String</code> to <code>var.methodName</code>
+ * is represented by a fold-left of <code>Select</code> nodes with the leftmost string represented by
+ * a <code>Ident</code> node. This method generates such an expression.
+ *
+ * For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).
+ *
+ * @see com.sun.tools.javac.tree.JCTree.JCIdent
+ * @see com.sun.tools.javac.tree.JCTree.JCFieldAccess
+ */
static JCExpression chainDots(TreeMaker maker, JavacAST.Node node, String... elems) {
assert elems != null;
assert elems.length > 0;