本文整理汇总了Java中com.android.tools.lint.client.api.JavaParser.ResolvedMethod方法的典型用法代码示例。如果您正苦于以下问题:Java JavaParser.ResolvedMethod方法的具体用法?Java JavaParser.ResolvedMethod怎么用?Java JavaParser.ResolvedMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.client.api.JavaParser
的用法示例。
在下文中一共展示了JavaParser.ResolvedMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAddReplaceOpen
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private static boolean isAddReplaceOpen(@NonNull JavaContext context, @NonNull MethodInvocation node) {
String methodName = node.astName().astValue();
if (ADD_TRANSACTION.equals(methodName) || OPEN_TRANSACTION.equals(methodName) || REPLACE_TRANSACTION.equals(methodName)) {
JavaParser.ResolvedNode resolved = context.resolve(node);
if (resolved instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedClass containingClass = method.getContainingClass();
if (containingClass.isSubclassOf(ACTIVITY_MANAGER, false)) {
return true;
}
}
}
return false;
}
示例2: report
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private static void report(JavaContext context, MethodInvocation node) {
// Make sure the call is on a view
JavaParser.ResolvedNode resolved = context.resolve(node);
if (resolved instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedClass containingClass = method.getContainingClass();
if (!containingClass.isSubclassOf(CLASS_VIEW, false)) {
return;
}
}
String name = node.astName().astValue();
String suggestion = Character.toLowerCase(name.charAt(2)) + name.substring(3);
String message = String.format(
// Keep in sync with {@link #getOldValue} and {@link #getNewValue} below!
"Suspicious method call; should probably call \"`%1$s`\" rather than \"`%2$s`\"",
suggestion, name);
context.report(ISSUE, node, context.getLocation(node.astName()), message);
}
示例3: createJavaVisitor
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public AstVisitor createJavaVisitor(final JavaContext context) {
return new ForwardingAstVisitor() {
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
JavaParser.ResolvedNode resolve = context.resolve(node);
if (resolve instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolve;
// 方法所在的类校验
JavaParser.ResolvedClass containingClass = method.getContainingClass();
if (containingClass.matches("android.util.Log")) {
context.report(ISSUE, node, context.getLocation(node),
"请使用Ln,避免使用Log");
return true;
}
if (node.toString().startsWith("System.out.println")) {
context.report(ISSUE, node, context.getLocation(node),
"请使用Ln,避免使用System.out.println");
return true;
}
}
return super.visitMethodInvocation(node);
}
};
}
示例4: parseResolvedMethod
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
public static JavaParser.ResolvedMethod parseResolvedMethod(
@NonNull JavaContext context, @NonNull Node node) {
if (null == context || null == node) {
return null;
}
JavaParser.ResolvedNode resolvedNode = null;
try {
resolvedNode = context.resolve(node);
} catch (Exception e) {
// TODO
}
return (resolvedNode instanceof JavaParser.ResolvedMethod) ?
(JavaParser.ResolvedMethod)resolvedNode : null;
}
示例5: visitMethod
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass)context.resolve(JavaContext.findSurroundingClass(node));
JavaParser.ResolvedMethod sorroundingMethod = (JavaParser.ResolvedMethod)context.resolve(JavaContext.findSurroundingMethod(node));
if (sorroundingMethod.getName().equals("onCreateViewHolder")
&& sorroundingClass.isSubclassOf("android.support.v7.widget.RecyclerView.Adapter", false)){
String layoutString = getParamWithLayoutAnnotation(context, node);
if (layoutString == null){
return;
}
if (!isFileStringStartWithPrefix(layoutString, "item_")) {
context.report(ISSUE,
node,
context.getLocation(node),
"Layout resource file in ViewHolder must be named with prefix `item_`.");
}
}
}
示例6: searchSetPriorityNodes
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* 给定thread变量名,获取其所有的setPriority()节点列表
*
* @param operand
* @param node
* @param setPriorityNodes
*/
private void searchSetPriorityNodes(Node operand, Node node, ArrayList<MethodInvocation> setPriorityNodes) {
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null != resolvedMethod &&
"setPriority".equals(resolvedMethod.getName()) &&
resolvedMethod.getContainingClass().isSubclassOf("java.lang.Thread", false) &&
node instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation)node;
// 这里比较的是Node.toString()而非Node本身,原因在于,赋值节点的operand是Identifier,
// 而此处Thread.setPriority()节点的operand确实VariableReference。虽然它们的字符串值
// 相同,但是在AST里却是不同类型的节点。
if (methodInvocation.rawOperand().toString().equals(operand.toString())) {
setPriorityNodes.add(methodInvocation);
}
}
List<Node> children = node.getChildren();
if (null != children && !children.isEmpty()) {
for (Node child : node.getChildren()) {
searchSetPriorityNodes(operand, child, setPriorityNodes);
}
}
}
示例7: visitMethodInvocation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null == resolvedMethod) {
return super.visitMethodInvocation(node);
}
// The containing class must be subclass of android.app.ActivityManager
JavaParser.ResolvedClass resolvedClass = resolvedMethod.getContainingClass();
if (!resolvedClass.isSubclassOf("android.app.ActivityManager", false)) {
return super.visitMethodInvocation(node);
}
// Only handle ActivityManager.getRunningAppProcesses()
if (!getRunningAppProcesses_SIGNATURE.equals(resolvedMethod.getSignature())) {
return super.visitMethodInvocation(node);
}
mContext.report(
GetRunningAppProcessesDetector.ISSUE,
mContext.getLocation(node),
"Please DO NOT invoke ActivityManager.getRunningAppProcesses(), since it may cause performance issue and not applicable in Android 5.1+ .");
return super.visitMethodInvocation(node);
}
示例8: isThisMethodHasLayoutAnnotation_ForActivity
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* As there are more than one methods overload "setContentView",
* we have to identify the one we want to check, whose param has an Annotation of "@LayoutRes".
* In fact, {public void setContentView(@LayoutRes int layoutResID)} is the one we are looking for.
*/
private boolean isThisMethodHasLayoutAnnotation_ForActivity(@NonNull JavaContext context, @NonNull MethodInvocation node) {
JavaParser.ResolvedNode resolved = context.resolve(node);
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
if (node.astArguments().size() != 1) {
return false;
}
Iterable<JavaParser.ResolvedAnnotation> annotations = method.getParameterAnnotations(0);
for (JavaParser.ResolvedAnnotation annotation : annotations) {
if ("android.support.annotation.LayoutRes".equals(annotation.getName())) {
return true;
}
}
return false;
}
示例9: checkRuleViolation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private boolean checkRuleViolation(JavaContext context, MethodInvocation node) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) context.resolve(node);
JavaParser.ResolvedClass containingClass = method.getContainingClass();
String containingClassName = containingClass.getName();
if (mWrapperClassName.equals(containingClassName)) {
return false;
}
for (String targetClassName : mTargetClassNames) {
if (targetClassName.equals(containingClassName)) {
return true;
}
if (containingClass.isSubclassOf(targetClassName, false)) {
return true;
}
}
return false;
}
示例10: isInsideDialogFragment
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private boolean isInsideDialogFragment(JavaContext context, MethodInvocation node) {
Node parent = node.getParent();
while (parent != null) {
Object resolvedNode = context.resolve(parent);
if (resolvedNode instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolvedNode;
if (isDialogFragment(method.getContainingClass())) {
return true;
}
}
parent = parent.getParent();
}
return false;
}
示例11: visitMethodInvocation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(@NonNull MethodInvocation call) {
JavaParser.ResolvedNode resolved = mContext.resolve(call);
if (resolved instanceof JavaParser.ResolvedMethod) {
if (!checkTransactionHasACommit(mContext, call)) {
showCommitMessage(mContext, call);
}
}
return false;
}
示例12: isSharedPreferenceGetString
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private static boolean isSharedPreferenceGetString(@NonNull JavaContext context,
@NonNull MethodInvocation call) {
if (!GET_STRING_METHOD.equals(call.astName().astValue())) {
return false;
}
JavaParser.ResolvedNode resolved = context.resolve(call);
if (resolved instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod resolvedMethod = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedClass containingClass = resolvedMethod.getContainingClass();
return containingClass.isSubclassOf(ANDROID_CONTENT_SHARED_PREFERENCES, false);
}
return false; // not certain
}
示例13: printMissingMethod
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
private void printMissingMethod(MethodDeclaration node) {
// Ignore constructor
if (null == node.astReturnTypeReference()) {
return;
}
// Only public/protected methods
Modifiers modifiers = node.astModifiers();
if (null == modifiers ||
(!modifiers.isPublic() && !modifiers.isProtected())) {
return;
}
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null == resolvedMethod) {
return;
}
JavaParser.ResolvedClass resolvedClass = resolvedMethod.getContainingClass();
if (null == resolvedClass || !isInAndroidSdk(resolvedClass)) {
return;
}
if (isRemoved(node)) {
appendMethod(removedMethods, resolvedClass.getName(), resolvedMethod.getSignature());
}
if (isHide(node)) {
appendMethod(hideMethods, resolvedClass.getName(), resolvedMethod.getSignature());
}
}
示例14: visitConstructorInvocation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
Node containingMethod = JavaContext.findSurroundingMethod(node);
if (null == containingMethod) {
return super.visitConstructorInvocation(node);
}
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, containingMethod);
if (null == resolvedMethod) {
return super.visitConstructorInvocation(node);
}
JavaParser.ResolvedClass resolvedClass = resolvedMethod.getContainingClass();
if (null == resolvedClass) {
return super.visitConstructorInvocation(node);
}
for (String observedClass : OBSERVED_METHODS.keySet()) {
if (resolvedClass.isSubclassOf(observedClass, false) &&
OBSERVED_METHODS.get(observedClass).contains(resolvedMethod.getName())) {
mContext.report(
WrongAllocationDetector.ISSUE,
mContext.getLocation(node),
String.format("Please don't create new objects in %s : %s", resolvedClass.getName(), resolvedMethod.getName())
);
}
}
return super.visitConstructorInvocation(node);
}
示例15: visitMethodInvocation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null == resolvedMethod) {
return super.visitMethodInvocation(node);
}
checkSingleThreadIterating(node);
checkMultiThreadSync(node);
return super.visitMethodInvocation(node);
}