@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " directly. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } };
@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"); } } } }
@Override public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) { StrictListAccessor<Expression, MethodInvocation> args = node.astArguments(); if (args.isEmpty()) { return;
public void emptyDeclarationMustHaveNoModifiers(EmptyDeclaration node) { Modifiers modifiers = node.astModifiers(); if (!modifiers.astKeywords().isEmpty() || !modifiers.astAnnotations().isEmpty()) { node.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, "Empty Declarations cannot have modifiers.")); } }
public void checkSwitchStartsWithDefaultOrCase(Switch node) { Block body = node.astBody(); if (body != null) { Statement first = body.astContents().first(); if (first != null && !(first instanceof Case) && !(first instanceof Default)) { node.addMessage(error(SWITCH_DOES_NOT_START_WITH_CASE, "switch statements should start with a default or case statement.")); } } } }
@Override public void visitTypeApply(JCTypeApply node) { TypeReference ref = (TypeReference) toTree(node.clazz, FlagKey.TYPE_REFERENCE); TypeReferencePart last = ref.astParts().last(); fillList(node.arguments, last.rawTypeArguments(), FlagKey.TYPE_REFERENCE); setPos(node, ref); setConversionPositionInfo(last, "<", getPosition(node)); set(node, ref); }
private void constructorInvocationMustBeFirst(Statement node, String desc) { if (node.getParent() == null) return; Block b = node.upToBlock(); if (b == null || b.upToConstructorDeclaration() == null || b.astContents().first() != node) { node.addMessage(error(CONSTRUCTOR_INVOCATION_NOT_LEGAL_HERE, "Calling " + desc + " must be the first statement in a constructor.")); return; } }
@Override public void visitArrayTypeReference(ArrayTypeReference node) { lombok.ast.TypeReference ref = new lombok.ast.TypeReference(); ref.astArrayDimensions(((node.bits & ASTNode.IsVarArgs) == 0) ? node.dimensions : node.dimensions - 1); lombok.ast.TypeReferencePart part = new lombok.ast.TypeReferencePart(); part.astIdentifier(toIdentifier(node.token, node.sourceStart, node.sourceEnd)); ref.astParts().addToEnd(part); set(node, setPosition(node, ref)); }
public void checkStaticInitializerInNonStaticType(StaticInitializer node) { TypeDeclaration parent = node.upUpToTypeDeclaration(); if (parent != null) { if (!parent.astModifiers().isStatic()) { node.addMessage(error(INITIALIZER_STATIC_IN_NON_STATIC_TYPE, "static initializers are only allowed in top-level or static types declarations.")); } } }
public void checkNotLoneTry(Try node) { if (node.rawCatches().size() == 0 && node.rawFinally() == null) { node.addMessage(error(TRY_LONE_TRY, "try statement with no catches and no finally")); } }
@Override public void visitCaseStatement(CaseStatement node) { if (node.constantExpression == null) { lombok.ast.Default defaultStat = new lombok.ast.Default(); //TODO still have fix drunken positioning. set(node, setPosition(node, defaultStat)); return; } lombok.ast.Case caseStat = new lombok.ast.Case(); caseStat.astCondition((lombok.ast.Expression) toTree(node.constantExpression)); set(node, setPosition(node, caseStat)); }
public void emptyDeclarationMustHaveNoModifiers(EmptyDeclaration node) { Modifiers modifiers = node.astModifiers(); if (!modifiers.astKeywords().isEmpty() || !modifiers.astAnnotations().isEmpty()) { node.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, "Empty Declarations cannot have modifiers.")); } }
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("wait") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't wait on object. Use Timer's wait instead."); } return super.visitMethodInvocation(node); } };
public void checkSwitchStartsWithDefaultOrCase(Switch node) { Block body = node.astBody(); if (body != null) { Statement first = body.astContents().first(); if (first != null && !(first instanceof Case) && !(first instanceof Default)) { node.addMessage(error(SWITCH_DOES_NOT_START_WITH_CASE, "switch statements should start with a default or case statement.")); } } } }
@Override public void visitTypeApply(JCTypeApply node) { TypeReference ref = (TypeReference) toTree(node.clazz, FlagKey.TYPE_REFERENCE); TypeReferencePart last = ref.astParts().last(); fillList(node.arguments, last.rawTypeArguments(), FlagKey.TYPE_REFERENCE); setPos(node, ref); setConversionPositionInfo(last, "<", getPosition(node)); set(node, ref); }
public void checkStaticInitializerInNonStaticType(StaticInitializer node) { TypeDeclaration parent = node.upUpToTypeDeclaration(); if (parent != null) { if (!parent.astModifiers().isStatic()) { node.addMessage(error(INITIALIZER_STATIC_IN_NON_STATIC_TYPE, "static initializers are only allowed in top-level or static types declarations.")); } } }
public void emptyDeclarationMustHaveNoModifiers(EmptyDeclaration node) { Modifiers modifiers = node.astModifiers(); if (!modifiers.astKeywords().isEmpty() || !modifiers.astAnnotations().isEmpty()) { node.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, "Empty Declarations cannot have modifiers.")); } }
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("sleep") && operand.toString().equals("Thread") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, node, context.getLocation(node), "Don't call sleep. Use MockTimer instead."); } return super.visitMethodInvocation(node); } };
public void checkSwitchStartsWithDefaultOrCase(Switch node) { Block body = node.astBody(); if (body != null) { Statement first = body.astContents().first(); if (first != null && !(first instanceof Case) && !(first instanceof Default)) { node.addMessage(error(SWITCH_DOES_NOT_START_WITH_CASE, "switch statements should start with a default or case statement.")); } } } }
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && operand.toString().equals("System") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " on system. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } };