本文整理汇总了Java中lombok.ast.MethodInvocation类的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocation类的具体用法?Java MethodInvocation怎么用?Java MethodInvocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodInvocation类属于lombok.ast包,在下文中一共展示了MethodInvocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: argumentsAsString
import lombok.ast.MethodInvocation; //导入依赖的package包/类
public static String argumentsAsString(MethodInvocation node, String messageFormat) {
StringBuilder buffer = new StringBuilder();
StrictListAccessor<Expression, MethodInvocation> expressions = node.astArguments();
for (Expression expression : expressions) {
if (expression instanceof VariableReference) {
buffer.append(expression);
buffer.append(ClassDefinition.DOT);
} else if (expression instanceof Select) {
if (buffer.length() != 0) {
buffer.append(MethodDefinition.formatAsArgument(expression));
} else {
buffer.append(expression);
}
} else {
buffer.append(expression);
}
}
return MessageFormat.format(messageFormat, buffer.toString());
}
示例2: visitMethod
import lombok.ast.MethodInvocation; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
if (!isNode(context, node, MethodDefinitions.ALL_OF)) {
return;
}
// is parent onView or withView?
Node parentNode = node.getParent();
if (isInvalidParent(context, parentNode)) {
return;
}
MethodInvocation matcher = extractMatcher(context, node);
// has withXXX()
if (!isWithNode(context, matcher)) {
return;
}
String message = argumentsAsString(matcher, MESSAGE_FORMAT);
context.report(ISSUE, node, context.getLocation(parentNode), message);
}
示例3: extractMatcher
import lombok.ast.MethodInvocation; //导入依赖的package包/类
/**
* Extract non-isDisplayed part or null
*/
@Nullable
private MethodInvocation extractMatcher(JavaContext context, MethodInvocation node) {
// Only 2 items in allOf()?
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args == null || args.size() != 2) {
return null;
}
// has isDisplayed()
boolean foundIsDisplayed = false;
MethodInvocation other = null;
for (Expression next : args) {
if (next instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) next;
if (isNode(context, invocation, MethodDefinitions.IS_DISPLAYED)) {
foundIsDisplayed = true;
} else {
other = invocation;
}
}
}
if (!foundIsDisplayed || other == null) {
return null;
}
return other;
}
示例4: visitMethod
import lombok.ast.MethodInvocation; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor,
@NonNull MethodInvocation node) {
VariableReference ref = (VariableReference) node.astOperand();
if (!"QMUILog".equals(ref.astIdentifier().astValue())) {
return;
}
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args.isEmpty()) {
return;
}
for (Expression expression : args) {
String input = expression.toString();
if (input != null && input.contains("fuck")) {
context.report(
ISSUE_F_WORD, expression,
context.getLocation(expression), "\uD83D\uDD95");
}
}
}
示例5: isAddReplaceOpen
import lombok.ast.MethodInvocation; //导入依赖的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;
}
示例6: createJavaVisitor
import lombok.ast.MethodInvocation; //导入依赖的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);
}
};
}
示例7: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (1 == MissingApiChecker.MODE) {
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null == resolvedMethod) {
return super.visitMethodInvocation(node);
}
String clazzName = resolvedMethod.getContainingClass().getName();
String methodSignature = resolvedMethod.getSignature();
boolean isMissing = validateRemoved(node, clazzName, methodSignature);
if (!isMissing) {
isMissing = validateHide(node, clazzName, methodSignature);
}
}
return super.visitMethodInvocation(node);
}
示例8: searchSetPriorityNodes
import lombok.ast.MethodInvocation; //导入依赖的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);
}
}
}
示例9: validateSetLowerPriority
import lombok.ast.MethodInvocation; //导入依赖的package包/类
/**
* 检查Thread.setPriority()节点是否设置了较低优先级
*
* @param node Thread.setPriority()节点
* @return true: 较低优先级
* false: 不低于当前线程优先级
*/
private boolean validateSetLowerPriority(MethodInvocation node) {
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (null == args || 1 != args.size()) {
throw new IllegalArgumentException("The number of arguments is mismatched for Thread.setPriority().");
}
// 因为setPriority()的参数未必是常量,所以在纯语法分析中直接比较是很困难的,这里为
// 简化问题,只对设置较高优先级的情形返回false
String priority = args.first().toString();
if (priority.contains("NORM_PRIORITY") || // Thread.NORM_PRIORITY
priority.contains("MAX_PRIORITY") || // Thread.MAX_PRIORITY
priority.contains("THREAD_PRIORITY_DEFAULT") || // Process.THREAD_PRIORITY_DEFAULT
priority.contains("THREAD_PRIORITY_MORE_FAVORABLE") || // Process.THREAD_PRIORITY_MORE_FAVORABLE
priority.contains("THREAD_PRIORITY_FOREGROUND") || // Process.THREAD_PRIORITY_FOREGROUND
priority.contains("THREAD_PRIORITY_DISPLAY") || // Process.THREAD_PRIORITY_DISPLAY
priority.contains("THREAD_PRIORITY_URGENT_DISPLAY") || // Process.THREAD_PRIORITY_URGENT_DISPLAY
priority.contains("THREAD_PRIORITY_AUDIO") || // Process.THREAD_PRIORITY_AUDIO
priority.contains("THREAD_PRIORITY_URGENT_AUDIO")) { // Process.THREAD_PRIORITY_URGENT_AUDIO
return false;
}
return true;
}
示例10: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入依赖的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);
}
示例11: visitMethod
import lombok.ast.MethodInvocation; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
//String methodName = node.astName().astValue();
StrictListAccessor<Expression, MethodInvocation> arguments = node.astArguments();
Iterator<Expression> argIterator = arguments.iterator();
while (argIterator.hasNext()){
Expression mArg = argIterator.next();
if (mArg instanceof BinaryExpression){
context.report(ISSUE,
node,
context.getLocation(node),
"You should pass in a value or variable as a parameter, rather than passing in operands and operator as parameters.");
}
}
}
示例12: isThisInstanceOfActivity_ForActivity
import lombok.ast.MethodInvocation; //导入依赖的package包/类
/**
* If setContentView is called by 'this' instance,
* this method will check if 'this' is an instance of a Class inherit from android.app.Activity, for eaxmple AppCompatActivity or FragmentActivity, and so on.
*/
private boolean isThisInstanceOfActivity_ForActivity(@NonNull JavaContext context, @NonNull MethodInvocation node) {
Node currentNode = node.getParent();
JavaParser.ResolvedNode resolved = context.resolve(JavaContext.findSurroundingClass(node));
JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass) resolved;
while (sorroundingClass != null) {
//System.out.println("sorroundingClass = " + sorroundingClass);
if ("android.app.Activity".equals(sorroundingClass.getName())) {
return true;
} else {
sorroundingClass = sorroundingClass.getSuperClass();
}
}
return false;
}
示例13: isThisMethodHasLayoutAnnotation_ForActivity
import lombok.ast.MethodInvocation; //导入依赖的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;
}
示例14: isInflateCalledInOnCreateView_ForFragment
import lombok.ast.MethodInvocation; //导入依赖的package包/类
/**
* inflater.inflate() can be called from anywhere.
* We only care about the one call in {public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)}.
* This method whill check that.
*/
private boolean isInflateCalledInOnCreateView_ForFragment(@NonNull JavaContext context, @NonNull MethodInvocation node) {
Node surroundingNode = JavaContext.findSurroundingMethod(node);
JavaParser.ResolvedNode resolvedNode = context.resolve(surroundingNode);
try {
String resolvedNodeName = resolvedNode.getName();
if ("onCreateView".equals(resolvedNodeName)) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}
示例15: getParamWithLayoutAnnotation_ForFragment
import lombok.ast.MethodInvocation; //导入依赖的package包/类
/**
* There are more than one methods overloading in the name of "inflate()" in android.view.LayoutInflater.<br>
* We only care about those having an param with `@LayoutRes` annotation,
* for example {public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)}.<br>
* This method will find out the resource param with an `@LayoutRes` annotation in String format, for example `R.layout.fragment_blank` .<br>
* If no such param exists, <B>null</B> will be returned.
*/
private String getParamWithLayoutAnnotation_ForFragment(@NonNull JavaContext context, @NonNull MethodInvocation node) {
Iterator<Expression> arguments = node.astArguments().iterator();
Expression argument = arguments.next();
JavaParser.ResolvedNode resolved = context.resolve(node);
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedAnnotation layoutParamAnnotation = method.getParameterAnnotation("android.support.annotation.LayoutRes", 0);
if (layoutParamAnnotation != null) {
return argument.toString();
} else {
return null;
}
}