use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ServiceActionHandler method process.
@Override
public void process(Element element, EIntentServiceHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
String methodName = element.getSimpleName().toString();
ServiceAction annotation = element.getAnnotation(ServiceAction.class);
String extraKey = annotation.value();
if (extraKey.isEmpty()) {
extraKey = methodName;
}
JFieldVar actionKeyField = createStaticActionField(holder, extraKey, methodName);
addActionInOnHandleIntent(holder, executableElement, methodName, actionKeyField);
addActionToIntentBuilder(holder, executableElement, methodName, actionKeyField);
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class SharedPrefHandler method getValidMethods.
private List<ExecutableElement> getValidMethods(Element element) {
List<? extends Element> members = element.getEnclosedElements();
List<ExecutableElement> methods = ElementFilter.methodsIn(members);
List<ExecutableElement> validMethods = new ArrayList<>();
for (ExecutableElement method : methods) {
validMethods.add(method);
}
return validMethods;
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class WakeLockHandler method process.
@Override
public void process(Element element, EComponentHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
WakeLock annotation = executableElement.getAnnotation(WakeLock.class);
String tag = extractTag(executableElement);
Level level = annotation.level();
Flag[] flags = annotation.flags();
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(method);
JBlock methodBody = method.body();
IJExpression levelAndFlags = getClasses().POWER_MANAGER.staticRef(level.name());
if (flags.length > 0) {
for (Flag flag : flags) {
levelAndFlags = levelAndFlags.bor(getClasses().POWER_MANAGER.staticRef(flag.name()));
}
}
JInvocation newWakeLock = holder.getPowerManagerRef().invoke("newWakeLock").arg(levelAndFlags).arg(JExpr.lit(tag));
JVar wakeLock = methodBody.decl(getClasses().WAKE_LOCK, "wakeLock", JExpr._null());
JTryBlock tryBlock = methodBody._try();
tryBlock.body().assign(wakeLock, newWakeLock);
tryBlock.body().add(wakeLock.invoke("acquire"));
tryBlock.body().add(previousMethodBody);
JBlock finallyBlock = tryBlock._finally();
JConditional ifStatement = finallyBlock._if(wakeLock.ne(JExpr._null()));
ifStatement._then().add(wakeLock.invoke("release"));
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class CoreValidatorHelper method isSharedPreference.
public void isSharedPreference(Element element, ElementValidation valid) {
TypeMirror type = element.asType();
if (element instanceof ExecutableElement) {
element = ((ExecutableElement) element).getParameters().get(0);
type = element.asType();
}
/*
* The type is not available yet because it has just been generated
*/
if (type instanceof ErrorType || type.getKind() == TypeKind.ERROR) {
String elementTypeName = type.toString();
boolean sharedPrefValidatedInRound = false;
if (elementTypeName.endsWith(classSuffix())) {
String prefTypeName = elementTypeName.substring(0, elementTypeName.length() - classSuffix().length());
prefTypeName = prefTypeName.replace(classSuffix() + ".", ".");
Set<? extends Element> sharedPrefElements = validatedModel().getRootAnnotatedElements(SharedPref.class.getName());
for (Element sharedPrefElement : sharedPrefElements) {
TypeElement sharedPrefTypeElement = (TypeElement) sharedPrefElement;
String sharedPrefQualifiedName = sharedPrefTypeElement.getQualifiedName().toString();
if (sharedPrefQualifiedName.endsWith(prefTypeName)) {
sharedPrefValidatedInRound = true;
break;
}
}
}
if (!sharedPrefValidatedInRound) {
valid.invalidate();
}
} else {
extendsType(element, SharedPreferencesHelper.class.getName(), valid);
}
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class TraceHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
String tag = extractTag(executableElement);
int level = executableElement.getAnnotation(Trace.class).level();
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(method);
JBlock methodBody = method.body();
JInvocation isLoggableInvocation = getClasses().LOG.staticInvoke("isLoggable");
isLoggableInvocation.arg(tag).arg(logLevelFromInt(level, getClasses().LOG));
JConditional ifStatement = methodBody._if(isLoggableInvocation);
JInvocation currentTimeInvoke = getClasses().SYSTEM.staticInvoke("currentTimeMillis");
JBlock thenBody = ifStatement._then();
// Log In
String logMethodName = logMethodNameFromLevel(level);
JInvocation logEnterInvoke = getClasses().LOG.staticInvoke(logMethodName);
logEnterInvoke.arg(tag);
logEnterInvoke.arg(getEnterMessage(method, executableElement));
thenBody.add(logEnterInvoke);
JVar startDeclaration = thenBody.decl(getCodeModel().LONG, "traceStart" + generationSuffix(), currentTimeInvoke);
JTryBlock tryBlock;
JVar result = null;
if (method.type().fullName().equals("void")) {
tryBlock = thenBody._try();
tryBlock.body().add(previousMethodBody);
} else {
JInvocation superCall = codeModelHelper.getSuperCall(holder, method);
result = thenBody.decl(getJClass(Object.class), "traceResult" + generationSuffix(), JExpr._null());
tryBlock = thenBody._try();
tryBlock.body().assign(result, superCall);
tryBlock.body()._return(JExpr.cast(boxify(method.type()), result));
}
JBlock finallyBlock = tryBlock._finally();
JVar durationDeclaration = finallyBlock.decl(getCodeModel().LONG, "traceDuration" + generationSuffix(), currentTimeInvoke.minus(startDeclaration));
JInvocation logExitInvoke = getClasses().LOG.staticInvoke(logMethodName);
logExitInvoke.arg(tag);
logExitInvoke.arg(getExitMessage(executableElement, method, result, durationDeclaration));
finallyBlock.add(logExitInvoke);
JBlock elseBlock = ifStatement._else();
elseBlock.add(previousMethodBody);
}
Aggregations