public final class ExternalAnnotationUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ExternalAnnotationUtil.MergeStrategy
Strategy for merging a new signature with an existing (possibly annotated) signature.
|
Modifier and Type | Field and Description |
---|---|
static char |
NO_ANNOTATION
Represents absence of a null annotation.
|
static char |
NONNULL
Representation of a 'nonnull' annotation, independent of the concrete annotation name used in Java sources.
|
static char |
NULLABLE
Representation of a 'nullable' annotation, independent of the concrete annotation name used in Java sources.
|
Constructor and Description |
---|
ExternalAnnotationUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
annotateMember(String typeName,
IFile file,
String selector,
String originalSignature,
String annotatedSignature,
ExternalAnnotationUtil.MergeStrategy mergeStrategy,
IProgressMonitor monitor)
Update the given external annotation file with details regarding annotations of one specific method or field.
|
static void |
annotateMethodParameterType(String typeName,
IFile file,
String selector,
String originalSignature,
String annotatedParameterType,
int paramIdx,
ExternalAnnotationUtil.MergeStrategy mergeStrategy,
IProgressMonitor monitor)
Update the given external annotation file with details regarding annotations of a parameter type of a given method.
|
static void |
annotateMethodReturnType(String typeName,
IFile file,
String selector,
String originalSignature,
String annotatedReturnType,
ExternalAnnotationUtil.MergeStrategy mergeStrategy,
IProgressMonitor monitor)
Update the given external annotation file with details regarding annotations of the return type of a given method.
|
static String[] |
annotateParameterType(String originalSignature,
String annotatedType,
int paramIdx,
ExternalAnnotationUtil.MergeStrategy mergeStrategy)
Apply the specified changes on a parameter within the given signature.
|
static String[] |
annotateReturnType(String originalSignature,
String annotatedType,
ExternalAnnotationUtil.MergeStrategy mergeStrategy)
Apply the specified changes on the return type of the given signature.
|
static String[] |
annotateType(String originalSignature,
String annotatedType,
ExternalAnnotationUtil.MergeStrategy mergeStrategy)
Apply the specified changes on the given type.
|
static String |
extractGenericSignature(IMethodBinding methodBinding)
Answer the give method's signature in class file format.
|
static String |
extractGenericTypeSignature(ITypeBinding type)
Answer the given types's signature in class file format.
|
static String |
getAnnotatedSignature(String typeName,
IFile file,
String selector,
String originalSignature)
Retrieve the annotated signature of a specified member as found in the given external annotation file, if any.
|
static IFile |
getAnnotationFile(IJavaProject project,
ITypeBinding type,
IProgressMonitor monitor)
Answer the external annotation file corresponding to the given type as seen from the given project.
|
static String |
insertParameterAnnotation(String methodSignature,
int paramIdx,
char annotation,
ExternalAnnotationUtil.MergeStrategy mergeStrategy)
Insert an encoded annotation into the given methodSignature affecting one of its parameters.
|
static String |
insertReturnAnnotation(String methodSignature,
char annotation,
ExternalAnnotationUtil.MergeStrategy mergeStrategy)
Insert an encoded annotation into the given methodSignature affecting its return type.
|
public static final char NULLABLE
public static final char NONNULL
public static final char NO_ANNOTATION
public static String extractGenericSignature(IMethodBinding methodBinding)
methodBinding
- binding representing a methodpublic static String extractGenericTypeSignature(ITypeBinding type)
type
- binding representing a typepublic static String insertReturnAnnotation(String methodSignature, char annotation, ExternalAnnotationUtil.MergeStrategy mergeStrategy)
This method is suitable for declaration annotations.
methodSignature
- a method signature in class file formatannotation
- one of NULLABLE
and NONNULL
.mergeStrategy
- when passing ExternalAnnotationUtil.MergeStrategy.ADD_ANNOTATIONS
this method will
refuse to overwrite any existing annotation in the specified locationIllegalArgumentException
- if the method signature is malformed or its return type is not a reference type.public static String insertParameterAnnotation(String methodSignature, int paramIdx, char annotation, ExternalAnnotationUtil.MergeStrategy mergeStrategy)
This method is suitable for declaration annotations.
methodSignature
- a method signature in class file formatparamIdx
- 0-based index of the parameter to which the annotation should be attachedannotation
- one of NULLABLE
and NONNULL
.mergeStrategy
- when passing ExternalAnnotationUtil.MergeStrategy.ADD_ANNOTATIONS
this method will
refuse to overwrite any existing annotation in the specified locationIllegalArgumentException
- if the method signature is malformed or its specified parameter type is not a reference type.public static IFile getAnnotationFile(IJavaProject project, ITypeBinding type, IProgressMonitor monitor) throws CoreException
project
- current project that references the given type from a jar file.type
- the type for which external annotations are soughtmonitor
- progress monitor to be passed through into file operationsCoreException
- Signals a problem in accessing any of the relevant elements: the project, the type,
the containing jar file and finally the sought annotation file.public static void annotateMember(String typeName, IFile file, String selector, String originalSignature, String annotatedSignature, ExternalAnnotationUtil.MergeStrategy mergeStrategy, IProgressMonitor monitor) throws CoreException, IOException
This method is suitable for declaration annotations and type use annotations.
typeName
- binary name (slash separated) of the type being annotatedfile
- a file assumed to be in .eea format, will be created if it doesn't exist.selector
- selector of the method or fieldoriginalSignature
- unannotated signature of the member, used for identificationannotatedSignature
- new signatures whose annotations should be superimposed on the membermergeStrategy
- controls how old and new signatures should be mergedmonitor
- progress monitor to be passed through into file operations, or null if no reporting is desiredCoreException
- if access to the file failsIOException
- if reading file content failspublic static void annotateMethodReturnType(String typeName, IFile file, String selector, String originalSignature, String annotatedReturnType, ExternalAnnotationUtil.MergeStrategy mergeStrategy, IProgressMonitor monitor) throws CoreException, IOException, IllegalArgumentException
This method is suitable for declaration annotations and type use annotations.
typeName
- binary name (slash separated) of the type being annotatedfile
- a file assumed to be in .eea format, will be created if it doesn't exist.selector
- selector of the methodoriginalSignature
- unannotated signature of the member, used for identificationannotatedReturnType
- signature of the new return type whose annotations should be superimposed on the methodmergeStrategy
- controls how old and new signatures should be mergedmonitor
- progress monitor to be passed through into file operations, or null if no reporting is desiredCoreException
- if access to the file failsIOException
- if reading file content failsIllegalArgumentException
- if the annotatedReturnType does not structurally match to originalSignaturepublic static void annotateMethodParameterType(String typeName, IFile file, String selector, String originalSignature, String annotatedParameterType, int paramIdx, ExternalAnnotationUtil.MergeStrategy mergeStrategy, IProgressMonitor monitor) throws CoreException, IOException, IllegalArgumentException
This method is suitable for declaration annotations and type use annotations.
typeName
- binary name (slash separated) of the type being annotatedfile
- a file assumed to be in .eea format, will be created if it doesn't exist.selector
- selector of the methodoriginalSignature
- unannotated signature of the member, used for identificationannotatedParameterType
- signature of the new parameter type whose annotations should be superimposed on the methodparamIdx
- 0-based index of the parameter to which the annotation should be attachedmergeStrategy
- controls how old and new signatures should be mergedmonitor
- progress monitor to be passed through into file operations, or null if no reporting is desiredCoreException
- if access to the file failsIOException
- if reading file content failsIllegalArgumentException
- if the annotatedParameterType does not structurally match to originalSignaturepublic static String getAnnotatedSignature(String typeName, IFile file, String selector, String originalSignature)
typeName
- fully qualified slash-separated name of the type for which the file defines external annotationsfile
- a file assumed to be in .eea format, must not be null, but may not existselector
- name of the member whose annotation we are looking fororiginalSignature
- the unannotated signature by which the member is identifiedpublic static String[] annotateType(String originalSignature, String annotatedType, ExternalAnnotationUtil.MergeStrategy mergeStrategy)
originalSignature
- the original type signature, may be annotated alreadyannotatedType
- a type signature with additional annotations (incl. NO_ANNOTATION
).mergeStrategy
- controls how old and new signatures should be mergedpublic static String[] annotateReturnType(String originalSignature, String annotatedType, ExternalAnnotationUtil.MergeStrategy mergeStrategy)
originalSignature
- the original full signature, may be annotated alreadyannotatedType
- a type signature with additional annotations (incl. NO_ANNOTATION
).mergeStrategy
- controls how old and new signatures should be mergedpublic static String[] annotateParameterType(String originalSignature, String annotatedType, int paramIdx, ExternalAnnotationUtil.MergeStrategy mergeStrategy)
originalSignature
- the original full signature, may be annotated alreadyannotatedType
- a type signature with additional annotations (incl. NO_ANNOTATION
).paramIdx
- the index of a parameter to annotatedmergeStrategy
- controls how old and new signatures should be merged
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.