X Tutup
Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.helper;

import org.androidannotations.holder.GeneratedClassHolder;

public final class LogHelper {

private static final int MAX_TAG_LEN = 23;

private LogHelper() {
}

/**
* Log tag length needs to be limited to 23.
*
* @see <a href=
* "http://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int)">
* Log.isLoggable() JavaDoc</a>
*/
public static String trimLogTag(String tag) {
if (tag == null) {
return "";
} else if (tag.length() > MAX_TAG_LEN) {
return tag.substring(0, MAX_TAG_LEN);
} else {
return tag;
}
}

/**
* Log tag length needs to be limited to 23.
*
* @see <a href=
* "http://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int)">
* Log.isLoggable() JavaDoc</a>
*/
public static String logTagForClassHolder(GeneratedClassHolder holder) {
return trimLogTag(holder.getGeneratedClass().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.helger.jcodemodel.JExpr.cast;
import static com.helger.jcodemodel.JExpr.lit;
import static org.androidannotations.helper.LogHelper.logTagForClassHolder;

import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EBeanHo
cond._then().add(fieldRef.assign(cast(extendingContextClass, holder.getContextRef())));

JInvocation warningInvoke = getClasses().LOG.staticInvoke("w");
warningInvoke.arg(holder.getGeneratedClass().name());
warningInvoke.arg(logTagForClassHolder(holder));
warningInvoke.arg(lit("Due to Context class ").plus(holder.getContextRef().invoke("getClass").invoke("getSimpleName"))
.plus(lit(", the @RootContext " + extendingContextClass.name() + " won't be populated")));
cond._else().add(warningInvoke);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.androidannotations.helper.AndroidConstants.LOG_INFO;
import static org.androidannotations.helper.AndroidConstants.LOG_VERBOSE;
import static org.androidannotations.helper.AndroidConstants.LOG_WARN;
import static org.androidannotations.helper.LogHelper.trimLogTag;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void process(Element element, EComponentHolder holder) throws Exception {
JBlock methodBody = method.body();

JInvocation isLoggableInvocation = getClasses().LOG.staticInvoke("isLoggable");
isLoggableInvocation.arg(JExpr.lit(tag)).arg(logLevelFromInt(level, getClasses().LOG));
isLoggableInvocation.arg(tag).arg(logLevelFromInt(level, getClasses().LOG));

JConditional ifStatement = methodBody._if(isLoggableInvocation);

Expand Down Expand Up @@ -243,9 +244,6 @@ private String extractTag(Element element) {
if (Trace.DEFAULT_TAG.equals(tag)) {
tag = element.getEnclosingElement().getSimpleName().toString();
}
if (tag.length() > 23) {
tag = tag.substring(0, 23);
}
return tag;
return trimLogTag(tag);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.androidannotations.internal.core.handler;

import static org.androidannotations.helper.LogHelper.logTagForClassHolder;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;

Expand Down Expand Up @@ -102,7 +104,7 @@ public void process(Element element, EComponentHolder holder) {

JInvocation errorInvoke = catchBody.staticInvoke(getClasses().LOG, "e");

errorInvoke.arg(holder.getGeneratedClass().name());
errorInvoke.arg(logTagForClassHolder(holder));
errorInvoke.arg("Error in transaction");
errorInvoke.arg(exceptionParam);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.helger.jcodemodel.JExpr._new;
import static com.helger.jcodemodel.JExpr.cast;
import static org.androidannotations.helper.LogHelper.logTagForClassHolder;

import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, ECompon
String fieldName = param.getSimpleName().toString();
catchBlock.body() //
.staticInvoke(getClasses().LOG, "e") //
.arg(holder.getGeneratedClass().name()) //
.arg(logTagForClassHolder(holder))//
.arg("Could not create DAO " + fieldName) //
.arg(exception);
}
Expand Down
X Tutup