use of com.oracle.truffle.dsl.processor.LanguageRegistrationProcessor.SortedProperties in project graal by oracle.
the class InstrumentRegistrationProcessor method generateFile.
private void generateFile(List<TypeElement> instruments) {
String filename = "META-INF/truffle/instrument";
Properties p = new SortedProperties();
int numInstruments = loadIfFileAlreadyExists(filename, p);
for (TypeElement l : instruments) {
Registration annotation = l.getAnnotation(Registration.class);
if (annotation == null) {
continue;
}
int instNum = findInstrument(annotation.id(), p);
if (instNum == 0) {
// not found
numInstruments += 1;
instNum = numInstruments;
}
String prefix = "instrument" + instNum + ".";
String className = processingEnv.getElementUtils().getBinaryName(l).toString();
p.setProperty(prefix + "id", annotation.id());
p.setProperty(prefix + "name", annotation.name());
p.setProperty(prefix + "version", annotation.version());
p.setProperty(prefix + "className", className);
p.setProperty(prefix + "internal", Boolean.toString(annotation.internal()));
int serviceCounter = 0;
for (AnnotationMirror anno : l.getAnnotationMirrors()) {
final String annoName = anno.getAnnotationType().asElement().toString();
if (Registration.class.getCanonicalName().equals(annoName)) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : anno.getElementValues().entrySet()) {
final Name attrName = entry.getKey().getSimpleName();
if (attrName.contentEquals("services")) {
AnnotationValue attrValue = entry.getValue();
List<?> classes = (List<?>) attrValue.getValue();
for (Object clazz : classes) {
AnnotationValue clazzValue = (AnnotationValue) clazz;
p.setProperty(prefix + "service" + serviceCounter++, clazzValue.getValue().toString());
}
}
}
}
}
}
if (numInstruments > 0) {
try {
FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename);
try (OutputStream os = file.openOutputStream()) {
p.store(os, "Generated by " + InstrumentRegistrationProcessor.class.getName());
}
} catch (IOException e) {
processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), instruments.get(0));
}
}
}
Aggregations