本文整理汇总了Java中lombok.ast.AstVisitor类的典型用法代码示例。如果您正苦于以下问题:Java AstVisitor类的具体用法?Java AstVisitor怎么用?Java AstVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AstVisitor类属于lombok.ast包,在下文中一共展示了AstVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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);
}
示例2: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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");
}
}
}
示例3: createJavaVisitor
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public AstVisitor createJavaVisitor(final @NonNull JavaContext context) {
return new ForwardingAstVisitor() {
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
TypeReference reference = node.astTypeReference();
String typeName = reference.astParts().last().astIdentifier().astValue();
// TODO: Should we handle factory method constructions of HashMaps as well,
// e.g. via Guava? This is a bit trickier since we need to infer the type
// arguments from the calling context.
if (typeName.equals(HASH_MAP)) {
checkHashMap(context, node, reference);
}
return super.visitConstructorInvocation(node);
}
};
}
示例4: createJavaVisitor
import lombok.ast.AstVisitor; //导入依赖的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);
}
};
}
示例5: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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: visitMethod
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass)context.resolve(JavaContext.findSurroundingClass(node));
JavaParser.ResolvedMethod sorroundingMethod = (JavaParser.ResolvedMethod)context.resolve(JavaContext.findSurroundingMethod(node));
if (sorroundingMethod.getName().equals("onCreateViewHolder")
&& sorroundingClass.isSubclassOf("android.support.v7.widget.RecyclerView.Adapter", false)){
String layoutString = getParamWithLayoutAnnotation(context, node);
if (layoutString == null){
return;
}
if (!isFileStringStartWithPrefix(layoutString, "item_")) {
context.report(ISSUE,
node,
context.getLocation(node),
"Layout resource file in ViewHolder must be named with prefix `item_`.");
}
}
}
示例7: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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()));
}
}
}
}
示例9: visitResourceReference
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitResourceReference(
@NonNull JavaContext context,
@Nullable AstVisitor visitor,
@NonNull Node node,
@NonNull String type,
@NonNull String name,
boolean isFramework) {
if (context.getProject().isGradleProject() && !isFramework) {
Project project = context.getProject();
if (project.getGradleProjectModel() != null && project.getCurrentVariant() != null) {
ResourceType resourceType = ResourceType.getEnum(type);
if (resourceType != null && isPrivate(context, resourceType, name)) {
String message = createUsageErrorMessage(context, resourceType, name);
context.report(ISSUE, node, context.getLocation(node), message);
}
}
}
}
示例10: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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);
}
}
示例11: visitMethod
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
if (mDependsOnAppCompat && isAppBarActivityCall(context, node)) {
String name = node.astName().astValue();
String replace = null;
if (GET_ACTION_BAR.equals(name)) {
replace = "getSupportActionBar";
} else if (START_ACTION_MODE.equals(name)) {
replace = "startSupportActionMode";
} else if (SET_PROGRESS_BAR_VIS.equals(name)) {
replace = "setSupportProgressBarVisibility";
} else if (SET_PROGRESS_BAR_IN_VIS.equals(name)) {
replace = "setSupportProgressBarIndeterminateVisibility";
} else if (SET_PROGRESS_BAR_INDETERMINATE.equals(name)) {
replace = "setSupportProgressBarIndeterminate";
} else if (REQUEST_WINDOW_FEATURE.equals(name)) {
replace = "supportRequestWindowFeature";
}
if (replace != null) {
String message = String.format(ERROR_MESSAGE_FORMAT, replace, name);
context.report(ISSUE, node, context.getLocation(node), message);
}
}
}
示例12: visitMethod
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull MethodInvocation node) {
assert node.astName().astValue().equals("sendTextMessage") || //$NON-NLS-1$
node.astName().astValue().equals("sendMultipartTextMessage"); //$NON-NLS-1$
if (node.astOperand() == null) {
// "sendTextMessage"/"sendMultipartTextMessage" in the code with no operand
return;
}
StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
if (args.size() == 5) {
Expression destinationAddress = args.first();
if (destinationAddress instanceof StringLiteral) {
String number = ((StringLiteral) destinationAddress).astValue();
if (!number.startsWith("+")) { //$NON-NLS-1$
context.report(ISSUE, node, context.getLocation(destinationAddress),
"To make sure the SMS can be sent by all users, please start the SMS number " +
"with a + and a country code or restrict the code invocation to people in the country " +
"you are targeting.");
}
}
}
}
示例13: visitMethod
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
if (isNode(context, node, METHOD_CALL)) {
MethodInvocation first = getFirstArgument(node);
if (isWithNode(context, first)) {
String message = argumentsAsString(first, MESSAGE_FORMAT);
context.report(ISSUE, node, context.getLocation(node), message);
}
}
}
示例14: visitMethod
import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
if (isNode(context, node, METHOD_CALL)) {
String message = argumentsAsString(node, MESSAGE_FORMAT);
context.report(ISSUE, node, context.getLocation(node), message);
}
}
示例15: visitMethod
import lombok.ast.AstVisitor; //导入依赖的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) {
}
}
}
}