use of javax.lang.model.element.ExecutableElement in project EventBus by greenrobot.
the class EventBusAnnotationProcessor method writeCreateSubscriberMethods.
private void writeCreateSubscriberMethods(BufferedWriter writer, List<ExecutableElement> methods, String callPrefix, String myPackage) throws IOException {
for (ExecutableElement method : methods) {
List<? extends VariableElement> parameters = method.getParameters();
TypeMirror paramType = getParamTypeMirror(parameters.get(0), null);
TypeElement paramElement = (TypeElement) processingEnv.getTypeUtils().asElement(paramType);
String methodName = method.getSimpleName().toString();
String eventClass = getClassString(paramElement, myPackage) + ".class";
Subscribe subscribe = method.getAnnotation(Subscribe.class);
List<String> parts = new ArrayList<>();
parts.add(callPrefix + "(\"" + methodName + "\",");
String lineEnd = "),";
if (subscribe.priority() == 0 && !subscribe.sticky()) {
if (subscribe.threadMode() == ThreadMode.POSTING) {
parts.add(eventClass + lineEnd);
} else {
parts.add(eventClass + ",");
parts.add("ThreadMode." + subscribe.threadMode().name() + lineEnd);
}
} else {
parts.add(eventClass + ",");
parts.add("ThreadMode." + subscribe.threadMode().name() + ",");
parts.add(subscribe.priority() + ",");
parts.add(subscribe.sticky() + lineEnd);
}
writeLine(writer, 3, parts.toArray(new String[parts.size()]));
if (verbose) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Indexed @Subscribe at " + method.getEnclosingElement().getSimpleName() + "." + methodName + "(" + paramElement.getSimpleName() + ")");
}
}
}
use of javax.lang.model.element.ExecutableElement in project EventBus by greenrobot.
the class EventBusAnnotationProcessor method checkForSubscribersToSkip.
/**
* Subscriber classes should be skipped if their class or any involved event class are not visible to the index.
*/
private void checkForSubscribersToSkip(Messager messager, String myPackage) {
for (TypeElement skipCandidate : methodsByClass.keySet()) {
TypeElement subscriberClass = skipCandidate;
while (subscriberClass != null) {
if (!isVisible(myPackage, subscriberClass)) {
boolean added = classesToSkip.add(skipCandidate);
if (added) {
String msg;
if (subscriberClass.equals(skipCandidate)) {
msg = "Falling back to reflection because class is not public";
} else {
msg = "Falling back to reflection because " + skipCandidate + " has a non-public super class";
}
messager.printMessage(Diagnostic.Kind.NOTE, msg, subscriberClass);
}
break;
}
List<ExecutableElement> methods = methodsByClass.get(subscriberClass);
if (methods != null) {
for (ExecutableElement method : methods) {
String skipReason = null;
VariableElement param = method.getParameters().get(0);
TypeMirror typeMirror = getParamTypeMirror(param, messager);
if (!(typeMirror instanceof DeclaredType) || !(((DeclaredType) typeMirror).asElement() instanceof TypeElement)) {
skipReason = "event type cannot be processed";
}
if (skipReason == null) {
TypeElement eventTypeElement = (TypeElement) ((DeclaredType) typeMirror).asElement();
if (!isVisible(myPackage, eventTypeElement)) {
skipReason = "event type is not public";
}
}
if (skipReason != null) {
boolean added = classesToSkip.add(skipCandidate);
if (added) {
String msg = "Falling back to reflection because " + skipReason;
if (!subscriberClass.equals(skipCandidate)) {
msg += " (found in super class for " + skipCandidate + ")";
}
messager.printMessage(Diagnostic.Kind.NOTE, msg, param);
}
break;
}
}
}
subscriberClass = getSuperclass(subscriberClass);
}
}
}
use of javax.lang.model.element.ExecutableElement in project tiger by google.
the class Utils method findAllModulesRecursively.
@SuppressWarnings("unchecked")
public static Set<TypeElement> findAllModulesRecursively(TypeElement inModule) {
Set<TypeElement> result = new HashSet<>();
result.add(inModule);
for (AnnotationMirror annotationMirror : inModule.getAnnotationMirrors()) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
ExecutableElement key = entry.getKey();
/** Checks for {@link Module.includes}. */
if (key.getSimpleName().contentEquals("includes")) {
for (AnnotationValue annotationValue : (List<AnnotationValue>) entry.getValue().getValue()) {
TypeElement childModule = (TypeElement) ((DeclaredType) annotationValue.getValue()).asElement();
result.addAll(findAllModulesRecursively(childModule));
}
}
}
}
return result;
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class JavadocConverter method visitParam.
@Override
public Void visitParam(ParamTree node, TagElement tag) {
DCTree.DCIdentifier identifier = (DCTree.DCIdentifier) node.getName();
if (identifier == null || node.isTypeParameter()) {
return null;
}
List<? extends VariableElement> params = element instanceof ExecutableElement ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
tag.setTagName(TagElement.TAG_PARAM);
String name = identifier.toString();
VariableElement param = null;
for (VariableElement p : params) {
if (name.equals(p.getSimpleName().toString())) {
param = p;
break;
}
}
// param will be null if the @param tag refers to a nonexistent parameter.
TreeNode nameNode = param != null ? new SimpleName(param) : new SimpleName(name);
setPos(identifier, nameNode);
tag.addFragment(nameNode);
scan(node.getDescription(), tag);
int lastEnd = nameNode.getStartPosition();
for (TreeNode fragment : tag.getFragments()) {
// TODO(tball): remove and fix JavadocGenerator after javac switch.
if (fragment.getKind() == TreeNode.Kind.TEXT_ELEMENT) {
TextElement text = (TextElement) fragment;
text.setText(" " + text.getText());
text.setSourceRange(text.getStartPosition(), text.getLength() + 1);
}
int thisEnd = lastEnd + fragment.getLength();
setPos(fragment, lastEnd, thisEnd);
lastEnd = thisEnd;
}
setPos(tag, pos(node), endPos(node));
tag.setLineNumber(nameNode.getLineNumber());
return null;
}
use of javax.lang.model.element.ExecutableElement in project j2objc by google.
the class JdtAnnotationMirror method getElementValues.
@Override
public Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValues() {
Map<ExecutableElement, AnnotationValue> elementValues = new HashMap<>();
for (IMemberValuePairBinding pair : binding.getAllMemberValuePairs()) {
ExecutableElement element = new JdtExecutableElement(pair.getMethodBinding());
AnnotationValue value = new JdtAnnotationValue(pair.getValue());
elementValues.put(element, value);
}
return elementValues;
}
Aggregations