@ Nonnull public static InterfaceAnalysis analyze ( @ Nonnull final String code ) { Check . notNull ( code , "code" ) ; final CompilationUnit unit = Check . notNull ( SourceCodeReader . parse ( code ) , "compilationUnit" ) ; final List < TypeDeclaration > types = Check . notEmpty ( unit . getTypes ( ) , "typeDeclarations" ) ; Check . stateIsTrue ( types . size ( ) == 1 , "only one interface declaration per analysis is supported" ) ; final ClassOrInterfaceDeclaration type = ( ClassOrInterfaceDeclaration ) types . get ( 0 ) ; final Imports imports = SourceCodeReader . findImports ( unit . getImports ( ) ) ; final Package pkg = unit . getPackage ( ) != null ? new Package ( unit . getPackage ( ) . getName ( ) . toString ( ) ) : Package . UNDEFINED ; final List < Annotation > annotations = SourceCodeReader . findAnnotations ( type . getAnnotations ( ) , imports ) ; final List < Method > methods = SourceCodeReader . findMethods ( type . getMembers ( ) , imports ) ; Check . stateIsTrue ( ! hasPossibleMutatingMethods ( methods ) , "The passed interface '%s' seems to have mutating methods" , type . getName ( ) ) ; final List < Interface > extendsInterfaces = SourceCodeReader . findExtends ( type ) ; final String interfaceName = type . getName ( ) ; return new ImmutableInterfaceAnalysis ( annotations , extendsInterfaces , imports . asList ( ) , interfaceName , methods , pkg ) ; }
Analyzes the source code of an interface . The specified interface must not contain methods that changes the state of the corresponding object itself .