Lombok - v0.10.8

lombok.eclipse.handlers
Class EclipseHandlerUtil

java.lang.Object
  extended by lombok.eclipse.handlers.EclipseHandlerUtil

public class EclipseHandlerUtil
extends Object

Container for static utility methods useful to handlers written for eclipse.


Nested Class Summary
static class EclipseHandlerUtil.MemberExistsResult
          Serves as return value for the methods that check for the existence of fields and methods.
 
Method Summary
static boolean annotationTypeMatches(Class<? extends Annotation> type, EclipseNode node)
          Checks if the provided annotation type is likely to be the intended type for the given annotation node.
static EclipseHandlerUtil.MemberExistsResult constructorExists(EclipseNode node)
          Checks if there is a (non-default) constructor.
static org.eclipse.jdt.internal.compiler.ast.Annotation copyAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation annotation, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
           
static org.eclipse.jdt.internal.compiler.ast.Annotation[] copyAnnotations(org.eclipse.jdt.internal.compiler.ast.ASTNode source, org.eclipse.jdt.internal.compiler.ast.Annotation[]... allAnnotations)
           
static org.eclipse.jdt.internal.compiler.ast.TypeReference copyType(org.eclipse.jdt.internal.compiler.ast.TypeReference ref, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          You can't share TypeReference objects or subtle errors start happening.
static org.eclipse.jdt.internal.compiler.ast.TypeParameter[] copyTypeParams(org.eclipse.jdt.internal.compiler.ast.TypeParameter[] params, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          You can't share TypeParameter objects or bad things happen; for example, one 'T' resolves differently from another 'T', even for the same T in a single class file.
static org.eclipse.jdt.internal.compiler.ast.TypeReference[] copyTypes(org.eclipse.jdt.internal.compiler.ast.TypeReference[] refs, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          Convenience method that creates a new array and copies each TypeReference in the source array via copyType(TypeReference, ASTNode).
static
<A extends Annotation>
AnnotationValues<A>
createAnnotation(Class<A> type, EclipseNode annotationNode)
          Provides AnnotationValues with the data it needs to do its thing.
static List<Integer> createListOfNonExistentFields(List<String> list, EclipseNode type, boolean excludeStandard, boolean excludeTransient)
          Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.
static org.eclipse.jdt.internal.compiler.ast.Annotation[] createSuppressWarningsAll(org.eclipse.jdt.internal.compiler.ast.ASTNode source, org.eclipse.jdt.internal.compiler.ast.Annotation[] originalAnnotationArray)
           
static void error(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration cud, String message, String bundleName, Throwable error)
          Generates an error in the Eclipse error log.
static void error(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration cud, String message, Throwable error)
          Generates an error in the Eclipse error log.
static EclipseHandlerUtil.MemberExistsResult fieldExists(String fieldName, EclipseNode node)
          Checks if there is a field with the provided name.
static boolean filterField(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration declaration)
          Checks if the field should be included in operations that work on 'all' fields: If the field is static, or starts with a '$', or is actually an enum constant, 'false' is returned, indicating you should skip it.
static org.eclipse.jdt.internal.compiler.ast.Statement generateNullCheck(org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration variable, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          Generates a new statement that checks if the given variable is null, and if so, throws a NullPointerException with the variable name as message.
static org.eclipse.jdt.internal.compiler.ast.ASTNode getGeneratedBy(org.eclipse.jdt.internal.compiler.ast.ASTNode node)
           
static void injectField(EclipseNode type, org.eclipse.jdt.internal.compiler.ast.FieldDeclaration field)
          Inserts a field into an existing type.
static void injectFieldSuppressWarnings(EclipseNode type, org.eclipse.jdt.internal.compiler.ast.FieldDeclaration field)
          Inserts a field into an existing type.
static void injectMethod(EclipseNode type, org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration method)
          Inserts a method into an existing type.
static boolean isGenerated(org.eclipse.jdt.internal.compiler.ast.ASTNode node)
           
static org.eclipse.jdt.internal.compiler.ast.CastExpression makeCastExpression(org.eclipse.jdt.internal.compiler.ast.Expression ref, org.eclipse.jdt.internal.compiler.ast.TypeReference castTo, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          In eclipse 3.7+, the CastExpression constructor was changed from a really weird version to a less weird one.
static org.eclipse.jdt.internal.compiler.ast.IntLiteral makeIntLiteral(char[] token, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          In eclipse 3.7+, IntLiterals are created using a factory-method Unfortunately that means we need to use reflection as we want to be compatible with eclipse versions before 3.7.
static org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation makeMarkerAnnotation(char[][] name, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
          Create an annotation of the given name, and is marked as being generated by the given source.
static org.eclipse.jdt.internal.compiler.ast.TypeReference makeType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding, org.eclipse.jdt.internal.compiler.ast.ASTNode pos, boolean allowCompound)
           
static EclipseHandlerUtil.MemberExistsResult methodExists(String methodName, EclipseNode node)
          Wrapper for methodExists(String, EclipseNode, boolean) with caseSensitive = true.
static EclipseHandlerUtil.MemberExistsResult methodExists(String methodName, EclipseNode node, boolean caseSensitive)
          Checks if there is a method with the provided name.
static org.eclipse.jdt.internal.compiler.ast.ASTNode setGeneratedBy(org.eclipse.jdt.internal.compiler.ast.ASTNode node, org.eclipse.jdt.internal.compiler.ast.ASTNode source)
           
static int toEclipseModifier(AccessLevel value)
          Turns an AccessLevel instance into the flag bit used by eclipse.
static boolean typeMatches(Class<?> type, EclipseNode node, org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef)
          Checks if the given TypeReference node is likely to be a reference to the provided class.
static void warning(String message, String bundleName, Throwable error)
          Generates a warning in the Eclipse error log.
static void warning(String message, Throwable error)
          Generates a warning in the Eclipse error log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

error

public static void error(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration cud,
                         String message,
                         Throwable error)
Generates an error in the Eclipse error log. Note that most people never look at it!

Parameters:
cud - The CompilationUnitDeclaration where the error occurred. An error will be generated on line 0 linking to the error log entry. Can be null.
message - Human readable description of the problem.
error - The associated exception. Can be null.

error

public static void error(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration cud,
                         String message,
                         String bundleName,
                         Throwable error)
Generates an error in the Eclipse error log. Note that most people never look at it!

Parameters:
cud - The CompilationUnitDeclaration where the error occurred. An error will be generated on line 0 linking to the error log entry. Can be null.
message - Human readable description of the problem.
bundleName - Can be null to default to org.eclipse.jdt.core which is usually right.
error - The associated exception. Can be null.

warning

public static void warning(String message,
                           Throwable error)
Generates a warning in the Eclipse error log. Note that most people never look at it!

Parameters:
message - Human readable description of the problem.
error - The associated exception. Can be null.

warning

public static void warning(String message,
                           String bundleName,
                           Throwable error)
Generates a warning in the Eclipse error log. Note that most people never look at it!

Parameters:
message - Human readable description of the problem.
bundleName - Can be null to default to org.eclipse.jdt.core which is usually right.
error - The associated exception. Can be null.

getGeneratedBy

public static org.eclipse.jdt.internal.compiler.ast.ASTNode getGeneratedBy(org.eclipse.jdt.internal.compiler.ast.ASTNode node)

isGenerated

public static boolean isGenerated(org.eclipse.jdt.internal.compiler.ast.ASTNode node)

setGeneratedBy

public static org.eclipse.jdt.internal.compiler.ast.ASTNode setGeneratedBy(org.eclipse.jdt.internal.compiler.ast.ASTNode node,
                                                                           org.eclipse.jdt.internal.compiler.ast.ASTNode source)

typeMatches

public static boolean typeMatches(Class<?> type,
                                  EclipseNode node,
                                  org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef)
Checks if the given TypeReference node is likely to be a reference to the provided class.

Parameters:
type - An actual type. This method checks if typeNode is likely to be a reference to this type.
node - A Lombok AST node. Any node in the appropriate compilation unit will do (used to get access to import statements).
typeRef - A type reference to check.

copyAnnotation

public static org.eclipse.jdt.internal.compiler.ast.Annotation copyAnnotation(org.eclipse.jdt.internal.compiler.ast.Annotation annotation,
                                                                              org.eclipse.jdt.internal.compiler.ast.ASTNode source)

copyTypeParams

public static org.eclipse.jdt.internal.compiler.ast.TypeParameter[] copyTypeParams(org.eclipse.jdt.internal.compiler.ast.TypeParameter[] params,
                                                                                   org.eclipse.jdt.internal.compiler.ast.ASTNode source)
You can't share TypeParameter objects or bad things happen; for example, one 'T' resolves differently from another 'T', even for the same T in a single class file. Unfortunately the TypeParameter type hierarchy is complicated and there's no clone method on TypeParameter itself. This method can clone them.


copyTypes

public static org.eclipse.jdt.internal.compiler.ast.TypeReference[] copyTypes(org.eclipse.jdt.internal.compiler.ast.TypeReference[] refs,
                                                                              org.eclipse.jdt.internal.compiler.ast.ASTNode source)
Convenience method that creates a new array and copies each TypeReference in the source array via copyType(TypeReference, ASTNode).


copyType

public static org.eclipse.jdt.internal.compiler.ast.TypeReference copyType(org.eclipse.jdt.internal.compiler.ast.TypeReference ref,
                                                                           org.eclipse.jdt.internal.compiler.ast.ASTNode source)
You can't share TypeReference objects or subtle errors start happening. Unfortunately the TypeReference type hierarchy is complicated and there's no clone method on TypeReference itself. This method can clone them.


copyAnnotations

public static org.eclipse.jdt.internal.compiler.ast.Annotation[] copyAnnotations(org.eclipse.jdt.internal.compiler.ast.ASTNode source,
                                                                                 org.eclipse.jdt.internal.compiler.ast.Annotation[]... allAnnotations)

annotationTypeMatches

public static boolean annotationTypeMatches(Class<? extends Annotation> type,
                                            EclipseNode node)
Checks if the provided annotation type is likely to be the intended type for the given annotation node. This is a guess, but a decent one.


makeType

public static org.eclipse.jdt.internal.compiler.ast.TypeReference makeType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding,
                                                                           org.eclipse.jdt.internal.compiler.ast.ASTNode pos,
                                                                           boolean allowCompound)

createAnnotation

public static <A extends Annotation> AnnotationValues<A> createAnnotation(Class<A> type,
                                                                          EclipseNode annotationNode)
Provides AnnotationValues with the data it needs to do its thing.


toEclipseModifier

public static int toEclipseModifier(AccessLevel value)
Turns an AccessLevel instance into the flag bit used by eclipse.


filterField

public static boolean filterField(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration declaration)
Checks if the field should be included in operations that work on 'all' fields: If the field is static, or starts with a '$', or is actually an enum constant, 'false' is returned, indicating you should skip it.


fieldExists

public static EclipseHandlerUtil.MemberExistsResult fieldExists(String fieldName,
                                                                EclipseNode node)
Checks if there is a field with the provided name.

Parameters:
fieldName - the field name to check for.
node - Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.

methodExists

public static EclipseHandlerUtil.MemberExistsResult methodExists(String methodName,
                                                                 EclipseNode node)
Wrapper for methodExists(String, EclipseNode, boolean) with caseSensitive = true.


methodExists

public static EclipseHandlerUtil.MemberExistsResult methodExists(String methodName,
                                                                 EclipseNode node,
                                                                 boolean caseSensitive)
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.

Parameters:
methodName - the method name to check for.
node - Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
caseSensitive - If the search should be case sensitive.

constructorExists

public static EclipseHandlerUtil.MemberExistsResult constructorExists(EclipseNode node)
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.

Parameters:
node - Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.

injectFieldSuppressWarnings

public static void injectFieldSuppressWarnings(EclipseNode type,
                                               org.eclipse.jdt.internal.compiler.ast.FieldDeclaration field)
Inserts a field into an existing type. The type must represent a TypeDeclaration. The field carries the @SuppressWarnings("all") annotation.


injectField

public static void injectField(EclipseNode type,
                               org.eclipse.jdt.internal.compiler.ast.FieldDeclaration field)
Inserts a field into an existing type. The type must represent a TypeDeclaration.


injectMethod

public static void injectMethod(EclipseNode type,
                                org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration method)
Inserts a method into an existing type. The type must represent a TypeDeclaration.


createSuppressWarningsAll

public static org.eclipse.jdt.internal.compiler.ast.Annotation[] createSuppressWarningsAll(org.eclipse.jdt.internal.compiler.ast.ASTNode source,
                                                                                           org.eclipse.jdt.internal.compiler.ast.Annotation[] originalAnnotationArray)

generateNullCheck

public static org.eclipse.jdt.internal.compiler.ast.Statement generateNullCheck(org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration variable,
                                                                                org.eclipse.jdt.internal.compiler.ast.ASTNode source)
Generates a new statement that checks if the given variable is null, and if so, throws a NullPointerException with the variable name as message.


makeMarkerAnnotation

public static org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation makeMarkerAnnotation(char[][] name,
                                                                                          org.eclipse.jdt.internal.compiler.ast.ASTNode source)
Create an annotation of the given name, and is marked as being generated by the given source.


createListOfNonExistentFields

public static List<Integer> createListOfNonExistentFields(List<String> list,
                                                          EclipseNode type,
                                                          boolean excludeStandard,
                                                          boolean excludeTransient)
Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.


makeCastExpression

public static org.eclipse.jdt.internal.compiler.ast.CastExpression makeCastExpression(org.eclipse.jdt.internal.compiler.ast.Expression ref,
                                                                                      org.eclipse.jdt.internal.compiler.ast.TypeReference castTo,
                                                                                      org.eclipse.jdt.internal.compiler.ast.ASTNode source)
In eclipse 3.7+, the CastExpression constructor was changed from a really weird version to a less weird one. Unfortunately that means we need to use reflection as we want to be compatible with eclipse versions before 3.7 and 3.7+.

Parameters:
ref - The foo in (String)foo.
castTo - The String in (String)foo.

makeIntLiteral

public static org.eclipse.jdt.internal.compiler.ast.IntLiteral makeIntLiteral(char[] token,
                                                                              org.eclipse.jdt.internal.compiler.ast.ASTNode source)
In eclipse 3.7+, IntLiterals are created using a factory-method Unfortunately that means we need to use reflection as we want to be compatible with eclipse versions before 3.7.


Lombok - v0.10.8

Copyright © 2009-2011 The Project Lombok Authors, licensed under the MIT licence.