本文整理汇总了Java中lombok.ast.MethodInvocation.astOperand方法的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocation.astOperand方法的具体用法?Java MethodInvocation.astOperand怎么用?Java MethodInvocation.astOperand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lombok.ast.MethodInvocation
的用法示例。
在下文中一共展示了MethodInvocation.astOperand方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
}
示例2: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
// Call is only allowed if it is both only called on the super class (invoke special)
// as well as within the same overriding method (e.g. you can't call super.onLayout
// from the onMeasure method)
Expression operand = node.astOperand();
if (!(operand instanceof Super)) {
report(context, node);
return;
}
Node method = StringFormatDetector.getParentMethod(node);
if (!(method instanceof MethodDeclaration) ||
!((MethodDeclaration)method).astMethodName().astValue().equals(
node.astName().astValue())) {
report(context, node);
}
}
示例3: isNode
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
* Does the given {@code argument} match the given {@code methodDefinition}?
* This method will first check the operand if it's there or imports if it's not there.
* @param context The context
* @param argument The argument we are trying to match
* @param methodDefinition The method we are matching against
* @return {@code true} if it matches, false otherwise
*/
public static boolean isNode(JavaContext context, MethodInvocation argument, MethodDefinition methodDefinition) {
if (methodDefinition == null || argument == null
|| !methodDefinition.methodName.equals(argument.getDescription())) {
return false;
}
Expression operand = argument.astOperand();
if (operand != null) {
return methodDefinition.classMatches(operand.toString());
}
// method found in the code with no operand, see if there is an import for it.
return ImportFinder.hasImport(context, methodDefinition);
}
示例4: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
System.out.println("ReceiverFinder::visitMethodInvocation " + node);
if(node == this.mTarget) {
this.mSeenTarget = true;
} else if((this.mSeenTarget || node.astOperand() == this.mTarget) && "show".equals(node.astName().astValue())) {
this.mFound = true;
}
return true;
}
示例5: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (node == mTarget) {
mSeenTarget = true;
} else if ((mSeenTarget || node.astOperand() == mTarget)
&& "show".equals(node.astName().astValue())) { //$NON-NLS-1$
// TODO: Do more flow analysis to see whether we're really calling show
// on the right type of object?
mFound = true;
}
return true;
}
示例6: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (node.astOperand() != null) {
String methodName = node.astName().astValue();
if (methodName.equals(INFLATE) && node.astArguments().size() >= 1) {
// See if we're inside a conditional
boolean insideIf = false;
Node p = node.getParent();
while (p != null) {
if (p instanceof If || p instanceof InlineIfExpression
|| p instanceof Switch) {
insideIf = true;
mHaveConditional = true;
break;
} else if (p == node) {
break;
}
p = p.getParent();
}
if (!insideIf) {
// Rather than reporting immediately, we only report if we didn't
// find any conditionally executed inflate statements in the method.
// This is because there are cases where getView method is complicated
// and inflates not just the top level layout but also children
// of the view, and we don't want to flag these. (To be more accurate
// should perform flow analysis and only report unconditional inflation
// of layouts that wind up flowing to the return value; that requires
// more work, and this simple heuristic is good enough for nearly all test
// cases I've come across.
if (mNodes == null) {
mNodes = Lists.newArrayList();
}
mNodes.add(node);
}
}
}
return super.visitMethodInvocation(node);
}
示例7: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
if (mFormatStrings == null && !context.getClient().supportsProjectResources()) {
return;
}
String methodName = node.astName().astValue();
if (methodName.equals(FORMAT_METHOD)) {
// String.format(getResources().getString(R.string.foo), arg1, arg2, ...)
// Check that the arguments in R.string.foo match arg1, arg2, ...
if (node.astOperand() instanceof VariableReference) {
VariableReference ref = (VariableReference) node.astOperand();
if ("String".equals(ref.astIdentifier().astValue())) { //$NON-NLS-1$
// Found a String.format call
// Look inside to see if we can find an R string
// Find surrounding method
checkFormatCall(context, node);
}
}
} else {
// getResources().getString(R.string.foo, arg1, arg2, ...)
// Check that the arguments in R.string.foo match arg1, arg2, ...
if (node.astArguments().size() > 1 && node.astOperand() != null ) {
checkFormatCall(context, node);
}
}
}
示例8: isCommittedInChainedCalls
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
* @return true if exists a commit or a getIntent
*/
private static boolean isCommittedInChainedCalls(@NonNull JavaContext context, @NonNull MethodInvocation node) {
JavaParser.ResolvedVariable boundVariable = getVariable(context, node);
if (boundVariable == null) {
Node parent = node.getParent();
while (parent instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) parent;
if (isTransactionCommitMethodCall(methodInvocation)) {
return true;
}
parent = parent.getParent();
}
}
if (boundVariable != null) {
Node method = JavaContext.findSurroundingMethod(node);
if (method == null) {
return true;
}
FinishVisitor commitVisitor = new FinishVisitor(context, boundVariable) {
@Override
protected boolean isCleanupCall(@NonNull MethodInvocation call) {
if (isTransactionCommitMethodCall(call)) {
Expression operand = call.astOperand();
if (operand != null) {
JavaParser.ResolvedNode resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
} else if (resolved instanceof JavaParser.ResolvedMethod
&& operand instanceof MethodInvocation
&& isCommittedInChainedCalls(mContext, (MethodInvocation) operand)) {
// Check that the target of the committed chains is the
// right variable!
while (operand instanceof MethodInvocation) {
operand = ((MethodInvocation) operand).astOperand();
}
if (operand instanceof VariableReference) {
resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
}
}
}
}
}
return false;
}
};
method.accept(commitVisitor);
if (commitVisitor.isCleanedUp()) {
return true;
}
}
return false;
}
示例9: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation call) {
String lhs = getLhs(call);
if (lhs == null) {
return;
}
Node method = JavaContext.findSurroundingMethod(call);
if (method == null) {
return;
} else if (method != mLastMethod) {
mIds = Maps.newHashMap();
mLhs = Maps.newHashMap();
mCallOperands = Maps.newHashMap();
mLastMethod = method;
}
String callOperand = call.astOperand() != null ? call.astOperand().toString() : "";
Expression first = call.astArguments().first();
if (first instanceof Select) {
Select select = (Select) first;
String id = select.astIdentifier().astValue();
Expression operand = select.astOperand();
if (operand instanceof Select) {
Select type = (Select) operand;
if (type.astIdentifier().astValue().equals(RESOURCE_CLZ_ID)) {
if (mIds.containsKey(id)) {
if (lhs.equals(mLhs.get(id))) {
return;
}
if (!callOperand.equals(mCallOperands.get(id))) {
return;
}
MethodInvocation earlierCall = mIds.get(id);
if (!isReachableFrom(method, earlierCall, call)) {
return;
}
Location location = context.getLocation(call);
Location secondary = context.getLocation(earlierCall);
secondary.setMessage("First usage here");
location.setSecondary(secondary);
context.report(ISSUE, call, location, String.format(
"The id `%1$s` has already been looked up in this method; possible " +
"cut & paste error?", first.toString()));
} else {
mIds.put(id, call);
mLhs.put(id, lhs);
mCallOperands.put(id, callOperand);
}
}
}
}
}
示例10: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (node == mTarget) {
mSeenTarget = true;
} else if (mAllowCommitBeforeTarget || mSeenTarget || node.astOperand() == mTarget) {
String name = node.astName().astValue();
boolean isCommit = "commit".equals(name);
if (isCommit || "apply".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$
// TODO: Do more flow analysis to see whether we're really calling commit/apply
// on the right type of object?
mFound = true;
ResolvedNode resolved = mContext.resolve(node);
if (resolved instanceof JavaParser.ResolvedMethod) {
ResolvedMethod method = (ResolvedMethod) resolved;
JavaParser.ResolvedClass clz = method.getContainingClass();
if (clz.isSubclassOf("android.content.SharedPreferences.Editor", false)
&& mContext.getProject().getMinSdkVersion().getApiLevel() >= 9) {
// See if the return value is read: can only replace commit with
// apply if the return value is not considered
Node parent = node.getParent();
boolean returnValueIgnored = false;
if (parent instanceof MethodDeclaration ||
parent instanceof ConstructorDeclaration ||
parent instanceof ClassDeclaration ||
parent instanceof Block ||
parent instanceof ExpressionStatement) {
returnValueIgnored = true;
} else if (parent instanceof Statement) {
if (parent instanceof If) {
returnValueIgnored = ((If) parent).astCondition() != node;
} else if (parent instanceof Return) {
returnValueIgnored = false;
} else if (parent instanceof VariableDeclaration) {
returnValueIgnored = false;
} else if (parent instanceof For) {
returnValueIgnored = ((For) parent).astCondition() != node;
} else if (parent instanceof While) {
returnValueIgnored = ((While) parent).astCondition() != node;
} else if (parent instanceof DoWhile) {
returnValueIgnored = ((DoWhile) parent).astCondition() != node;
} else if (parent instanceof Case) {
returnValueIgnored = ((Case) parent).astCondition() != node;
} else if (parent instanceof Assert) {
returnValueIgnored = ((Assert) parent).astAssertion() != node;
} else {
returnValueIgnored = true;
}
}
if (returnValueIgnored && isCommit) {
String message = "Consider using `apply()` instead; `commit` writes "
+ "its data to persistent storage immediately, whereas "
+ "`apply` will handle it in the background";
mContext.report(ISSUE, node, mContext.getLocation(node), message);
}
}
}
}
}
return super.visitMethodInvocation(node);
}
示例11: checkRecycled
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
private static void checkRecycled(@NonNull final JavaContext context, @NonNull Node node,
@NonNull final String recycleType, @NonNull final String recycleName) {
ResolvedVariable boundVariable = getVariable(context, node);
if (boundVariable == null) {
return;
}
Node method = JavaContext.findSurroundingMethod(node);
if (method == null) {
return;
}
FinishVisitor visitor = new FinishVisitor(context, boundVariable) {
@Override
protected boolean isCleanupCall(@NonNull MethodInvocation call) {
String methodName = call.astName().astValue();
if (!recycleName.equals(methodName)) {
return false;
}
ResolvedNode resolved = mContext.resolve(call);
if (resolved instanceof ResolvedMethod) {
ResolvedClass containingClass = ((ResolvedMethod) resolved).getContainingClass();
if (containingClass.isSubclassOf(recycleType, false)) {
// Yes, called the right recycle() method; now make sure
// we're calling it on the right variable
Expression operand = call.astOperand();
if (operand != null) {
resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
}
}
}
}
return false;
}
};
method.accept(visitor);
if (visitor.isCleanedUp() || visitor.variableEscapes()) {
return;
}
String className = recycleType.substring(recycleType.lastIndexOf('.') + 1);
String message;
if (RECYCLE.equals(recycleName)) {
message = String.format(
"This `%1$s` should be recycled after use with `#recycle()`", className);
} else {
message = String.format(
"This `%1$s` should be freed up after use with `#%2$s()`", className,
recycleName);
}
Node locationNode = node instanceof MethodInvocation ?
((MethodInvocation) node).astName() : node;
Location location = context.getLocation(locationNode);
context.report(RECYCLE_RESOURCE, node, location, message);
}