This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2035: Rename ModifierAnnotation to LanguageAnnotation, since i…
…t now handles documentation annotations too.
- Loading branch information
1 parent
9b670ee
commit 63d764a
Showing
4 changed files
with
212 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
compiler-java/src/com/redhat/ceylon/compiler/loader/LanguageAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package com.redhat.ceylon.compiler.loader; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.redhat.ceylon.compiler.loader.mirror.AnnotationMirror; | ||
import com.redhat.ceylon.compiler.typechecker.model.Annotation; | ||
|
||
/** | ||
* Enumerates the language module annotations and allows them to be loaded from mirrors | ||
*/ | ||
public enum LanguageAnnotation { | ||
/* modifier annotations */ | ||
ANNOTATION("annotation", 1L<<0, AbstractModelLoader.CEYLON_LANGUAGE_ANNOTATION_ANNOTATION), | ||
SHARED("shared", 1L<<1, AbstractModelLoader.CEYLON_LANGUAGE_SHARED_ANNOTATION), | ||
VARIABLE("variable", 1L<<2, AbstractModelLoader.CEYLON_LANGUAGE_VARIABLE_ANNOTATION), | ||
ABSTRACT("abstract", 1L<<3, AbstractModelLoader.CEYLON_LANGUAGE_ABSTRACT_ANNOTATION), | ||
SEALED("sealed", 1L<<4, AbstractModelLoader.CEYLON_LANGUAGE_SEALED_ANNOTATION), | ||
FINAL("final", 1L<<5, AbstractModelLoader.CEYLON_LANGUAGE_FINAL_ANNOTATION), | ||
ACTUAL("actual", 1L<<6, AbstractModelLoader.CEYLON_LANGUAGE_ACTUAL_ANNOTATION), | ||
FORMAL("formal", 1L<<7, AbstractModelLoader.CEYLON_LANGUAGE_FORMAL_ANNOTATION), | ||
DEFAULT("default", 1L<<8, AbstractModelLoader.CEYLON_LANGUAGE_DEFAULT_ANNOTATION), | ||
LATE("late", 1L<<9, AbstractModelLoader.CEYLON_LANGUAGE_LATE_ANNOTATION), | ||
NATIVE("native", 1L<<10, AbstractModelLoader.CEYLON_LANGUAGE_NATIVE_ANNOTATION), | ||
OPTIONAL("optional", 1L<<11, AbstractModelLoader.CEYLON_LANGUAGE_OPTIONAL_ANNOTATION), | ||
SERIALIZABLE("serializable", 1L<<12, AbstractModelLoader.CEYLON_LANGUAGE_SERIALIZABLE_ANNOTATION), | ||
|
||
/* documentation annotations */ | ||
DOC("doc", 0, AbstractModelLoader.CEYLON_LANGUAGE_DOC_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
anno.addPositionalArgment((String)mirror.getValue("description")); | ||
return Collections.singletonList(anno); | ||
} | ||
}, | ||
THROWS("throws", 0, AbstractModelLoader.CEYLON_LANGUAGE_THROWS_ANNOTATIONS) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
List<AnnotationMirror> thrownExceptions = (List<AnnotationMirror>)mirror.getValue("value"); | ||
List<Annotation> result = new ArrayList<Annotation>(thrownExceptions.size()); | ||
for (AnnotationMirror thrown : thrownExceptions) { | ||
Annotation anno = new Annotation(name); | ||
// can't decode the declaration | ||
anno.addPositionalArgment(parseMetamodelReference((String)thrown.getValue("type"))); | ||
anno.addPositionalArgment((String)thrown.getValue("when")); | ||
result.add(anno); | ||
} | ||
return result; | ||
} | ||
}, | ||
BY("by", 0, AbstractModelLoader.CEYLON_LANGUAGE_AUTHORS_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
for (String author : (List<String>)mirror.getValue("authors")) { | ||
anno.addPositionalArgment(author); | ||
} | ||
return Collections.singletonList(anno); | ||
} | ||
}, | ||
SEE("see", 0, AbstractModelLoader.CEYLON_LANGUAGE_SEE_ANNOTATIONS) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
List<AnnotationMirror> sees = (List<AnnotationMirror>)mirror.getValue("value"); | ||
List<Annotation> result = new ArrayList<Annotation>(sees.size()); | ||
for (AnnotationMirror see : sees) { | ||
Annotation anno = new Annotation(name); | ||
// can't decode the declaration | ||
for (String s : (List<String>)see.getValue("programElements")) { | ||
anno.addPositionalArgment(parseMetamodelReference(s)); | ||
} | ||
result.add(anno); | ||
} | ||
return result; | ||
} | ||
|
||
}, | ||
LICENSE("license", 0, AbstractModelLoader.CEYLON_LANGUAGE_LICENSE_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
anno.addPositionalArgment((String)mirror.getValue("description")); | ||
return Collections.singletonList(anno); | ||
} | ||
}, | ||
DEPRECATED("deprecated", 0, AbstractModelLoader.CEYLON_LANGUAGE_DEPRECATED_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
anno.addPositionalArgment((String)mirror.getValue("reason")); | ||
return Collections.singletonList(anno); | ||
} | ||
}, | ||
TAGGED("tagged", 0, AbstractModelLoader.CEYLON_LANGUAGE_TAGS_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
for (String tag : (List<String>)mirror.getValue("tags")) { | ||
anno.addPositionalArgment(tag); | ||
} | ||
return Collections.singletonList(anno); | ||
} | ||
}, | ||
SUPPRESS_WARNINGS("suppressWarnings", 0, AbstractModelLoader.CEYLON_LANGUAGE_SUPPRESS_WARNINGS_ANNOTATION) { | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
Annotation anno = new Annotation(name); | ||
anno.addPositionalArgment((String)mirror.getValue("warnings")); | ||
return Collections.singletonList(anno); | ||
} | ||
}; | ||
|
||
/** | ||
* The unqualified Ceylon name of the annotation, e.g. {@code shared} | ||
*/ | ||
public final String name; | ||
|
||
/** | ||
* The mask used to address this modifier when encoded as a long. | ||
* zero if this annotation is not a model annotation | ||
*/ | ||
public final long mask; | ||
/** | ||
* The qualifier Java name of the annotation type, e.g. {@code ceylon.language.Shared$annotation$} | ||
*/ | ||
public final String annotationType; | ||
|
||
LanguageAnnotation(String name, long mask, String annotationType) { | ||
this.name = name; | ||
this.mask = mask; | ||
this.annotationType = annotationType; | ||
} | ||
|
||
/** | ||
* Whether this annotation is a <em>modifier annotation</em> | ||
* (i.e. one whose annotation class is nullary, and | ||
* therefore whose presence/absence is all that matters) | ||
*/ | ||
public boolean isModifier() { | ||
return mask != 0; | ||
} | ||
|
||
/** | ||
* Construct a Ceylon annotation model from the information stored in | ||
* the mirror of the Ceylon annotation. | ||
* @param mirror The mirror of the Ceylon annotation. | ||
* @return | ||
*/ | ||
public List<Annotation> makeFromCeylonAnnotation(AnnotationMirror mirror) { | ||
return Collections.singletonList(new Annotation(name)); | ||
} | ||
|
||
protected String parseMetamodelReference(String s) { | ||
return s.replaceAll("^.*::[C]", "").replaceAll("^.*\\.[C]", ""); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
compiler-java/src/com/redhat/ceylon/compiler/loader/ModifierAnnotation.java
This file was deleted.
Oops, something went wrong.