/** * Return {@code true} if any of the given methods are abstract. * * @param methods the methods being tested * @return {@code true} if any of the given methods are abstract */ private boolean hasAbstractMethod(MethodElement[] methods) { for (MethodElement method : methods) { if (method.isAbstract()) { return true; } } return false; }
public void test_visitMethodDeclaration_static() { ElementHolder holder = new ElementHolder(); ElementBuilder builder = new ElementBuilder(holder); String methodName = "m"; MethodDeclaration methodDeclaration = methodDeclaration( Keyword.STATIC, null, null, null, identifier(methodName), formalParameterList(), blockFunctionBody()); methodDeclaration.accept(builder); MethodElement[] methods = holder.getMethods(); assertLength(1, methods); MethodElement method = methods[0]; assertNotNull(method); assertEquals(methodName, method.getName()); assertLength(0, method.getFunctions()); assertLength(0, method.getLabels()); assertLength(0, method.getLocalVariables()); assertLength(0, method.getParameters()); assertFalse(method.isAbstract()); assertTrue(method.isStatic()); assertFalse(method.isSynthetic()); }
public void test_visitClassDeclaration_withMembers() { ElementHolder holder = new ElementHolder(); ElementBuilder builder = new ElementBuilder(holder); String className = "C"; String typeVariableName = "E"; String fieldName = "f"; String methodName = "m"; ClassDeclaration classDeclaration = classDeclaration( null, className, typeParameterList(typeVariableName), null, null, null, fieldDeclaration(false, null, variableDeclaration(fieldName)), methodDeclaration( null, null, null, null, identifier(methodName), formalParameterList(), blockFunctionBody())); classDeclaration.accept(builder); ClassElement[] types = holder.getTypes(); assertLength(1, types); ClassElement type = types[0]; assertNotNull(type); assertEquals(className, type.getName()); assertFalse(type.isAbstract()); assertFalse(type.isSynthetic()); TypeVariableElement[] typeVariables = type.getTypeVariables(); assertLength(1, typeVariables); TypeVariableElement typeVariable = typeVariables[0]; assertNotNull(typeVariable); assertEquals(typeVariableName, typeVariable.getName()); FieldElement[] fields = type.getFields(); assertLength(1, fields); FieldElement field = fields[0]; assertNotNull(field); assertEquals(fieldName, field.getName()); MethodElement[] methods = type.getMethods(); assertLength(1, methods); MethodElement method = methods[0]; assertNotNull(method); assertEquals(methodName, method.getName()); }
public void test_metadata_method() throws Exception { Source source = addSource( createSource( // "const A = null;", "class C {", " @A void m() {}", "}")); LibraryElement library = resolve(source); assertNotNull(library); CompilationUnitElement unit = library.getDefiningCompilationUnit(); assertNotNull(unit); ClassElement[] classes = unit.getTypes(); assertLength(1, classes); MethodElement method = classes[0].getMethods()[0]; ElementAnnotation[] annotations = method.getMetadata(); assertLength(1, annotations); assertNoErrors(source); verify(source); }
public void test_visitMethodDeclaration_withMembers() { ElementHolder holder = new ElementHolder(); ElementBuilder builder = new ElementBuilder(holder); String methodName = "m"; String parameterName = "p"; String localVariableName = "v"; String labelName = "l"; String exceptionParameterName = "e"; MethodDeclaration methodDeclaration = methodDeclaration( null, null, null, null, identifier(methodName), formalParameterList(simpleFormalParameter(parameterName)), blockFunctionBody( variableDeclarationStatement(Keyword.VAR, variableDeclaration(localVariableName)), tryStatement( block(labeledStatement(list(label(labelName)), returnStatement())), catchClause(exceptionParameterName)))); methodDeclaration.accept(builder); MethodElement[] methods = holder.getMethods(); assertLength(1, methods); MethodElement method = methods[0]; assertNotNull(method); assertEquals(methodName, method.getName()); assertFalse(method.isAbstract()); assertFalse(method.isStatic()); assertFalse(method.isSynthetic()); VariableElement[] parameters = method.getParameters(); assertLength(1, parameters); VariableElement parameter = parameters[0]; assertNotNull(parameter); assertEquals(parameterName, parameter.getName()); VariableElement[] localVariables = method.getLocalVariables(); assertLength(2, localVariables); VariableElement firstVariable = localVariables[0]; VariableElement secondVariable = localVariables[1]; assertNotNull(firstVariable); assertNotNull(secondVariable); assertTrue( (firstVariable.getName().equals(localVariableName) && secondVariable.getName().equals(exceptionParameterName)) || (firstVariable.getName().equals(exceptionParameterName) && secondVariable.getName().equals(localVariableName))); LabelElement[] labels = method.getLabels(); assertLength(1, labels); LabelElement label = labels[0]; assertNotNull(label); assertEquals(labelName, label.getName()); }