@CopyMethod static String getDescription(MethodDeclaration self) { return self.astMethodName().astValue(); } }
@CopyMethod static String getDescription(MethodDeclaration self) { return self.astMethodName().astValue(); } }
@CopyMethod static String getDescription(MethodDeclaration self) { return self.astMethodName().astValue(); } }
@Override public boolean visitMethodDeclaration(MethodDeclaration node) { if (ON_CREATE_OPTIONS_MENU.equals(node.astMethodName().astValue())) { // Gather any R.menu references found in this method node.accept(new MenuFinder()); } return super.visitMethodDeclaration(node); }
if (ON_LAYOUT.equals(node.astMethodName().astValue())) { StrictListAccessor<VariableDefinition, MethodDeclaration> parameters = node.astParameters();
/** * Returns true if this method looks like it's overriding android.view.View's * {@code public void layout(int l, int t, int r, int b)} */ private static boolean isLayoutMethod(MethodDeclaration node) { if (LAYOUT.equals(node.astMethodName().astValue())) { StrictListAccessor<VariableDefinition, MethodDeclaration> parameters = node.astParameters(); if (parameters != null && parameters.size() == 4) { Iterator<VariableDefinition> iterator = parameters.iterator(); for (int i = 0; i < 4; i++) { if (!iterator.hasNext()) { return false; } VariableDefinition next = iterator.next(); TypeReferencePart type = next.astTypeReference().astParts().last(); if (!TYPE_INT.equals(type.getTypeName())) { return false; } } return true; } } return false; }
/** * Returns true if this method looks like it's overriding android.view.View's * {@code protected void onDraw(Canvas canvas)} */ private static boolean isOnDrawMethod(MethodDeclaration node) { if (ON_DRAW.equals(node.astMethodName().astValue())) { StrictListAccessor<VariableDefinition, MethodDeclaration> parameters = node.astParameters(); if (parameters != null && parameters.size() == 1) { VariableDefinition arg0 = parameters.first(); TypeReferencePart type = arg0.astTypeReference().astParts().last(); String typeName = type.getTypeName(); if (typeName.equals(CANVAS)) { return true; } } } return false; }
@Override public boolean visitMethodDeclaration(MethodDeclaration node) { JCMethodDecl methodDef = treeMaker.MethodDef( (JCModifiers)toTree(node.astModifiers()), toName(node.astMethodName()), toExpression(node.astReturnTypeReference()), toList(JCTypeParameter.class, node.astTypeVariables()), toList(JCVariableDecl.class, node.astParameters()), toList(JCExpression.class, node.astThrownTypeReferences()), (JCBlock)toTree(node.astBody()), null ); for (JCVariableDecl decl : methodDef.params) { decl.mods.flags |= Flags.PARAMETER; } int start = node.astMethodName().getPosition().getStart(); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, methodDef)); }
@Override public boolean visitMethodDeclaration(MethodDeclaration node) { JCMethodDecl methodDef = treeMaker.MethodDef( (JCModifiers)toTree(node.astModifiers()), toName(node.astMethodName()), toExpression(node.astReturnTypeReference()), toList(JCTypeParameter.class, node.astTypeVariables()), toList(JCVariableDecl.class, node.astParameters()), toList(JCExpression.class, node.astThrownTypeReferences()), (JCBlock)toTree(node.astBody()), null ); for (JCVariableDecl decl : methodDef.params) { decl.mods.flags |= Flags.PARAMETER; } int start = node.astMethodName().getPosition().getStart(); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, methodDef)); }
@Override public boolean visitMethodDeclaration(MethodDeclaration node) { JCMethodDecl methodDef = treeMaker.MethodDef( (JCModifiers)toTree(node.astModifiers()), toName(node.astMethodName()), toExpression(node.astReturnTypeReference()), toList(JCTypeParameter.class, node.astTypeVariables()), toList(JCVariableDecl.class, node.astParameters()), toList(JCExpression.class, node.astThrownTypeReferences()), (JCBlock)toTree(node.astBody()), null ); for (JCVariableDecl decl : methodDef.params) { decl.mods.flags |= Flags.PARAMETER; } int start = node.astMethodName().getPosition().getStart(); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, methodDef)); }
/** * Returns true if this method looks like it's overriding android.view.View's * {@code protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)} */ private static boolean isOnMeasureMethod(MethodDeclaration node) { if (ON_MEASURE.equals(node.astMethodName().astValue())) { StrictListAccessor<VariableDefinition, MethodDeclaration> parameters = node.astParameters(); if (parameters != null && parameters.size() == 2) { VariableDefinition arg0 = parameters.first(); VariableDefinition arg1 = parameters.last(); TypeReferencePart type1 = arg0.astTypeReference().astParts().last(); TypeReferencePart type2 = arg1.astTypeReference().astParts().last(); return TYPE_INT.equals(type1.getTypeName()) && TYPE_INT.equals(type2.getTypeName()); } } return false; }
private static void checkCallSuper(@NonNull JavaContext context, @NonNull MethodDeclaration declaration, @NonNull ResolvedMethod method) { ResolvedMethod superMethod = getRequiredSuperMethod(method); if (superMethod != null) { if (!SuperCallVisitor.callsSuper(context, declaration, superMethod)) { String methodName = method.getName(); String message = "Overriding method should call `super." + methodName + "`"; Location location = context.getLocation(declaration.astMethodName()); context.report(ISSUE, declaration, location, message); } } }
@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); } }
@Override @NonNull public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) { // The range on method name identifiers is wrong in the ECJ nodes; just take start of // name + length of name if (node instanceof MethodDeclaration) { MethodDeclaration declaration = (MethodDeclaration) node; Identifier identifier = declaration.astMethodName(); Location location = getLocation(context, identifier); com.android.tools.lint.detector.api.Position start = location.getStart(); com.android.tools.lint.detector.api.Position end = location.getEnd(); int methodNameLength = identifier.astValue().length(); if (start != null && end != null && end.getOffset() - start.getOffset() > methodNameLength) { end = new DefaultPosition(start.getLine(), start.getColumn() + methodNameLength, start.getOffset() + methodNameLength); return Location.create(location.getFile(), start, end); } return location; } return super.getNameLocation(context, node); }
@Override public void visitMethodDeclaration(MethodDeclaration node) { lombok.ast.MethodDeclaration decl = new lombok.ast.MethodDeclaration(); decl.astMethodName(toIdentifier(node.selector, node.sourceStart, node.sourceEnd)); decl.astJavadoc((lombok.ast.Comment) toTree(node.javadoc)); lombok.ast.Modifiers modifiers = toModifiers(node.modifiers, node.annotations, node.modifiersSourceStart, node.declarationSourceStart); decl.astModifiers(modifiers); decl.astReturnTypeReference((lombok.ast.TypeReference) toTree(node.returnType)); boolean semiColonBody = ((node.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0); if (!modifiers.isAbstract() && !node.isNative() && !semiColonBody) { lombok.ast.Block block = toBlock(node.statements); block.setPosition(toPosition(node.bodyStart - 1, node.bodyEnd + 1)); decl.astBody(block); } fillList(node.arguments, decl.rawParameters(), FlagKey.AS_DEFINITION, FlagKey.NO_VARDECL_FOLDING); fillList(node.typeParameters, decl.rawTypeVariables()); fillList(node.thrownExceptions, decl.rawThrownTypeReferences()); setConversionPositionInfo(decl, "signature", toPosition(node.sourceStart, node.sourceEnd)); decl.setPosition(toPosition(node.declarationSourceStart, node.declarationSourceEnd)); set(node, decl); }
@Override public void visitMethodDeclaration(MethodDeclaration node) { lombok.ast.MethodDeclaration decl = new lombok.ast.MethodDeclaration(); decl.astMethodName(toIdentifier(node.selector, node.sourceStart, node.sourceEnd)); decl.astJavadoc((lombok.ast.Comment) toTree(node.javadoc)); lombok.ast.Modifiers modifiers = toModifiers(node.modifiers, node.annotations, node.modifiersSourceStart, node.declarationSourceStart); decl.astModifiers(modifiers); decl.astReturnTypeReference((lombok.ast.TypeReference) toTree(node.returnType)); boolean semiColonBody = ((node.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0); if (!modifiers.isAbstract() && !node.isNative() && !semiColonBody) { lombok.ast.Block block = toBlock(node.statements); block.setPosition(toPosition(node.bodyStart - 1, node.bodyEnd + 1)); decl.astBody(block); } fillList(node.arguments, decl.rawParameters(), FlagKey.AS_DEFINITION, FlagKey.NO_VARDECL_FOLDING); fillList(node.typeParameters, decl.rawTypeVariables()); fillList(node.thrownExceptions, decl.rawThrownTypeReferences()); setConversionPositionInfo(decl, "signature", toPosition(node.sourceStart, node.sourceEnd)); decl.setPosition(toPosition(node.declarationSourceStart, node.declarationSourceEnd)); set(node, decl); }
@Override public void visitMethodDeclaration(MethodDeclaration node) { lombok.ast.MethodDeclaration decl = new lombok.ast.MethodDeclaration(); decl.astMethodName(toIdentifier(node.selector, node.sourceStart, node.sourceEnd)); decl.astJavadoc((lombok.ast.Comment) toTree(node.javadoc)); lombok.ast.Modifiers modifiers = toModifiers(node.modifiers, node.annotations, node.modifiersSourceStart, node.declarationSourceStart); decl.astModifiers(modifiers); decl.astReturnTypeReference((lombok.ast.TypeReference) toTree(node.returnType)); boolean semiColonBody = ((node.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0); if (!modifiers.isAbstract() && !node.isNative() && !semiColonBody) { lombok.ast.Block block = toBlock(node.statements); block.setPosition(toPosition(node.bodyStart - 1, node.bodyEnd + 1)); decl.astBody(block); } fillList(node.arguments, decl.rawParameters(), FlagKey.AS_DEFINITION, FlagKey.NO_VARDECL_FOLDING); fillList(node.typeParameters, decl.rawTypeVariables()); fillList(node.thrownExceptions, decl.rawThrownTypeReferences()); setConversionPositionInfo(decl, "signature", toPosition(node.sourceStart, node.sourceEnd)); decl.setPosition(toPosition(node.declarationSourceStart, node.declarationSourceEnd)); set(node, decl); }
decl.astMethodName(createIdentifierIfNeeded(name, currentPos())).rawBody(body); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); int extraDims = dims == null ? 0 : dims.size();
decl.astMethodName(createIdentifierIfNeeded(name, currentPos())).rawBody(body); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); int extraDims = dims == null ? 0 : dims.size();
formatter.space(); formatter.nameNextElement("methodName"); visit(node.astMethodName()); formatter.append("("); visitAll("parameter", node.rawParameters(), ", ", "", "");