Class AnnotationFileParser
- java.lang.Object
-
- org.checkerframework.framework.stub.AnnotationFileParser
-
public class AnnotationFileParser extends java.lang.Object
This class has three static methods. Each method parses an annotation file and adds annotations to theAnnotationFileParser.AnnotationFileAnnotations
passed as an argument.The first main entry point is
parseStubFile(String, InputStream, AnnotatedTypeFactory, ProcessingEnvironment, AnnotationFileAnnotations, AnnotationFileUtil.AnnotationFileType, AnnotationFileElementTypes)
, which side-effects its last argument. It operates in two steps. First, it calls the Annotation File Parser to parse an annotation file. Then, it walks the AST to create/collect types and declaration annotations.The second main entry point is
parseAjavaFile(String, InputStream, CompilationUnitTree, AnnotatedTypeFactory, ProcessingEnvironment, AnnotationFileAnnotations, AnnotationFileElementTypes)
. This behaves the same asparseStubFile(String, InputStream, AnnotatedTypeFactory, ProcessingEnvironment, AnnotationFileAnnotations, AnnotationFileUtil.AnnotationFileType, AnnotationFileElementTypes)
, but takes an ajava file instead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AnnotationFileParser.AnnotationFileAnnotations
The result of calling AnnotationFileParser.parse: the annotated types and declaration annotations from the file.static class
AnnotationFileParser.AnnotationFileParserException
An exception indicating a problem while parsing an annotation file.static class
AnnotationFileParser.RecordComponentStub
Information about a record component: its type, and whether there was an accessor in the stubs for that component.static class
AnnotationFileParser.RecordStub
Information about a record from a stub file.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement>
annosInPackage(javax.lang.model.element.PackageElement packageElement)
All annotations defined in the package (but not those nested within classes in the package).static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement>
annosInType(javax.lang.model.element.TypeElement typeElement)
All annotations declared (directly) within a class.static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement>
createNameToAnnotationMap(java.util.List<javax.lang.model.element.TypeElement> typeElements)
All annotations declared within any of the given elements.static void
parseAjavaFile(java.lang.String filename, java.io.InputStream inputStream, com.sun.source.tree.CompilationUnitTree root, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations ajavaAnnos, AnnotationFileElementTypes fileElementTypes)
The main entry point when parsing an ajava file.static void
parseJdkFileAsStub(java.lang.String filename, java.io.InputStream inputStream, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations stubAnnos, AnnotationFileElementTypes fileElementTypes)
Parse a stub file that is a part of the annotated JDK and side-effects thestubAnnos
argument.static void
parseStubFile(java.lang.String filename, java.io.InputStream inputStream, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations annotationFileAnnos, AnnotationFileUtil.AnnotationFileType fileType, AnnotationFileElementTypes fileElementTypes)
The main entry point.static <K,V>
voidputAllNew(java.util.Map<K,V> m, java.util.Map<K,V> m2)
Just like Map.putAll, but modifies existing values usingputIfAbsent(Map, Object, Object)
.static <K,V>
voidputIfAbsent(java.util.Map<K,V> m, K key, V value)
Just like Map.put, but does not override any existing value in the map.
-
-
-
Method Detail
-
annosInPackage
public static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement> annosInPackage(javax.lang.model.element.PackageElement packageElement)
All annotations defined in the package (but not those nested within classes in the package). Keys are both fully-qualified and simple names.- Parameters:
packageElement
- a package- Returns:
- a map from annotation name to TypeElement
-
annosInType
public static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement> annosInType(javax.lang.model.element.TypeElement typeElement)
All annotations declared (directly) within a class. Keys are both fully-qualified and simple names.- Parameters:
typeElement
- a type- Returns:
- a map from annotation name to TypeElement
-
createNameToAnnotationMap
public static java.util.Map<java.lang.String,javax.lang.model.element.TypeElement> createNameToAnnotationMap(java.util.List<javax.lang.model.element.TypeElement> typeElements)
All annotations declared within any of the given elements.- Parameters:
typeElements
- the elements whose annotations to retrieve- Returns:
- a map from annotation names (both fully-qualified and simple names) to TypeElement
-
parseStubFile
public static void parseStubFile(java.lang.String filename, java.io.InputStream inputStream, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations annotationFileAnnos, AnnotationFileUtil.AnnotationFileType fileType, AnnotationFileElementTypes fileElementTypes)
The main entry point. Parse a stub file and side-effects theannotationFileAnnos
argument.- Parameters:
filename
- name of stub file, used only for diagnostic messagesinputStream
- of stub file to parseatypeFactory
- the type factoryprocessingEnv
- the processing environmentannotationFileAnnos
- annotations from the annotation file; side-effected by this methodfileType
- the annotation file type and sourcefileElementTypes
- the manager that controls the stub file parsing process
-
parseAjavaFile
public static void parseAjavaFile(java.lang.String filename, java.io.InputStream inputStream, com.sun.source.tree.CompilationUnitTree root, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations ajavaAnnos, AnnotationFileElementTypes fileElementTypes)
The main entry point when parsing an ajava file. Parses an ajava file and side-effects the last two arguments.- Parameters:
filename
- name of ajava file, used only for diagnostic messagesinputStream
- of ajava file to parseroot
- javac tree for the file to be parsedatypeFactory
- the type factoryprocessingEnv
- the processing environmentajavaAnnos
- annotations from the ajava file; side-effected by this methodfileElementTypes
- the manager that controls the stub file parsing process
-
parseJdkFileAsStub
public static void parseJdkFileAsStub(java.lang.String filename, java.io.InputStream inputStream, AnnotatedTypeFactory atypeFactory, javax.annotation.processing.ProcessingEnvironment processingEnv, AnnotationFileParser.AnnotationFileAnnotations stubAnnos, AnnotationFileElementTypes fileElementTypes)
Parse a stub file that is a part of the annotated JDK and side-effects thestubAnnos
argument.- Parameters:
filename
- name of stub file, used only for diagnostic messagesinputStream
- of stub file to parseatypeFactory
- the type factoryprocessingEnv
- the processing environmentstubAnnos
- annotations from the stub file; side-effected by this methodfileElementTypes
- the manager that controls the stub file parsing process
-
putIfAbsent
public static <K,V> void putIfAbsent(java.util.Map<K,V> m, K key, V value)
Just like Map.put, but does not override any existing value in the map.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
m
- a mapkey
- a keyvalue
- the value to associate with the key, if the key isn't already in the map
-
putAllNew
public static <K,V> void putAllNew(java.util.Map<K,V> m, java.util.Map<K,V> m2)
Just like Map.putAll, but modifies existing values usingputIfAbsent(Map, Object, Object)
.- Type Parameters:
K
- the key type for the mapsV
- the value type for the maps- Parameters:
m
- the destination mapm2
- the source map
-
-