use of javax.lang.model.util.Elements in project ceylon-compiler by ceylon.
the class Main method main.
public static void main(String[] args) throws Exception {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
JavacTask javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
Elements elements = javac.getElements();
final Set<String> packages = new LinkedHashSet<String>();
int nestedClasses = 0;
int classes = 0;
for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
if (type.endsWith("package-info"))
continue;
try {
TypeElement elem = elements.getTypeElement(type);
if (elem == null && type.indexOf('$') > 0) {
nestedClasses++;
type = null;
continue;
}
classes++;
packages.add(getPackage(elem).getQualifiedName().toString());
// force completion
elements.getTypeElement(type).getKind();
type = null;
} finally {
if (type != null)
System.err.println("Looking at " + type);
}
}
javac = null;
elements = null;
javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
elements = javac.getElements();
for (String name : packages) {
PackageElement pe = elements.getPackageElement(name);
for (Element e : pe.getEnclosedElements()) {
e.getSimpleName().getClass();
}
}
/*
* A few sanity checks based on current values:
*
* packages: 775, classes: 12429 + 5917
*
* As the platform evolves the numbers are likely to grow
* monotonically but in case somebody gets a clever idea for
* limiting the number of packages exposed, this number might
* drop. So we test low values.
*/
System.out.format("packages: %s, classes: %s + %s%n", packages.size(), classes, nestedClasses);
if (classes < 9000)
throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
if (packages.size() < 530)
throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
if (nestedClasses < 3000)
throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
}
use of javax.lang.model.util.Elements in project androidannotations by androidannotations.
the class AndroidRClassFinder method find.
public IRClass find() throws RClassNotFoundException {
Elements elementUtils = processingEnv.getElementUtils();
TypeElement androidRType = elementUtils.getTypeElement("android.R");
if (androidRType == null) {
LOGGER.error("The android.R class cannot be found");
throw new RClassNotFoundException("The android.R class cannot be found");
}
LOGGER.info("Found Android class: {}", androidRType.toString());
return new RClass(androidRType);
}
use of javax.lang.model.util.Elements in project androidannotations by androidannotations.
the class ProjectRClassFinder method find.
public IRClass find(AndroidManifest manifest) throws RClassNotFoundException {
Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
String rClass = getRClassPackageName(manifest) + "." + getRClassSimpleName();
TypeElement rType = elementUtils.getTypeElement(rClass);
if (rType == null) {
LOGGER.error("The generated {} class cannot be found", rClass);
throw new RClassNotFoundException("The generated " + rClass + " class cannot be found");
}
LOGGER.info("Found project R class: {}", rType.toString());
return new RClass(rType);
}
use of javax.lang.model.util.Elements in project qpid-broker-j by apache.
the class ManagedAttributeValueTypeValidator method process.
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
Elements elementUtils = processingEnv.getElementUtils();
TypeElement annotationElement = elementUtils.getTypeElement(MANAGED_ATTRIBUTE_VALUE_TYPE_CLASS_NAME);
for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement)) {
boolean isAbstract = isAbstract(annotationElement, e);
if (!isAbstract) {
checkAnnotationIsOnInterface(annotationElement, e);
}
if (!isContent(e)) {
checkAllMethodsAreAccessors(e, isAbstract);
}
}
return false;
}
use of javax.lang.model.util.Elements in project qpid-broker-j by apache.
the class OperationAnnotationValidator method getErasure.
private static TypeMirror getErasure(ProcessingEnvironment processingEnv, final String className) {
final Types typeUtils = processingEnv.getTypeUtils();
final Elements elementUtils = processingEnv.getElementUtils();
return typeUtils.erasure(elementUtils.getTypeElement(className).asType());
}
Aggregations