本文整理汇总了Java中lombok.ast.MethodInvocation.astArguments方法的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocation.astArguments方法的具体用法?Java MethodInvocation.astArguments怎么用?Java MethodInvocation.astArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lombok.ast.MethodInvocation
的用法示例。
在下文中一共展示了MethodInvocation.astArguments方法的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: 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;
}
示例3: 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");
}
}
}
示例4: 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;
}
示例5: 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.");
}
}
}
示例6: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (node.astName().astValue().equals(SET_THEME)) {
// Look at argument
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args.size() == 1) {
Expression arg = args.first();
if (arg instanceof Select) {
String resource = arg.toString();
if (resource.startsWith(R_STYLE_PREFIX)) {
if (mActivityToTheme == null) {
mActivityToTheme = new HashMap<String, String>();
}
String name = ((Select) arg).astIdentifier().astValue();
mActivityToTheme.put(mClassFqn, STYLE_RESOURCE_PREFIX + name);
}
}
}
}
return false;
}
示例7: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
ResolvedNode resolved = context.resolve(node);
if (!(resolved instanceof ResolvedMethod) ||
!((ResolvedMethod) resolved).getContainingClass()
.isSubclassOf(PACKAGE_MANAGER_CLASS, false)) {
return;
}
StrictListAccessor<Expression, MethodInvocation> argumentList = node.astArguments();
// Ignore if the method doesn't fit our description.
if (argumentList != null && argumentList.size() == 2) {
TypeDescriptor firstParameterType = context.getType(argumentList.first());
if (firstParameterType != null
&& firstParameterType.matchesSignature(JavaParser.TYPE_STRING)) {
maybeReportIssue(calculateValue(context, argumentList.last()), context, node);
}
}
}
示例8: getArgument
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
public Expression getArgument(int argument) {
if (!(mTargetNode instanceof MethodInvocation)) {
return null;
}
MethodInvocation call = (MethodInvocation) mTargetNode;
StrictListAccessor<Expression, MethodInvocation> args = call.astArguments();
if (argument >= args.size()) {
return null;
}
Iterator<Expression> iterator = args.iterator();
int index = 0;
while (iterator.hasNext()) {
Expression arg = iterator.next();
if (index++ == argument) {
return arg;
}
}
return null;
}
示例9: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(
@NonNull JavaContext context,
@Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
StrictListAccessor<Expression, MethodInvocation> argumentList = node.astArguments();
if (argumentList != null && argumentList.size() == 1) {
Expression argument = argumentList.first();
if (argument instanceof Select) {
String expression = argument.toString();
if (expression.startsWith(R_LAYOUT_RESOURCE_PREFIX)) {
whiteListLayout(expression.substring(R_LAYOUT_RESOURCE_PREFIX.length()));
}
}
}
}
示例10: getFirstArgument
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
public static MethodInvocation getFirstArgument(MethodInvocation node) {
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args != null && args.size() >= 1) {
Expression expression = args.first();
// Skip anything that is not a method call, such as operands
if (expression instanceof MethodInvocation) {
return (MethodInvocation) expression;
}
}
return null;
}
示例11: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args.isEmpty()) {
return;
}
Project project = context.getProject();
List<File> resourceFolder = project.getResourceFolders();
if (resourceFolder.isEmpty()) {
return;
}
String resourcePath = resourceFolder.get(0).getAbsolutePath();
for (Expression expression : args) {
String input = expression.toString();
if (input != null && input.contains("R.drawable")) {
// 找出 drawable 相关的参数
// 获取 drawable 名字
String drawableName = input.replace("R.drawable.", "");
try {
// 若 drawable 为 Vector Drawable,则文件后缀为 xml,根据 resource 路径,drawable 名字,文件后缀拼接出完整路径
FileInputStream fileInputStream = new FileInputStream(resourcePath + "/drawable/" + drawableName + ".xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
String line = reader.readLine();
if (line.contains("vector")) {
// 若文件存在,并且包含首行包含 vector,则为 Vector Drawable,抛出警告
context.report(ISSUE_JAVA_VECTOR_DRAWABLE, node, context.getLocation(node), expression.toString() + " 为 Vector Drawable,请使用 getVectorDrawable 方法获取,避免 4.0 及以下版本的系统产生 Crash");
}
fileInputStream.close();
} catch (Exception ignored) {
}
}
}
}
示例12: isSetContentViewOnThis_ForActivity
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
* If user make this call "setContentView(R.layout.activity_main)" without an explict instance, return true.
* Else if "this.setContentView(R.layout.activity_main)", then return true.
* Else if "someobj.setContentView(R.layout.activity_main)", return false.
*/
private boolean isSetContentViewOnThis_ForActivity(@NonNull MethodInvocation node) {
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
String argOwner = args.owner().toString();
if (argOwner.startsWith("setContentView(")
|| argOwner.startsWith("this.setContentView(")) {
return true;
} else {
return false;
}
}
示例13: getArgumentNode
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
* Returns the given argument of the given call
*
* @param call the call containing arguments
* @param index the index of the target argument
* @return the argument at the given index
* @throws IllegalArgumentException if index is outside the valid range
*/
@NonNull
public static Node getArgumentNode(@NonNull MethodInvocation call, int index) {
int i = 0;
for (Expression parameter : call.astArguments()) {
if (i == index) {
return parameter;
}
i++;
}
throw new IllegalArgumentException(Integer.toString(index));
}
示例14: visitMethod
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
if (node.getParent() instanceof Cast) {
Cast cast = (Cast) node.getParent();
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args.size() == 1) {
String name = stripPackage(args.first().toString());
String expectedClass = getExpectedType(name);
if (expectedClass != null) {
String castType = cast.astTypeReference().getTypeName();
if (castType.indexOf('.') == -1) {
expectedClass = stripPackage(expectedClass);
}
if (!castType.equals(expectedClass)) {
// It's okay to mix and match
// android.content.ClipboardManager and android.text.ClipboardManager
if (isClipboard(castType) && isClipboard(expectedClass)) {
return;
}
String message = String.format(
"Suspicious cast to `%1$s` for a `%2$s`: expected `%3$s`",
stripPackage(castType), name, stripPackage(expectedClass));
context.report(ISSUE, node, context.getLocation(cast), message);
}
}
}
}
}
示例15: visitMethodInvocation
import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
if (SET_SMALL_ICON.equals(node.astName().astValue())) {
StrictListAccessor<Expression,MethodInvocation> arguments = node.astArguments();
if (arguments.size() == 1 && arguments.first() instanceof Select) {
handleSelect((Select) arguments.first());
}
}
return super.visitMethodInvocation(node);
}