本文整理汇总了Java中lombok.ast.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于lombok.ast包,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:vincetreur,项目名称:Ristretto,代码行数:20,代码来源:DetectorUtils.java
示例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;
}
开发者ID:vincetreur,项目名称:Ristretto,代码行数:29,代码来源:AllOfIsDisplayedDetector.java
示例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");
}
}
}
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:23,代码来源:QMUIFWordDetector.java
示例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);
}
开发者ID:massivedisaster,项目名称:ActivityFragmentManager,代码行数:17,代码来源:CommitTransaction.java
示例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);
}
开发者ID:massivedisaster,项目名称:ActivityFragmentManager,代码行数:19,代码来源:CommitTransaction.java
示例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;
}
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:30,代码来源:ThreadPriorityAstVisitor.java
示例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.");
}
}
}
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:18,代码来源:NotOperatorArgumentDetector.java
示例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;
}
}
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:23,代码来源:ActivityFragmentLayoutNameDetector.java
示例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;
}
}
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:23,代码来源:ViewHolderItemNameDetector.java
示例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;
}
开发者ID:tynn,项目名称:simplDb,代码行数:21,代码来源:SimplLintVisitor.java
示例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;
}
开发者ID:tynn,项目名称:simplDb,代码行数:18,代码来源:SimplLintVisitor.java
示例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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:OverdrawDetector.java
示例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);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:AlarmDetector.java
示例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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CutPasteDetector.java
示例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);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GetSignaturesDetector.java
示例16: isStringParameter
import lombok.ast.Expression; //导入依赖的package包/类
private static boolean isStringParameter(
@NonNull Expression expression, @NonNull JavaContext context) {
if (expression instanceof StringLiteral) {
return true;
} else {
ResolvedNode resolvedNode = context.resolve(expression);
if (resolvedNode instanceof ResolvedField) {
if (((ResolvedField) resolvedNode).getValue() instanceof String) {
return true;
}
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:GetSignaturesDetector.java
示例17: addReferencedVariables
import lombok.ast.Expression; //导入依赖的package包/类
/** Adds any variables referenced in the given expression into the given list */
private static void addReferencedVariables(Collection<String> variables,
Expression expression) {
if (expression instanceof BinaryExpression) {
BinaryExpression binary = (BinaryExpression) expression;
addReferencedVariables(variables, binary.astLeft());
addReferencedVariables(variables, binary.astRight());
} else if (expression instanceof UnaryExpression) {
UnaryExpression unary = (UnaryExpression) expression;
addReferencedVariables(variables, unary.astOperand());
} else if (expression instanceof VariableReference) {
VariableReference reference = (VariableReference) expression;
variables.add(reference.astIdentifier().astValue());
} else if (expression instanceof Select) {
Select select = (Select) expression;
if (select.astOperand() instanceof This) {
variables.add(select.astIdentifier().astValue());
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JavaPerformanceDetector.java
示例18: visitBinaryExpression
import lombok.ast.Expression; //导入依赖的package包/类
@Override
public boolean visitBinaryExpression(BinaryExpression node) {
BinaryOperator operator = node.astOperator();
if (operator == BinaryOperator.ASSIGN || operator == BinaryOperator.OR_ASSIGN) {
Expression left = node.astLeft();
String variable;
if (left instanceof Select && ((Select) left).astOperand() instanceof This) {
variable = ((Select) left).astIdentifier().astValue();
} else {
variable = left.toString();
}
mVariables.add(variable);
}
return super.visitBinaryExpression(node);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JavaPerformanceDetector.java
示例19: getArgumentType
import lombok.ast.Expression; //导入依赖的package包/类
/** Returns the argument type of the given formatting argument of the
* target node. Note: This is in the formatting string, which is one higher
* than the String.format parameter number, since the first argument is the
* formatting string itself.
*
* @param argument the argument number
* @return the class (such as {@link Integer#TYPE} etc) or null if not known
*/
public Class<?> getArgumentType(int argument) {
Expression arg = getArgument(argument);
if (arg != null) {
// Look up type based on the source code literals
Class<?> type = getType(arg);
if (type != null) {
return type;
}
// If the AST supports type resolution, use that for other types
// of expressions
if (mContext != null) {
return getTypeClass(mContext.getType(arg));
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:StringFormatDetector.java
示例20: getArgument
import lombok.ast.Expression; //导入依赖的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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:StringFormatDetector.java
注:本文中的lombok.ast.Expression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论