本文整理汇总了Java中lombok.ast.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于lombok.ast包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: argumentsAsString
import lombok.ast.Expression; //导入依赖的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.Expression; //导入依赖的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.Expression; //导入依赖的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: visitVariableDefinitionEntry
import lombok.ast.Expression; //导入依赖的package包/类
@Override
public boolean visitVariableDefinitionEntry(VariableDefinitionEntry node) {
Expression initializer = node.astInitializer();
if (initializer instanceof VariableReference) {
JavaParser.ResolvedNode resolved = mContext.resolve(initializer);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
JavaParser.ResolvedNode resolvedVariable = mContext.resolve(node);
if (resolvedVariable instanceof JavaParser.ResolvedVariable) {
JavaParser.ResolvedVariable variable = (JavaParser.ResolvedVariable) resolvedVariable;
mVariables.add(variable);
}
}
}
return super.visitVariableDefinitionEntry(node);
}
示例5: visitBinaryExpression
import lombok.ast.Expression; //导入依赖的package包/类
@Override
public boolean visitBinaryExpression(BinaryExpression node) {
if (node.astOperator() == BinaryOperator.ASSIGN) {
Expression rhs = node.astRight();
if (rhs instanceof VariableReference) {
JavaParser.ResolvedNode resolved = mContext.resolve(rhs);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
JavaParser.ResolvedNode resolvedLhs = mContext.resolve(node.astLeft());
if (resolvedLhs instanceof JavaParser.ResolvedVariable) {
JavaParser.ResolvedVariable variable = (JavaParser.ResolvedVariable) resolvedLhs;
mVariables.add(variable);
}
}
}
}
return super.visitBinaryExpression(node);
}
示例6: validateSetLowerPriority
import lombok.ast.Expression; //导入依赖的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;
}
示例7: visitMethod
import lombok.ast.Expression; //导入依赖的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.");
}
}
}
示例8: getParamWithLayoutAnnotation_ForFragment
import lombok.ast.Expression; //导入依赖的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;
}
}
示例9: getParamWithLayoutAnnotation
import lombok.ast.Expression; //导入依赖的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(@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;
}
}
示例10: verifyColumn
import lombok.ast.Expression; //导入依赖的package包/类
private boolean verifyColumn(Modifiers node) {
VariableDefinitionEntry var = getPublicStaticFinalStringVar(node);
if (var == null)
return false;
Expression initializer = var.astInitializer();
if (!(initializer instanceof StringLiteral))
return false;
String name = SimplName.from(var.astName().astValue());
String value = ((StringLiteral) initializer).astValue();
if (!name.equals(value))
mContext.report(COLUMN_NAME, node, mContext.getLocation(node.getParent()), "must match " + SimplName.quote(name));
if (SqlKeywords.contain(name))
mContext.report(SQL_KEYWORD, mContext.getLocation(var.astName()), "use quoted with ContentValues");
return true;
}
示例11: verifyConstraint
import lombok.ast.Expression; //导入依赖的package包/类
private boolean verifyConstraint(Modifiers node) {
VariableDefinitionEntry var = getPublicStaticFinalStringVar(node);
if (var == null)
return false;
Expression initializer = var.astInitializer();
if (!(initializer instanceof StringLiteral))
return false;
String name = SimplName.from(var.astName().astValue());
String value = ((StringLiteral) initializer).astValue();
if (!name.equals(value))
mContext.report(CONSTRAINT_NAME, node, mContext.getLocation(node.getParent()), "must match " + SimplName.quote(name));
return true;
}
示例12: visitMethodInvocation
import lombok.ast.Expression; //导入依赖的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;
}
示例13: ensureAtLeast
import lombok.ast.Expression; //导入依赖的package包/类
private static void ensureAtLeast(@NonNull JavaContext context,
@NonNull MethodInvocation node, int parameter, long min) {
Iterator<Expression> iterator = node.astArguments().iterator();
Expression argument = null;
for (int i = 0; i <= parameter; i++) {
if (!iterator.hasNext()) {
return;
}
argument = iterator.next();
}
if (argument == null) {
return;
}
long value = getLongValue(context, argument);
if (value < min) {
String message = String.format("Value will be forced up to %d as of Android 5.1; "
+ "don't rely on this to be exact", min);
context.report(ISSUE, argument, context.getLocation(argument), message);
}
}
示例14: getLhs
import lombok.ast.Expression; //导入依赖的package包/类
@Nullable
private static String getLhs(@NonNull MethodInvocation call) {
Node parent = call.getParent();
if (parent instanceof Cast) {
parent = parent.getParent();
}
if (parent instanceof VariableDefinitionEntry) {
VariableDefinitionEntry vde = (VariableDefinitionEntry) parent;
return vde.astName().astValue();
} else if (parent instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) parent;
Expression left = be.astLeft();
if (left instanceof VariableReference || left instanceof Select) {
return be.astLeft().toString();
} else if (left instanceof ArrayAccess) {
ArrayAccess aa = (ArrayAccess) left;
return aa.astOperand().toString();
}
}
return null;
}
示例15: visitMethod
import lombok.ast.Expression; //导入依赖的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);
}
}
}