text
stringlengths 30
1.67M
|
|---|
<s> package org . eclipse . jdt . internal . compiler . batch ; import java . io . BufferedInputStream ; import java . io . ByteArrayInputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . FilenameFilter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . LineNumberReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . io . StringReader ; import java . io . StringWriter ; import java . io . UnsupportedEncodingException ; import java . lang . reflect . Field ; import java . text . DateFormat ; import java . text . MessageFormat ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Date ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import java . util . MissingResourceException ; import java . util . Properties ; import java . util . ResourceBundle ; import java . util . Set ; import java . util . StringTokenizer ; import org . eclipse . jdt . core . compiler . CategorizedProblem ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . compiler . CompilationProgress ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . compiler . batch . BatchCompiler ; import org . eclipse . jdt . internal . compiler . AbstractAnnotationProcessorManager ; import org . eclipse . jdt . internal . compiler . ClassFile ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . Compiler ; import org . eclipse . jdt . internal . compiler . ICompilerRequestor ; import org . eclipse . jdt . internal . compiler . IErrorHandlingPolicy ; import org . eclipse . jdt . internal . compiler . IProblemFactory ; import org . eclipse . jdt . internal . compiler . batch . FileSystem . Classpath ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . env . AccessRule ; import org . eclipse . jdt . internal . compiler . env . AccessRuleSet ; import org . eclipse . jdt . internal . compiler . env . ICompilationUnit ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . impl . CompilerStats ; import org . eclipse . jdt . internal . compiler . lookup . LookupEnvironment ; import org . eclipse . jdt . internal . compiler . lookup . ReferenceBinding ; import org . eclipse . jdt . internal . compiler . problem . DefaultProblemFactory ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; import org . eclipse . jdt . internal . compiler . problem . ProblemSeverities ; import org . eclipse . jdt . internal . compiler . util . GenericXMLWriter ; import org . eclipse . jdt . internal . compiler . util . HashtableOfInt ; import org . eclipse . jdt . internal . compiler . util . HashtableOfObject ; import org . eclipse . jdt . internal . compiler . util . Messages ; import org . eclipse . jdt . internal . compiler . util . SuffixConstants ; import org . eclipse . jdt . internal . compiler . util . Util ; public class Main implements ProblemSeverities , SuffixConstants { public static class Logger { private PrintWriter err ; private PrintWriter log ; private Main main ; private PrintWriter out ; private HashMap parameters ; int tagBits ; private static final String CLASS = "<STR_LIT:class>" ; private static final String CLASS_FILE = "<STR_LIT>" ; private static final String CLASSPATH = "<STR_LIT>" ; private static final String CLASSPATH_FILE = "<STR_LIT>" ; private static final String CLASSPATH_FOLDER = "<STR_LIT>" ; private static final String CLASSPATH_ID = "<STR_LIT:id>" ; private static final String CLASSPATH_JAR = "<STR_LIT>" ; private static final String CLASSPATHS = "<STR_LIT>" ; private static final String COMMAND_LINE_ARGUMENT = "<STR_LIT>" ; private static final String COMMAND_LINE_ARGUMENTS = "<STR_LIT>" ; private static final String COMPILER = "<STR_LIT>" ; private static final String COMPILER_COPYRIGHT = "<STR_LIT>" ; private static final String COMPILER_NAME = "<STR_LIT:name>" ; private static final String COMPILER_VERSION = "<STR_LIT:version>" ; public static final int EMACS = <NUM_LIT:2> ; private static final String ERROR = "<STR_LIT>" ; private static final String ERROR_TAG = "<STR_LIT:error>" ; private static final String WARNING_TAG = "<STR_LIT>" ; private static final String EXCEPTION = "<STR_LIT>" ; private static final String EXTRA_PROBLEM_TAG = "<STR_LIT>" ; private static final String EXTRA_PROBLEMS = "<STR_LIT>" ; private static final HashtableOfInt FIELD_TABLE = new HashtableOfInt ( ) ; private static final String KEY = "<STR_LIT:key>" ; private static final String MESSAGE = "<STR_LIT:message>" ; private static final String NUMBER_OF_CLASSFILES = "<STR_LIT>" ; private static final String NUMBER_OF_ERRORS = "<STR_LIT>" ; private static final String NUMBER_OF_LINES = "<STR_LIT>" ; private static final String NUMBER_OF_PROBLEMS = "<STR_LIT>" ; private static final String NUMBER_OF_TASKS = "<STR_LIT>" ; private static final String NUMBER_OF_WARNINGS = "<STR_LIT>" ; private static final String OPTION = "<STR_LIT>" ; private static final String OPTIONS = "<STR_LIT>" ; private static final String OUTPUT = "<STR_LIT>" ; private static final String PACKAGE = "<STR_LIT>" ; private static final String PATH = "<STR_LIT:path>" ; private static final String PROBLEM_ARGUMENT = "<STR_LIT>" ; private static final String PROBLEM_ARGUMENT_VALUE = "<STR_LIT:value>" ; private static final String PROBLEM_ARGUMENTS = "<STR_LIT>" ; private static final String PROBLEM_CATEGORY_ID = "<STR_LIT>" ; private static final String ID = "<STR_LIT:id>" ; private static final String PROBLEM_ID = "<STR_LIT>" ; private static final String PROBLEM_LINE = "<STR_LIT>" ; private static final String PROBLEM_OPTION_KEY = "<STR_LIT>" ; private static final String PROBLEM_MESSAGE = "<STR_LIT:message>" ; private static final String PROBLEM_SEVERITY = "<STR_LIT>" ; private static final String PROBLEM_SOURCE_END = "<STR_LIT>" ; private static final String PROBLEM_SOURCE_START = "<STR_LIT>" ; private static final String PROBLEM_SUMMARY = "<STR_LIT>" ; private static final String PROBLEM_TAG = "<STR_LIT>" ; private static final String PROBLEMS = "<STR_LIT>" ; private static final String SOURCE = "<STR_LIT:source>" ; private static final String SOURCE_CONTEXT = "<STR_LIT>" ; private static final String SOURCE_END = "<STR_LIT>" ; private static final String SOURCE_START = "<STR_LIT>" ; private static final String SOURCES = "<STR_LIT>" ; private static final String STATS = "<STR_LIT>" ; private static final String TASK = "<STR_LIT>" ; private static final String TASKS = "<STR_LIT>" ; private static final String TIME = "<STR_LIT>" ; private static final String VALUE = "<STR_LIT:value>" ; private static final String WARNING = "<STR_LIT>" ; public static final int XML = <NUM_LIT:1> ; private static final String XML_DTD_DECLARATION = "<STR_LIT>" ; static { try { Class c = IProblem . class ; Field [ ] fields = c . getFields ( ) ; for ( int i = <NUM_LIT:0> , max = fields . length ; i < max ; i ++ ) { Field field = fields [ i ] ; if ( field . getType ( ) . equals ( Integer . TYPE ) ) { Integer value = ( Integer ) field . get ( null ) ; int key2 = value . intValue ( ) & IProblem . IgnoreCategoriesMask ; if ( key2 == <NUM_LIT:0> ) { key2 = Integer . MAX_VALUE ; } Logger . FIELD_TABLE . put ( key2 , field . getName ( ) ) ; } } } catch ( SecurityException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } } public Logger ( Main main , PrintWriter out , PrintWriter err ) { this . out = out ; this . err = err ; this . parameters = new HashMap ( ) ; this . main = main ; } public String buildFileName ( String outputPath , String relativeFileName ) { char fileSeparatorChar = File . separatorChar ; String fileSeparator = File . separator ; outputPath = outputPath . replace ( '<CHAR_LIT:/>' , fileSeparatorChar ) ; StringBuffer outDir = new StringBuffer ( outputPath ) ; if ( ! outputPath . endsWith ( fileSeparator ) ) { outDir . append ( fileSeparator ) ; } StringTokenizer tokenizer = new StringTokenizer ( relativeFileName , fileSeparator ) ; String token = tokenizer . nextToken ( ) ; while ( tokenizer . hasMoreTokens ( ) ) { outDir . append ( token ) . append ( fileSeparator ) ; token = tokenizer . nextToken ( ) ; } return outDir . append ( token ) . toString ( ) ; } public void close ( ) { if ( this . log != null ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { endTag ( Logger . COMPILER ) ; flush ( ) ; } this . log . close ( ) ; } } public void compiling ( ) { printlnOut ( this . main . bind ( "<STR_LIT>" ) ) ; } private void endLoggingExtraProblems ( ) { endTag ( Logger . EXTRA_PROBLEMS ) ; } private void endLoggingProblems ( ) { endTag ( Logger . PROBLEMS ) ; } public void endLoggingSource ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { endTag ( Logger . SOURCE ) ; } } public void endLoggingSources ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { endTag ( Logger . SOURCES ) ; } } public void endLoggingTasks ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { endTag ( Logger . TASKS ) ; } } private void endTag ( String name ) { if ( this . log != null ) { ( ( GenericXMLWriter ) this . log ) . endTag ( name , true , true ) ; } } private String errorReportSource ( CategorizedProblem problem , char [ ] unitSource , int bits ) { int startPosition = problem . getSourceStart ( ) ; int endPosition = problem . getSourceEnd ( ) ; if ( unitSource == null ) { if ( problem . getOriginatingFileName ( ) != null ) { try { unitSource = Util . getFileCharContent ( new File ( new String ( problem . getOriginatingFileName ( ) ) ) , null ) ; } catch ( IOException e ) { } } } int length = unitSource == null ? <NUM_LIT:0> : unitSource . length ; if ( ( startPosition > endPosition ) || ( ( startPosition < <NUM_LIT:0> ) && ( endPosition < <NUM_LIT:0> ) ) || length == <NUM_LIT:0> ) return Messages . problem_noSourceInformation ; StringBuffer errorBuffer = new StringBuffer ( ) ; if ( ( bits & Main . Logger . EMACS ) == <NUM_LIT:0> ) { errorBuffer . append ( '<CHAR_LIT:U+0020>' ) . append ( Messages . bind ( Messages . problem_atLine , String . valueOf ( problem . getSourceLineNumber ( ) ) ) ) ; errorBuffer . append ( Util . LINE_SEPARATOR ) ; } errorBuffer . append ( '<STR_LIT:\t>' ) ; char c ; final char SPACE = '<CHAR_LIT:U+0020>' ; final char MARK = '<CHAR_LIT>' ; final char TAB = '<STR_LIT:\t>' ; int begin ; int end ; for ( begin = startPosition >= length ? length - <NUM_LIT:1> : startPosition ; begin > <NUM_LIT:0> ; begin -- ) { if ( ( c = unitSource [ begin - <NUM_LIT:1> ] ) == '<STR_LIT:\n>' || c == '<STR_LIT>' ) break ; } for ( end = endPosition >= length ? length - <NUM_LIT:1> : endPosition ; end + <NUM_LIT:1> < length ; end ++ ) { if ( ( c = unitSource [ end + <NUM_LIT:1> ] ) == '<STR_LIT>' || c == '<STR_LIT:\n>' ) break ; } while ( ( c = unitSource [ begin ] ) == '<CHAR_LIT:U+0020>' || c == '<STR_LIT:\t>' ) begin ++ ; errorBuffer . append ( unitSource , begin , end - begin + <NUM_LIT:1> ) ; errorBuffer . append ( Util . LINE_SEPARATOR ) . append ( "<STR_LIT:t>" ) ; for ( int i = begin ; i < startPosition ; i ++ ) { errorBuffer . append ( ( unitSource [ i ] == TAB ) ? TAB : SPACE ) ; } for ( int i = startPosition ; i <= ( endPosition >= length ? length - <NUM_LIT:1> : endPosition ) ; i ++ ) { errorBuffer . append ( MARK ) ; } return errorBuffer . toString ( ) ; } private void extractContext ( CategorizedProblem problem , char [ ] unitSource ) { int startPosition = problem . getSourceStart ( ) ; int endPosition = problem . getSourceEnd ( ) ; if ( unitSource == null ) { if ( problem . getOriginatingFileName ( ) != null ) { try { unitSource = Util . getFileCharContent ( new File ( new String ( problem . getOriginatingFileName ( ) ) ) , null ) ; } catch ( IOException e ) { } } } int length = unitSource == null ? <NUM_LIT:0> : unitSource . length ; if ( ( startPosition > endPosition ) || ( ( startPosition < <NUM_LIT:0> ) && ( endPosition < <NUM_LIT:0> ) ) || ( length <= <NUM_LIT:0> ) || ( endPosition > length ) ) { this . parameters . put ( Logger . VALUE , Messages . problem_noSourceInformation ) ; this . parameters . put ( Logger . SOURCE_START , "<STR_LIT:-1>" ) ; this . parameters . put ( Logger . SOURCE_END , "<STR_LIT:-1>" ) ; printTag ( Logger . SOURCE_CONTEXT , this . parameters , true , true ) ; return ; } char c ; int begin , end ; for ( begin = startPosition >= length ? length - <NUM_LIT:1> : startPosition ; begin > <NUM_LIT:0> ; begin -- ) { if ( ( c = unitSource [ begin - <NUM_LIT:1> ] ) == '<STR_LIT:\n>' || c == '<STR_LIT>' ) break ; } for ( end = endPosition >= length ? length - <NUM_LIT:1> : endPosition ; end + <NUM_LIT:1> < length ; end ++ ) { if ( ( c = unitSource [ end + <NUM_LIT:1> ] ) == '<STR_LIT>' || c == '<STR_LIT:\n>' ) break ; } while ( ( c = unitSource [ begin ] ) == '<CHAR_LIT:U+0020>' || c == '<STR_LIT:\t>' ) begin ++ ; while ( ( c = unitSource [ end ] ) == '<CHAR_LIT:U+0020>' || c == '<STR_LIT:\t>' ) end -- ; StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( unitSource , begin , end - begin + <NUM_LIT:1> ) ; this . parameters . put ( Logger . VALUE , String . valueOf ( buffer ) ) ; this . parameters . put ( Logger . SOURCE_START , Integer . toString ( startPosition - begin ) ) ; this . parameters . put ( Logger . SOURCE_END , Integer . toString ( endPosition - begin ) ) ; printTag ( Logger . SOURCE_CONTEXT , this . parameters , true , true ) ; } public void flush ( ) { this . out . flush ( ) ; this . err . flush ( ) ; if ( this . log != null ) { this . log . flush ( ) ; } } private String getFieldName ( int id ) { int key2 = id & IProblem . IgnoreCategoriesMask ; if ( key2 == <NUM_LIT:0> ) { key2 = Integer . MAX_VALUE ; } return ( String ) Logger . FIELD_TABLE . get ( key2 ) ; } private String getProblemOptionKey ( int problemID ) { int irritant = ProblemReporter . getIrritant ( problemID ) ; return CompilerOptions . optionKeyFromIrritant ( irritant ) ; } public void logAverage ( ) { Arrays . sort ( this . main . compilerStats ) ; long lineCount = this . main . compilerStats [ <NUM_LIT:0> ] . lineCount ; final int length = this . main . maxRepetition ; long sum = <NUM_LIT:0> ; long parseSum = <NUM_LIT:0> , resolveSum = <NUM_LIT:0> , analyzeSum = <NUM_LIT:0> , generateSum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:1> , max = length - <NUM_LIT:1> ; i < max ; i ++ ) { CompilerStats stats = this . main . compilerStats [ i ] ; sum += stats . elapsedTime ( ) ; parseSum += stats . parseTime ; resolveSum += stats . resolveTime ; analyzeSum += stats . analyzeTime ; generateSum += stats . generateTime ; } long time = sum / ( length - <NUM_LIT:2> ) ; long parseTime = parseSum / ( length - <NUM_LIT:2> ) ; long resolveTime = resolveSum / ( length - <NUM_LIT:2> ) ; long analyzeTime = analyzeSum / ( length - <NUM_LIT:2> ) ; long generateTime = generateSum / ( length - <NUM_LIT:2> ) ; printlnOut ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( lineCount ) , String . valueOf ( time ) , String . valueOf ( ( ( int ) ( lineCount * <NUM_LIT> / time ) ) / <NUM_LIT> ) , } ) ) ; if ( ( this . main . timing & Main . TIMING_DETAILED ) != <NUM_LIT:0> ) { printlnOut ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( parseTime ) , String . valueOf ( ( ( int ) ( parseTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( resolveTime ) , String . valueOf ( ( ( int ) ( resolveTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( analyzeTime ) , String . valueOf ( ( ( int ) ( analyzeTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( generateTime ) , String . valueOf ( ( ( int ) ( generateTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , } ) ) ; } } public void logClassFile ( boolean generatePackagesStructure , String outputPath , String relativeFileName ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { String fileName = null ; if ( generatePackagesStructure ) { fileName = buildFileName ( outputPath , relativeFileName ) ; } else { char fileSeparatorChar = File . separatorChar ; String fileSeparator = File . separator ; outputPath = outputPath . replace ( '<CHAR_LIT:/>' , fileSeparatorChar ) ; int indexOfPackageSeparator = relativeFileName . lastIndexOf ( fileSeparatorChar ) ; if ( indexOfPackageSeparator == - <NUM_LIT:1> ) { if ( outputPath . endsWith ( fileSeparator ) ) { fileName = outputPath + relativeFileName ; } else { fileName = outputPath + fileSeparator + relativeFileName ; } } else { int length = relativeFileName . length ( ) ; if ( outputPath . endsWith ( fileSeparator ) ) { fileName = outputPath + relativeFileName . substring ( indexOfPackageSeparator + <NUM_LIT:1> , length ) ; } else { fileName = outputPath + fileSeparator + relativeFileName . substring ( indexOfPackageSeparator + <NUM_LIT:1> , length ) ; } } } File f = new File ( fileName ) ; try { this . parameters . put ( Logger . PATH , f . getCanonicalPath ( ) ) ; printTag ( Logger . CLASS_FILE , this . parameters , true , true ) ; } catch ( IOException e ) { logNoClassFileCreated ( outputPath , relativeFileName , e ) ; } } } public void logClasspath ( FileSystem . Classpath [ ] classpaths ) { if ( classpaths == null ) return ; if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { final int length = classpaths . length ; if ( length != <NUM_LIT:0> ) { printTag ( Logger . CLASSPATHS , null , true , false ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { String classpath = classpaths [ i ] . getPath ( ) ; this . parameters . put ( Logger . PATH , classpath ) ; File f = new File ( classpath ) ; String id = null ; if ( f . isFile ( ) ) { if ( Util . isPotentialZipArchive ( classpath ) ) { id = Logger . CLASSPATH_JAR ; } else { id = Logger . CLASSPATH_FILE ; } } else if ( f . isDirectory ( ) ) { id = Logger . CLASSPATH_FOLDER ; } if ( id != null ) { this . parameters . put ( Logger . CLASSPATH_ID , id ) ; printTag ( Logger . CLASSPATH , this . parameters , true , true ) ; } } endTag ( Logger . CLASSPATHS ) ; } } } public void logCommandLineArguments ( String [ ] commandLineArguments ) { if ( commandLineArguments == null ) return ; if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { final int length = commandLineArguments . length ; if ( length != <NUM_LIT:0> ) { printTag ( Logger . COMMAND_LINE_ARGUMENTS , null , true , false ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { this . parameters . put ( Logger . VALUE , commandLineArguments [ i ] ) ; printTag ( Logger . COMMAND_LINE_ARGUMENT , this . parameters , true , true ) ; } endTag ( Logger . COMMAND_LINE_ARGUMENTS ) ; } } } public void logException ( Exception e ) { StringWriter writer = new StringWriter ( ) ; PrintWriter printWriter = new PrintWriter ( writer ) ; e . printStackTrace ( printWriter ) ; printWriter . flush ( ) ; printWriter . close ( ) ; final String stackTrace = writer . toString ( ) ; if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { LineNumberReader reader = new LineNumberReader ( new StringReader ( stackTrace ) ) ; String line ; int i = <NUM_LIT:0> ; StringBuffer buffer = new StringBuffer ( ) ; String message = e . getMessage ( ) ; if ( message != null ) { buffer . append ( message ) . append ( Util . LINE_SEPARATOR ) ; } try { while ( ( line = reader . readLine ( ) ) != null && i < <NUM_LIT:4> ) { buffer . append ( line ) . append ( Util . LINE_SEPARATOR ) ; i ++ ; } reader . close ( ) ; } catch ( IOException e1 ) { } message = buffer . toString ( ) ; this . parameters . put ( Logger . MESSAGE , message ) ; this . parameters . put ( Logger . CLASS , e . getClass ( ) ) ; printTag ( Logger . EXCEPTION , this . parameters , true , true ) ; } String message = e . getMessage ( ) ; if ( message == null ) { this . printlnErr ( stackTrace ) ; } else { this . printlnErr ( message ) ; } } private void logExtraProblem ( CategorizedProblem problem , int localErrorCount , int globalErrorCount ) { char [ ] originatingFileName = problem . getOriginatingFileName ( ) ; String fileName = originatingFileName == null ? this . main . bind ( "<STR_LIT>" ) : new String ( originatingFileName ) ; if ( ( this . tagBits & Logger . EMACS ) != <NUM_LIT:0> ) { String result = fileName + "<STR_LIT::>" + problem . getSourceLineNumber ( ) + "<STR_LIT::U+0020>" + ( problem . isError ( ) ? this . main . bind ( "<STR_LIT>" ) : this . main . bind ( "<STR_LIT>" ) ) + "<STR_LIT::U+0020>" + problem . getMessage ( ) ; this . printlnErr ( result ) ; final String errorReportSource = errorReportSource ( problem , null , this . tagBits ) ; this . printlnErr ( errorReportSource ) ; } else { if ( localErrorCount == <NUM_LIT:0> ) { this . printlnErr ( "<STR_LIT>" ) ; } printErr ( problem . isError ( ) ? this . main . bind ( "<STR_LIT>" , Integer . toString ( globalErrorCount ) , new String ( fileName ) ) : this . main . bind ( "<STR_LIT>" , Integer . toString ( globalErrorCount ) , new String ( fileName ) ) ) ; final String errorReportSource = errorReportSource ( problem , null , <NUM_LIT:0> ) ; this . printlnErr ( errorReportSource ) ; this . printlnErr ( problem . getMessage ( ) ) ; this . printlnErr ( "<STR_LIT>" ) ; } } public void loggingExtraProblems ( Main currentMain ) { ArrayList problems = currentMain . extraProblems ; final int count = problems . size ( ) ; int localErrorCount = <NUM_LIT:0> ; int localProblemCount = <NUM_LIT:0> ; if ( count != <NUM_LIT:0> ) { int errors = <NUM_LIT:0> ; int warnings = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { CategorizedProblem problem = ( CategorizedProblem ) problems . get ( i ) ; if ( problem != null ) { currentMain . globalProblemsCount ++ ; logExtraProblem ( problem , localProblemCount , currentMain . globalProblemsCount ) ; localProblemCount ++ ; if ( problem . isError ( ) ) { localErrorCount ++ ; errors ++ ; currentMain . globalErrorsCount ++ ; } else if ( problem . isWarning ( ) ) { currentMain . globalWarningsCount ++ ; warnings ++ ; } } } if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { if ( ( errors + warnings ) != <NUM_LIT:0> ) { startLoggingExtraProblems ( count ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { CategorizedProblem problem = ( CategorizedProblem ) problems . get ( i ) ; if ( problem != null ) { if ( problem . getID ( ) != IProblem . Task ) { logXmlExtraProblem ( problem , localProblemCount , currentMain . globalProblemsCount ) ; } } } endLoggingExtraProblems ( ) ; } } } } public void logIncorrectVMVersionForAnnotationProcessing ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . MESSAGE , this . main . bind ( "<STR_LIT>" ) ) ; printTag ( Logger . ERROR_TAG , this . parameters , true , true ) ; } this . printlnErr ( this . main . bind ( "<STR_LIT>" ) ) ; } public void logNoClassFileCreated ( String outputDir , String relativeFileName , IOException e ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . MESSAGE , this . main . bind ( "<STR_LIT>" , new String [ ] { outputDir , relativeFileName , e . getMessage ( ) } ) ) ; printTag ( Logger . ERROR_TAG , this . parameters , true , true ) ; } this . printlnErr ( this . main . bind ( "<STR_LIT>" , new String [ ] { outputDir , relativeFileName , e . getMessage ( ) } ) ) ; } public void logNumberOfClassFilesGenerated ( int exportedClassFilesCounter ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . VALUE , new Integer ( exportedClassFilesCounter ) ) ; printTag ( Logger . NUMBER_OF_CLASSFILES , this . parameters , true , true ) ; } if ( exportedClassFilesCounter == <NUM_LIT:1> ) { printlnOut ( this . main . bind ( "<STR_LIT>" ) ) ; } else { printlnOut ( this . main . bind ( "<STR_LIT>" , String . valueOf ( exportedClassFilesCounter ) ) ) ; } } public void logOptions ( Map options ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { printTag ( Logger . OPTIONS , null , true , false ) ; final Set entriesSet = options . entrySet ( ) ; Object [ ] entries = entriesSet . toArray ( ) ; Arrays . sort ( entries , new Comparator ( ) { public int compare ( Object o1 , Object o2 ) { Map . Entry entry1 = ( Map . Entry ) o1 ; Map . Entry entry2 = ( Map . Entry ) o2 ; return ( ( String ) entry1 . getKey ( ) ) . compareTo ( ( String ) entry2 . getKey ( ) ) ; } } ) ; for ( int i = <NUM_LIT:0> , max = entries . length ; i < max ; i ++ ) { Map . Entry entry = ( Map . Entry ) entries [ i ] ; String key = ( String ) entry . getKey ( ) ; this . parameters . put ( Logger . KEY , key ) ; this . parameters . put ( Logger . VALUE , entry . getValue ( ) ) ; printTag ( Logger . OPTION , this . parameters , true , true ) ; } endTag ( Logger . OPTIONS ) ; } } public void logPendingError ( String error ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . MESSAGE , error ) ; printTag ( Logger . ERROR_TAG , this . parameters , true , true ) ; } this . printlnErr ( error ) ; } public void logWarning ( String message ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . MESSAGE , message ) ; printTag ( Logger . WARNING_TAG , this . parameters , true , true ) ; } this . printlnOut ( message ) ; } private void logProblem ( CategorizedProblem problem , int localErrorCount , int globalErrorCount , char [ ] unitSource ) { if ( ( this . tagBits & Logger . EMACS ) != <NUM_LIT:0> ) { String result = ( new String ( problem . getOriginatingFileName ( ) ) + "<STR_LIT::>" + problem . getSourceLineNumber ( ) + "<STR_LIT::U+0020>" + ( problem . isError ( ) ? this . main . bind ( "<STR_LIT>" ) : this . main . bind ( "<STR_LIT>" ) ) + "<STR_LIT::U+0020>" + problem . getMessage ( ) ) ; this . printlnErr ( result ) ; final String errorReportSource = errorReportSource ( problem , unitSource , this . tagBits ) ; if ( errorReportSource . length ( ) != <NUM_LIT:0> ) this . printlnErr ( errorReportSource ) ; } else { if ( localErrorCount == <NUM_LIT:0> ) { this . printlnErr ( "<STR_LIT>" ) ; } printErr ( problem . isError ( ) ? this . main . bind ( "<STR_LIT>" , Integer . toString ( globalErrorCount ) , new String ( problem . getOriginatingFileName ( ) ) ) : this . main . bind ( "<STR_LIT>" , Integer . toString ( globalErrorCount ) , new String ( problem . getOriginatingFileName ( ) ) ) ) ; try { final String errorReportSource = errorReportSource ( problem , unitSource , <NUM_LIT:0> ) ; this . printlnErr ( errorReportSource ) ; this . printlnErr ( problem . getMessage ( ) ) ; } catch ( Exception e ) { this . printlnErr ( this . main . bind ( "<STR_LIT>" , problem . toString ( ) ) ) ; } this . printlnErr ( "<STR_LIT>" ) ; } } public int logProblems ( CategorizedProblem [ ] problems , char [ ] unitSource , Main currentMain ) { final int count = problems . length ; int localErrorCount = <NUM_LIT:0> ; int localProblemCount = <NUM_LIT:0> ; if ( count != <NUM_LIT:0> ) { int errors = <NUM_LIT:0> ; int warnings = <NUM_LIT:0> ; int tasks = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { CategorizedProblem problem = problems [ i ] ; if ( problem != null ) { currentMain . globalProblemsCount ++ ; logProblem ( problem , localProblemCount , currentMain . globalProblemsCount , unitSource ) ; localProblemCount ++ ; if ( problem . isError ( ) ) { localErrorCount ++ ; errors ++ ; currentMain . globalErrorsCount ++ ; } else if ( problem . getID ( ) == IProblem . Task ) { currentMain . globalTasksCount ++ ; tasks ++ ; } else { currentMain . globalWarningsCount ++ ; warnings ++ ; } } } if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { if ( ( errors + warnings ) != <NUM_LIT:0> ) { startLoggingProblems ( errors , warnings ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { CategorizedProblem problem = problems [ i ] ; if ( problem != null ) { if ( problem . getID ( ) != IProblem . Task ) { logXmlProblem ( problem , unitSource ) ; } } } endLoggingProblems ( ) ; } if ( tasks != <NUM_LIT:0> ) { startLoggingTasks ( tasks ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { CategorizedProblem problem = problems [ i ] ; if ( problem != null ) { if ( problem . getID ( ) == IProblem . Task ) { logXmlTask ( problem , unitSource ) ; } } } endLoggingTasks ( ) ; } } } return localErrorCount ; } public void logProblemsSummary ( int globalProblemsCount , int globalErrorsCount , int globalWarningsCount , int globalTasksCount ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . NUMBER_OF_PROBLEMS , new Integer ( globalProblemsCount ) ) ; this . parameters . put ( Logger . NUMBER_OF_ERRORS , new Integer ( globalErrorsCount ) ) ; this . parameters . put ( Logger . NUMBER_OF_WARNINGS , new Integer ( globalWarningsCount ) ) ; this . parameters . put ( Logger . NUMBER_OF_TASKS , new Integer ( globalTasksCount ) ) ; printTag ( Logger . PROBLEM_SUMMARY , this . parameters , true , true ) ; } if ( globalProblemsCount == <NUM_LIT:1> ) { String message = null ; if ( globalErrorsCount == <NUM_LIT:1> ) { message = this . main . bind ( "<STR_LIT>" ) ; } else { message = this . main . bind ( "<STR_LIT>" ) ; } printErr ( this . main . bind ( "<STR_LIT>" , message ) ) ; } else { String errorMessage = null ; String warningMessage = null ; if ( globalErrorsCount > <NUM_LIT:0> ) { if ( globalErrorsCount == <NUM_LIT:1> ) { errorMessage = this . main . bind ( "<STR_LIT>" ) ; } else { errorMessage = this . main . bind ( "<STR_LIT>" , String . valueOf ( globalErrorsCount ) ) ; } } int warningsNumber = globalWarningsCount + globalTasksCount ; if ( warningsNumber > <NUM_LIT:0> ) { if ( warningsNumber == <NUM_LIT:1> ) { warningMessage = this . main . bind ( "<STR_LIT>" ) ; } else { warningMessage = this . main . bind ( "<STR_LIT>" , String . valueOf ( warningsNumber ) ) ; } } if ( errorMessage == null || warningMessage == null ) { if ( errorMessage == null ) { printErr ( this . main . bind ( "<STR_LIT>" , String . valueOf ( globalProblemsCount ) , warningMessage ) ) ; } else { printErr ( this . main . bind ( "<STR_LIT>" , String . valueOf ( globalProblemsCount ) , errorMessage ) ) ; } } else { printErr ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( globalProblemsCount ) , errorMessage , warningMessage } ) ) ; } } if ( ( this . tagBits & Logger . EMACS ) != <NUM_LIT:0> ) { this . printlnErr ( ) ; } } public void logProgress ( ) { printOut ( '<CHAR_LIT:.>' ) ; } public void logRepetition ( int i , int repetitions ) { printlnOut ( this . main . bind ( "<STR_LIT>" , String . valueOf ( i + <NUM_LIT:1> ) , String . valueOf ( repetitions ) ) ) ; } public void logTiming ( CompilerStats compilerStats ) { long time = compilerStats . elapsedTime ( ) ; long lineCount = compilerStats . lineCount ; if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . VALUE , new Long ( time ) ) ; printTag ( Logger . TIME , this . parameters , true , true ) ; this . parameters . put ( Logger . VALUE , new Long ( lineCount ) ) ; printTag ( Logger . NUMBER_OF_LINES , this . parameters , true , true ) ; } if ( lineCount != <NUM_LIT:0> ) { printlnOut ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( lineCount ) , String . valueOf ( time ) , String . valueOf ( ( ( int ) ( lineCount * <NUM_LIT> / time ) ) / <NUM_LIT> ) , } ) ) ; } else { printlnOut ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( time ) , } ) ) ; } if ( ( this . main . timing & Main . TIMING_DETAILED ) != <NUM_LIT:0> ) { printlnOut ( this . main . bind ( "<STR_LIT>" , new String [ ] { String . valueOf ( compilerStats . parseTime ) , String . valueOf ( ( ( int ) ( compilerStats . parseTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( compilerStats . resolveTime ) , String . valueOf ( ( ( int ) ( compilerStats . resolveTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( compilerStats . analyzeTime ) , String . valueOf ( ( ( int ) ( compilerStats . analyzeTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , String . valueOf ( compilerStats . generateTime ) , String . valueOf ( ( ( int ) ( compilerStats . generateTime * <NUM_LIT> / time ) ) / <NUM_LIT> ) , } ) ) ; } } public void logUsage ( String usage ) { printlnOut ( usage ) ; } public void logVersion ( final boolean printToOut ) { if ( this . log != null && ( this . tagBits & Logger . XML ) == <NUM_LIT:0> ) { final String version = this . main . bind ( "<STR_LIT>" , new String [ ] { this . main . bind ( "<STR_LIT>" ) , this . main . bind ( "<STR_LIT>" ) , this . main . bind ( "<STR_LIT>" ) } ) ; this . log . println ( "<STR_LIT>" + version ) ; if ( printToOut ) { this . out . println ( version ) ; this . out . flush ( ) ; } } else if ( printToOut ) { final String version = this . main . bind ( "<STR_LIT>" , new String [ ] { this . main . bind ( "<STR_LIT>" ) , this . main . bind ( "<STR_LIT>" ) , this . main . bind ( "<STR_LIT>" ) } ) ; this . out . println ( version ) ; this . out . flush ( ) ; } } public void logWrongJDK ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . MESSAGE , this . main . bind ( "<STR_LIT>" ) ) ; printTag ( Logger . ERROR , this . parameters , true , true ) ; } this . printlnErr ( this . main . bind ( "<STR_LIT>" ) ) ; } private void logXmlExtraProblem ( CategorizedProblem problem , int globalErrorCount , int localErrorCount ) { final int sourceStart = problem . getSourceStart ( ) ; final int sourceEnd = problem . getSourceEnd ( ) ; boolean isError = problem . isError ( ) ; this . parameters . put ( Logger . PROBLEM_SEVERITY , isError ? Logger . ERROR : Logger . WARNING ) ; this . parameters . put ( Logger . PROBLEM_LINE , new Integer ( problem . getSourceLineNumber ( ) ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_START , new Integer ( sourceStart ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_END , new Integer ( sourceEnd ) ) ; printTag ( Logger . EXTRA_PROBLEM_TAG , this . parameters , true , false ) ; this . parameters . put ( Logger . VALUE , problem . getMessage ( ) ) ; printTag ( Logger . PROBLEM_MESSAGE , this . parameters , true , true ) ; extractContext ( problem , null ) ; endTag ( Logger . EXTRA_PROBLEM_TAG ) ; } private void logXmlProblem ( CategorizedProblem problem , char [ ] unitSource ) { final int sourceStart = problem . getSourceStart ( ) ; final int sourceEnd = problem . getSourceEnd ( ) ; final int id = problem . getID ( ) ; this . parameters . put ( Logger . ID , getFieldName ( id ) ) ; this . parameters . put ( Logger . PROBLEM_ID , new Integer ( id ) ) ; boolean isError = problem . isError ( ) ; int severity = isError ? ProblemSeverities . Error : ProblemSeverities . Warning ; this . parameters . put ( Logger . PROBLEM_SEVERITY , isError ? Logger . ERROR : Logger . WARNING ) ; this . parameters . put ( Logger . PROBLEM_LINE , new Integer ( problem . getSourceLineNumber ( ) ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_START , new Integer ( sourceStart ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_END , new Integer ( sourceEnd ) ) ; String problemOptionKey = getProblemOptionKey ( id ) ; if ( problemOptionKey != null ) { this . parameters . put ( Logger . PROBLEM_OPTION_KEY , problemOptionKey ) ; } int categoryID = ProblemReporter . getProblemCategory ( severity , id ) ; this . parameters . put ( Logger . PROBLEM_CATEGORY_ID , new Integer ( categoryID ) ) ; printTag ( Logger . PROBLEM_TAG , this . parameters , true , false ) ; this . parameters . put ( Logger . VALUE , problem . getMessage ( ) ) ; printTag ( Logger . PROBLEM_MESSAGE , this . parameters , true , true ) ; extractContext ( problem , unitSource ) ; String [ ] arguments = problem . getArguments ( ) ; final int length = arguments . length ; if ( length != <NUM_LIT:0> ) { printTag ( Logger . PROBLEM_ARGUMENTS , null , true , false ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { this . parameters . put ( Logger . PROBLEM_ARGUMENT_VALUE , arguments [ i ] ) ; printTag ( Logger . PROBLEM_ARGUMENT , this . parameters , true , true ) ; } endTag ( Logger . PROBLEM_ARGUMENTS ) ; } endTag ( Logger . PROBLEM_TAG ) ; } private void logXmlTask ( CategorizedProblem problem , char [ ] unitSource ) { this . parameters . put ( Logger . PROBLEM_LINE , new Integer ( problem . getSourceLineNumber ( ) ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_START , new Integer ( problem . getSourceStart ( ) ) ) ; this . parameters . put ( Logger . PROBLEM_SOURCE_END , new Integer ( problem . getSourceEnd ( ) ) ) ; String problemOptionKey = getProblemOptionKey ( problem . getID ( ) ) ; if ( problemOptionKey != null ) { this . parameters . put ( Logger . PROBLEM_OPTION_KEY , problemOptionKey ) ; } printTag ( Logger . TASK , this . parameters , true , false ) ; this . parameters . put ( Logger . VALUE , problem . getMessage ( ) ) ; printTag ( Logger . PROBLEM_MESSAGE , this . parameters , true , true ) ; extractContext ( problem , unitSource ) ; endTag ( Logger . TASK ) ; } private void printErr ( String s ) { this . err . print ( s ) ; if ( ( this . tagBits & Logger . XML ) == <NUM_LIT:0> && this . log != null ) { this . log . print ( s ) ; } } private void printlnErr ( ) { this . err . println ( ) ; if ( ( this . tagBits & Logger . XML ) == <NUM_LIT:0> && this . log != null ) { this . log . println ( ) ; } } private void printlnErr ( String s ) { this . err . println ( s ) ; if ( ( this . tagBits & Logger . XML ) == <NUM_LIT:0> && this . log != null ) { this . log . println ( s ) ; } } private void printlnOut ( String s ) { this . out . println ( s ) ; if ( ( this . tagBits & Logger . XML ) == <NUM_LIT:0> && this . log != null ) { this . log . println ( s ) ; } } public void printNewLine ( ) { this . out . println ( ) ; } private void printOut ( char c ) { this . out . print ( c ) ; } public void printStats ( ) { final boolean isTimed = ( this . main . timing & TIMING_ENABLED ) != <NUM_LIT:0> ; if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { printTag ( Logger . STATS , null , true , false ) ; } if ( isTimed ) { CompilerStats compilerStats = this . main . batchCompiler . stats ; compilerStats . startTime = this . main . startTime ; compilerStats . endTime = System . currentTimeMillis ( ) ; logTiming ( compilerStats ) ; } if ( this . main . globalProblemsCount > <NUM_LIT:0> ) { logProblemsSummary ( this . main . globalProblemsCount , this . main . globalErrorsCount , this . main . globalWarningsCount , this . main . globalTasksCount ) ; } if ( this . main . exportedClassFilesCounter != <NUM_LIT:0> && ( this . main . showProgress || isTimed || this . main . verbose ) ) { logNumberOfClassFilesGenerated ( this . main . exportedClassFilesCounter ) ; } if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { endTag ( Logger . STATS ) ; } } private void printTag ( String name , HashMap params , boolean insertNewLine , boolean closeTag ) { if ( this . log != null ) { ( ( GenericXMLWriter ) this . log ) . printTag ( name , this . parameters , true , insertNewLine , closeTag ) ; } this . parameters . clear ( ) ; } public void setEmacs ( ) { this . tagBits |= Logger . EMACS ; } public void setLog ( String logFileName ) { final Date date = new Date ( ) ; final DateFormat dateFormat = DateFormat . getDateTimeInstance ( DateFormat . SHORT , DateFormat . LONG , Locale . getDefault ( ) ) ; try { int index = logFileName . lastIndexOf ( '<CHAR_LIT:.>' ) ; if ( index != - <NUM_LIT:1> ) { if ( logFileName . substring ( index ) . toLowerCase ( ) . equals ( "<STR_LIT>" ) ) { this . log = new GenericXMLWriter ( new OutputStreamWriter ( new FileOutputStream ( logFileName , false ) , Util . UTF_8 ) , Util . LINE_SEPARATOR , true ) ; this . tagBits |= Logger . XML ; this . log . println ( "<STR_LIT>" + dateFormat . format ( date ) + "<STR_LIT>" ) ; this . log . println ( Logger . XML_DTD_DECLARATION ) ; this . parameters . put ( Logger . COMPILER_NAME , this . main . bind ( "<STR_LIT>" ) ) ; this . parameters . put ( Logger . COMPILER_VERSION , this . main . bind ( "<STR_LIT>" ) ) ; this . parameters . put ( Logger . COMPILER_COPYRIGHT , this . main . bind ( "<STR_LIT>" ) ) ; printTag ( Logger . COMPILER , this . parameters , true , false ) ; } else { this . log = new PrintWriter ( new FileOutputStream ( logFileName , false ) ) ; this . log . println ( "<STR_LIT>" + dateFormat . format ( date ) ) ; } } else { this . log = new PrintWriter ( new FileOutputStream ( logFileName , false ) ) ; this . log . println ( "<STR_LIT>" + dateFormat . format ( date ) ) ; } } catch ( FileNotFoundException e ) { throw new IllegalArgumentException ( this . main . bind ( "<STR_LIT>" , logFileName ) ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( this . main . bind ( "<STR_LIT>" , logFileName ) ) ; } } private void startLoggingExtraProblems ( int count ) { this . parameters . put ( Logger . NUMBER_OF_PROBLEMS , new Integer ( count ) ) ; printTag ( Logger . EXTRA_PROBLEMS , this . parameters , true , false ) ; } private void startLoggingProblems ( int errors , int warnings ) { this . parameters . put ( Logger . NUMBER_OF_PROBLEMS , new Integer ( errors + warnings ) ) ; this . parameters . put ( Logger . NUMBER_OF_ERRORS , new Integer ( errors ) ) ; this . parameters . put ( Logger . NUMBER_OF_WARNINGS , new Integer ( warnings ) ) ; printTag ( Logger . PROBLEMS , this . parameters , true , false ) ; } public void startLoggingSource ( CompilationResult compilationResult ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { ICompilationUnit compilationUnit = compilationResult . compilationUnit ; if ( compilationUnit != null ) { char [ ] fileName = compilationUnit . getFileName ( ) ; File f = new File ( new String ( fileName ) ) ; if ( fileName != null ) { this . parameters . put ( Logger . PATH , f . getAbsolutePath ( ) ) ; } char [ ] [ ] packageName = compilationResult . packageName ; if ( packageName != null ) { this . parameters . put ( Logger . PACKAGE , new String ( CharOperation . concatWith ( packageName , File . separatorChar ) ) ) ; } CompilationUnit unit = ( CompilationUnit ) compilationUnit ; String destinationPath = unit . destinationPath ; if ( destinationPath == null ) { destinationPath = this . main . destinationPath ; } if ( destinationPath != null && destinationPath != NONE ) { if ( File . separatorChar == '<CHAR_LIT:/>' ) { this . parameters . put ( Logger . OUTPUT , destinationPath ) ; } else { this . parameters . put ( Logger . OUTPUT , destinationPath . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ) ; } } } printTag ( Logger . SOURCE , this . parameters , true , false ) ; } } public void startLoggingSources ( ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { printTag ( Logger . SOURCES , null , true , false ) ; } } public void startLoggingTasks ( int tasks ) { if ( ( this . tagBits & Logger . XML ) != <NUM_LIT:0> ) { this . parameters . put ( Logger . NUMBER_OF_TASKS , new Integer ( tasks ) ) ; printTag ( Logger . TASKS , this . parameters , true , false ) ; } } } public static class ResourceBundleFactory { private static HashMap Cache = new HashMap ( ) ; public static synchronized ResourceBundle getBundle ( Locale locale ) { ResourceBundle bundle = ( ResourceBundle ) Cache . get ( locale ) ; if ( bundle == null ) { bundle = ResourceBundle . getBundle ( Main . bundleName , locale ) ; Cache . put ( locale , bundle ) ; } return bundle ; } } boolean enableJavadocOn ; boolean warnJavadocOn ; boolean warnAllJavadocOn ; public Compiler batchCompiler ; public ResourceBundle bundle ; protected FileSystem . Classpath [ ] checkedClasspaths ; public Locale compilerLocale ; public CompilerOptions compilerOptions ; public CompilationProgress progress ; public String destinationPath ; public String [ ] destinationPaths ; private boolean didSpecifySource ; private boolean didSpecifyTarget ; public String [ ] encodings ; public int exportedClassFilesCounter ; public String [ ] filenames ; public String [ ] classNames ; public int globalErrorsCount ; public int globalProblemsCount ; public int globalTasksCount ; public int globalWarningsCount ; private File javaHomeCache ; private boolean javaHomeChecked = false ; public long lineCount0 ; public String log ; public Logger logger ; public int maxProblems ; public Map options ; protected PrintWriter out ; public boolean proceed = true ; public boolean proceedOnError = false ; public boolean produceRefInfo = false ; public int currentRepetition , maxRepetition ; public boolean showProgress = false ; public long startTime ; public ArrayList pendingErrors ; public boolean systemExitWhenFinished = true ; public static final int TIMING_DISABLED = <NUM_LIT:0> ; public static final int TIMING_ENABLED = <NUM_LIT:1> ; public static final int TIMING_DETAILED = <NUM_LIT:2> ; public int timing = TIMING_DISABLED ; public CompilerStats [ ] compilerStats ; public boolean verbose = false ; private String [ ] expandedCommandLine ; private PrintWriter err ; ArrayList extraProblems ; public final static String bundleName = "<STR_LIT>" ; public static final int DEFAULT_SIZE_CLASSPATH = <NUM_LIT:4> ; public static final String NONE = "<STR_LIT:none>" ; public static boolean compile ( String commandLine ) { return new Main ( new PrintWriter ( System . out ) , new PrintWriter ( System . err ) , false , null , null ) . compile ( tokenize ( commandLine ) ) ; } public static boolean compile ( String commandLine , PrintWriter outWriter , PrintWriter errWriter ) { return new Main ( outWriter , errWriter , false , null , null ) . compile ( tokenize ( commandLine ) ) ; } public static boolean compile ( String [ ] commandLineArguments , PrintWriter outWriter , PrintWriter errWriter , CompilationProgress progress ) { return new Main ( outWriter , errWriter , false , null , progress ) . compile ( commandLineArguments ) ; } public static File [ ] [ ] getLibrariesFiles ( File [ ] files ) { FilenameFilter filter = new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return Util . isPotentialZipArchive ( name ) ; } } ; final int filesLength = files . length ; File [ ] [ ] result = new File [ filesLength ] [ ] ; for ( int i = <NUM_LIT:0> ; i < filesLength ; i ++ ) { File currentFile = files [ i ] ; if ( currentFile . exists ( ) && currentFile . isDirectory ( ) ) { result [ i ] = currentFile . listFiles ( filter ) ; } } return result ; } public static void main ( String [ ] argv ) { new Main ( new PrintWriter ( System . out ) , new PrintWriter ( System . err ) , true , null , null ) . compile ( argv ) ; } public static String [ ] tokenize ( String commandLine ) { int count = <NUM_LIT:0> ; String [ ] arguments = new String [ <NUM_LIT:10> ] ; StringTokenizer tokenizer = new StringTokenizer ( commandLine , "<STR_LIT>" , true ) ; String token = Util . EMPTY_STRING ; boolean insideQuotes = false ; boolean startNewToken = true ; while ( tokenizer . hasMoreTokens ( ) ) { token = tokenizer . nextToken ( ) ; if ( token . equals ( "<STR_LIT:U+0020>" ) ) { if ( insideQuotes ) { arguments [ count - <NUM_LIT:1> ] += token ; startNewToken = false ; } else { startNewToken = true ; } } else if ( token . equals ( "<STR_LIT:\">" ) ) { if ( ! insideQuotes && startNewToken ) { if ( count == arguments . length ) System . arraycopy ( arguments , <NUM_LIT:0> , ( arguments = new String [ count * <NUM_LIT:2> ] ) , <NUM_LIT:0> , count ) ; arguments [ count ++ ] = Util . EMPTY_STRING ; } insideQuotes = ! insideQuotes ; startNewToken = false ; } else { if ( insideQuotes ) { arguments [ count - <NUM_LIT:1> ] += token ; } else { if ( token . length ( ) > <NUM_LIT:0> && ! startNewToken ) { arguments [ count - <NUM_LIT:1> ] += token ; } else { if ( count == arguments . length ) System . arraycopy ( arguments , <NUM_LIT:0> , ( arguments = new String [ count * <NUM_LIT:2> ] ) , <NUM_LIT:0> , count ) ; String trimmedToken = token . trim ( ) ; if ( trimmedToken . length ( ) != <NUM_LIT:0> ) { arguments [ count ++ ] = trimmedToken ; } } } startNewToken = false ; } } System . arraycopy ( arguments , <NUM_LIT:0> , arguments = new String [ count ] , <NUM_LIT:0> , count ) ; return arguments ; } public Main ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExitWhenFinished ) { this ( outWriter , errWriter , systemExitWhenFinished , null , null ) ; } public Main ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExitWhenFinished , Map customDefaultOptions ) { this ( outWriter , errWriter , systemExitWhenFinished , customDefaultOptions , null ) ; } public Main ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExitWhenFinished , Map customDefaultOptions , CompilationProgress compilationProgress ) { this . initialize ( outWriter , errWriter , systemExitWhenFinished , customDefaultOptions , compilationProgress ) ; this . relocalize ( ) ; } public void addExtraProblems ( CategorizedProblem problem ) { if ( this . extraProblems == null ) { this . extraProblems = new ArrayList ( ) ; } this . extraProblems . add ( problem ) ; } protected void addNewEntry ( ArrayList paths , String currentClasspathName , ArrayList currentRuleSpecs , String customEncoding , String destPath , boolean isSourceOnly , boolean rejectDestinationPathOnJars ) { int rulesSpecsSize = currentRuleSpecs . size ( ) ; AccessRuleSet accessRuleSet = null ; if ( rulesSpecsSize != <NUM_LIT:0> ) { AccessRule [ ] accessRules = new AccessRule [ currentRuleSpecs . size ( ) ] ; boolean rulesOK = true ; Iterator i = currentRuleSpecs . iterator ( ) ; int j = <NUM_LIT:0> ; while ( i . hasNext ( ) ) { String ruleSpec = ( String ) i . next ( ) ; char key = ruleSpec . charAt ( <NUM_LIT:0> ) ; String pattern = ruleSpec . substring ( <NUM_LIT:1> ) ; if ( pattern . length ( ) > <NUM_LIT:0> ) { switch ( key ) { case '<CHAR_LIT>' : accessRules [ j ++ ] = new AccessRule ( pattern . toCharArray ( ) , <NUM_LIT:0> ) ; break ; case '<CHAR_LIT>' : accessRules [ j ++ ] = new AccessRule ( pattern . toCharArray ( ) , IProblem . DiscouragedReference ) ; break ; case '<CHAR_LIT:->' : accessRules [ j ++ ] = new AccessRule ( pattern . toCharArray ( ) , IProblem . ForbiddenReference ) ; break ; case '<CHAR_LIT>' : accessRules [ j ++ ] = new AccessRule ( pattern . toCharArray ( ) , IProblem . ForbiddenReference , true ) ; break ; default : rulesOK = false ; } } else { rulesOK = false ; } } if ( rulesOK ) { accessRuleSet = new AccessRuleSet ( accessRules , AccessRestriction . COMMAND_LINE , currentClasspathName ) ; } else { if ( currentClasspathName . length ( ) != <NUM_LIT:0> ) { addPendingErrors ( this . bind ( "<STR_LIT>" , currentClasspathName ) ) ; } return ; } } if ( NONE . equals ( destPath ) ) { destPath = NONE ; } if ( rejectDestinationPathOnJars && destPath != null && Util . isPotentialZipArchive ( currentClasspathName ) ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentClasspathName ) ) ; } FileSystem . Classpath currentClasspath = FileSystem . getClasspath ( currentClasspathName , customEncoding , isSourceOnly , accessRuleSet , destPath ) ; if ( currentClasspath != null ) { paths . add ( currentClasspath ) ; } else if ( currentClasspathName . length ( ) != <NUM_LIT:0> ) { addPendingErrors ( this . bind ( "<STR_LIT>" , currentClasspathName ) ) ; } } void addPendingErrors ( String message ) { if ( this . pendingErrors == null ) { this . pendingErrors = new ArrayList ( ) ; } this . pendingErrors . add ( message ) ; } public String bind ( String id ) { return bind ( id , ( String [ ] ) null ) ; } public String bind ( String id , String binding ) { return bind ( id , new String [ ] { binding } ) ; } public String bind ( String id , String binding1 , String binding2 ) { return bind ( id , new String [ ] { binding1 , binding2 } ) ; } public String bind ( String id , String [ ] arguments ) { if ( id == null ) return "<STR_LIT>" ; String message = null ; try { message = this . bundle . getString ( id ) ; } catch ( MissingResourceException e ) { return "<STR_LIT>" + id + "<STR_LIT>" + Main . bundleName ; } return MessageFormat . format ( message , arguments ) ; } private boolean checkVMVersion ( long minimalSupportedVersion ) { String classFileVersion = System . getProperty ( "<STR_LIT>" ) ; if ( classFileVersion == null ) { return false ; } int index = classFileVersion . indexOf ( '<CHAR_LIT:.>' ) ; if ( index == - <NUM_LIT:1> ) { return false ; } int majorVersion ; try { majorVersion = Integer . parseInt ( classFileVersion . substring ( <NUM_LIT:0> , index ) ) ; } catch ( NumberFormatException e ) { return false ; } switch ( majorVersion ) { case <NUM_LIT> : return ClassFileConstants . JDK1_1 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_2 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_3 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_4 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_5 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_6 >= minimalSupportedVersion ; case <NUM_LIT> : return ClassFileConstants . JDK1_7 >= minimalSupportedVersion ; } return false ; } public boolean compile ( String [ ] argv ) { try { configure ( argv ) ; if ( this . progress != null ) this . progress . begin ( this . filenames == null ? <NUM_LIT:0> : this . filenames . length * this . maxRepetition ) ; if ( this . proceed ) { if ( this . showProgress ) this . logger . compiling ( ) ; for ( this . currentRepetition = <NUM_LIT:0> ; this . currentRepetition < this . maxRepetition ; this . currentRepetition ++ ) { this . globalProblemsCount = <NUM_LIT:0> ; this . globalErrorsCount = <NUM_LIT:0> ; this . globalWarningsCount = <NUM_LIT:0> ; this . globalTasksCount = <NUM_LIT:0> ; this . exportedClassFilesCounter = <NUM_LIT:0> ; if ( this . maxRepetition > <NUM_LIT:1> ) { this . logger . flush ( ) ; this . logger . logRepetition ( this . currentRepetition , this . maxRepetition ) ; } performCompilation ( ) ; } if ( this . compilerStats != null ) { this . logger . logAverage ( ) ; } if ( this . showProgress ) this . logger . printNewLine ( ) ; } if ( this . systemExitWhenFinished ) { this . logger . flush ( ) ; this . logger . close ( ) ; System . exit ( this . globalErrorsCount > <NUM_LIT:0> ? - <NUM_LIT:1> : <NUM_LIT:0> ) ; } } catch ( IllegalArgumentException e ) { this . logger . logException ( e ) ; if ( this . systemExitWhenFinished ) { this . logger . flush ( ) ; this . logger . close ( ) ; System . exit ( - <NUM_LIT:1> ) ; } return false ; } catch ( RuntimeException e ) { this . logger . logException ( e ) ; if ( this . systemExitWhenFinished ) { this . logger . flush ( ) ; this . logger . close ( ) ; System . exit ( - <NUM_LIT:1> ) ; } return false ; } finally { this . logger . flush ( ) ; this . logger . close ( ) ; if ( this . progress != null ) this . progress . done ( ) ; } if ( this . globalErrorsCount == <NUM_LIT:0> && ( this . progress == null || ! this . progress . isCanceled ( ) ) ) return true ; return false ; } public void configure ( String [ ] argv ) { if ( ( argv == null ) || ( argv . length == <NUM_LIT:0> ) ) { printUsage ( ) ; return ; } final int INSIDE_CLASSPATH_start = <NUM_LIT:1> ; final int INSIDE_DESTINATION_PATH = <NUM_LIT:3> ; final int INSIDE_TARGET = <NUM_LIT:4> ; final int INSIDE_LOG = <NUM_LIT:5> ; final int INSIDE_REPETITION = <NUM_LIT:6> ; final int INSIDE_SOURCE = <NUM_LIT:7> ; final int INSIDE_DEFAULT_ENCODING = <NUM_LIT:8> ; final int INSIDE_BOOTCLASSPATH_start = <NUM_LIT:9> ; final int INSIDE_MAX_PROBLEMS = <NUM_LIT:11> ; final int INSIDE_EXT_DIRS = <NUM_LIT:12> ; final int INSIDE_SOURCE_PATH_start = <NUM_LIT> ; final int INSIDE_ENDORSED_DIRS = <NUM_LIT:15> ; final int INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH = <NUM_LIT:16> ; final int INSIDE_PROCESSOR_PATH_start = <NUM_LIT> ; final int INSIDE_PROCESSOR_start = <NUM_LIT> ; final int INSIDE_S_start = <NUM_LIT> ; final int INSIDE_CLASS_NAMES = <NUM_LIT:20> ; final int INSIDE_WARNINGS_PROPERTIES = <NUM_LIT> ; final int DEFAULT = <NUM_LIT:0> ; ArrayList bootclasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; String sourcepathClasspathArg = null ; ArrayList sourcepathClasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; ArrayList classpaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; ArrayList extdirsClasspaths = null ; ArrayList endorsedDirClasspaths = null ; int index = - <NUM_LIT:1> ; int filesCount = <NUM_LIT:0> ; int classCount = <NUM_LIT:0> ; int argCount = argv . length ; int mode = DEFAULT ; this . maxRepetition = <NUM_LIT:0> ; boolean printUsageRequired = false ; String usageSection = null ; boolean printVersionRequired = false ; boolean didSpecifyDeprecation = false ; boolean didSpecifyCompliance = false ; boolean didSpecifyDisabledAnnotationProcessing = false ; boolean encounteredGroovySourceFile = false ; String customEncoding = null ; String customDestinationPath = null ; String currentSourceDirectory = null ; String currentArg = Util . EMPTY_STRING ; Set specifiedEncodings = null ; boolean needExpansion = false ; loop : for ( int i = <NUM_LIT:0> ; i < argCount ; i ++ ) { if ( argv [ i ] . startsWith ( "<STR_LIT:@>" ) ) { needExpansion = true ; break loop ; } } String [ ] newCommandLineArgs = null ; if ( needExpansion ) { newCommandLineArgs = new String [ argCount ] ; index = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < argCount ; i ++ ) { String [ ] newArgs = null ; String arg = argv [ i ] . trim ( ) ; if ( arg . startsWith ( "<STR_LIT:@>" ) ) { try { LineNumberReader reader = new LineNumberReader ( new StringReader ( new String ( Util . getFileCharContent ( new File ( arg . substring ( <NUM_LIT:1> ) ) , null ) ) ) ) ; StringBuffer buffer = new StringBuffer ( ) ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( ! line . startsWith ( "<STR_LIT:#>" ) ) { buffer . append ( line ) . append ( "<STR_LIT:U+0020>" ) ; } } newArgs = tokenize ( buffer . toString ( ) ) ; } catch ( IOException e ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , arg ) ) ; } } if ( newArgs != null ) { int newCommandLineArgsLength = newCommandLineArgs . length ; int newArgsLength = newArgs . length ; System . arraycopy ( newCommandLineArgs , <NUM_LIT:0> , ( newCommandLineArgs = new String [ newCommandLineArgsLength + newArgsLength - <NUM_LIT:1> ] ) , <NUM_LIT:0> , index ) ; System . arraycopy ( newArgs , <NUM_LIT:0> , newCommandLineArgs , index , newArgsLength ) ; index += newArgsLength ; } else { newCommandLineArgs [ index ++ ] = arg ; } } index = - <NUM_LIT:1> ; } else { newCommandLineArgs = argv ; for ( int i = <NUM_LIT:0> ; i < argCount ; i ++ ) { newCommandLineArgs [ i ] = newCommandLineArgs [ i ] . trim ( ) ; } } argCount = newCommandLineArgs . length ; this . expandedCommandLine = newCommandLineArgs ; while ( ++ index < argCount ) { if ( customEncoding != null ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg , customEncoding ) ) ; } currentArg = newCommandLineArgs [ index ] ; switch ( mode ) { case DEFAULT : if ( currentArg . startsWith ( "<STR_LIT:[>" ) ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } if ( currentArg . endsWith ( "<STR_LIT:]>" ) ) { int encodingStart = currentArg . indexOf ( '<CHAR_LIT:[>' ) + <NUM_LIT:1> ; if ( encodingStart <= <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } int encodingEnd = currentArg . length ( ) - <NUM_LIT:1> ; if ( encodingStart >= <NUM_LIT:1> ) { if ( encodingStart < encodingEnd ) { customEncoding = currentArg . substring ( encodingStart , encodingEnd ) ; try { new InputStreamReader ( new ByteArrayInputStream ( new byte [ <NUM_LIT:0> ] ) , customEncoding ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , customEncoding ) ) ; } } currentArg = currentArg . substring ( <NUM_LIT:0> , encodingStart - <NUM_LIT:1> ) ; } } if ( currentArg . endsWith ( SuffixConstants . SUFFIX_STRING_java ) || currentArg . endsWith ( "<STR_LIT>" ) ) { if ( currentArg . endsWith ( "<STR_LIT>" ) ) { encounteredGroovySourceFile = true ; } if ( this . filenames == null ) { this . filenames = new String [ argCount - index ] ; this . encodings = new String [ argCount - index ] ; this . destinationPaths = new String [ argCount - index ] ; } else if ( filesCount == this . filenames . length ) { int length = this . filenames . length ; System . arraycopy ( this . filenames , <NUM_LIT:0> , ( this . filenames = new String [ length + argCount - index ] ) , <NUM_LIT:0> , length ) ; System . arraycopy ( this . encodings , <NUM_LIT:0> , ( this . encodings = new String [ length + argCount - index ] ) , <NUM_LIT:0> , length ) ; System . arraycopy ( this . destinationPaths , <NUM_LIT:0> , ( this . destinationPaths = new String [ length + argCount - index ] ) , <NUM_LIT:0> , length ) ; } this . filenames [ filesCount ] = currentArg ; this . encodings [ filesCount ++ ] = customEncoding ; customEncoding = null ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( this . log != null ) throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; mode = INSIDE_LOG ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( this . maxRepetition > <NUM_LIT:0> ) throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; mode = INSIDE_REPETITION ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( this . maxProblems > <NUM_LIT:0> ) throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; mode = INSIDE_MAX_PROBLEMS ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_SOURCE ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_DEFAULT_ENCODING ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( didSpecifyCompliance ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } didSpecifyCompliance = true ; this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_3 ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( didSpecifyCompliance ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } didSpecifyCompliance = true ; this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_4 ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { if ( didSpecifyCompliance ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } didSpecifyCompliance = true ; this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_5 ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { if ( didSpecifyCompliance ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } didSpecifyCompliance = true ; this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_6 ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { if ( didSpecifyCompliance ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } didSpecifyCompliance = true ; this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_7 ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( this . destinationPath != null ) { StringBuffer errorMessage = new StringBuffer ( ) ; errorMessage . append ( currentArg ) ; if ( ( index + <NUM_LIT:1> ) < argCount ) { errorMessage . append ( '<CHAR_LIT:U+0020>' ) ; errorMessage . append ( newCommandLineArgs [ index + <NUM_LIT:1> ] ) ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorMessage . toString ( ) ) ) ; } mode = INSIDE_DESTINATION_PATH ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_CLASSPATH_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( bootclasspaths . size ( ) > <NUM_LIT:0> ) { StringBuffer errorMessage = new StringBuffer ( ) ; errorMessage . append ( currentArg ) ; if ( ( index + <NUM_LIT:1> ) < argCount ) { errorMessage . append ( '<CHAR_LIT:U+0020>' ) ; errorMessage . append ( newCommandLineArgs [ index + <NUM_LIT:1> ] ) ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorMessage . toString ( ) ) ) ; } mode = INSIDE_BOOTCLASSPATH_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( sourcepathClasspathArg != null ) { StringBuffer errorMessage = new StringBuffer ( ) ; errorMessage . append ( currentArg ) ; if ( ( index + <NUM_LIT:1> ) < argCount ) { errorMessage . append ( '<CHAR_LIT:U+0020>' ) ; errorMessage . append ( newCommandLineArgs [ index + <NUM_LIT:1> ] ) ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorMessage . toString ( ) ) ) ; } mode = INSIDE_SOURCE_PATH_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( extdirsClasspaths != null ) { StringBuffer errorMessage = new StringBuffer ( ) ; errorMessage . append ( currentArg ) ; if ( ( index + <NUM_LIT:1> ) < argCount ) { errorMessage . append ( '<CHAR_LIT:U+0020>' ) ; errorMessage . append ( newCommandLineArgs [ index + <NUM_LIT:1> ] ) ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorMessage . toString ( ) ) ) ; } mode = INSIDE_EXT_DIRS ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { if ( endorsedDirClasspaths != null ) { StringBuffer errorMessage = new StringBuffer ( ) ; errorMessage . append ( currentArg ) ; if ( ( index + <NUM_LIT:1> ) < argCount ) { errorMessage . append ( '<CHAR_LIT:U+0020>' ) ; errorMessage . append ( newCommandLineArgs [ index + <NUM_LIT:1> ] ) ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorMessage . toString ( ) ) ) ; } mode = INSIDE_ENDORSED_DIRS ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . showProgress = true ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; int length = currentArg . length ( ) ; if ( length > <NUM_LIT:15> ) { if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_FatalOptionalError , CompilerOptions . ENABLED ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } } else { this . options . put ( CompilerOptions . OPTION_FatalOptionalError , CompilerOptions . DISABLED ) ; } this . proceedOnError = true ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . timing = TIMING_ENABLED ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . timing = TIMING_ENABLED | TIMING_DETAILED ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . logger . logVersion ( true ) ; this . proceed = false ; return ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { printVersionRequired = true ; mode = DEFAULT ; continue ; } if ( "<STR_LIT>" . equals ( currentArg ) ) { didSpecifyDeprecation = true ; this . options . put ( CompilerOptions . OPTION_ReportDeprecation , CompilerOptions . WARNING ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { printUsageRequired = true ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { printUsageRequired = true ; usageSection = "<STR_LIT>" ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { this . systemExitWhenFinished = false ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { this . verbose = true ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { this . produceRefInfo = true ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . options . put ( CompilerOptions . OPTION_InlineJsr , CompilerOptions . ENABLED ) ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; String debugOption = currentArg ; int length = currentArg . length ( ) ; if ( length == <NUM_LIT:2> ) { this . options . put ( CompilerOptions . OPTION_LocalVariableAttribute , CompilerOptions . GENERATE ) ; this . options . put ( CompilerOptions . OPTION_LineNumberAttribute , CompilerOptions . GENERATE ) ; this . options . put ( CompilerOptions . OPTION_SourceFileAttribute , CompilerOptions . GENERATE ) ; continue ; } if ( length > <NUM_LIT:3> ) { this . options . put ( CompilerOptions . OPTION_LocalVariableAttribute , CompilerOptions . DO_NOT_GENERATE ) ; this . options . put ( CompilerOptions . OPTION_LineNumberAttribute , CompilerOptions . DO_NOT_GENERATE ) ; this . options . put ( CompilerOptions . OPTION_SourceFileAttribute , CompilerOptions . DO_NOT_GENERATE ) ; if ( length == <NUM_LIT:7> && debugOption . equals ( "<STR_LIT>" + NONE ) ) continue ; StringTokenizer tokenizer = new StringTokenizer ( debugOption . substring ( <NUM_LIT:3> , debugOption . length ( ) ) , "<STR_LIT:U+002C>" ) ; while ( tokenizer . hasMoreTokens ( ) ) { String token = tokenizer . nextToken ( ) ; if ( token . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_LocalVariableAttribute , CompilerOptions . GENERATE ) ; } else if ( token . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_LineNumberAttribute , CompilerOptions . GENERATE ) ; } else if ( token . equals ( "<STR_LIT:source>" ) ) { this . options . put ( CompilerOptions . OPTION_SourceFileAttribute , CompilerOptions . GENERATE ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , debugOption ) ) ; } } continue ; } throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , debugOption ) ) ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { disableWarnings ( ) ; mode = DEFAULT ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; String warningOption = currentArg ; int length = currentArg . length ( ) ; if ( length == <NUM_LIT:10> && warningOption . equals ( "<STR_LIT>" + NONE ) ) { disableWarnings ( ) ; continue ; } if ( length <= <NUM_LIT:6> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , warningOption ) ) ; } int warnTokenStart ; boolean isEnabling , allowPlusOrMinus ; switch ( warningOption . charAt ( <NUM_LIT:6> ) ) { case '<CHAR_LIT>' : warnTokenStart = <NUM_LIT:7> ; isEnabling = true ; allowPlusOrMinus = true ; break ; case '<CHAR_LIT:->' : warnTokenStart = <NUM_LIT:7> ; isEnabling = false ; allowPlusOrMinus = true ; break ; default : disableWarnings ( ) ; warnTokenStart = <NUM_LIT:6> ; isEnabling = true ; allowPlusOrMinus = false ; } StringTokenizer tokenizer = new StringTokenizer ( warningOption . substring ( warnTokenStart , warningOption . length ( ) ) , "<STR_LIT:U+002C>" ) ; int tokenCounter = <NUM_LIT:0> ; if ( didSpecifyDeprecation ) { this . options . put ( CompilerOptions . OPTION_ReportDeprecation , CompilerOptions . WARNING ) ; } while ( tokenizer . hasMoreTokens ( ) ) { String token = tokenizer . nextToken ( ) ; tokenCounter ++ ; switch ( token . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT>' : if ( allowPlusOrMinus ) { isEnabling = true ; token = token . substring ( <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , token ) ) ; } break ; case '<CHAR_LIT:->' : if ( allowPlusOrMinus ) { isEnabling = false ; token = token . substring ( <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , token ) ) ; } } handleWarningToken ( token , isEnabling ) ; } if ( tokenCounter == <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; String errorOption = currentArg ; int length = currentArg . length ( ) ; if ( length <= <NUM_LIT:5> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , errorOption ) ) ; } int errorTokenStart ; boolean isEnabling , allowPlusOrMinus ; switch ( errorOption . charAt ( <NUM_LIT:5> ) ) { case '<CHAR_LIT>' : errorTokenStart = <NUM_LIT:6> ; isEnabling = true ; allowPlusOrMinus = true ; break ; case '<CHAR_LIT:->' : errorTokenStart = <NUM_LIT:6> ; isEnabling = false ; allowPlusOrMinus = true ; break ; default : disableErrors ( ) ; errorTokenStart = <NUM_LIT:5> ; isEnabling = true ; allowPlusOrMinus = false ; } StringTokenizer tokenizer = new StringTokenizer ( errorOption . substring ( errorTokenStart , errorOption . length ( ) ) , "<STR_LIT:U+002C>" ) ; int tokenCounter = <NUM_LIT:0> ; while ( tokenizer . hasMoreTokens ( ) ) { String token = tokenizer . nextToken ( ) ; tokenCounter ++ ; switch ( token . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT>' : if ( allowPlusOrMinus ) { isEnabling = true ; token = token . substring ( <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , token ) ) ; } break ; case '<CHAR_LIT:->' : if ( allowPlusOrMinus ) { isEnabling = false ; token = token . substring ( <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , token ) ) ; } break ; } handleErrorToken ( token , isEnabling ) ; } if ( tokenCounter == <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_TARGET ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_PreserveUnusedLocal , CompilerOptions . PRESERVE ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . enableJavadocOn = true ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; this . logger . setEmacs ( ) ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_PROCESSOR_PATH_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_PROCESSOR_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_GenerateClassFiles , CompilerOptions . DISABLED ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { didSpecifyDisabledAnnotationProcessing = true ; this . options . put ( CompilerOptions . OPTION_Process_Annotations , CompilerOptions . DISABLED ) ; mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_S_start ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; continue ; } if ( currentArg . startsWith ( "<STR_LIT>" ) ) { mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = DEFAULT ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_CLASS_NAMES ; continue ; } if ( currentArg . equals ( "<STR_LIT>" ) ) { mode = INSIDE_WARNINGS_PROPERTIES ; continue ; } break ; case INSIDE_TARGET : if ( this . didSpecifyTarget ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } this . didSpecifyTarget = true ; if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_1 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_2 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_3 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT:5>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_5 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT:6>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_6 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_7 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_JSR14 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_CLDC1_1 ) ; this . options . put ( CompilerOptions . OPTION_InlineJsr , CompilerOptions . ENABLED ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } mode = DEFAULT ; continue ; case INSIDE_LOG : this . log = currentArg ; mode = DEFAULT ; continue ; case INSIDE_REPETITION : try { this . maxRepetition = Integer . parseInt ( currentArg ) ; if ( this . maxRepetition <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } mode = DEFAULT ; continue ; case INSIDE_MAX_PROBLEMS : try { this . maxProblems = Integer . parseInt ( currentArg ) ; if ( this . maxProblems <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } this . options . put ( CompilerOptions . OPTION_MaxProblemPerUnit , currentArg ) ; } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } mode = DEFAULT ; continue ; case INSIDE_SOURCE : if ( this . didSpecifySource ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } this . didSpecifySource = true ; if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_3 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_4 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT:5>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_5 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT:6>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_6 ) ; } else if ( currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) || currentArg . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_7 ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } mode = DEFAULT ; continue ; case INSIDE_DEFAULT_ENCODING : if ( specifiedEncodings != null ) { if ( ! specifiedEncodings . contains ( currentArg ) ) { if ( specifiedEncodings . size ( ) > <NUM_LIT:1> ) { this . logger . logWarning ( this . bind ( "<STR_LIT>" , currentArg , getAllEncodings ( specifiedEncodings ) ) ) ; } else { this . logger . logWarning ( this . bind ( "<STR_LIT>" , currentArg , getAllEncodings ( specifiedEncodings ) ) ) ; } } } else { specifiedEncodings = new HashSet ( ) ; } try { new InputStreamReader ( new ByteArrayInputStream ( new byte [ <NUM_LIT:0> ] ) , currentArg ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } specifiedEncodings . add ( currentArg ) ; this . options . put ( CompilerOptions . OPTION_Encoding , currentArg ) ; mode = DEFAULT ; continue ; case INSIDE_DESTINATION_PATH : setDestinationPath ( currentArg . equals ( NONE ) ? NONE : currentArg ) ; mode = DEFAULT ; continue ; case INSIDE_CLASSPATH_start : mode = DEFAULT ; index += processPaths ( newCommandLineArgs , index , currentArg , classpaths ) ; continue ; case INSIDE_BOOTCLASSPATH_start : mode = DEFAULT ; index += processPaths ( newCommandLineArgs , index , currentArg , bootclasspaths ) ; continue ; case INSIDE_SOURCE_PATH_start : mode = DEFAULT ; String [ ] sourcePaths = new String [ <NUM_LIT:1> ] ; index += processPaths ( newCommandLineArgs , index , currentArg , sourcePaths ) ; sourcepathClasspathArg = sourcePaths [ <NUM_LIT:0> ] ; continue ; case INSIDE_EXT_DIRS : if ( currentArg . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } StringTokenizer tokenizer = new StringTokenizer ( currentArg , File . pathSeparator , false ) ; extdirsClasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; while ( tokenizer . hasMoreTokens ( ) ) extdirsClasspaths . add ( tokenizer . nextToken ( ) ) ; mode = DEFAULT ; continue ; case INSIDE_ENDORSED_DIRS : if ( currentArg . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } tokenizer = new StringTokenizer ( currentArg , File . pathSeparator , false ) ; endorsedDirClasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; while ( tokenizer . hasMoreTokens ( ) ) endorsedDirClasspaths . add ( tokenizer . nextToken ( ) ) ; mode = DEFAULT ; continue ; case INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH : if ( currentArg . endsWith ( "<STR_LIT:]>" ) ) { customDestinationPath = currentArg . substring ( <NUM_LIT:0> , currentArg . length ( ) - <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , "<STR_LIT>" + currentArg ) ) ; } break ; case INSIDE_PROCESSOR_PATH_start : mode = DEFAULT ; continue ; case INSIDE_PROCESSOR_start : mode = DEFAULT ; continue ; case INSIDE_S_start : mode = DEFAULT ; continue ; case INSIDE_CLASS_NAMES : tokenizer = new StringTokenizer ( currentArg , "<STR_LIT:U+002C>" ) ; if ( this . classNames == null ) { this . classNames = new String [ DEFAULT_SIZE_CLASSPATH ] ; } while ( tokenizer . hasMoreTokens ( ) ) { if ( this . classNames . length == classCount ) { System . arraycopy ( this . classNames , <NUM_LIT:0> , ( this . classNames = new String [ classCount * <NUM_LIT:2> ] ) , <NUM_LIT:0> , classCount ) ; } this . classNames [ classCount ++ ] = tokenizer . nextToken ( ) ; } mode = DEFAULT ; continue ; case INSIDE_WARNINGS_PROPERTIES : initializeWarnings ( currentArg ) ; mode = DEFAULT ; continue ; } if ( customDestinationPath == null ) { if ( File . separatorChar != '<CHAR_LIT:/>' ) { currentArg = currentArg . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ; } if ( currentArg . endsWith ( "<STR_LIT>" ) ) { currentSourceDirectory = currentArg . substring ( <NUM_LIT:0> , currentArg . length ( ) - <NUM_LIT:3> ) ; mode = INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH ; continue ; } currentSourceDirectory = currentArg ; } File dir = new File ( currentSourceDirectory ) ; if ( ! dir . isDirectory ( ) ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentSourceDirectory ) ) ; } String [ ] result = FileFinder . find ( dir , SuffixConstants . SUFFIX_STRING_JAVA ) ; if ( NONE . equals ( customDestinationPath ) ) { customDestinationPath = NONE ; } if ( this . filenames != null ) { int length = result . length ; System . arraycopy ( this . filenames , <NUM_LIT:0> , ( this . filenames = new String [ length + filesCount ] ) , <NUM_LIT:0> , filesCount ) ; System . arraycopy ( this . encodings , <NUM_LIT:0> , ( this . encodings = new String [ length + filesCount ] ) , <NUM_LIT:0> , filesCount ) ; System . arraycopy ( this . destinationPaths , <NUM_LIT:0> , ( this . destinationPaths = new String [ length + filesCount ] ) , <NUM_LIT:0> , filesCount ) ; System . arraycopy ( result , <NUM_LIT:0> , this . filenames , filesCount , length ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { this . encodings [ filesCount + i ] = customEncoding ; this . destinationPaths [ filesCount + i ] = customDestinationPath ; } filesCount += length ; customEncoding = null ; customDestinationPath = null ; currentSourceDirectory = null ; } else { this . filenames = result ; filesCount = this . filenames . length ; this . encodings = new String [ filesCount ] ; this . destinationPaths = new String [ filesCount ] ; for ( int i = <NUM_LIT:0> ; i < filesCount ; i ++ ) { this . encodings [ i ] = customEncoding ; this . destinationPaths [ i ] = customDestinationPath ; } customEncoding = null ; customDestinationPath = null ; currentSourceDirectory = null ; } mode = DEFAULT ; continue ; } if ( this . enableJavadocOn ) { this . options . put ( CompilerOptions . OPTION_DocCommentSupport , CompilerOptions . ENABLED ) ; } else if ( this . warnJavadocOn || this . warnAllJavadocOn ) { this . options . put ( CompilerOptions . OPTION_DocCommentSupport , CompilerOptions . ENABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportUnusedParameterIncludeDocCommentReference , CompilerOptions . DISABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference , CompilerOptions . DISABLED ) ; } if ( this . warnJavadocOn ) { this . options . put ( CompilerOptions . OPTION_ReportInvalidJavadocTags , CompilerOptions . ENABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportInvalidJavadocTagsDeprecatedRef , CompilerOptions . ENABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportInvalidJavadocTagsNotVisibleRef , CompilerOptions . ENABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportMissingJavadocTagsVisibility , CompilerOptions . PRIVATE ) ; } if ( encounteredGroovySourceFile ) { this . options . put ( CompilerOptions . OPTIONG_BuildGroovyFiles , CompilerOptions . ENABLED ) ; } else { this . options . put ( CompilerOptions . OPTIONG_BuildGroovyFiles , CompilerOptions . DISABLED ) ; } if ( printUsageRequired || ( filesCount == <NUM_LIT:0> && classCount == <NUM_LIT:0> ) ) { if ( usageSection == null ) { printUsage ( ) ; } else { printUsage ( usageSection ) ; } this . proceed = false ; return ; } if ( this . log != null ) { this . logger . setLog ( this . log ) ; } else { this . showProgress = false ; } this . logger . logVersion ( printVersionRequired ) ; validateOptions ( didSpecifyCompliance ) ; if ( ! didSpecifyDisabledAnnotationProcessing && CompilerOptions . versionToJdkLevel ( this . options . get ( CompilerOptions . OPTION_Compliance ) ) >= ClassFileConstants . JDK1_6 ) { this . options . put ( CompilerOptions . OPTION_Process_Annotations , CompilerOptions . ENABLED ) ; } this . logger . logCommandLineArguments ( newCommandLineArgs ) ; this . logger . logOptions ( this . options ) ; if ( this . maxRepetition == <NUM_LIT:0> ) { this . maxRepetition = <NUM_LIT:1> ; } if ( this . maxRepetition >= <NUM_LIT:3> && ( this . timing & TIMING_ENABLED ) != <NUM_LIT:0> ) { this . compilerStats = new CompilerStats [ this . maxRepetition ] ; } if ( filesCount != <NUM_LIT:0> ) { System . arraycopy ( this . filenames , <NUM_LIT:0> , ( this . filenames = new String [ filesCount ] ) , <NUM_LIT:0> , filesCount ) ; } if ( classCount != <NUM_LIT:0> ) { System . arraycopy ( this . classNames , <NUM_LIT:0> , ( this . classNames = new String [ classCount ] ) , <NUM_LIT:0> , classCount ) ; } setPaths ( bootclasspaths , sourcepathClasspathArg , sourcepathClasspaths , classpaths , extdirsClasspaths , endorsedDirClasspaths , customEncoding ) ; if ( specifiedEncodings != null && specifiedEncodings . size ( ) > <NUM_LIT:1> ) { this . logger . logWarning ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Encoding ) , getAllEncodings ( specifiedEncodings ) ) ) ; } if ( this . pendingErrors != null ) { for ( Iterator iterator = this . pendingErrors . iterator ( ) ; iterator . hasNext ( ) ; ) { String message = ( String ) iterator . next ( ) ; this . logger . logPendingError ( message ) ; } this . pendingErrors = null ; } } private static String getAllEncodings ( Set encodings ) { int size = encodings . size ( ) ; String [ ] allEncodings = new String [ size ] ; encodings . toArray ( allEncodings ) ; Arrays . sort ( allEncodings ) ; StringBuffer buffer = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { if ( i > <NUM_LIT:0> ) { buffer . append ( "<STR_LIT:U+002CU+0020>" ) ; } buffer . append ( allEncodings [ i ] ) ; } return String . valueOf ( buffer ) ; } private void initializeWarnings ( String propertiesFile ) { File file = new File ( propertiesFile ) ; if ( ! file . exists ( ) ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , propertiesFile ) ) ; } BufferedInputStream stream = null ; Properties properties = null ; try { stream = new BufferedInputStream ( new FileInputStream ( propertiesFile ) ) ; properties = new Properties ( ) ; properties . load ( stream ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , propertiesFile ) ) ; } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( IOException e ) { } } } for ( Iterator iterator = properties . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) iterator . next ( ) ; final String key = ( String ) entry . getKey ( ) ; if ( key . startsWith ( "<STR_LIT>" ) ) { this . options . put ( key , entry . getValue ( ) ) ; } } } protected void disableWarnings ( ) { Object [ ] entries = this . options . entrySet ( ) . toArray ( ) ; for ( int i = <NUM_LIT:0> , max = entries . length ; i < max ; i ++ ) { Map . Entry entry = ( Map . Entry ) entries [ i ] ; if ( ! ( entry . getKey ( ) instanceof String ) ) continue ; if ( ! ( entry . getValue ( ) instanceof String ) ) continue ; if ( ( ( String ) entry . getValue ( ) ) . equals ( CompilerOptions . WARNING ) ) { this . options . put ( entry . getKey ( ) , CompilerOptions . IGNORE ) ; } } this . options . put ( CompilerOptions . OPTION_TaskTags , Util . EMPTY_STRING ) ; } protected void disableErrors ( ) { Object [ ] entries = this . options . entrySet ( ) . toArray ( ) ; for ( int i = <NUM_LIT:0> , max = entries . length ; i < max ; i ++ ) { Map . Entry entry = ( Map . Entry ) entries [ i ] ; if ( ! ( entry . getKey ( ) instanceof String ) ) continue ; if ( ! ( entry . getValue ( ) instanceof String ) ) continue ; if ( ( ( String ) entry . getValue ( ) ) . equals ( CompilerOptions . ERROR ) ) { this . options . put ( entry . getKey ( ) , CompilerOptions . IGNORE ) ; } } } public String extractDestinationPathFromSourceFile ( CompilationResult result ) { ICompilationUnit compilationUnit = result . compilationUnit ; if ( compilationUnit != null ) { char [ ] fileName = compilationUnit . getFileName ( ) ; int lastIndex = CharOperation . lastIndexOf ( java . io . File . separatorChar , fileName ) ; if ( lastIndex != - <NUM_LIT:1> ) { final String outputPathName = new String ( fileName , <NUM_LIT:0> , lastIndex ) ; final File output = new File ( outputPathName ) ; if ( output . exists ( ) && output . isDirectory ( ) ) { return outputPathName ; } } } return System . getProperty ( "<STR_LIT>" ) ; } public ICompilerRequestor getBatchRequestor ( ) { return new ICompilerRequestor ( ) { int lineDelta = <NUM_LIT:0> ; public void acceptResult ( CompilationResult compilationResult ) { if ( compilationResult . lineSeparatorPositions != null ) { int unitLineCount = compilationResult . lineSeparatorPositions . length ; this . lineDelta += unitLineCount ; if ( Main . this . showProgress && this . lineDelta > <NUM_LIT> ) { Main . this . logger . logProgress ( ) ; this . lineDelta = <NUM_LIT:0> ; } } Main . this . logger . startLoggingSource ( compilationResult ) ; if ( compilationResult . hasProblems ( ) || compilationResult . hasTasks ( ) ) { Main . this . logger . logProblems ( compilationResult . getAllProblems ( ) , compilationResult . compilationUnit . getContents ( ) , Main . this ) ; } outputClassFiles ( compilationResult ) ; Main . this . logger . endLoggingSource ( ) ; } } ; } public CompilationUnit [ ] getCompilationUnits ( ) { int fileCount = this . filenames . length ; CompilationUnit [ ] units = new CompilationUnit [ fileCount ] ; HashtableOfObject knownFileNames = new HashtableOfObject ( fileCount ) ; String defaultEncoding = ( String ) this . options . get ( CompilerOptions . OPTION_Encoding ) ; if ( Util . EMPTY_STRING . equals ( defaultEncoding ) ) defaultEncoding = null ; for ( int i = <NUM_LIT:0> ; i < fileCount ; i ++ ) { char [ ] charName = this . filenames [ i ] . toCharArray ( ) ; if ( knownFileNames . get ( charName ) != null ) throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , this . filenames [ i ] ) ) ; knownFileNames . put ( charName , charName ) ; File file = new File ( this . filenames [ i ] ) ; if ( ! file . exists ( ) ) throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , this . filenames [ i ] ) ) ; String encoding = this . encodings [ i ] ; if ( encoding == null ) encoding = defaultEncoding ; units [ i ] = new CompilationUnit ( null , this . filenames [ i ] , encoding , this . destinationPaths [ i ] ) ; } return units ; } public IErrorHandlingPolicy getHandlingPolicy ( ) { return new IErrorHandlingPolicy ( ) { public boolean proceedOnErrors ( ) { return Main . this . proceedOnError ; } public boolean stopOnFirstError ( ) { return false ; } } ; } public File getJavaHome ( ) { if ( ! this . javaHomeChecked ) { this . javaHomeChecked = true ; this . javaHomeCache = Util . getJavaHome ( ) ; } return this . javaHomeCache ; } public FileSystem getLibraryAccess ( ) { return new FileSystem ( this . checkedClasspaths , this . filenames ) ; } public IProblemFactory getProblemFactory ( ) { return new DefaultProblemFactory ( this . compilerLocale ) ; } protected ArrayList handleBootclasspath ( ArrayList bootclasspaths , String customEncoding ) { final int bootclasspathsSize = bootclasspaths == null ? <NUM_LIT:0> : bootclasspaths . size ( ) ; if ( bootclasspathsSize != <NUM_LIT:0> ) { String [ ] paths = new String [ bootclasspathsSize ] ; bootclasspaths . toArray ( paths ) ; bootclasspaths . clear ( ) ; for ( int i = <NUM_LIT:0> ; i < bootclasspathsSize ; i ++ ) { processPathEntries ( DEFAULT_SIZE_CLASSPATH , bootclasspaths , paths [ i ] , customEncoding , false , true ) ; } } else { bootclasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; try { Util . collectRunningVMBootclasspath ( bootclasspaths ) ; } catch ( IllegalStateException e ) { this . logger . logWrongJDK ( ) ; this . proceed = false ; return null ; } } return bootclasspaths ; } protected ArrayList handleClasspath ( ArrayList classpaths , String customEncoding ) { final int classpathsSize = classpaths == null ? <NUM_LIT:0> : classpaths . size ( ) ; if ( classpathsSize != <NUM_LIT:0> ) { String [ ] paths = new String [ classpathsSize ] ; classpaths . toArray ( paths ) ; classpaths . clear ( ) ; for ( int i = <NUM_LIT:0> ; i < classpathsSize ; i ++ ) { processPathEntries ( DEFAULT_SIZE_CLASSPATH , classpaths , paths [ i ] , customEncoding , false , true ) ; } } else { classpaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; String classProp = System . getProperty ( "<STR_LIT>" ) ; if ( ( classProp == null ) || ( classProp . length ( ) == <NUM_LIT:0> ) ) { addPendingErrors ( this . bind ( "<STR_LIT>" ) ) ; final Classpath classpath = FileSystem . getClasspath ( System . getProperty ( "<STR_LIT>" ) , customEncoding , null ) ; if ( classpath != null ) { classpaths . add ( classpath ) ; } } else { StringTokenizer tokenizer = new StringTokenizer ( classProp , File . pathSeparator ) ; String token ; while ( tokenizer . hasMoreTokens ( ) ) { token = tokenizer . nextToken ( ) ; FileSystem . Classpath currentClasspath = FileSystem . getClasspath ( token , customEncoding , null ) ; if ( currentClasspath != null ) { classpaths . add ( currentClasspath ) ; } else if ( token . length ( ) != <NUM_LIT:0> ) { addPendingErrors ( this . bind ( "<STR_LIT>" , token ) ) ; } } } } ArrayList result = new ArrayList ( ) ; HashMap knownNames = new HashMap ( ) ; FileSystem . ClasspathSectionProblemReporter problemReporter = new FileSystem . ClasspathSectionProblemReporter ( ) { public void invalidClasspathSection ( String jarFilePath ) { addPendingErrors ( bind ( "<STR_LIT>" , jarFilePath ) ) ; } public void multipleClasspathSections ( String jarFilePath ) { addPendingErrors ( bind ( "<STR_LIT>" , jarFilePath ) ) ; } } ; while ( ! classpaths . isEmpty ( ) ) { Classpath current = ( Classpath ) classpaths . remove ( <NUM_LIT:0> ) ; String currentPath = current . getPath ( ) ; if ( knownNames . get ( currentPath ) == null ) { knownNames . put ( currentPath , current ) ; result . add ( current ) ; List linkedJars = current . fetchLinkedJars ( problemReporter ) ; if ( linkedJars != null ) { classpaths . addAll ( <NUM_LIT:0> , linkedJars ) ; } } } return result ; } protected ArrayList handleEndorseddirs ( ArrayList endorsedDirClasspaths ) { final File javaHome = getJavaHome ( ) ; if ( endorsedDirClasspaths == null ) { endorsedDirClasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; String endorsedDirsStr = System . getProperty ( "<STR_LIT>" ) ; if ( endorsedDirsStr == null ) { if ( javaHome != null ) { endorsedDirClasspaths . add ( javaHome . getAbsolutePath ( ) + "<STR_LIT>" ) ; } } else { StringTokenizer tokenizer = new StringTokenizer ( endorsedDirsStr , File . pathSeparator ) ; while ( tokenizer . hasMoreTokens ( ) ) { endorsedDirClasspaths . add ( tokenizer . nextToken ( ) ) ; } } } if ( endorsedDirClasspaths . size ( ) != <NUM_LIT:0> ) { File [ ] directoriesToCheck = new File [ endorsedDirClasspaths . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < directoriesToCheck . length ; i ++ ) directoriesToCheck [ i ] = new File ( ( String ) endorsedDirClasspaths . get ( i ) ) ; endorsedDirClasspaths . clear ( ) ; File [ ] [ ] endorsedDirsJars = getLibrariesFiles ( directoriesToCheck ) ; if ( endorsedDirsJars != null ) { for ( int i = <NUM_LIT:0> , max = endorsedDirsJars . length ; i < max ; i ++ ) { File [ ] current = endorsedDirsJars [ i ] ; if ( current != null ) { for ( int j = <NUM_LIT:0> , max2 = current . length ; j < max2 ; j ++ ) { FileSystem . Classpath classpath = FileSystem . getClasspath ( current [ j ] . getAbsolutePath ( ) , null , null ) ; if ( classpath != null ) { endorsedDirClasspaths . add ( classpath ) ; } } } else if ( directoriesToCheck [ i ] . isFile ( ) ) { addPendingErrors ( this . bind ( "<STR_LIT>" , directoriesToCheck [ i ] . getAbsolutePath ( ) ) ) ; } } } } return endorsedDirClasspaths ; } protected ArrayList handleExtdirs ( ArrayList extdirsClasspaths ) { final File javaHome = getJavaHome ( ) ; if ( extdirsClasspaths == null ) { extdirsClasspaths = new ArrayList ( DEFAULT_SIZE_CLASSPATH ) ; String extdirsStr = System . getProperty ( "<STR_LIT>" ) ; if ( extdirsStr == null ) { extdirsClasspaths . add ( javaHome . getAbsolutePath ( ) + "<STR_LIT>" ) ; } else { StringTokenizer tokenizer = new StringTokenizer ( extdirsStr , File . pathSeparator ) ; while ( tokenizer . hasMoreTokens ( ) ) extdirsClasspaths . add ( tokenizer . nextToken ( ) ) ; } } if ( extdirsClasspaths . size ( ) != <NUM_LIT:0> ) { File [ ] directoriesToCheck = new File [ extdirsClasspaths . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < directoriesToCheck . length ; i ++ ) directoriesToCheck [ i ] = new File ( ( String ) extdirsClasspaths . get ( i ) ) ; extdirsClasspaths . clear ( ) ; File [ ] [ ] extdirsJars = getLibrariesFiles ( directoriesToCheck ) ; if ( extdirsJars != null ) { for ( int i = <NUM_LIT:0> , max = extdirsJars . length ; i < max ; i ++ ) { File [ ] current = extdirsJars [ i ] ; if ( current != null ) { for ( int j = <NUM_LIT:0> , max2 = current . length ; j < max2 ; j ++ ) { FileSystem . Classpath classpath = FileSystem . getClasspath ( current [ j ] . getAbsolutePath ( ) , null , null ) ; if ( classpath != null ) { extdirsClasspaths . add ( classpath ) ; } } } else if ( directoriesToCheck [ i ] . isFile ( ) ) { addPendingErrors ( this . bind ( "<STR_LIT>" , directoriesToCheck [ i ] . getAbsolutePath ( ) ) ) ; } } } } return extdirsClasspaths ; } protected void handleWarningToken ( String token , boolean isEnabling ) { handleErrorOrWarningToken ( token , isEnabling , ProblemSeverities . Warning ) ; } protected void handleErrorToken ( String token , boolean isEnabling ) { handleErrorOrWarningToken ( token , isEnabling , ProblemSeverities . Error ) ; } private void setSeverity ( String compilerOptions , int severity , boolean isEnabling ) { if ( isEnabling ) { switch ( severity ) { case ProblemSeverities . Error : this . options . put ( compilerOptions , CompilerOptions . ERROR ) ; break ; case ProblemSeverities . Warning : this . options . put ( compilerOptions , CompilerOptions . WARNING ) ; break ; default : this . options . put ( compilerOptions , CompilerOptions . IGNORE ) ; } } else { switch ( severity ) { case ProblemSeverities . Error : String currentValue = ( String ) this . options . get ( compilerOptions ) ; if ( CompilerOptions . ERROR . equals ( currentValue ) ) { this . options . put ( compilerOptions , CompilerOptions . IGNORE ) ; } break ; case ProblemSeverities . Warning : currentValue = ( String ) this . options . get ( compilerOptions ) ; if ( CompilerOptions . WARNING . equals ( currentValue ) ) { this . options . put ( compilerOptions , CompilerOptions . IGNORE ) ; } break ; default : this . options . put ( compilerOptions , CompilerOptions . IGNORE ) ; } } } private void handleErrorOrWarningToken ( String token , boolean isEnabling , int severity ) { if ( token . length ( ) == <NUM_LIT:0> ) return ; switch ( token . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT:a>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportDeprecation , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportDeprecationInDeprecatedCode , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportDeprecationWhenOverridingDeprecatedMethod , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { this . warnAllJavadocOn = this . warnJavadocOn = isEnabling ; setSeverity ( CompilerOptions . OPTION_ReportInvalidJavadoc , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportMissingJavadocTags , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportMissingJavadocComments , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportAssertIdentifier , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportDeadCode , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportDeadCodeInTrivialIfStatement , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingOverrideAnnotation , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; return ; } break ; case '<CHAR_LIT:b>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportAutoboxing , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT:c>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMethodWithConstructorName , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportPossibleAccidentalBooleanAssignment , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportComparingIdentical , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNoImplicitStringConversion , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT:deprecation>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportDeprecation , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportDeprecationInDeprecatedCode , CompilerOptions . DISABLED ) ; this . options . put ( CompilerOptions . OPTION_ReportDeprecationWhenOverridingDeprecatedMethod , CompilerOptions . DISABLED ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingDeprecatedAnnotation , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportDiscouragedReference , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportDeadCode , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportDeadCodeInTrivialIfStatement , CompilerOptions . DISABLED ) ; return ; } break ; case '<CHAR_LIT:e>' : if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportIncompleteEnumSwitch , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUndocumentedEmptyBlock , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportEnumIdentifier , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportFieldHiding , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportFinalParameterBound , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportFinallyBlockNotCompletingNormally , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportForbiddenReference , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportFallthroughCase , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportHiddenCatchBlock , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportLocalVariableHiding , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportFieldHiding , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportTypeParameterHiding , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingHashCodeMethod , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportIndirectStaticAccess , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportIncompatibleNonInheritedInterfaceMethod , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportAnnotationSuperInterface , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportRedundantSuperinterface , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { this . warnJavadocOn = isEnabling ; setSeverity ( CompilerOptions . OPTION_ReportInvalidJavadoc , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportMissingJavadocTags , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportLocalVariableHiding , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportHiddenCatchBlock , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNonExternalizedStringLiteral , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNoEffectAssignment , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNoImplicitStringConversion , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT:null>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNullReference , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportPotentialNullReference , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportRedundantNullCheck , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNullReference , severity , isEnabling ) ; if ( ! isEnabling ) { setSeverity ( CompilerOptions . OPTION_ReportPotentialNullReference , ProblemSeverities . Ignore , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportRedundantNullCheck , ProblemSeverities . Ignore , isEnabling ) ; } return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingSynchronizedOnInheritedMethod , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingOverrideAnnotation , severity , isEnabling ) ; this . options . put ( CompilerOptions . OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation , CompilerOptions . DISABLED ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportOverridingPackageDefaultMethod , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportParameterAssignment , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportRawTypeReference , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportRedundantSuperinterface , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { this . options . put ( CompilerOptions . OPTION_ReportSpecialParameterHidingField , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportSyntheticAccessEmulation , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNonStaticAccessToStatic , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingSynchronizedOnInheritedMethod , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportEmptyStatement , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT:serial>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportMissingSerialVersion , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { switch ( severity ) { case ProblemSeverities . Warning : this . options . put ( CompilerOptions . OPTION_SuppressWarnings , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; this . options . put ( CompilerOptions . OPTION_SuppressOptionalErrors , CompilerOptions . DISABLED ) ; break ; case ProblemSeverities . Error : this . options . put ( CompilerOptions . OPTION_SuppressWarnings , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; this . options . put ( CompilerOptions . OPTION_SuppressOptionalErrors , isEnabling ? CompilerOptions . ENABLED : CompilerOptions . DISABLED ) ; } return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportNonStaticAccessToStatic , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportIndirectStaticAccess , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportOverridingMethodWithoutSuperInvocation , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . startsWith ( "<STR_LIT>" ) ) { String taskTags = Util . EMPTY_STRING ; int start = token . indexOf ( '<CHAR_LIT:(>' ) ; int end = token . indexOf ( '<CHAR_LIT:)>' ) ; if ( start >= <NUM_LIT:0> && end >= <NUM_LIT:0> && start < end ) { taskTags = token . substring ( start + <NUM_LIT:1> , end ) . trim ( ) ; taskTags = taskTags . replace ( '<CHAR_LIT>' , '<CHAR_LIT:U+002C>' ) ; } if ( taskTags . length ( ) == <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , token ) ) ; } this . options . put ( CompilerOptions . OPTION_TaskTags , isEnabling ? taskTags : Util . EMPTY_STRING ) ; setSeverity ( CompilerOptions . OPTION_ReportTasks , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportTypeParameterHiding , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedLocal , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedParameter , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedImport , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedObjectAllocation , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedPrivateMember , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedLabel , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnnecessaryTypeCheck , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT:unchecked>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUncheckedTypeOperation , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnnecessaryElse , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedDeclaredThrownException , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) || token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnqualifiedFieldAccess , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT:unused>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedLocal , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedParameter , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedImport , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedPrivateMember , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedDeclaredThrownException , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedLabel , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedTypeArgumentsForMethodInvocation , severity , isEnabling ) ; return ; } else if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnusedTypeArgumentsForMethodInvocation , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportVarargsArgumentNeedCast , severity , isEnabling ) ; return ; } break ; case '<CHAR_LIT>' : if ( token . equals ( "<STR_LIT>" ) ) { setSeverity ( CompilerOptions . OPTION_ReportUnhandledWarningToken , severity , isEnabling ) ; setSeverity ( CompilerOptions . OPTION_ReportUnusedWarningToken , severity , isEnabling ) ; return ; } break ; } String message = null ; switch ( severity ) { case ProblemSeverities . Warning : message = this . bind ( "<STR_LIT>" , token ) ; break ; case ProblemSeverities . Error : message = this . bind ( "<STR_LIT>" , token ) ; } addPendingErrors ( message ) ; } protected void initialize ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExit ) { this . initialize ( outWriter , errWriter , systemExit , null , null ) ; } protected void initialize ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExit , Map customDefaultOptions ) { this . initialize ( outWriter , errWriter , systemExit , customDefaultOptions , null ) ; } protected void initialize ( PrintWriter outWriter , PrintWriter errWriter , boolean systemExit , Map customDefaultOptions , CompilationProgress compilationProgress ) { this . logger = new Logger ( this , outWriter , errWriter ) ; this . proceed = true ; this . out = outWriter ; this . err = errWriter ; this . systemExitWhenFinished = systemExit ; this . options = new CompilerOptions ( ) . getMap ( ) ; this . progress = compilationProgress ; if ( customDefaultOptions != null ) { this . didSpecifySource = customDefaultOptions . get ( CompilerOptions . OPTION_Source ) != null ; this . didSpecifyTarget = customDefaultOptions . get ( CompilerOptions . OPTION_TargetPlatform ) != null ; for ( Iterator iter = customDefaultOptions . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) iter . next ( ) ; this . options . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } } else { this . didSpecifySource = false ; this . didSpecifyTarget = false ; } this . classNames = null ; } protected void initializeAnnotationProcessorManager ( ) { try { Class c = Class . forName ( "<STR_LIT>" ) ; AbstractAnnotationProcessorManager annotationManager = ( AbstractAnnotationProcessorManager ) c . newInstance ( ) ; annotationManager . configure ( this , this . expandedCommandLine ) ; annotationManager . setErr ( this . err ) ; annotationManager . setOut ( this . out ) ; this . batchCompiler . annotationProcessorManager = annotationManager ; } catch ( ClassNotFoundException e ) { } catch ( InstantiationException e ) { throw new org . eclipse . jdt . internal . compiler . problem . AbortCompilation ( ) ; } catch ( IllegalAccessException e ) { throw new org . eclipse . jdt . internal . compiler . problem . AbortCompilation ( ) ; } catch ( UnsupportedClassVersionError e ) { this . logger . logIncorrectVMVersionForAnnotationProcessing ( ) ; } } public void outputClassFiles ( CompilationResult unitResult ) { if ( ! ( ( unitResult == null ) || ( unitResult . hasErrors ( ) && ! this . proceedOnError ) ) ) { ClassFile [ ] classFiles = unitResult . getClassFiles ( ) ; String currentDestinationPath = null ; boolean generateClasspathStructure = false ; CompilationUnit compilationUnit = ( CompilationUnit ) unitResult . compilationUnit ; if ( compilationUnit . destinationPath == null ) { if ( this . destinationPath == null ) { currentDestinationPath = extractDestinationPathFromSourceFile ( unitResult ) ; } else if ( this . destinationPath != NONE ) { currentDestinationPath = this . destinationPath ; generateClasspathStructure = true ; } } else if ( compilationUnit . destinationPath != NONE ) { currentDestinationPath = compilationUnit . destinationPath ; generateClasspathStructure = true ; } if ( currentDestinationPath != null ) { for ( int i = <NUM_LIT:0> , fileCount = classFiles . length ; i < fileCount ; i ++ ) { ClassFile classFile = classFiles [ i ] ; char [ ] filename = classFile . fileName ( ) ; int length = filename . length ; char [ ] relativeName = new char [ length + <NUM_LIT:6> ] ; System . arraycopy ( filename , <NUM_LIT:0> , relativeName , <NUM_LIT:0> , length ) ; System . arraycopy ( SuffixConstants . SUFFIX_class , <NUM_LIT:0> , relativeName , length , <NUM_LIT:6> ) ; CharOperation . replace ( relativeName , '<CHAR_LIT:/>' , File . separatorChar ) ; String relativeStringName = new String ( relativeName ) ; try { if ( this . compilerOptions . verbose ) this . out . println ( Messages . bind ( Messages . compilation_write , new String [ ] { String . valueOf ( this . exportedClassFilesCounter + <NUM_LIT:1> ) , relativeStringName } ) ) ; Util . writeToDisk ( generateClasspathStructure , currentDestinationPath , relativeStringName , classFile ) ; this . logger . logClassFile ( generateClasspathStructure , currentDestinationPath , relativeStringName ) ; this . exportedClassFilesCounter ++ ; } catch ( IOException e ) { this . logger . logNoClassFileCreated ( currentDestinationPath , relativeStringName , e ) ; } } this . batchCompiler . lookupEnvironment . releaseClassFiles ( classFiles ) ; } } } public void performCompilation ( ) { this . startTime = System . currentTimeMillis ( ) ; FileSystem environment = getLibraryAccess ( ) ; this . compilerOptions = new CompilerOptions ( this . options ) ; this . compilerOptions . performMethodsFullRecovery = false ; this . compilerOptions . performStatementsRecovery = false ; this . batchCompiler = new Compiler ( environment , getHandlingPolicy ( ) , this . compilerOptions , getBatchRequestor ( ) , getProblemFactory ( ) , this . out , this . progress ) ; this . batchCompiler . remainingIterations = this . maxRepetition - this . currentRepetition ; String setting = System . getProperty ( "<STR_LIT>" ) ; this . batchCompiler . useSingleThread = setting != null && setting . equals ( "<STR_LIT:true>" ) ; if ( this . compilerOptions . complianceLevel >= ClassFileConstants . JDK1_6 && this . compilerOptions . processAnnotations ) { if ( checkVMVersion ( ClassFileConstants . JDK1_6 ) ) { initializeAnnotationProcessorManager ( ) ; if ( this . classNames != null ) { this . batchCompiler . setBinaryTypes ( processClassNames ( this . batchCompiler . lookupEnvironment ) ) ; } } else { this . logger . logIncorrectVMVersionForAnnotationProcessing ( ) ; } } this . compilerOptions . verbose = this . verbose ; this . compilerOptions . produceReferenceInfo = this . produceRefInfo ; try { this . logger . startLoggingSources ( ) ; this . batchCompiler . compile ( getCompilationUnits ( ) ) ; } finally { this . logger . endLoggingSources ( ) ; } if ( this . extraProblems != null ) { this . logger . loggingExtraProblems ( this ) ; this . extraProblems = null ; } if ( this . compilerStats != null ) { this . compilerStats [ this . currentRepetition ] = this . batchCompiler . stats ; } this . logger . printStats ( ) ; environment . cleanup ( ) ; } public void printUsage ( ) { printUsage ( "<STR_LIT>" ) ; } private void printUsage ( String sectionID ) { this . logger . logUsage ( this . bind ( sectionID , new String [ ] { System . getProperty ( "<STR_LIT>" ) , this . bind ( "<STR_LIT>" ) , this . bind ( "<STR_LIT>" ) , this . bind ( "<STR_LIT>" ) } ) ) ; this . logger . flush ( ) ; } private ReferenceBinding [ ] processClassNames ( LookupEnvironment environment ) { int length = this . classNames . length ; ReferenceBinding [ ] referenceBindings = new ReferenceBinding [ length ] ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { String currentName = this . classNames [ i ] ; char [ ] [ ] compoundName = null ; if ( currentName . indexOf ( '<CHAR_LIT:.>' ) != - <NUM_LIT:1> ) { char [ ] typeName = currentName . toCharArray ( ) ; compoundName = CharOperation . splitOn ( '<CHAR_LIT:.>' , typeName ) ; } else { compoundName = new char [ ] [ ] { currentName . toCharArray ( ) } ; } ReferenceBinding type = environment . getType ( compoundName ) ; if ( type != null && type . isValidBinding ( ) ) { if ( type . isBinaryBinding ( ) ) { referenceBindings [ i ] = type ; } } else { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentName ) ) ; } } return referenceBindings ; } public void processPathEntries ( final int defaultSize , final ArrayList paths , final String currentPath , String customEncoding , boolean isSourceOnly , boolean rejectDestinationPathOnJars ) { String currentClasspathName = null ; String currentDestinationPath = null ; ArrayList currentRuleSpecs = new ArrayList ( defaultSize ) ; StringTokenizer tokenizer = new StringTokenizer ( currentPath , File . pathSeparator + "<STR_LIT:[]>" , true ) ; ArrayList tokens = new ArrayList ( ) ; while ( tokenizer . hasMoreTokens ( ) ) { tokens . add ( tokenizer . nextToken ( ) ) ; } final int start = <NUM_LIT:0> ; final int readyToClose = <NUM_LIT:1> ; final int readyToCloseEndingWithRules = <NUM_LIT:2> ; final int readyToCloseOrOtherEntry = <NUM_LIT:3> ; final int rulesNeedAnotherRule = <NUM_LIT:4> ; final int rulesStart = <NUM_LIT:5> ; final int rulesReadyToClose = <NUM_LIT:6> ; final int destinationPathReadyToClose = <NUM_LIT:7> ; final int readyToCloseEndingWithDestinationPath = <NUM_LIT:8> ; final int destinationPathStart = <NUM_LIT:9> ; final int bracketOpened = <NUM_LIT:10> ; final int bracketClosed = <NUM_LIT:11> ; final int error = <NUM_LIT> ; int state = start ; String token = null ; int cursor = <NUM_LIT:0> , tokensNb = tokens . size ( ) , bracket = - <NUM_LIT:1> ; while ( cursor < tokensNb && state != error ) { token = ( String ) tokens . get ( cursor ++ ) ; if ( token . equals ( File . pathSeparator ) ) { switch ( state ) { case start : case readyToCloseOrOtherEntry : case bracketOpened : break ; case readyToClose : case readyToCloseEndingWithRules : case readyToCloseEndingWithDestinationPath : state = readyToCloseOrOtherEntry ; addNewEntry ( paths , currentClasspathName , currentRuleSpecs , customEncoding , currentDestinationPath , isSourceOnly , rejectDestinationPathOnJars ) ; currentRuleSpecs . clear ( ) ; break ; case rulesReadyToClose : state = rulesNeedAnotherRule ; break ; case destinationPathReadyToClose : throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentPath ) ) ; case bracketClosed : cursor = bracket + <NUM_LIT:1> ; state = rulesStart ; break ; default : state = error ; } } else if ( token . equals ( "<STR_LIT:[>" ) ) { switch ( state ) { case start : currentClasspathName = "<STR_LIT>" ; case readyToClose : bracket = cursor - <NUM_LIT:1> ; case bracketClosed : state = bracketOpened ; break ; case readyToCloseEndingWithRules : state = destinationPathStart ; break ; case readyToCloseEndingWithDestinationPath : state = rulesStart ; break ; case bracketOpened : default : state = error ; } } else if ( token . equals ( "<STR_LIT:]>" ) ) { switch ( state ) { case rulesReadyToClose : state = readyToCloseEndingWithRules ; break ; case destinationPathReadyToClose : state = readyToCloseEndingWithDestinationPath ; break ; case bracketOpened : state = bracketClosed ; break ; case bracketClosed : default : state = error ; } } else { switch ( state ) { case start : case readyToCloseOrOtherEntry : state = readyToClose ; currentClasspathName = token ; break ; case rulesStart : if ( token . startsWith ( "<STR_LIT>" ) ) { if ( currentDestinationPath != null ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentPath ) ) ; } currentDestinationPath = token . substring ( <NUM_LIT:3> ) . trim ( ) ; state = destinationPathReadyToClose ; break ; } case rulesNeedAnotherRule : if ( currentDestinationPath != null ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentPath ) ) ; } state = rulesReadyToClose ; currentRuleSpecs . add ( token ) ; break ; case destinationPathStart : if ( ! token . startsWith ( "<STR_LIT>" ) ) { state = error ; } else { currentDestinationPath = token . substring ( <NUM_LIT:3> ) . trim ( ) ; state = destinationPathReadyToClose ; } break ; case bracketClosed : for ( int i = bracket ; i < cursor ; i ++ ) { currentClasspathName += ( String ) tokens . get ( i ) ; } state = readyToClose ; break ; case bracketOpened : break ; default : state = error ; } } if ( state == bracketClosed && cursor == tokensNb ) { cursor = bracket + <NUM_LIT:1> ; state = rulesStart ; } } switch ( state ) { case readyToCloseOrOtherEntry : break ; case readyToClose : case readyToCloseEndingWithRules : case readyToCloseEndingWithDestinationPath : addNewEntry ( paths , currentClasspathName , currentRuleSpecs , customEncoding , currentDestinationPath , isSourceOnly , rejectDestinationPathOnJars ) ; break ; case bracketOpened : case bracketClosed : default : if ( currentPath . length ( ) != <NUM_LIT:0> ) { addPendingErrors ( this . bind ( "<STR_LIT>" , currentPath ) ) ; } } } private int processPaths ( String [ ] args , int index , String currentArg , ArrayList paths ) { int localIndex = index ; int count = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> , max = currentArg . length ( ) ; i < max ; i ++ ) { switch ( currentArg . charAt ( i ) ) { case '<CHAR_LIT:[>' : count ++ ; break ; case '<CHAR_LIT:]>' : count -- ; break ; } } if ( count == <NUM_LIT:0> ) { paths . add ( currentArg ) ; } else if ( count > <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } else { StringBuffer currentPath = new StringBuffer ( currentArg ) ; while ( true ) { if ( localIndex >= args . length ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } localIndex ++ ; String nextArg = args [ localIndex ] ; for ( int i = <NUM_LIT:0> , max = nextArg . length ( ) ; i < max ; i ++ ) { switch ( nextArg . charAt ( i ) ) { case '<CHAR_LIT:[>' : if ( count > <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , nextArg ) ) ; } count ++ ; break ; case '<CHAR_LIT:]>' : count -- ; break ; } } if ( count == <NUM_LIT:0> ) { currentPath . append ( '<CHAR_LIT:U+0020>' ) ; currentPath . append ( nextArg ) ; paths . add ( currentPath . toString ( ) ) ; return localIndex - index ; } else if ( count < <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , nextArg ) ) ; } else { currentPath . append ( '<CHAR_LIT:U+0020>' ) ; currentPath . append ( nextArg ) ; } } } return localIndex - index ; } private int processPaths ( String [ ] args , int index , String currentArg , String [ ] paths ) { int localIndex = index ; int count = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> , max = currentArg . length ( ) ; i < max ; i ++ ) { switch ( currentArg . charAt ( i ) ) { case '<CHAR_LIT:[>' : count ++ ; break ; case '<CHAR_LIT:]>' : count -- ; break ; } } if ( count == <NUM_LIT:0> ) { paths [ <NUM_LIT:0> ] = currentArg ; } else { StringBuffer currentPath = new StringBuffer ( currentArg ) ; while ( true ) { localIndex ++ ; if ( localIndex >= args . length ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } String nextArg = args [ localIndex ] ; for ( int i = <NUM_LIT:0> , max = nextArg . length ( ) ; i < max ; i ++ ) { switch ( nextArg . charAt ( i ) ) { case '<CHAR_LIT:[>' : if ( count > <NUM_LIT:1> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } count ++ ; break ; case '<CHAR_LIT:]>' : count -- ; break ; } } if ( count == <NUM_LIT:0> ) { currentPath . append ( '<CHAR_LIT:U+0020>' ) ; currentPath . append ( nextArg ) ; paths [ <NUM_LIT:0> ] = currentPath . toString ( ) ; return localIndex - index ; } else if ( count < <NUM_LIT:0> ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , currentArg ) ) ; } else { currentPath . append ( '<CHAR_LIT:U+0020>' ) ; currentPath . append ( nextArg ) ; } } } return localIndex - index ; } public void relocalize ( ) { relocalize ( Locale . getDefault ( ) ) ; } private void relocalize ( Locale locale ) { this . compilerLocale = locale ; try { this . bundle = ResourceBundleFactory . getBundle ( locale ) ; } catch ( MissingResourceException e ) { System . out . println ( "<STR_LIT>" + Main . bundleName . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) + "<STR_LIT>" + locale ) ; throw e ; } } public void setDestinationPath ( String dest ) { this . destinationPath = dest ; } public void setLocale ( Locale locale ) { relocalize ( locale ) ; } protected void setPaths ( ArrayList bootclasspaths , String sourcepathClasspathArg , ArrayList sourcepathClasspaths , ArrayList classpaths , ArrayList extdirsClasspaths , ArrayList endorsedDirClasspaths , String customEncoding ) { bootclasspaths = handleBootclasspath ( bootclasspaths , customEncoding ) ; classpaths = handleClasspath ( classpaths , customEncoding ) ; if ( sourcepathClasspathArg != null ) { processPathEntries ( DEFAULT_SIZE_CLASSPATH , sourcepathClasspaths , sourcepathClasspathArg , customEncoding , true , false ) ; } extdirsClasspaths = handleExtdirs ( extdirsClasspaths ) ; endorsedDirClasspaths = handleEndorseddirs ( endorsedDirClasspaths ) ; bootclasspaths . addAll ( endorsedDirClasspaths ) ; bootclasspaths . addAll ( extdirsClasspaths ) ; bootclasspaths . addAll ( sourcepathClasspaths ) ; bootclasspaths . addAll ( classpaths ) ; classpaths = bootclasspaths ; classpaths = FileSystem . ClasspathNormalizer . normalize ( classpaths ) ; this . checkedClasspaths = new FileSystem . Classpath [ classpaths . size ( ) ] ; classpaths . toArray ( this . checkedClasspaths ) ; this . logger . logClasspath ( this . checkedClasspaths ) ; } protected void validateOptions ( boolean didSpecifyCompliance ) { if ( didSpecifyCompliance ) { Object version = this . options . get ( CompilerOptions . OPTION_Compliance ) ; if ( CompilerOptions . VERSION_1_3 . equals ( version ) ) { if ( ! this . didSpecifySource ) this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_3 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_1 ) ; } else if ( CompilerOptions . VERSION_1_4 . equals ( version ) ) { if ( this . didSpecifySource ) { Object source = this . options . get ( CompilerOptions . OPTION_Source ) ; if ( CompilerOptions . VERSION_1_3 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_2 ) ; } else if ( CompilerOptions . VERSION_1_4 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } } else { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_3 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_2 ) ; } } else if ( CompilerOptions . VERSION_1_5 . equals ( version ) ) { if ( this . didSpecifySource ) { Object source = this . options . get ( CompilerOptions . OPTION_Source ) ; if ( CompilerOptions . VERSION_1_3 . equals ( source ) || CompilerOptions . VERSION_1_4 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } else if ( CompilerOptions . VERSION_1_5 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_5 ) ; } } else { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_5 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_5 ) ; } } else if ( CompilerOptions . VERSION_1_6 . equals ( version ) ) { if ( this . didSpecifySource ) { Object source = this . options . get ( CompilerOptions . OPTION_Source ) ; if ( CompilerOptions . VERSION_1_3 . equals ( source ) || CompilerOptions . VERSION_1_4 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } else if ( CompilerOptions . VERSION_1_5 . equals ( source ) || CompilerOptions . VERSION_1_6 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_6 ) ; } } else { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_6 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_6 ) ; } } else if ( CompilerOptions . VERSION_1_7 . equals ( version ) ) { if ( this . didSpecifySource ) { Object source = this . options . get ( CompilerOptions . OPTION_Source ) ; if ( CompilerOptions . VERSION_1_3 . equals ( source ) || CompilerOptions . VERSION_1_4 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } else if ( CompilerOptions . VERSION_1_5 . equals ( source ) || CompilerOptions . VERSION_1_6 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_6 ) ; } else if ( CompilerOptions . VERSION_1_7 . equals ( source ) ) { if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_7 ) ; } } else { this . options . put ( CompilerOptions . OPTION_Source , CompilerOptions . VERSION_1_7 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_7 ) ; } } } else if ( this . didSpecifySource ) { Object version = this . options . get ( CompilerOptions . OPTION_Source ) ; if ( CompilerOptions . VERSION_1_4 . equals ( version ) ) { if ( ! didSpecifyCompliance ) this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_4 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_4 ) ; } else if ( CompilerOptions . VERSION_1_5 . equals ( version ) ) { if ( ! didSpecifyCompliance ) this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_5 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_5 ) ; } else if ( CompilerOptions . VERSION_1_6 . equals ( version ) ) { if ( ! didSpecifyCompliance ) this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_6 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_6 ) ; } else if ( CompilerOptions . VERSION_1_7 . equals ( version ) ) { if ( ! didSpecifyCompliance ) this . options . put ( CompilerOptions . OPTION_Compliance , CompilerOptions . VERSION_1_7 ) ; if ( ! this . didSpecifyTarget ) this . options . put ( CompilerOptions . OPTION_TargetPlatform , CompilerOptions . VERSION_1_7 ) ; } } final Object sourceVersion = this . options . get ( CompilerOptions . OPTION_Source ) ; final Object compliance = this . options . get ( CompilerOptions . OPTION_Compliance ) ; if ( sourceVersion . equals ( CompilerOptions . VERSION_1_7 ) && CompilerOptions . versionToJdkLevel ( compliance ) < ClassFileConstants . JDK1_7 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Compliance ) , CompilerOptions . VERSION_1_7 ) ) ; } else if ( sourceVersion . equals ( CompilerOptions . VERSION_1_6 ) && CompilerOptions . versionToJdkLevel ( compliance ) < ClassFileConstants . JDK1_6 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Compliance ) , CompilerOptions . VERSION_1_6 ) ) ; } else if ( sourceVersion . equals ( CompilerOptions . VERSION_1_5 ) && CompilerOptions . versionToJdkLevel ( compliance ) < ClassFileConstants . JDK1_5 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Compliance ) , CompilerOptions . VERSION_1_5 ) ) ; } else if ( sourceVersion . equals ( CompilerOptions . VERSION_1_4 ) && CompilerOptions . versionToJdkLevel ( compliance ) < ClassFileConstants . JDK1_4 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Compliance ) , CompilerOptions . VERSION_1_4 ) ) ; } if ( this . didSpecifyTarget ) { final Object targetVersion = this . options . get ( CompilerOptions . OPTION_TargetPlatform ) ; if ( CompilerOptions . VERSION_JSR14 . equals ( targetVersion ) ) { if ( CompilerOptions . versionToJdkLevel ( sourceVersion ) < ClassFileConstants . JDK1_5 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , ( String ) sourceVersion ) ) ; } } else if ( CompilerOptions . VERSION_CLDC1_1 . equals ( targetVersion ) ) { if ( this . didSpecifySource && CompilerOptions . versionToJdkLevel ( sourceVersion ) >= ClassFileConstants . JDK1_4 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , ( String ) sourceVersion ) ) ; } if ( CompilerOptions . versionToJdkLevel ( compliance ) >= ClassFileConstants . JDK1_5 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , ( String ) sourceVersion ) ) ; } } else { if ( CompilerOptions . versionToJdkLevel ( sourceVersion ) >= ClassFileConstants . JDK1_7 && CompilerOptions . versionToJdkLevel ( targetVersion ) < ClassFileConstants . JDK1_7 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , CompilerOptions . VERSION_1_7 ) ) ; } if ( CompilerOptions . versionToJdkLevel ( sourceVersion ) >= ClassFileConstants . JDK1_6 && CompilerOptions . versionToJdkLevel ( targetVersion ) < ClassFileConstants . JDK1_6 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , CompilerOptions . VERSION_1_6 ) ) ; } if ( CompilerOptions . versionToJdkLevel ( sourceVersion ) >= ClassFileConstants . JDK1_5 && CompilerOptions . versionToJdkLevel ( targetVersion ) < ClassFileConstants . JDK1_5 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , CompilerOptions . VERSION_1_5 ) ) ; } if ( CompilerOptions . versionToJdkLevel ( sourceVersion ) >= ClassFileConstants . JDK1_4 && CompilerOptions . versionToJdkLevel ( targetVersion ) < ClassFileConstants . JDK1_4 ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) targetVersion , CompilerOptions . VERSION_1_4 ) ) ; } if ( CompilerOptions . versionToJdkLevel ( compliance ) < CompilerOptions . versionToJdkLevel ( targetVersion ) ) { throw new IllegalArgumentException ( this . bind ( "<STR_LIT>" , ( String ) this . options . get ( CompilerOptions . OPTION_Compliance ) , ( String ) targetVersion ) ) ; } } } } } </s>
|
<s> package org . eclipse . jdt . internal . compiler . batch ; import java . io . File ; import java . io . FilenameFilter ; import java . io . IOException ; import java . util . Hashtable ; import java . util . List ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileReader ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFormatException ; import org . eclipse . jdt . internal . compiler . env . AccessRuleSet ; import org . eclipse . jdt . internal . compiler . env . NameEnvironmentAnswer ; import org . eclipse . jdt . internal . compiler . parser . ScannerHelper ; import org . eclipse . jdt . internal . compiler . util . Util ; public class ClasspathDirectory extends ClasspathLocation { private Hashtable directoryCache ; private String [ ] missingPackageHolder = new String [ <NUM_LIT:1> ] ; private int mode ; private String encoding ; ClasspathDirectory ( File directory , String encoding , int mode , AccessRuleSet accessRuleSet , String destinationPath ) { super ( accessRuleSet , destinationPath ) ; this . mode = mode ; try { this . path = directory . getCanonicalPath ( ) ; } catch ( IOException e ) { this . path = directory . getAbsolutePath ( ) ; } if ( ! this . path . endsWith ( File . separator ) ) this . path += File . separator ; this . directoryCache = new Hashtable ( <NUM_LIT:11> ) ; this . encoding = encoding ; } String [ ] directoryList ( String qualifiedPackageName ) { String [ ] dirList = ( String [ ] ) this . directoryCache . get ( qualifiedPackageName ) ; if ( dirList == this . missingPackageHolder ) return null ; if ( dirList != null ) return dirList ; File dir = new File ( this . path + qualifiedPackageName ) ; notFound : if ( dir . isDirectory ( ) ) { int index = qualifiedPackageName . length ( ) ; int last = qualifiedPackageName . lastIndexOf ( File . separatorChar ) ; while ( -- index > last && ! ScannerHelper . isUpperCase ( qualifiedPackageName . charAt ( index ) ) ) { } if ( index > last ) { if ( last == - <NUM_LIT:1> ) { if ( ! doesFileExist ( qualifiedPackageName , Util . EMPTY_STRING ) ) break notFound ; } else { String packageName = qualifiedPackageName . substring ( last + <NUM_LIT:1> ) ; String parentPackage = qualifiedPackageName . substring ( <NUM_LIT:0> , last ) ; if ( ! doesFileExist ( packageName , parentPackage ) ) break notFound ; } } if ( ( dirList = dir . list ( ) ) == null ) dirList = CharOperation . NO_STRINGS ; this . directoryCache . put ( qualifiedPackageName , dirList ) ; return dirList ; } this . directoryCache . put ( qualifiedPackageName , this . missingPackageHolder ) ; return null ; } boolean doesFileExist ( String fileName , String qualifiedPackageName ) { String [ ] dirList = directoryList ( qualifiedPackageName ) ; if ( dirList == null ) return false ; for ( int i = dirList . length ; -- i >= <NUM_LIT:0> ; ) if ( fileName . equals ( dirList [ i ] ) ) return true ; return false ; } public List fetchLinkedJars ( FileSystem . ClasspathSectionProblemReporter problemReporter ) { return null ; } public NameEnvironmentAnswer findClass ( char [ ] typeName , String qualifiedPackageName , String qualifiedBinaryFileName ) { return findClass ( typeName , qualifiedPackageName , qualifiedBinaryFileName , false ) ; } public NameEnvironmentAnswer findClass ( char [ ] typeName , String qualifiedPackageName , String qualifiedBinaryFileName , boolean asBinaryOnly ) { if ( ! isPackage ( qualifiedPackageName ) ) return null ; String fileName = new String ( typeName ) ; boolean binaryExists = ( ( this . mode & BINARY ) != <NUM_LIT:0> ) && doesFileExist ( fileName + SUFFIX_STRING_class , qualifiedPackageName ) ; boolean sourceExists = ( ( this . mode & SOURCE ) != <NUM_LIT:0> ) && doesFileExist ( fileName + SUFFIX_STRING_java , qualifiedPackageName ) ; if ( sourceExists && ! asBinaryOnly ) { String fullSourcePath = this . path + qualifiedBinaryFileName . substring ( <NUM_LIT:0> , qualifiedBinaryFileName . length ( ) - <NUM_LIT:6> ) + SUFFIX_STRING_java ; if ( ! binaryExists ) return new NameEnvironmentAnswer ( new CompilationUnit ( null , fullSourcePath , this . encoding , this . destinationPath ) , fetchAccessRestriction ( qualifiedBinaryFileName ) ) ; String fullBinaryPath = this . path + qualifiedBinaryFileName ; long binaryModified = new File ( fullBinaryPath ) . lastModified ( ) ; long sourceModified = new File ( fullSourcePath ) . lastModified ( ) ; if ( sourceModified > binaryModified ) return new NameEnvironmentAnswer ( new CompilationUnit ( null , fullSourcePath , this . encoding , this . destinationPath ) , fetchAccessRestriction ( qualifiedBinaryFileName ) ) ; } if ( binaryExists ) { try { ClassFileReader reader = ClassFileReader . read ( this . path + qualifiedBinaryFileName ) ; if ( reader != null ) return new NameEnvironmentAnswer ( reader , fetchAccessRestriction ( qualifiedBinaryFileName ) ) ; } catch ( IOException e ) { } catch ( ClassFormatException e ) { } } return null ; } public char [ ] [ ] [ ] findTypeNames ( String qualifiedPackageName ) { if ( ! isPackage ( qualifiedPackageName ) ) { return null ; } File dir = new File ( this . path + qualifiedPackageName ) ; if ( ! dir . exists ( ) || ! dir . isDirectory ( ) ) { return null ; } String [ ] listFiles = dir . list ( new FilenameFilter ( ) { public boolean accept ( File directory , String name ) { String fileName = name . toLowerCase ( ) ; return fileName . endsWith ( "<STR_LIT:.class>" ) || fileName . endsWith ( "<STR_LIT>" ) ; } } ) ; int length ; if ( listFiles == null || ( length = listFiles . length ) == <NUM_LIT:0> ) { return null ; } char [ ] [ ] [ ] result = new char [ length ] [ ] [ ] ; char [ ] [ ] packageName = CharOperation . splitOn ( File . separatorChar , qualifiedPackageName . toCharArray ( ) ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { String fileName = listFiles [ i ] ; int indexOfLastDot = fileName . indexOf ( '<CHAR_LIT:.>' ) ; result [ i ] = CharOperation . arrayConcat ( packageName , fileName . substring ( <NUM_LIT:0> , indexOfLastDot ) . toCharArray ( ) ) ; } return result ; } public void initialize ( ) throws IOException { } public boolean isPackage ( String qualifiedPackageName ) { return directoryList ( qualifiedPackageName ) != null ; } public void reset ( ) { this . directoryCache = new Hashtable ( <NUM_LIT:11> ) ; } public String toString ( ) { return "<STR_LIT>" + this . path ; } public char [ ] normalizedPath ( ) { if ( this . normalizedPath == null ) { this . normalizedPath = this . path . toCharArray ( ) ; if ( File . separatorChar == '<STR_LIT:\\>' ) { CharOperation . replace ( this . normalizedPath , '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } } return this . normalizedPath ; } public String getPath ( ) { return this . path ; } } </s>
|
<s> package org . eclipse . jdt . core . compiler . batch ; import java . io . PrintWriter ; import org . eclipse . jdt . core . compiler . CompilationProgress ; import org . eclipse . jdt . internal . compiler . batch . Main ; public final class BatchCompiler { public static boolean compile ( String commandLine , PrintWriter outWriter , PrintWriter errWriter , CompilationProgress progress ) { return Main . compile ( Main . tokenize ( commandLine ) , outWriter , errWriter , progress ) ; } public static boolean compile ( String [ ] commandLineArguments , PrintWriter outWriter , PrintWriter errWriter , CompilationProgress progress ) { return Main . compile ( commandLineArguments , outWriter , errWriter , progress ) ; } private BatchCompiler ( ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . util . Arrays ; import java . util . Collection ; import java . util . List ; import java . util . Stack ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . dsl . pointcuts . BindingSet ; import org . codehaus . groovy . eclipse . dsl . pointcuts . GroovyDSLDContext ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . codehaus . jdt . groovy . model . ModuleNodeMapper . ModuleNodeInfo ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . groovy . tests . search . AbstractGroovySearchTest ; import org . eclipse . jdt . groovy . search . ITypeRequestor ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorWithRequestor ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; public class PointcutEvaluationTests extends AbstractGroovySearchTest { public static Test suite ( ) { return new TestSuite ( PointcutEvaluationTests . class ) ; } class PointcutEvaluationRequestor implements ITypeRequestor { private final IPointcut toMatch ; private final GroovyDSLDContext context ; Stack < BindingSet > matches = new Stack < BindingSet > ( ) ; BindingSet largestMatch = null ; Collection < ? > largestMatchResult = null ; public PointcutEvaluationRequestor ( IPointcut toMatch , GroovyCompilationUnit unit ) throws CoreException { super ( ) ; this . toMatch = toMatch ; this . context = createContext ( unit ) ; } private GroovyDSLDContext createContext ( GroovyCompilationUnit unit ) throws CoreException { ModuleNodeInfo info = unit . getModuleInfo ( true ) ; GroovyDSLDContext context = new GroovyDSLDContext ( unit , info . module , info . resolver ) ; context . resetBinding ( ) ; return context ; } public VisitStatus acceptASTNode ( ASTNode node , TypeLookupResult result , IJavaElement enclosingElement ) { context . setCurrentScope ( result . scope ) ; context . setTargetType ( result . type ) ; context . resetBinding ( ) ; Collection < ? > matchResult = toMatch . matches ( context , result . type ) ; if ( result != null ) { BindingSet set = context . getCurrentBinding ( ) ; matches . push ( set ) ; if ( largestMatch == null || largestMatch . size ( ) <= set . size ( ) ) { largestMatch = set ; largestMatchResult = matchResult ; } } return VisitStatus . CONTINUE ; } Collection < ? > getLargestMatchResult ( ) { return largestMatchResult ; } BindingSet getLargestMatch ( ) { return largestMatch ; } boolean hasMatches ( ) { return ! matches . isEmpty ( ) ; } } class BindingResult { public BindingResult ( String bindingName , String bindingToString ) { super ( ) ; this . bindingName = bindingName ; this . bindingToString = bindingToString ; } final String bindingName ; final String bindingToString ; @ Override public String toString ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( bindingName ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( bindingToString ) ; builder . append ( "<STR_LIT:]>" ) ; return builder . toString ( ) ; } } public PointcutEvaluationTests ( String name ) { super ( name ) ; } public void testEvaluateTypeMethodField1 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField2 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField3 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField4Fail ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testEvaluateTypeMethodField5 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField5b ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField5c ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField6Fail_a ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testEvaluateTypeMethodField6Fail_b ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testEvaluateTypeMethodField6Fail_c ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , null ) ; } public void testEvaluateTypeMethodField7a ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField7b ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField8 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField8b ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateTypeMethodField9Fail_a ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testEvaluateTypeMethodField9Fail_b ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testAnnotation1 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation2 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation3 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation4 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation5 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation6 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotation7Fail ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testAnnotation8 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateFileExtension1 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateFileExtension2Fail ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testEvaluateNature1 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testEvaluateNature2Fail ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testPackagePath ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:p>" ) ; } public void testPackagePathFail ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" , null ) ; } public void testNamedBinding1 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testNamedBinding2 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testNamedBinding3 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testNamedBinding4 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testNamedBinding5 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testNamedBinding6 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" ) ; } public void testNamedBinding6a ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding1 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding2 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding3 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding4 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding4Fail ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testTypesNamedBinding5 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding6 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding7 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding8 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding9 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding10Fail ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testTypesNamedBinding11 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding12 ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding13 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding14 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding15 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding16 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding17 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testTypesNamedBinding18Fail ( ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnd1 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:a>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:d>" , "<STR_LIT>" ) ) ; } public void testAnd2 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , null ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testOr1 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:a>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:d>" , "<STR_LIT>" ) ) ; } public void testOr2 ( ) throws Exception { doTestOfLastMatch ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:a>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) , new BindingResult ( "<STR_LIT:c>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding1 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding2 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding3 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding4 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding5 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding6 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotationBinding7Fail ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testAnnotationBinding8 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } public void testAnnotationBinding9 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; doTestOfLastBindingSet ( "<STR_LIT>" , "<STR_LIT>" , new BindingResult ( "<STR_LIT:b>" , "<STR_LIT>" ) ) ; } private void doTestOfLastBindingSet ( String cuContents , String pointcutText , BindingResult ... results ) throws Exception { doTestOfLastBindingSet ( "<STR_LIT:p>" , cuContents , pointcutText , results ) ; } private void doTestOfLastBindingSet ( String pkg , String cuContents , String pointcutText , BindingResult ... results ) throws Exception { GroovyCompilationUnit unit = createUnit ( pkg , "<STR_LIT>" , cuContents ) ; BindingSet bindings = evaluateForBindings ( unit , pointcutText ) ; assertAllBindings ( bindings , results ) ; } private void doTestOfLastMatch ( String cuContents , String pointcutText , String name ) throws Exception { doTestOfLastMatch ( "<STR_LIT:p>" , cuContents , pointcutText , name ) ; } private void doTestOfLastMatch ( String pkg , String cuContents , String pointcutText , String name ) throws Exception { GroovyCompilationUnit unit = createUnit ( pkg , "<STR_LIT>" , cuContents ) ; Collection < ? > match = evaluateForMatch ( unit , pointcutText ) ; assertSingleBinding ( name , match ) ; } private void assertAllBindings ( BindingSet bindings , BindingResult ... results ) { if ( results . length == <NUM_LIT:0> ) { assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , bindings . getBindings ( ) . size ( ) ) ; return ; } assertNotNull ( "<STR_LIT>" + Arrays . toString ( results ) , bindings ) ; for ( BindingResult result : results ) { Collection < ? > o = bindings . getBinding ( result . bindingName ) ; if ( o == null ) { fail ( "<STR_LIT>" + result . bindingName + "<STR_LIT>" + "<STR_LIT>" + bindings . getBindings ( ) ) ; } assertSingleBinding ( result . bindingToString , o ) ; } assertEquals ( "<STR_LIT>" + Arrays . toString ( results ) + "<STR_LIT>" + bindings . getBindings ( ) , results . length , bindings . getBindings ( ) . size ( ) ) ; } private void assertSingleBinding ( String bindingToString , Collection < ? > binding ) { if ( bindingToString == null ) { assertNull ( "<STR_LIT>" , binding ) ; return ; } assertNotNull ( "<STR_LIT>" , binding ) ; String [ ] split = bindingToString . split ( "<STR_LIT:U+002CU+0020>" ) ; assertEquals ( "<STR_LIT>" + BindingSet . printCollection ( binding ) , split . length , binding . size ( ) ) ; List < String > asList = Arrays . asList ( split ) ; for ( Object object : binding ) { String name = extractName ( object ) ; assertTrue ( "<STR_LIT>" + name + "<STR_LIT>" + asList , asList . contains ( name ) ) ; } } private String extractName ( Object defaultBinding ) { if ( defaultBinding == null ) { return null ; } else if ( defaultBinding instanceof ClassNode ) { return ( ( ClassNode ) defaultBinding ) . getName ( ) ; } else if ( defaultBinding instanceof FieldNode ) { FieldNode fieldNode = ( FieldNode ) defaultBinding ; return fieldNode . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + fieldNode . getName ( ) ; } else if ( defaultBinding instanceof MethodNode ) { MethodNode methodNode = ( MethodNode ) defaultBinding ; return methodNode . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + methodNode . getName ( ) ; } else if ( defaultBinding instanceof AnnotationNode ) { AnnotationNode annotationNode = ( AnnotationNode ) defaultBinding ; return "<STR_LIT:@>" + annotationNode . getClassNode ( ) . getName ( ) ; } else if ( defaultBinding instanceof Collection < ? > ) { StringBuilder sb = new StringBuilder ( ) ; for ( Object item : ( ( Collection < ? > ) defaultBinding ) ) { sb . append ( extractName ( item ) ) ; sb . append ( "<STR_LIT:U+002CU+0020>" ) ; } sb . replace ( sb . length ( ) - <NUM_LIT:2> , sb . length ( ) , "<STR_LIT>" ) ; return sb . toString ( ) ; } else { return defaultBinding . toString ( ) ; } } private Collection < ? > evaluateForMatch ( GroovyCompilationUnit unit , String pointcutText ) throws CoreException { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( pointcutText ) ; PointcutEvaluationRequestor requestor = new PointcutEvaluationRequestor ( pc , unit ) ; TypeInferencingVisitorWithRequestor visitor = factory . createVisitor ( unit ) ; visitor . visitCompilationUnit ( requestor ) ; return requestor . hasMatches ( ) ? requestor . getLargestMatchResult ( ) : null ; } private BindingSet evaluateForBindings ( GroovyCompilationUnit unit , String pointcutText ) throws CoreException { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( pointcutText ) ; PointcutEvaluationRequestor requestor = new PointcutEvaluationRequestor ( pc , unit ) ; TypeInferencingVisitorWithRequestor visitor = factory . createVisitor ( unit ) ; visitor . visitCompilationUnit ( requestor ) ; return requestor . hasMatches ( ) ? requestor . getLargestMatch ( ) : null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . io . IOException ; import java . net . MalformedURLException ; import java . net . URL ; import org . codehaus . groovy . eclipse . codeassist . tests . CompletionTestCase ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . RefreshDSLDJob ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class DSLContentAssistTests extends CompletionTestCase { private static final String COMMAND_CHAIN_NO_ARGS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private static final String COMMAND_CHAIN_ONE_ARG = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private static final String COMMAND_CHAIN_TWO_ARGS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private static final String NO_PARENS_FOR_DELEGATE = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private static final String SET_DELEGATE_ON_INT = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; public DSLContentAssistTests ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; createGenericProject ( ) ; IProject project = getDefaultProject ( ) ; AbstractDSLInferencingTest . refreshExternalFoldersProject ( ) ; GroovyRuntime . addLibraryToClasspath ( JavaCore . create ( project ) , GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , false ) ; env . fullBuild ( ) ; new RefreshDSLDJob ( project ) . run ( null ) ; GroovyDSLCoreActivator . getDefault ( ) . getContainerListener ( ) . ignoreProject ( project ) ; } public void testDSLProposalFirstStaticField ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:.>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testDSLProposalFirstStaticMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:.>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testDSLProposalFirstMethod1 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT:20> ) { AbstractDSLInferencingTest . addGroovyJarToProject ( "<STR_LIT>" , getDefaultProject ( ) ) ; } String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testDSLProposalFirstMethod2 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT:20> ) { AbstractDSLInferencingTest . addGroovyJarToProject ( "<STR_LIT>" , getDefaultProject ( ) ) ; } String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testDSLProposalFirstMethod3 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT:20> ) { AbstractDSLInferencingTest . addGroovyJarToProject ( "<STR_LIT>" , getDefaultProject ( ) ) ; } String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testEmptyClosure1 ( ) throws Exception { createDsls ( SET_DELEGATE_ON_INT ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testEmptyClosure2 ( ) throws Exception { createDsls ( SET_DELEGATE_ON_INT ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testCommandChain1 ( ) throws Exception { createDsls ( COMMAND_CHAIN_NO_ARGS ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testCommandChain2 ( ) throws Exception { createDsls ( COMMAND_CHAIN_NO_ARGS ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testCommandChain3 ( ) throws Exception { createDsls ( COMMAND_CHAIN_NO_ARGS ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testCommandChain4 ( ) throws Exception { createDsls ( COMMAND_CHAIN_ONE_ARG ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testCommandChain5 ( ) throws Exception { createDsls ( COMMAND_CHAIN_TWO_ARGS ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testDelegatesToNoParens1 ( ) throws Exception { createDsls ( NO_PARENS_FOR_DELEGATE ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } public void testDelegatesToNoParens2 ( ) throws Exception { createDsls ( NO_PARENS_FOR_DELEGATE ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; Document doc = new Document ( contents ) ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; ICompletionProposal proposal = findFirstProposal ( proposals , "<STR_LIT>" , false ) ; applyProposalAndCheck ( doc , proposal , contents . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } protected void addJarToProject ( String jarName ) throws JavaModelException , IOException { String externalFilePath = findExternalFilePath ( jarName ) ; env . addExternalJar ( getDefaultProject ( ) . getFullPath ( ) , externalFilePath ) ; } protected String findExternalFilePath ( String jarName ) throws MalformedURLException , IOException { URL url = GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceURL ( jarName ) ; URL resolved = FileLocator . resolve ( url ) ; String externalFilePath = resolved . getFile ( ) ; return externalFilePath ; } protected String [ ] createDsls ( String ... dsls ) { return createDsls ( <NUM_LIT:0> , dsls ) ; } protected String [ ] createDsls ( int startWith , String ... dsls ) { int i = startWith ; System . out . println ( "<STR_LIT>" + dsls . length + "<STR_LIT>" ) ; for ( String dsl : dsls ) { System . out . println ( "<STR_LIT>" + dsl + "<STR_LIT:n>" ) ; IPath path = env . addFile ( getDefaultProject ( ) . getFullPath ( ) , "<STR_LIT>" + i ++ + "<STR_LIT>" , dsl ) ; IFile file = env . getWorkspace ( ) . getRoot ( ) . getFile ( path ) ; if ( ! file . exists ( ) ) { fail ( "<STR_LIT>" + file + "<STR_LIT>" ) ; } } return dsls ; } protected IProject getDefaultProject ( ) { return env . getProject ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jdt . internal . core . ExternalPackageFragmentRoot ; public class BuiltInDSLInferencingTests extends AbstractDSLInferencingTest { public BuiltInDSLInferencingTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new TestSuite ( BuiltInDSLInferencingTests . class ) ; } @ Override protected void setUp ( ) throws Exception { doRemoveClasspathContainer = false ; super . setUp ( ) ; } public void testSanity ( ) throws Exception { IJavaProject javaProject = JavaCore . create ( project ) ; assertTrue ( "<STR_LIT>" , GroovyRuntime . hasClasspathContainer ( javaProject , GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID ) ) ; IClasspathContainer container = JavaCore . getClasspathContainer ( GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , javaProject ) ; IClasspathEntry [ ] cpes = container . getClasspathEntries ( ) ; assertEquals ( "<STR_LIT>" + Arrays . toString ( cpes ) , <NUM_LIT:2> , cpes . length ) ; IClasspathEntry pluginEntry = null ; IClasspathEntry [ ] entries = javaProject . getResolvedClasspath ( true ) ; for ( IClasspathEntry entry : entries ) { if ( entry . getPath ( ) . toString ( ) . contains ( "<STR_LIT>" ) ) { pluginEntry = entry ; } } IPackageFragmentRoot root = null ; List < String > elements = new ArrayList < String > ( ) ; for ( IJavaElement elt : javaProject . getChildren ( ) ) { elements . add ( elt . getElementName ( ) ) ; if ( elt . getElementName ( ) . contains ( "<STR_LIT>" ) ) { root = ( IPackageFragmentRoot ) elt ; } } List < String > possibleFrags = new ArrayList < String > ( ) ; for ( IPackageFragment frag : javaProject . getPackageFragments ( ) ) { if ( frag . getElementName ( ) . equals ( "<STR_LIT>" ) ) { possibleFrags . add ( frag . toString ( ) ) ; possibleFrags . add ( "<STR_LIT>" ) ; for ( IJavaElement child : frag . getChildren ( ) ) { possibleFrags . add ( "<STR_LIT:U+0020U+0020U+0020U+0020>" + child . getElementName ( ) ) ; } possibleFrags . add ( "<STR_LIT>" ) ; } } assertNotNull ( "<STR_LIT>" + printList ( elements ) + "<STR_LIT>" + printList ( possibleFrags ) , pluginEntry ) ; assertNotNull ( "<STR_LIT>" + printList ( elements ) + "<STR_LIT>" + printList ( possibleFrags ) , root ) ; assertTrue ( "<STR_LIT>" , root . exists ( ) ) ; ExternalPackageFragmentRoot ext = ( ExternalPackageFragmentRoot ) root ; ext . resource ( ) . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; root . close ( ) ; root . open ( null ) ; IPackageFragment frag = root . getPackageFragment ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , frag . exists ( ) ) ; } private String printList ( List < String > elements ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; for ( String elt : elements ) { sb . append ( elt ) . append ( "<STR_LIT:n>" ) ; } sb . append ( "<STR_LIT:]>" ) ; return sb . toString ( ) ; } public void testSingleton ( ) throws Exception { String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testDelegate1 ( ) throws Exception { String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT:get>" ) ; int end = start + "<STR_LIT:get>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegate2 ( ) throws Exception { String contents = "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT:get>" ) ; int end = start + "<STR_LIT:get>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testMixin ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" , start ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" , start ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" , start ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSwingBuilder1 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT:20> ) { addGroovyJarToProject ( "<STR_LIT>" ) ; } String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSwingBuilder2 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT:20> ) { addGroovyJarToProject ( "<STR_LIT>" ) ; } String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . dsl . pointcuts . StringObjectVector ; public class StringObjectVectorTests extends TestCase { private final Object obj1 = new Object ( ) ; private final Object obj2 = new Object ( ) ; private final Object obj3 = new Object ( ) ; private final Object obj4 = new Object ( ) ; private final Object obj5 = new Object ( ) ; private final String str1 = "<STR_LIT:1>" ; private final String str2 = "<STR_LIT:2>" ; private final String str3 = "<STR_LIT:3>" ; private final String str4 = "<STR_LIT:4>" ; private final String str5 = "<STR_LIT:5>" ; public void testCreateAndResiveVector ( ) throws Exception { StringObjectVector vector = new StringObjectVector ( <NUM_LIT:3> ) ; assertEquals ( <NUM_LIT:0> , vector . size ) ; assertEquals ( <NUM_LIT:3> , vector . maxSize ) ; vector . add ( str1 , obj1 ) ; assertEquals ( <NUM_LIT:1> , vector . size ) ; assertEquals ( <NUM_LIT:3> , vector . maxSize ) ; vector . add ( str2 , obj2 ) ; assertEquals ( <NUM_LIT:2> , vector . size ) ; assertEquals ( <NUM_LIT:3> , vector . maxSize ) ; vector . add ( str3 , obj3 ) ; assertEquals ( <NUM_LIT:3> , vector . size ) ; assertEquals ( <NUM_LIT:3> , vector . maxSize ) ; vector . add ( str4 , obj4 ) ; assertEquals ( <NUM_LIT:4> , vector . size ) ; assertEquals ( <NUM_LIT:6> , vector . maxSize ) ; vector . add ( str5 , obj5 ) ; assertEquals ( <NUM_LIT:5> , vector . size ) ; assertEquals ( <NUM_LIT:6> , vector . maxSize ) ; } public void testFindAndContains ( ) throws Exception { StringObjectVector vector = new StringObjectVector ( <NUM_LIT:3> ) ; vector . add ( str1 , obj1 ) ; vector . add ( str2 , obj2 ) ; vector . add ( str3 , obj3 ) ; vector . add ( str4 , obj4 ) ; vector . add ( str5 , obj5 ) ; assertEquals ( "<STR_LIT>" , obj1 , vector . find ( str1 ) ) ; assertEquals ( "<STR_LIT>" , obj2 , vector . find ( str2 ) ) ; assertEquals ( "<STR_LIT>" , obj3 , vector . find ( str3 ) ) ; assertEquals ( "<STR_LIT>" , obj4 , vector . find ( str4 ) ) ; assertEquals ( "<STR_LIT>" , obj5 , vector . find ( str5 ) ) ; assertFalse ( vector . contains ( null ) ) ; assertFalse ( vector . contains ( new Object ( ) ) ) ; assertFalse ( vector . containsName ( "<STR_LIT>" ) ) ; assertFalse ( vector . contains ( str1 ) ) ; assertTrue ( vector . contains ( obj1 ) ) ; assertTrue ( vector . contains ( obj2 ) ) ; assertTrue ( vector . contains ( obj3 ) ) ; assertTrue ( vector . contains ( obj4 ) ) ; assertTrue ( vector . contains ( obj5 ) ) ; assertTrue ( vector . containsName ( str1 ) ) ; assertTrue ( vector . containsName ( str2 ) ) ; assertTrue ( vector . containsName ( str3 ) ) ; assertTrue ( vector . containsName ( str4 ) ) ; assertTrue ( vector . containsName ( str5 ) ) ; assertNull ( vector . find ( "<STR_LIT>" ) ) ; assertNull ( vector . find ( null ) ) ; assertEquals ( <NUM_LIT:5> , vector . size ) ; vector . add ( null , obj1 ) ; assertEquals ( <NUM_LIT:6> , vector . size ) ; assertEquals ( obj1 , vector . find ( null ) ) ; } public void testElementAtNameAt ( ) throws Exception { StringObjectVector vector = new StringObjectVector ( <NUM_LIT:3> ) ; try { vector . elementAt ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } try { vector . nameAt ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } vector . add ( str1 , obj1 ) ; vector . add ( str2 , obj2 ) ; vector . add ( str3 , obj3 ) ; vector . add ( str4 , obj4 ) ; vector . add ( str5 , obj5 ) ; assertEquals ( "<STR_LIT>" , obj1 , vector . elementAt ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , obj2 , vector . elementAt ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , obj3 , vector . elementAt ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , obj4 , vector . elementAt ( <NUM_LIT:3> ) ) ; assertEquals ( "<STR_LIT>" , obj5 , vector . elementAt ( <NUM_LIT:4> ) ) ; assertEquals ( "<STR_LIT>" , str1 , vector . nameAt ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , str2 , vector . nameAt ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , str3 , vector . nameAt ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , str4 , vector . nameAt ( <NUM_LIT:3> ) ) ; assertEquals ( "<STR_LIT>" , str5 , vector . nameAt ( <NUM_LIT:4> ) ) ; try { vector . elementAt ( <NUM_LIT:5> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } try { vector . nameAt ( <NUM_LIT:5> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } try { vector . elementAt ( - <NUM_LIT:1> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } try { vector . nameAt ( - <NUM_LIT:1> ) ; fail ( "<STR_LIT>" ) ; } catch ( ArrayIndexOutOfBoundsException e ) { } vector . add ( null , null ) ; vector . add ( null , null ) ; assertEquals ( "<STR_LIT>" , null , vector . nameAt ( <NUM_LIT:5> ) ) ; assertEquals ( "<STR_LIT>" , null , vector . nameAt ( <NUM_LIT:6> ) ) ; assertEquals ( "<STR_LIT>" , null , vector . elementAt ( <NUM_LIT:5> ) ) ; assertEquals ( "<STR_LIT>" , null , vector . elementAt ( <NUM_LIT:6> ) ) ; } public void testGetNameAndValue ( ) throws Exception { StringObjectVector vector = new StringObjectVector ( <NUM_LIT:3> ) ; vector . add ( str1 , obj1 ) ; vector . add ( str2 , obj2 ) ; vector . add ( str3 , obj3 ) ; vector . add ( str4 , obj4 ) ; vector . add ( str5 , obj5 ) ; Object [ ] elts = vector . getElements ( ) ; assertEquals ( <NUM_LIT:5> , elts . length ) ; assertEquals ( obj1 , elts [ <NUM_LIT:0> ] ) ; assertEquals ( obj2 , elts [ <NUM_LIT:1> ] ) ; assertEquals ( obj3 , elts [ <NUM_LIT:2> ] ) ; assertEquals ( obj4 , elts [ <NUM_LIT:3> ] ) ; assertEquals ( obj5 , elts [ <NUM_LIT:4> ] ) ; String [ ] names = vector . getNames ( ) ; assertEquals ( <NUM_LIT:5> , names . length ) ; assertEquals ( str1 , names [ <NUM_LIT:0> ] ) ; assertEquals ( str2 , names [ <NUM_LIT:1> ] ) ; assertEquals ( str3 , names [ <NUM_LIT:2> ] ) ; assertEquals ( str4 , names [ <NUM_LIT:3> ] ) ; assertEquals ( str5 , names [ <NUM_LIT:4> ] ) ; vector . add ( null , null ) ; vector . add ( null , null ) ; elts = vector . getElements ( ) ; assertEquals ( <NUM_LIT:7> , elts . length ) ; assertEquals ( obj1 , elts [ <NUM_LIT:0> ] ) ; assertEquals ( obj2 , elts [ <NUM_LIT:1> ] ) ; assertEquals ( obj3 , elts [ <NUM_LIT:2> ] ) ; assertEquals ( obj4 , elts [ <NUM_LIT:3> ] ) ; assertEquals ( obj5 , elts [ <NUM_LIT:4> ] ) ; assertEquals ( null , elts [ <NUM_LIT:5> ] ) ; assertEquals ( null , elts [ <NUM_LIT:6> ] ) ; names = vector . getNames ( ) ; assertEquals ( <NUM_LIT:7> , names . length ) ; assertEquals ( str1 , names [ <NUM_LIT:0> ] ) ; assertEquals ( str2 , names [ <NUM_LIT:1> ] ) ; assertEquals ( str3 , names [ <NUM_LIT:2> ] ) ; assertEquals ( str4 , names [ <NUM_LIT:3> ] ) ; assertEquals ( str5 , names [ <NUM_LIT:4> ] ) ; assertEquals ( null , names [ <NUM_LIT:5> ] ) ; assertEquals ( null , names [ <NUM_LIT:6> ] ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . util . Collections ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . DSLPreferences ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . CurrentTypePointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . FindFieldPointcut ; import org . eclipse . core . resources . IStorage ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; public class DSLStoreTests extends AbstractDSLInferencingTest { public static Test suite ( ) { return new TestSuite ( DSLStoreTests . class ) ; } public DSLStoreTests ( String name ) { super ( name ) ; } public void testNothing ( ) throws Exception { assertDSLStore ( <NUM_LIT:0> , Collections . EMPTY_MAP , Collections . EMPTY_MAP ) ; } public void testSingleSimple ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; } public void testSingleTwice ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:2> } ) ) ; } public void testTwoPointcuts ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; } public void testTwoPointcutsTwoFiles ( ) throws Exception { createDsls ( "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; } public void testTwoFilesEachWith2Pointcuts ( ) throws Exception { createDsls ( "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; } public void testTwoFilesEachWith2PointcutsEachUsedTwice ( ) throws Exception { createDsls ( "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> } ) ) ; } public void testCraziness ( ) throws Exception { createDsls ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:3> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:2> ) } , new String [ ] { } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) , createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:2> ) } , new Integer [ ] { <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:5> } ) ) ; } public void testAddAndRemove ( ) throws Exception { assertDSLStore ( <NUM_LIT:0> , Collections . EMPTY_MAP , Collections . EMPTY_MAP ) ; createDsls ( "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; createDsls ( <NUM_LIT:1> , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; deleteDslFile ( <NUM_LIT:1> ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; deleteDslFile ( <NUM_LIT:0> ) ; assertDSLStore ( <NUM_LIT:0> , Collections . EMPTY_MAP , Collections . EMPTY_MAP ) ; } public void testChange ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:0> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; } public void testDisabledOfFile ( ) throws Exception { createDsls ( "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; DSLPreferences . setDisabledScripts ( new String [ ] { DSLDStore . toUniqueString ( project . getFile ( "<STR_LIT>" ) ) } ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { } , new String [ ] { createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; DSLPreferences . setDisabledScripts ( new String [ ] { } ) ; createDsls ( "<STR_LIT>" , "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:2> , createExpectedPointcuts ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) } , new String [ ] { createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , <NUM_LIT:0> ) , createSemiUniqueName ( FindFieldPointcut . class , <NUM_LIT:1> ) } , new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ) ) ; } public void testDisabledOfJar ( ) throws Exception { addJarToProject ( "<STR_LIT>" ) ; env . fullBuild ( ) ; IPackageFragmentRoot root = JavaCore . create ( project ) . getPackageFragmentRoot ( findExternalFilePath ( "<STR_LIT>" ) ) ; IStorage storage = ( IStorage ) root . getPackageFragment ( "<STR_LIT>" ) . getNonJavaResources ( ) [ <NUM_LIT:0> ] ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new IStorage [ ] { storage } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , storage ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , storage ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; DSLPreferences . setDisabledScripts ( new String [ ] { DSLDStore . toUniqueString ( storage ) } ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new String [ ] { } ) , createExpectedContributionCount ( new String [ ] { } , new Integer [ ] { } ) ) ; DSLPreferences . setDisabledScripts ( new String [ ] { } ) ; assertDSLStore ( <NUM_LIT:1> , createExpectedPointcuts ( new IStorage [ ] { storage } , new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , storage ) } ) , createExpectedContributionCount ( new String [ ] { createSemiUniqueName ( CurrentTypePointcut . class , storage ) } , new Integer [ ] { <NUM_LIT:1> } ) ) ; removeJarFromProject ( "<STR_LIT>" ) ; assertDSLStore ( <NUM_LIT:0> , createExpectedPointcuts ( new String [ ] { } ) , createExpectedContributionCount ( new String [ ] { } , new Integer [ ] { } ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . io . IOException ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . dsl . RefreshDSLDJob ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; public class DSLInferencingTests extends AbstractDSLInferencingTest { private static final String SET_DELEGATE_TYPE_SCRIPT = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static final String SET_DELEGATE_TYPE_DSLD = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; public DSLInferencingTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new TestSuite ( DSLInferencingTests . class ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; createDSL ( ) ; } public void testRegisteredPointcut1 ( ) throws Exception { String contents = "<STR_LIT>" ; String name = "<STR_LIT>" ; assertDeclaringType ( contents , contents . indexOf ( name ) , contents . indexOf ( name ) + name . length ( ) , "<STR_LIT>" ) ; } public void testRegisteredPointcut2 ( ) throws Exception { String contents = "<STR_LIT>" ; String name = "<STR_LIT>" ; assertDeclaringType ( contents , contents . indexOf ( name ) , contents . indexOf ( name ) + name . length ( ) , "<STR_LIT>" ) ; } public void testContiribution1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void _testDelegatesTo3 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo4 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo5 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo6 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeclaringType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testGenerics1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testGenerics2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:x>" ; int start = contents . lastIndexOf ( "<STR_LIT:x>" ) ; int end = start + "<STR_LIT:x>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testGenerics3 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDeprecated1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeprecated ( contents , start , end ) ; } public void testDeprecated2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; assertDeprecated ( contents , start , end ) ; } public void testAssertVersion1 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , false ) ; } public void testAssertVersion2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSupportsVersion3 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , false ) ; } public void testSupportsVersion2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testIsThisType1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int loc = <NUM_LIT:0> ; int len = "<STR_LIT>" . length ( ) ; int num = <NUM_LIT:0> ; do { loc = contents . indexOf ( "<STR_LIT>" , loc + <NUM_LIT:1> ) ; if ( loc > <NUM_LIT:0> ) { if ( num % <NUM_LIT:3> == <NUM_LIT:0> ) { assertType ( contents , loc , loc + len , "<STR_LIT>" , true ) ; } else if ( num % <NUM_LIT:3> == <NUM_LIT:2> ) { assertUnknownConfidence ( contents , loc , loc + len , "<STR_LIT>" , true ) ; } else if ( num % <NUM_LIT:3> == <NUM_LIT:2> ) { assertUnknownConfidence ( contents , loc , loc + len , "<STR_LIT>" , true ) ; } } num ++ ; } while ( loc > <NUM_LIT:0> ) ; } public void testEnclosingCall1 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT:yes>" ) ; int end = start + "<STR_LIT:yes>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT:yes>" ) ; int end = start + "<STR_LIT:yes>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall3 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall4 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall5 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall6 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCall7 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testAnnotatedBy1 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT:name>" ) ; int end = start + "<STR_LIT:name>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testAnnotatedBy2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT:name>" ) ; int end = start + "<STR_LIT:name>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testHasArgument1 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testHasArgument2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testStaticContext1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testStaticContext2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testStaticContext3 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testStaticContext4 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testStaticContext5 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading1 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading3 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading4 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading5 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testOperatorOverloading6 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testIsThisType2 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testIsThisType3 ( ) throws Exception { createDsls ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCallName1 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testEnclosingCallName2 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo7 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT:foo>" ) ; int end = start + "<STR_LIT:foo>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo8 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testDelegatesTo9 ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; start = contents . lastIndexOf ( "<STR_LIT>" ) ; end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType1 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType1a ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType2 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType3 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType4 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType5 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType6 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType7 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType8 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testSetDelegateType9 ( ) throws Exception { createDsls ( SET_DELEGATE_TYPE_DSLD ) ; String contents = SET_DELEGATE_TYPE_SCRIPT ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertUnknownConfidence ( contents , start , end , "<STR_LIT>" , true ) ; } public void testMultiProject ( ) throws Exception { IPath otherPath = env . addProject ( "<STR_LIT>" , "<STR_LIT>" ) ; env . removePackageFragmentRoot ( otherPath , "<STR_LIT>" ) ; IPath root = env . addPackageFragmentRoot ( otherPath , "<STR_LIT:src>" , null , null , "<STR_LIT>" ) ; env . addFile ( env . addFolder ( root , "<STR_LIT>" ) , "<STR_LIT>" , "<STR_LIT>" ) ; env . fullBuild ( "<STR_LIT>" ) ; env . addRequiredProject ( project . getFullPath ( ) , otherPath ) ; RefreshDSLDJob job = new RefreshDSLDJob ( project ) ; job . run ( new NullProgressMonitor ( ) ) ; String contents = "<STR_LIT>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" , true ) ; } public void testNullType ( ) throws Exception { createDsls ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int start = contents . lastIndexOf ( "<STR_LIT>" ) ; int end = start + "<STR_LIT:foo>" . length ( ) ; assertType ( contents , start , end , "<STR_LIT>" ) ; } private void createDSL ( ) throws IOException { defaultFileExtension = "<STR_LIT>" ; createUnit ( "<STR_LIT>" , GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceContents ( "<STR_LIT>" ) ) ; defaultFileExtension = "<STR_LIT>" ; env . fullBuild ( ) ; expectingNoProblems ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . io . IOException ; import java . net . MalformedURLException ; import java . net . URL ; import java . util . Arrays ; import java . util . Comparator ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . IGroovyLogger ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . dsl . DSLDStore ; import org . codehaus . groovy . eclipse . dsl . DSLDStoreManager ; import org . codehaus . groovy . eclipse . dsl . DSLPreferences ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . RefreshDSLDJob ; import org . codehaus . groovy . eclipse . dsl . contributions . IContributionGroup ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . eclipse . core . internal . resources . Folder ; import org . eclipse . core . internal . resources . Workspace ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IStorage ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . groovy . tests . search . AbstractInferencingTest ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; public class AbstractDSLInferencingTest extends AbstractInferencingTest { public AbstractDSLInferencingTest ( String name ) { super ( name ) ; } public static class TestLogger implements IGroovyLogger { public void log ( TraceCategory category , String message ) { System . out . println ( category . getPaddedLabel ( ) + "<STR_LIT::U+0020>" + message ) ; } public boolean isCategoryEnabled ( TraceCategory category ) { return true ; } } TestLogger logger = new TestLogger ( ) ; protected boolean doRemoveClasspathContainer = true ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyLogManager . manager . addLogger ( logger ) ; if ( doRemoveClasspathContainer ) { GroovyRuntime . removeClasspathContainer ( GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , JavaCore . create ( project ) ) ; } else { refreshExternalFoldersProject ( ) ; GroovyRuntime . addLibraryToClasspath ( JavaCore . create ( project ) , GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , false ) ; env . fullBuild ( ) ; new RefreshDSLDJob ( project ) . run ( null ) ; } GroovyDSLCoreActivator . getDefault ( ) . getContainerListener ( ) . ignoreProject ( project ) ; } @ Override protected void tearDown ( ) throws Exception { GroovyLogManager . manager . removeLogger ( logger ) ; defaultFileExtension = "<STR_LIT>" ; super . tearDown ( ) ; } protected String [ ] createDsls ( String ... dsls ) { return createDsls ( <NUM_LIT:0> , dsls ) ; } protected String [ ] createDsls ( int startWith , String ... dsls ) { return createDsls ( startWith , project , dsls ) ; } protected String [ ] createDsls ( int startWith , IProject theProject , String ... dsls ) { int i = startWith ; System . out . println ( "<STR_LIT>" + dsls . length + "<STR_LIT>" ) ; for ( String dsl : dsls ) { System . out . println ( "<STR_LIT>" + dsl + "<STR_LIT:n>" ) ; IPath path = env . addFile ( theProject . getFullPath ( ) , "<STR_LIT>" + i ++ + "<STR_LIT>" , dsl ) ; IFile file = env . getWorkspace ( ) . getRoot ( ) . getFile ( path ) ; if ( ! file . exists ( ) ) { fail ( "<STR_LIT>" + file + "<STR_LIT>" ) ; } } return dsls ; } protected void deleteDslFile ( int fileNum ) { env . removeFile ( project . getFile ( "<STR_LIT>" + fileNum + "<STR_LIT>" ) . getFullPath ( ) ) ; } protected String [ ] createDSLsFromFiles ( String ... fileNames ) throws IOException { String [ ] dslContents = new String [ fileNames . length ] ; for ( int i = <NUM_LIT:0> ; i < fileNames . length ; i ++ ) { dslContents [ i ] = GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceContents ( fileNames [ i ] ) ; } return createDsls ( dslContents ) ; } protected void addJarToProject ( String jarName ) throws JavaModelException , IOException { String externalFilePath = findExternalFilePath ( jarName ) ; env . addExternalJar ( project . getFullPath ( ) , externalFilePath ) ; } protected void addGroovyJarToProject ( String jarName ) throws JavaModelException , IOException { addGroovyJarToProject ( jarName , project ) ; } static protected void addGroovyJarToProject ( String jarName , IProject project ) throws JavaModelException , IOException { URL url = CompilerUtils . getJarInGroovyLib ( jarName ) ; if ( url != null ) { env . addExternalJar ( project . getFullPath ( ) , url . getFile ( ) ) ; } else { fail ( "<STR_LIT>" + jarName + "<STR_LIT>" ) ; } } protected String findExternalFilePath ( String jarName ) throws MalformedURLException , IOException { URL url = GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceURL ( jarName ) ; URL resolved = FileLocator . resolve ( url ) ; String externalFilePath = resolved . getFile ( ) ; return externalFilePath ; } protected void removeJarFromProject ( String jarName ) throws JavaModelException , IOException { URL url = GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceURL ( jarName ) ; URL resolved = FileLocator . resolve ( url ) ; env . removeExternalJar ( project . getFullPath ( ) , new Path ( resolved . getFile ( ) ) ) ; } protected void assertDSLStore ( int expectedNumDslFiles , Map < String , List < String > > allExpectedPointcuts , Map < String , Integer > expectedContributionCounts ) { System . out . println ( "<STR_LIT>" ) ; GroovyRuntime . removeClasspathContainer ( GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , JavaCore . create ( project ) ) ; env . fullBuild ( ) ; RefreshDSLDJob job = new RefreshDSLDJob ( project ) ; job . run ( new NullProgressMonitor ( ) ) ; System . out . println ( "<STR_LIT>" ) ; DSLDStoreManager manager = GroovyDSLCoreActivator . getDefault ( ) . getContextStoreManager ( ) ; DSLDStore store = manager . getDSLDStore ( project ) ; Set < String > disabledScripts = DSLPreferences . getDisabledScriptsAsSet ( ) ; IStorage [ ] keys = store . getAllContextKeys ( ) ; Arrays . sort ( keys , new Comparator < IStorage > ( ) { public int compare ( IStorage o1 , IStorage o2 ) { return o1 . getFullPath ( ) . toPortableString ( ) . compareTo ( o2 . getFullPath ( ) . toPortableString ( ) ) ; } } ) ; assertEquals ( expectedNumDslFiles , keys . length ) ; int i = <NUM_LIT:0> ; for ( IStorage key : keys ) { String uniqueString = DSLDStore . toUniqueString ( key ) ; if ( key instanceof IFile ) { assertEquals ( project . getFullPath ( ) + "<STR_LIT>" + i ++ + "<STR_LIT>" , uniqueString ) ; } if ( disabledScripts . contains ( uniqueString ) ) { continue ; } Set < IPointcut > pcs = ( ( Map < IStorage , Set < IPointcut > > ) ReflectionUtils . getPrivateField ( DSLDStore . class , "<STR_LIT>" , store ) ) . get ( key ) ; List < String > expectedPcs = allExpectedPointcuts . get ( uniqueString ) ; for ( IPointcut pc : pcs ) { assertTrue ( "<STR_LIT>" + pc + "<STR_LIT>" + expectedPcs , expectedPcs . contains ( createSemiUniqueName ( pc ) ) ) ; List < IContributionGroup > group = ( ( Map < IPointcut , List < IContributionGroup > > ) ReflectionUtils . getPrivateField ( DSLDStore . class , "<STR_LIT>" , store ) ) . get ( pc ) ; int groupSize = group . size ( ) ; int expectedSize = expectedContributionCounts . get ( createSemiUniqueName ( pc ) ) ; assertEquals ( "<STR_LIT>" + pc , expectedSize , groupSize ) ; } assertEquals ( "<STR_LIT>" + expectedPcs + "<STR_LIT>" + pcs , expectedPcs . size ( ) , pcs . size ( ) ) ; } } protected Map < String , Integer > createExpectedContributionCount ( String [ ] pcs , Integer [ ] counts ) { Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( int i = <NUM_LIT:0> ; i < counts . length ; i ++ ) { map . put ( pcs [ i ] , counts [ i ] ) ; } return map ; } protected Map < String , List < String > > createExpectedPointcuts ( String [ ] ... pointcuts ) { Map < String , List < String > > map = new HashMap < String , List < String > > ( ) ; int i = <NUM_LIT:0> ; for ( String [ ] strings : pointcuts ) { String name = DSLDStore . toUniqueString ( project . getFile ( "<STR_LIT>" + i ++ + "<STR_LIT>" ) ) ; map . put ( name , Arrays . asList ( strings ) ) ; } return map ; } protected Map < String , List < String > > createExpectedPointcuts ( IStorage [ ] storages , String [ ] ... pointcuts ) { Map < String , List < String > > map = new HashMap < String , List < String > > ( ) ; int i = <NUM_LIT:0> ; for ( String [ ] strings : pointcuts ) { String name = DSLDStore . toUniqueString ( storages [ i ++ ] ) ; map . put ( name , Arrays . asList ( strings ) ) ; } return map ; } protected String createSemiUniqueName ( IPointcut pc ) { return pc . getClass ( ) . getName ( ) + "<STR_LIT::>" + pc . getContainerIdentifier ( ) . getFullPath ( ) . lastSegment ( ) ; } protected String createSemiUniqueName ( Class < ? extends IPointcut > pc , int cnt ) { return pc . getName ( ) + "<STR_LIT::>" + "<STR_LIT>" + cnt + "<STR_LIT>" ; } protected String createSemiUniqueName ( Class < ? extends IPointcut > pc , IStorage storage ) { return pc . getName ( ) + "<STR_LIT::>" + DSLDStore . toUniqueString ( storage ) ; } protected void assertDSLType ( String contents , String name ) { assertDeclaringType ( contents , contents . indexOf ( name ) , contents . indexOf ( name ) + name . length ( ) , "<STR_LIT>" , true ) ; } protected void assertUnknownDSLType ( String contents , String name ) { assertUnknownConfidence ( contents , contents . indexOf ( name ) , contents . indexOf ( name ) + name . length ( ) , "<STR_LIT>" , true ) ; } protected static void refreshExternalFoldersProject ( ) throws CoreException { Workspace workspace = ( Workspace ) ResourcesPlugin . getWorkspace ( ) ; IProject externalProject = workspace . getRoot ( ) . getProject ( "<STR_LIT>" ) ; if ( externalProject . exists ( ) ) { for ( IResource member : externalProject . members ( ) ) { if ( member instanceof Folder ) { Folder folder = ( Folder ) member ; workspace . getAliasManager ( ) . updateAliases ( folder , folder . getStore ( ) , IResource . DEPTH_INFINITE , null ) ; if ( folder . exists ( ) ) { folder . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; } } } } } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import static org . junit . Assert . assertTrue ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . Reader ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import junit . framework . Assert ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . groovy . tests . search . AbstractInferencingTest ; public class InferencerWorkload implements Iterable < InferencerWorkload . InferencerTask > { private static final String BEG_MARK_START = "<STR_LIT>" ; private static final String BEG_MARK_SEPARATOR = "<STR_LIT::>" ; private static final String BEG_MARK_END = "<STR_LIT>" ; private static final String END_MARK = "<STR_LIT>" ; private static final Map < String , String > DEFAULT_ALIASES = new HashMap < String , String > ( ) ; static { DEFAULT_ALIASES . put ( "<STR_LIT:B>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:C>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:D>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:F>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:I>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:S>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT:Z>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; DEFAULT_ALIASES . put ( "<STR_LIT>" , "<STR_LIT>" ) ; } public class InferencerTask { public final int start ; public final int end ; public final String expectedResultType ; public final String expectedDeclaringType ; public InferencerTask ( int start , int end , String expectResultType , String expectDeclaringType ) { this . start = start ; this . end = end ; this . expectedResultType = expectResultType ; this . expectedDeclaringType = expectDeclaringType ; } public String getContents ( ) { return InferencerWorkload . this . getContents ( ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + expectedResultType + "<STR_LIT>" + expectedDeclaringType + "<STR_LIT>" + getContents ( ) . substring ( start , end ) ; } } private List < InferencerTask > tasks ; private String contents ; private final Map < String , String > aliases ; private boolean aliasesLocked = false ; public InferencerWorkload ( File workloadDefinitionFile , String ... extraAliases ) throws Exception { this ( extractContents ( workloadDefinitionFile ) , extraAliases ) ; } private static String extractContents ( File workloadDefinitionFile ) throws Exception { Reader r = new FileReader ( workloadDefinitionFile ) ; BufferedReader br = new BufferedReader ( r ) ; StringBuilder sb = new StringBuilder ( ) ; try { String line ; while ( ( line = br . readLine ( ) ) != null ) { sb . append ( line + "<STR_LIT:n>" ) ; } } finally { br . close ( ) ; } return sb . toString ( ) ; } public InferencerWorkload ( String workloadDefinition , String ... extraAliases ) { aliases = new HashMap < String , String > ( DEFAULT_ALIASES ) ; for ( int i = <NUM_LIT:0> ; i < extraAliases . length ; i ++ ) { defAlias ( extraAliases [ i ++ ] , extraAliases [ i ] ) ; } aliasesLocked = true ; StringBuilder stripped = new StringBuilder ( ) ; tasks = new ArrayList < InferencerWorkload . InferencerTask > ( ) ; int readPos = <NUM_LIT:0> ; while ( readPos >= <NUM_LIT:0> && readPos < workloadDefinition . length ( ) ) { int headStart = workloadDefinition . indexOf ( BEG_MARK_START , readPos ) ; int separator = - <NUM_LIT:1> ; int headEnd = - <NUM_LIT:1> ; int tail = - <NUM_LIT:1> ; if ( headStart >= <NUM_LIT:0> ) { separator = workloadDefinition . indexOf ( BEG_MARK_SEPARATOR , headStart ) ; headEnd = workloadDefinition . indexOf ( BEG_MARK_END , headStart ) ; tail = workloadDefinition . indexOf ( END_MARK , headStart ) ; } if ( headStart >= <NUM_LIT:0> && separator > headStart && headEnd > separator && tail > headEnd ) { int start = readPos ; int end = headStart ; stripped . append ( workloadDefinition . substring ( start , end ) ) ; start = headStart + BEG_MARK_START . length ( ) ; end = separator ; String resultType = workloadDefinition . substring ( start , end ) ; if ( aliases . containsKey ( resultType ) ) { resultType = aliases . get ( resultType ) ; } if ( resultType . length ( ) == <NUM_LIT:0> ) { resultType = null ; } start = separator + BEG_MARK_SEPARATOR . length ( ) ; end = headEnd ; String declType = workloadDefinition . substring ( start , end ) ; if ( aliases . containsKey ( declType ) ) { declType = aliases . get ( declType ) ; } if ( declType . length ( ) == <NUM_LIT:0> ) { declType = null ; } start = headEnd + BEG_MARK_END . length ( ) ; end = tail ; String expression = workloadDefinition . substring ( start , end ) ; start = stripped . length ( ) ; stripped . append ( expression ) ; end = stripped . length ( ) ; tasks . add ( new InferencerTask ( start , end , resultType , declType ) ) ; readPos = tail + END_MARK . length ( ) ; } else { stripped . append ( workloadDefinition . substring ( readPos ) ) ; readPos = - <NUM_LIT:1> ; } } contents = stripped . toString ( ) ; } protected void defAlias ( String name , String expansion ) { Assert . assertTrue ( "<STR_LIT>" , ! aliasesLocked ) ; String existing = aliases . get ( name ) ; if ( existing != null ) { Assert . fail ( "<STR_LIT>" + name + "<STR_LIT>" + expansion + "<STR_LIT>" + expansion ) ; } else { aliases . put ( name , expansion ) ; } } public String getContents ( ) { return contents ; } public Iterator < InferencerTask > iterator ( ) { return tasks . iterator ( ) ; } public void perform ( GroovyCompilationUnit unit , boolean assumeNoUnknowns ) throws Exception { boolean doneSomething = false ; try { unit . becomeWorkingCopy ( null ) ; StringBuilder sb = new StringBuilder ( ) ; for ( InferencerTask task : this ) { doneSomething = true ; String res = AbstractInferencingTest . checkType ( unit , task . start , task . end , task . expectedResultType , task . expectedDeclaringType , assumeNoUnknowns , false ) ; if ( res != null ) { sb . append ( "<STR_LIT>" + res ) ; } assumeNoUnknowns = false ; } if ( sb . length ( ) > <NUM_LIT:0> ) { Assert . fail ( sb . toString ( ) ) ; } } finally { unit . discardWorkingCopy ( ) ; } assertTrue ( "<STR_LIT>" , doneSomething ) ; } public void perform ( GroovyCompilationUnit unit ) throws Exception { perform ( unit , false ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . PointcutVerificationException ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AbstractModifierPointcut . FinalPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AbstractModifierPointcut . PrivatePointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AbstractModifierPointcut . PublicPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AbstractModifierPointcut . StaticPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . AndPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . BindPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . CurrentTypePointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . EnclosingClassPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . EnclosingFieldPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . EnclosingMethodPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . EnclosingScriptPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . FileExtensionPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . FindAnnotationPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . FindFieldPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . FindPropertyPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . NamePointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . OrPointcut ; import org . codehaus . groovy . eclipse . dsl . pointcuts . impl . ProjectNaturePointcut ; import org . eclipse . jdt . core . groovy . tests . search . AbstractGroovySearchTest ; public class PointcutCreationTests extends AbstractGroovySearchTest { public static Test suite ( ) { return new TestSuite ( PointcutCreationTests . class ) ; } public PointcutCreationTests ( String name ) { super ( name ) ; } public void testPointcutCreation1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof CurrentTypePointcut ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , pc . getFirstArgument ( ) ) ; } public void testPointcutCreation2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof CurrentTypePointcut ) ; assertValidPointcut ( pc ) ; Object firstArgument = pc . getFirstArgument ( ) ; assertTrue ( firstArgument instanceof FindFieldPointcut ) ; pc = ( IPointcut ) firstArgument ; firstArgument = pc . getFirstArgument ( ) ; assertTrue ( firstArgument instanceof FindAnnotationPointcut ) ; pc = ( IPointcut ) firstArgument ; } public void testValidPointcutCreation1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof CurrentTypePointcut ) ; assertValidPointcut ( pc ) ; } public void testInvalidPointcutCreation1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof FileExtensionPointcut ) ; assertInvalidPointcut ( "<STR_LIT>" , pc ) ; } public void testValidPointcutCreation2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof CurrentTypePointcut ) ; assertValidPointcut ( pc ) ; } public void testInvalidPointcutCreation2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , pc instanceof CurrentTypePointcut ) ; assertInvalidPointcut ( "<STR_LIT>" , pc ) ; } public void testAnd1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; } public void testAnd2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testAnd3 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testAnd4 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testValidAnd1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; } public void testInvalidAnd1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getClass ( ) ) ; assertInvalidPointcut ( "<STR_LIT>" , pc ) ; } public void testOr1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; } public void testOr2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testOr3 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testOr4 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; pc = pc . normalize ( ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:2> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:2> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , pc . getArgumentValues ( ) . length ) ; } public void testOrAnd1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( CurrentTypePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( AndPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( CurrentTypePointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( CurrentTypePointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; } public void testAndOr1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , OrPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( AndPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( CurrentTypePointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( CurrentTypePointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; assertEquals ( CurrentTypePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; } public void testEnclosing1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , EnclosingClassPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; pc = ( IPointcut ) pc . getFirstArgument ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( FindPropertyPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( StaticPointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) . length ) ; assertEquals ( NamePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT:yes>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) ; } public void testEnclosing2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , EnclosingFieldPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; pc = ( IPointcut ) pc . getFirstArgument ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( FindPropertyPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( PublicPointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) . length ) ; assertEquals ( NamePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT:yes>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) ; } public void testEnclosing3 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , EnclosingMethodPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; pc = ( IPointcut ) pc . getFirstArgument ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( FindPropertyPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( PrivatePointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) . length ) ; assertEquals ( NamePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT:yes>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) ; } public void testEnclosing4 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , EnclosingScriptPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , AndPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; pc = ( IPointcut ) pc . getFirstArgument ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , pc . getArgumentValues ( ) . length ) ; assertEquals ( FindPropertyPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( FinalPointcut . class , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , ( ( IPointcut ) ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getArgumentValues ( ) . length ) ; assertEquals ( NamePointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT:yes>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getArgumentValues ( ) [ <NUM_LIT:0> ] ) ; } public void testBindAndFileExtension ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( BindPointcut . class , pc . getClass ( ) ) ; assertEquals ( FileExtensionPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT:b>" , pc . getFirstArgumentName ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; } public void testBindAndNature ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( BindPointcut . class , pc . getClass ( ) ) ; assertEquals ( ProjectNaturePointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertEquals ( "<STR_LIT:b>" , pc . getFirstArgumentName ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; } public void testBindAndFileExtensionInvalid ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( BindPointcut . class , pc . getClass ( ) ) ; assertEquals ( FileExtensionPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertInvalidPointcut ( "<STR_LIT>" , pc ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; } public void testVariable1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( BindPointcut . class , pc . getClass ( ) ) ; assertEquals ( "<STR_LIT:b>" , pc . getFirstArgumentName ( ) ) ; assertEquals ( FileExtensionPointcut . class , pc . getFirstArgument ( ) . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getFirstArgument ( ) ) . getFirstArgument ( ) ) ; } public void testVariable2 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" ) ; assertEquals ( AndPointcut . class , pc . getClass ( ) ) ; assertValidPointcut ( pc ) ; assertEquals ( FileExtensionPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:0> ] . getClass ( ) ) ; assertEquals ( FileExtensionPointcut . class , pc . getArgumentValues ( ) [ <NUM_LIT:1> ] . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:0> ] ) . getFirstArgument ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IPointcut ) pc . getArgumentValues ( ) [ <NUM_LIT:1> ] ) . getFirstArgument ( ) ) ; } public void testCustomPointcut1 ( ) throws Exception { IPointcut pc = new PointcutScriptExecutor ( ) . createPointcut ( "<STR_LIT>" + "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , pc . getClass ( ) . getName ( ) ) ; } protected void assertValidPointcut ( IPointcut pc ) throws PointcutVerificationException { try { pc . verify ( ) ; } catch ( PointcutVerificationException e ) { fail ( "<STR_LIT>" + e . getPointcutMessage ( ) ) ; } } protected void assertInvalidPointcut ( String expectedMessage , IPointcut pc ) { try { pc . verify ( ) ; fail ( "<STR_LIT>" + pc ) ; } catch ( PointcutVerificationException e ) { if ( ! e . getMessage ( ) . equals ( expectedMessage ) ) { fail ( "<STR_LIT>" + expectedMessage + "<STR_LIT>" + e . getPointcutMessage ( ) ) ; } } } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . io . IOException ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; public class MetaDSLInferencingTests extends AbstractDSLInferencingTest { public MetaDSLInferencingTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new TestSuite ( MetaDSLInferencingTests . class ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; createMetaDSL ( ) ; } public void testSimpleDSL ( ) throws Exception { assertType ( "<STR_LIT:foo>" , "<STR_LIT>" , true ) ; createDsls ( "<STR_LIT>" ) ; assertType ( "<STR_LIT:foo>" , "<STR_LIT>" , true ) ; deleteDslFile ( <NUM_LIT:0> ) ; assertType ( "<STR_LIT:foo>" , "<STR_LIT>" , true ) ; } public void testMetaDSL1 ( ) throws Exception { assertType ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testMetaDSL2 ( ) throws Exception { assertType ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testMetaDSL3 ( ) throws Exception { assertType ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testMetaDSL4 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; assertDSLType ( contents , "<STR_LIT>" ) ; assertDSLType ( contents , "<STR_LIT>" ) ; assertDSLType ( contents , "<STR_LIT>" ) ; assertDSLType ( contents , "<STR_LIT>" ) ; assertDSLType ( contents , "<STR_LIT>" ) ; } public void testMetaDSL5 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; } public void testMetaDSL6 ( ) throws Exception { defaultFileExtension = "<STR_LIT>" ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; } public void testMetaDSL7 ( ) throws Exception { defaultFileExtension = "<STR_LIT>" ; String contents = "<STR_LIT>" + "<STR_LIT:}>" ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; assertUnknownDSLType ( contents , "<STR_LIT>" ) ; } public void testBindings ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String name = "<STR_LIT:b>" ; assertDeclaringType ( contents , contents . lastIndexOf ( name ) , contents . lastIndexOf ( name ) + name . length ( ) , "<STR_LIT>" , true ) ; } private void createMetaDSL ( ) throws IOException { if ( GroovyUtils . GROOVY_LEVEL > <NUM_LIT> ) { createJavaUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; } else { createJavaUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; } defaultFileExtension = "<STR_LIT>" ; createUnit ( "<STR_LIT>" , GroovyDSLDTestsActivator . getDefault ( ) . getTestResourceContents ( "<STR_LIT>" ) ) ; env . fullBuild ( ) ; expectingNoProblems ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import junit . framework . Test ; import junit . framework . TestSuite ; public class SuggestionInferencingTests extends AbstractDSLInferencingTest { public SuggestionInferencingTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new TestSuite ( SuggestionInferencingTests . class ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; } public void testDoNothing ( ) throws Exception { } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllDSLTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( AllDSLTests . class . getPackage ( ) . getName ( ) ) ; suite . addTest ( PointcutCreationTests . suite ( ) ) ; suite . addTest ( PointcutEvaluationTests . suite ( ) ) ; suite . addTest ( MetaDSLInferencingTests . suite ( ) ) ; suite . addTest ( DSLInferencingTests . suite ( ) ) ; suite . addTest ( BuiltInDSLInferencingTests . suite ( ) ) ; suite . addTest ( DSLStoreTests . suite ( ) ) ; suite . addTestSuite ( StringObjectVectorTests . class ) ; suite . addTestSuite ( DSLContentAssistTests . class ) ; suite . addTestSuite ( DSLNamedArgContentAssistTests . class ) ; suite . addTestSuite ( SuggestionInferencingTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import org . codehaus . groovy . eclipse . codeassist . tests . CompletionTestCase ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . dsl . GroovyDSLCoreActivator ; import org . codehaus . groovy . eclipse . dsl . RefreshDSLDJob ; import org . eclipse . core . resources . IProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class DSLNamedArgContentAssistTests extends CompletionTestCase { public DSLNamedArgContentAssistTests ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; createGenericProject ( ) ; IProject project = env . getProject ( "<STR_LIT>" ) ; GroovyRuntime . addLibraryToClasspath ( JavaCore . create ( project ) , GroovyDSLCoreActivator . CLASSPATH_CONTAINER_ID , false ) ; env . fullBuild ( ) ; new RefreshDSLDJob ( project ) . run ( null ) ; GroovyDSLCoreActivator . getDefault ( ) . getContainerListener ( ) . ignoreProject ( project ) ; } public void testNamedArgs1 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNoNamedArgs1 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs2 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs3 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:U+002C>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs4 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:U+002C>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs5 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:U+002C>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNoNamedArgs6 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:U+0020>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testOptionalArgs1 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testOptionalArgs2 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testOptionalArgs3 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs7 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs8 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT:U+002C>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testParamGuessing1 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing3 ( ) throws Exception { createDSL ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } private static final String closuredsld = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private static final String closureContents = "<STR_LIT>" ; public void testClostureOp1 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT:test1>" ) ; } public void testClostureOp2 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp3 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp4 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp5 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp6 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp7 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp8 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp9 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } public void testClostureOp0 ( ) throws Exception { createDSL ( closuredsld ) ; checkProposalApplicationNonType ( closureContents , closureContents + "<STR_LIT>" , closureContents . length ( ) , "<STR_LIT>" ) ; } private void createDSL ( String dsldContents ) throws Exception { defaultFileExtension = "<STR_LIT>" ; create ( "<STR_LIT>" , dsldContents ) ; defaultFileExtension = "<STR_LIT>" ; env . fullBuild ( ) ; expectingNoProblems ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . net . MalformedURLException ; import java . net . URL ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class GroovyDSLDTestsActivator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static GroovyDSLDTestsActivator plugin ; public GroovyDSLDTestsActivator ( ) { } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; plugin = this ; } public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static GroovyDSLDTestsActivator getDefault ( ) { return plugin ; } public InputStream getTestResourceStream ( String fileName ) throws IOException { return getTestResourceURL ( fileName ) . openStream ( ) ; } public String getTestResourceContents ( String fileName ) throws IOException { InputStream stream = getTestResourceStream ( fileName ) ; return getContents ( stream ) ; } public URL getTestResourceURL ( String fileName ) throws MalformedURLException { IPath path = new Path ( "<STR_LIT>" ) . append ( fileName ) ; return new URL ( getBundle ( ) . getEntry ( "<STR_LIT:/>" ) , path . toString ( ) ) ; } public String getContents ( InputStream in ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; StringBuffer sb = new StringBuffer ( <NUM_LIT> ) ; try { int read = <NUM_LIT:0> ; while ( ( read = br . read ( ) ) != - <NUM_LIT:1> ) sb . append ( ( char ) read ) ; } finally { br . close ( ) ; } return sb . toString ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . dsl . tests ; import groovy . lang . Binding ; import groovy . lang . Closure ; import groovy . lang . GroovyCodeSource ; import groovy . lang . GroovyShell ; import groovy . lang . Script ; import java . util . Arrays ; import java . util . Collection ; import java . util . Iterator ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . eclipse . GroovyLogManager ; import org . codehaus . groovy . eclipse . TraceCategory ; import org . codehaus . groovy . eclipse . dsl . pointcuts . IPointcut ; import org . codehaus . groovy . eclipse . dsl . script . PointcutClosure ; import org . codehaus . groovy . eclipse . dsl . script . PointcutFactory ; import org . eclipse . core . resources . ResourcesPlugin ; public class PointcutScriptExecutor { private final class RegisterClosure extends Closure { private static final long serialVersionUID = <NUM_LIT> ; public RegisterClosure ( Object owner ) { super ( owner ) ; } @ Override public Object call ( Object arguments ) { return tryRegister ( arguments ) ; } @ Override public Object call ( Object ... arguments ) { return tryRegister ( arguments ) ; } } private final class PoincutBinding extends Binding { @ Override public Object invokeMethod ( String name , Object args ) { if ( name . equals ( "<STR_LIT>" ) ) { return tryRegister ( args ) ; } IPointcut pc = factory . createPointcut ( name ) ; if ( pc != null ) { configure ( pc , args ) ; return pc ; } else { return super . invokeMethod ( name , args ) ; } } @ Override public Object getVariable ( String name ) { if ( name . equals ( "<STR_LIT>" ) ) { return new RegisterClosure ( this ) ; } IPointcut pc = factory . createPointcut ( name ) ; if ( pc != null ) { return new PointcutClosure ( this , pc ) ; } else { return super . getVariable ( name ) ; } } private void configure ( IPointcut pointcut , Object arguments ) { if ( arguments instanceof Map < ? , ? > ) { for ( Entry < Object , Object > entry : ( ( Map < Object , Object > ) arguments ) . entrySet ( ) ) { Object key = entry . getKey ( ) ; pointcut . addArgument ( key == null ? null : key . toString ( ) , entry . getValue ( ) ) ; } } else if ( arguments instanceof Collection < ? > ) { for ( Object arg : ( Collection < Object > ) arguments ) { pointcut . addArgument ( arg ) ; } } else if ( arguments instanceof Object [ ] ) { for ( Object arg : ( Object [ ] ) arguments ) { pointcut . addArgument ( arg ) ; } } else if ( arguments != null ) { pointcut . addArgument ( arguments ) ; } } } private final static String DEFAULT_SCRIPT_NAME = "<STR_LIT>" ; private final PointcutFactory factory = new PointcutFactory ( ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( "<STR_LIT>" ) . getFile ( "<STR_LIT>" ) , ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( "<STR_LIT>" ) ) ; public IPointcut createPointcut ( String expression ) { GroovyCodeSource source = new GroovyCodeSource ( expression , DEFAULT_SCRIPT_NAME , GroovyShell . DEFAULT_CODE_BASE ) ; Script script = new GroovyShell ( this . getClass ( ) . getClassLoader ( ) ) . parse ( source ) ; script . setBinding ( new PoincutBinding ( ) ) ; Object res = script . run ( ) ; return res instanceof IPointcut ? ( IPointcut ) res : null ; } @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) protected Object tryRegister ( Object args ) { Object [ ] nameAndClass = extractArgsForRegister ( args ) ; if ( nameAndClass != null ) { factory . registerLocalPointcut ( ( String ) nameAndClass [ <NUM_LIT:0> ] , ( Closure ) nameAndClass [ <NUM_LIT:1> ] ) ; return nameAndClass [ <NUM_LIT:1> ] ; } else { GroovyLogManager . manager . log ( TraceCategory . DSL , "<STR_LIT>" + ( args instanceof Object [ ] ? Arrays . toString ( ( Object [ ] ) args ) : args ) ) ; return null ; } } protected Object [ ] extractArgsForRegister ( Object args ) { if ( args instanceof Object [ ] ) { Object [ ] arr = ( Object [ ] ) args ; if ( arr . length == <NUM_LIT:2> && arr [ <NUM_LIT:0> ] instanceof String && arr [ <NUM_LIT:1> ] instanceof Closure ) { return arr ; } } else if ( args instanceof Collection < ? > ) { Collection < Object > coll = ( Collection < Object > ) args ; Object [ ] arr = new Object [ <NUM_LIT:2> ] ; Iterator < Object > iter = coll . iterator ( ) ; if ( iter . hasNext ( ) && ( arr [ <NUM_LIT:0> ] = iter . next ( ) ) instanceof String && iter . hasNext ( ) && ( arr [ <NUM_LIT:1> ] = iter . next ( ) ) instanceof Closure && ! iter . hasNext ( ) ) { return arr ; } } else if ( args instanceof Map < ? , ? > ) { return extractArgsForRegister ( ( ( Map < Object , Object > ) args ) . values ( ) ) ; } return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( "<STR_LIT>" + AllTests . class . getPackage ( ) . getName ( ) ) ; suite . addTestSuite ( TokenStreamTests . class ) ; suite . addTestSuite ( ExpressionFinderTests . class ) ; suite . addTestSuite ( ArrayUtilsTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . core . impl . StringSourceBuffer ; public class ExpressionFinderTests extends TestCase { @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; } private void doFind ( String test ) { ExpressionFinder finder = new ExpressionFinder ( ) ; StringSourceBuffer sb = new StringSourceBuffer ( test ) ; try { assertEquals ( test , finder . findForCompletions ( sb , test . length ( ) - <NUM_LIT:1> ) ) ; } catch ( ParseException e ) { fail ( e . getMessage ( ) ) ; } } private void doFind ( String test , String expected , int offset ) { ExpressionFinder finder = new ExpressionFinder ( ) ; StringSourceBuffer sb = new StringSourceBuffer ( test ) ; try { assertEquals ( expected , finder . findForCompletions ( sb , offset ) ) ; } catch ( ParseException e ) { fail ( e . getMessage ( ) ) ; } } void doSplit ( String test , String expr , String prefix ) { ExpressionFinder finder = new ExpressionFinder ( ) ; StringSourceBuffer sb = new StringSourceBuffer ( test ) ; String foundExpr ; try { foundExpr = finder . findForCompletions ( sb , test . length ( ) - <NUM_LIT:1> ) ; String [ ] split = finder . splitForCompletion ( foundExpr ) ; assertEquals ( expr , split [ <NUM_LIT:0> ] ) ; assertEquals ( prefix , split [ <NUM_LIT:1> ] ) ; } catch ( ParseException e ) { fail ( e . getMessage ( ) ) ; } } void failSplit ( String test ) { ExpressionFinder finder = new ExpressionFinder ( ) ; String [ ] split = finder . splitForCompletion ( test ) ; assertEquals ( <NUM_LIT:2> , split . length ) ; assertEquals ( "<STR_LIT>" , split [ <NUM_LIT:0> ] ) ; assertEquals ( null , split [ <NUM_LIT:1> ] ) ; } public void testSimple1 ( ) { doFind ( "<STR_LIT:hello>" ) ; } public void testSimple2 ( ) { doFind ( "<STR_LIT>" ) ; } public void testSimple3 ( ) { doFind ( "<STR_LIT>" ) ; } public void testMultiple1 ( ) { doFind ( "<STR_LIT>" ) ; } public void testMultiple2 ( ) { doFind ( "<STR_LIT>" ) ; } public void testMultiple3 ( ) { doFind ( "<STR_LIT>" ) ; } public void testDotted1 ( ) { doFind ( "<STR_LIT>" ) ; } public void testDotted2 ( ) { doFind ( "<STR_LIT>" ) ; } public void testComplex1 ( ) { doFind ( "<STR_LIT>" ) ; } public void testComplex2 ( ) { doFind ( "<STR_LIT>" ) ; } public void testComplex3 ( ) { doFind ( "<STR_LIT>" ) ; } public void testComplex5 ( ) { doFind ( "<STR_LIT>" ) ; } public void testComplex6 ( ) { doFind ( "<STR_LIT>" ) ; } public void testInString1 ( ) { doFind ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testInString2 ( ) { doFind ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testInString3 ( ) { doFind ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testSplit1 ( ) { doSplit ( "<STR_LIT:hello>" , "<STR_LIT:hello>" , null ) ; } public void testSplit2 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT:hello>" , "<STR_LIT>" ) ; } public void testSplit3 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT:hello>" , "<STR_LIT:name>" ) ; } public void testSplit4 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:name>" ) ; } public void testSplit5 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit6 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit7 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:class>" ) ; } public void testSplit8 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT:[]>" , "<STR_LIT>" ) ; } public void testSplit9 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT:[]>" , "<STR_LIT>" ) ; } public void testSplit10 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit11 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit12 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit13 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit14 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSplit15 ( ) { doSplit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testFailSplit1 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit2 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit3 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit4 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit5 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit6 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit7 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit8 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testFailSplit9 ( ) { failSplit ( "<STR_LIT>" ) ; } public void testParenEOF ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testBraceEOF ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testBraceEOFNoSpace ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testWithLineComment ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testWithLineComment2 ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testWithLineComment3 ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testWithBlockComment ( ) { String test = "<STR_LIT>" ; doFind ( test , "<STR_LIT>" , test . length ( ) - <NUM_LIT:1> ) ; } public void testNewExpression ( ) { doFind ( "<STR_LIT>" ) ; doFind ( "<STR_LIT>" ) ; } public void testProblem ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String test = "<STR_LIT:.>" ; StringSourceBuffer sb = new StringSourceBuffer ( test ) ; assertNull ( finder . findForCompletions ( sb , test . length ( ) - <NUM_LIT:1> ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . core . impl . StringSourceBuffer ; public class TokenStreamTests extends TestCase { static int EOF = Token . EOF ; static int IDENT = Token . IDENT ; static int DOT = Token . DOT ; static int SEMI = Token . SEMI ; static int QUOTED_STRING = Token . QUOTED_STRING ; static int PAREN_BLOCK = Token . PAREN_BLOCK ; static int BRACE_BLOCK = Token . BRACE_BLOCK ; static int BRACK_BLOCK = Token . BRACK_BLOCK ; static int LINE_COMMENT = Token . LINE_COMMENT ; static int BLOCK_COMMENT = Token . BLOCK_COMMENT ; static int LINE_BREAK = Token . LINE_BREAK ; static int SAFE_DEREF = Token . SAFE_DEREF ; static int SPREAD = Token . SPREAD ; @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; } void doTest ( String sample , int off , int [ ] expected ) throws TokenStreamException { int offset = off ; if ( offset == - <NUM_LIT:1> ) { offset = sample . length ( ) - <NUM_LIT:1> ; } StringSourceBuffer sb = new StringSourceBuffer ( sample ) ; TokenStream stream = new TokenStream ( sb , offset ) ; List < Token > list = new ArrayList < Token > ( ) ; Token token = null ; while ( ( token = stream . next ( ) ) . type != Token . EOF ) { list . add ( token ) ; } list . add ( token ) ; for ( int i = <NUM_LIT:0> ; i < expected . length ; ++ i ) { assertEquals ( new Token ( expected [ i ] , - <NUM_LIT:1> , - <NUM_LIT:1> , null ) , list . get ( i ) ) ; } } private void doTestOffsets ( String sample , int [ ] offsetPairs ) { int offset = sample . length ( ) - <NUM_LIT:1> ; StringSourceBuffer sb = new StringSourceBuffer ( sample ) ; TokenStream stream = new TokenStream ( sb , offset ) ; List < Token > list = new ArrayList < Token > ( ) ; Token token = null ; try { while ( ( token = stream . next ( ) ) . type != Token . EOF ) { list . add ( token ) ; } } catch ( TokenStreamException e ) { fail ( e . getMessage ( ) ) ; } list . add ( token ) ; for ( int i = <NUM_LIT:0> ; i < offsetPairs . length ; i += <NUM_LIT:2> ) { assertEquals ( offsetPairs [ i ] , ( ( Token ) list . get ( i > > <NUM_LIT:1> ) ) . startOffset ) ; assertEquals ( offsetPairs [ i + <NUM_LIT:1> ] , ( ( Token ) list . get ( i > > <NUM_LIT:1> ) ) . endOffset ) ; } } public void testWhite1 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , EOF } ) ; } public void testWhite2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , EOF } ) ; } public void testWhite3 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { LINE_BREAK , IDENT , LINE_BREAK , EOF } ) ; } public void testWhite4 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { LINE_BREAK , IDENT , LINE_BREAK , EOF } ) ; } public void testWhite5 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { LINE_BREAK , IDENT , LINE_BREAK , EOF } ) ; } public void testSemi ( ) throws Exception { doTest ( "<STR_LIT:;>" , - <NUM_LIT:1> , new int [ ] { SEMI , EOF } ) ; } public void testSimple1 ( ) throws Exception { doTest ( "<STR_LIT:hello>" , - <NUM_LIT:1> , new int [ ] { IDENT , EOF } ) ; } public void testSimple2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , IDENT , EOF } ) ; } public void testSimple3 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , IDENT , EOF } ) ; } public void testSimple4 ( ) throws Exception { doTest ( "<STR_LIT>" , <NUM_LIT:2> , new int [ ] { DOT , IDENT , EOF } ) ; } public void testComplex1 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { BRACE_BLOCK , IDENT , DOT , IDENT , EOF } ) ; } public void testComplex2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { BRACE_BLOCK , IDENT , DOT , IDENT , EOF } ) ; } public void testComplex3 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { DOT , PAREN_BLOCK , IDENT , DOT , IDENT , EOF } ) ; } public void testComplex4 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , BRACK_BLOCK , IDENT , EOF } ) ; } public void testComplex5 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { DOT , BRACE_BLOCK , IDENT , DOT , BRACK_BLOCK , EOF } ) ; } public void testComplex6 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { DOT , BRACK_BLOCK , IDENT , EOF } ) ; } public void testOffsets1 ( ) throws Exception { doTestOffsets ( "<STR_LIT>" , new int [ ] { <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:2> } ) ; } public void testOffsets2 ( ) throws Exception { doTestOffsets ( "<STR_LIT>" , new int [ ] { <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:4> } ) ; } public void testQuote1 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , EOF } ) ; } public void testQuote2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , EOF } ) ; } public void testQuote3 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , EOF } ) ; } public void testQuote4 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , EOF } ) ; } public void testQuote5 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , LINE_BREAK , QUOTED_STRING , EOF } ) ; } public void testLineComment1 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , LINE_BREAK , LINE_COMMENT , EOF } ) ; } public void testLineComment2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { DOT , IDENT , LINE_BREAK , LINE_COMMENT , EOF } ) ; } public void testLineComment3 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { DOT , IDENT , LINE_BREAK , LINE_COMMENT , LINE_BREAK , IDENT , EOF } ) ; } public void testBlockComment1 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , LINE_BREAK , BLOCK_COMMENT , EOF } ) ; } public void testBlockComment2 ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { QUOTED_STRING , LINE_BREAK , BLOCK_COMMENT , EOF } ) ; } public void testSafeDeref ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , SAFE_DEREF , IDENT , EOF } ) ; } public void testSpread ( ) throws Exception { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , SPREAD , IDENT , EOF } ) ; } public void testError1 ( ) throws Exception { StringSourceBuffer sb = new StringSourceBuffer ( "<STR_LIT>" ) ; TokenStream stream = new TokenStream ( sb , "<STR_LIT>" . length ( ) - <NUM_LIT:1> ) ; try { stream . next ( ) ; fail ( "<STR_LIT>" ) ; } catch ( TokenStreamException e ) { } } public void testPeek ( ) throws TokenStreamException { StringSourceBuffer sb = new StringSourceBuffer ( "<STR_LIT:hello>" ) ; TokenStream stream = new TokenStream ( sb , "<STR_LIT:hello>" . length ( ) - <NUM_LIT:1> ) ; assertTrue ( stream . peek ( ) . type == Token . IDENT ) ; } public void testLast ( ) throws TokenStreamException { StringSourceBuffer sb = new StringSourceBuffer ( "<STR_LIT>" ) ; TokenStream stream = new TokenStream ( sb , "<STR_LIT>" . length ( ) - <NUM_LIT:1> ) ; Token next = stream . next ( ) ; assertTrue ( stream . last ( ) == next ) ; assertTrue ( stream . peek ( ) . type == Token . IDENT ) ; assertTrue ( stream . last ( ) == next ) ; } public void testArray1 ( ) throws TokenStreamException { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , BRACK_BLOCK , IDENT , EOF } ) ; } public void testArray2 ( ) throws TokenStreamException { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , BRACK_BLOCK , BRACK_BLOCK , IDENT , EOF } ) ; } public void testArray3 ( ) throws TokenStreamException { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , BRACK_BLOCK , BRACK_BLOCK , IDENT , EOF } ) ; } public void testArray4 ( ) throws TokenStreamException { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { IDENT , DOT , BRACK_BLOCK , BRACE_BLOCK , IDENT , EOF } ) ; } public void testArray5 ( ) throws TokenStreamException { doTest ( "<STR_LIT>" , - <NUM_LIT:1> , new int [ ] { BRACE_BLOCK , BRACK_BLOCK , IDENT , EOF } ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import junit . framework . TestCase ; public class ArrayUtilsTests extends TestCase { public void testArrayRemove1 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . remove ( new String [ ] { "<STR_LIT>" } , <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:0> , res . length ) ; } public void testArrayRemove2 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . remove ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayRemove3 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . remove ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayRemove4 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . remove ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" } , <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:2> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:1> ] ) ; } public void testArrayRemoveElement1 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { } , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:0> , res . length ) ; } public void testArrayRemoveElement2 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayRemoveElement3 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT:a>" ) ; assertEquals ( <NUM_LIT:0> , res . length ) ; } public void testArrayRemoveElement4 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , "<STR_LIT:a>" ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayRemoveElement5 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , "<STR_LIT:b>" ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayRemoveElement6 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" } , "<STR_LIT:b>" ) ; assertEquals ( <NUM_LIT:2> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:1> ] ) ; } public void testArrayRemoveElement7 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" } , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:2> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:1> ] ) ; } public void testArrayRemoveElement8 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . removeElement ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" } , "<STR_LIT:a>" ) ; assertEquals ( <NUM_LIT:2> , res . length ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:1> ] ) ; } public void testArrayAdd1 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ <NUM_LIT:0> ] , "<STR_LIT:a>" ) ; assertEquals ( <NUM_LIT:1> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; } public void testArrayAdd2 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT:b>" ) ; assertEquals ( <NUM_LIT:2> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:1> ] ) ; } public void testArrayAdd3 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:3> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:2> ] ) ; } public void testArrayAdd4 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , <NUM_LIT:0> , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:3> , res . length ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:2> ] ) ; } public void testArrayAdd5 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , <NUM_LIT:1> , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:3> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:2> ] ) ; } public void testArrayAdd6 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , <NUM_LIT:2> , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:3> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:2> ] ) ; } public void testArrayAdd7 ( ) throws Exception { String [ ] res = ( String [ ] ) ArrayUtils . add ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:d>" } , <NUM_LIT:2> , "<STR_LIT:c>" ) ; assertEquals ( <NUM_LIT:4> , res . length ) ; assertEquals ( "<STR_LIT:a>" , res [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT:b>" , res [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT:c>" , res [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT:d>" , res [ <NUM_LIT:3> ] ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . impl ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( "<STR_LIT>" + AllTests . class . getPackage ( ) . getName ( ) ) ; suite . addTestSuite ( StringSourceBufferTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . impl ; import junit . framework . TestCase ; public class StringSourceBufferTests extends TestCase { static String testString = "<STR_LIT>" ; static StringSourceBuffer buffer ; @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; buffer = new StringSourceBuffer ( testString ) ; } public void testLength ( ) { assertEquals ( testString . length ( ) , buffer . length ( ) ) ; } public void testGetChar ( ) { assertEquals ( '<CHAR_LIT>' , buffer . charAt ( <NUM_LIT:0> ) ) ; assertEquals ( '<CHAR_LIT>' , buffer . charAt ( testString . length ( ) - <NUM_LIT:1> ) ) ; } public void testGetText ( ) { assertEquals ( "<STR_LIT:Hello>" , buffer . subSequence ( <NUM_LIT:0> , "<STR_LIT:Hello>" . length ( ) ) ) ; int start = "<STR_LIT>" . length ( ) ; int end = start + "<STR_LIT>" . length ( ) ; assertEquals ( "<STR_LIT>" , buffer . subSequence ( start , end ) ) ; } public void testToAndFrom ( ) { int [ ] lineCol = buffer . toLineColumn ( <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:0> , buffer . toOffset ( lineCol [ <NUM_LIT:0> ] , lineCol [ <NUM_LIT:1> ] ) ) ; } public void testToLineColumn ( ) { int [ ] lineCol = buffer . toLineColumn ( <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:1> , lineCol [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:1> , lineCol [ <NUM_LIT:1> ] ) ; lineCol = buffer . toLineColumn ( "<STR_LIT>" . length ( ) ) ; assertEquals ( <NUM_LIT:2> , lineCol [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:1> , lineCol [ <NUM_LIT:1> ] ) ; lineCol = buffer . toLineColumn ( testString . length ( ) - <NUM_LIT:1> ) ; assertEquals ( <NUM_LIT:3> , lineCol [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" . length ( ) , lineCol [ <NUM_LIT:1> ] ) ; } public void testToOffset ( ) { assertEquals ( <NUM_LIT:0> , buffer . toOffset ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" . length ( ) , buffer . toOffset ( <NUM_LIT:2> , <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" . length ( ) , buffer . toOffset ( <NUM_LIT:3> , <NUM_LIT:1> ) ) ; assertEquals ( testString . length ( ) - <NUM_LIT:1> , buffer . toOffset ( <NUM_LIT:3> , "<STR_LIT>" . length ( ) ) ) ; } public void testWhite ( ) { new StringSourceBuffer ( "<STR_LIT>" ) ; new StringSourceBuffer ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . search ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . search . SearchMatch ; public class SyntheticMemberSearchTests extends EclipseTestCase { private IType gType ; class TestSearchRequestor implements ISearchRequestor { List < SearchMatch > matches = new ArrayList < SearchMatch > ( ) ; public void acceptMatch ( SearchMatch match ) { matches . add ( match ) ; } } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyNature ( testProject . getProject ( ) ) ; GroovyRuntime . addGroovyClasspathContainer ( testProject . getJavaProject ( ) ) ; gType = testProject . createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) . getType ( "<STR_LIT>" ) ; } public void testSearchInGroovy1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:3> , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInGroovy2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInGroovy3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInGroovy4 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInJava1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:3> , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInJava2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInJava3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInJava4 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; List < SearchMatch > matches = performSearch ( "<STR_LIT>" ) ; assertNumMatch ( <NUM_LIT:1> , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertNoMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; assertMatch ( "<STR_LIT>" , "<STR_LIT>" , contents , matches ) ; } public void testSearchInJava5 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; IType type = testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , contents ) . getType ( "<STR_LIT>" ) ; IField toSearch = type . getField ( "<STR_LIT>" ) ; SyntheticAccessorSearchRequestor synthRequestor = new SyntheticAccessorSearchRequestor ( ) ; TestSearchRequestor requestor = new TestSearchRequestor ( ) ; synthRequestor . findSyntheticMatches ( toSearch , requestor , null ) ; List < SearchMatch > matches = requestor . matches ; assertNumMatch ( <NUM_LIT:0> , matches ) ; } private IJavaElement findSearchTarget ( String name ) throws JavaModelException { for ( IJavaElement child : gType . getChildren ( ) ) { if ( child . getElementName ( ) . equals ( name ) ) { return child ; } } fail ( "<STR_LIT>" + name ) ; return null ; } private List < SearchMatch > performSearch ( String searchName ) throws CoreException { IJavaElement toSearch = findSearchTarget ( searchName ) ; SyntheticAccessorSearchRequestor synthRequestor = new SyntheticAccessorSearchRequestor ( ) ; TestSearchRequestor requestor = new TestSearchRequestor ( ) ; synthRequestor . findSyntheticMatches ( toSearch , requestor , null ) ; return requestor . matches ; } private String printMatches ( List < SearchMatch > matches ) { StringBuffer sb = new StringBuffer ( ) ; for ( Iterator < SearchMatch > matchIter = matches . iterator ( ) ; matchIter . hasNext ( ) ; ) { SearchMatch match = ( SearchMatch ) matchIter . next ( ) ; sb . append ( "<STR_LIT>" + match ) ; } return sb . toString ( ) ; } private void assertMatch ( String enclosingName , String matchName , String contents , List < SearchMatch > matches ) { int matchStart = <NUM_LIT:0> ; int matchIndex = <NUM_LIT:0> ; boolean matchFound = false ; for ( SearchMatch match : matches ) { if ( ( ( IJavaElement ) match . getElement ( ) ) . getElementName ( ) . equals ( enclosingName ) && contents . indexOf ( matchName , matchStart ) == match . getOffset ( ) && matchName . length ( ) == match . getLength ( ) ) { matchFound = true ; break ; } matchIndex ++ ; } if ( ! matchFound ) { fail ( "<STR_LIT>" + matchName + "<STR_LIT>" + printMatches ( matches ) ) ; } SearchMatch match = matches . remove ( matchIndex ) ; assertTrue ( "<STR_LIT>" , ( ( IJavaElement ) match . getElement ( ) ) . exists ( ) ) ; } private void assertNumMatch ( int expected , List < SearchMatch > matches ) { assertEquals ( "<STR_LIT>" + printMatches ( matches ) , expected , matches . size ( ) ) ; } private void assertNoMatch ( String enclosingName , String matchName , String contents , List < SearchMatch > matches ) { boolean matchFound = false ; for ( SearchMatch match : matches ) { if ( ( ( IJavaElement ) match . getElement ( ) ) . getElementName ( ) . equals ( enclosingName ) && contents . indexOf ( matchName ) == match . getOffset ( ) && matchName . length ( ) == match . getLength ( ) ) { matchFound = true ; break ; } } if ( matchFound ) { fail ( "<STR_LIT>" + matchName + "<STR_LIT>" + printMatches ( matches ) ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . Bundle ; import org . osgi . framework . BundleContext ; public class CoreTestsActivator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static CoreTestsActivator plugin ; public CoreTestsActivator ( ) { plugin = this ; } @ Override public void start ( BundleContext context ) throws Exception { super . start ( context ) ; } @ Override public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static CoreTestsActivator getDefault ( ) { return plugin ; } public static Bundle bundle ( ) { return getDefault ( ) . getBundle ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; public class CompilerSwitchTests extends EclipseTestCase { public void testname ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . core . search . SyntheticMemberSearchTests ; public class AllCoreTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( AllCoreTests . class . getPackage ( ) . getName ( ) ) ; suite . addTestSuite ( ClasspathContainerTest . class ) ; suite . addTest ( org . codehaus . groovy . eclipse . core . compiler . AllTests . suite ( ) ) ; suite . addTest ( org . codehaus . groovy . eclipse . core . impl . AllTests . suite ( ) ) ; suite . addTest ( org . codehaus . groovy . eclipse . core . util . AllTests . suite ( ) ) ; suite . addTestSuite ( SyntheticMemberSearchTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . core . builder . GroovyClasspathContainer ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . JavaModelManager ; public class ClasspathContainerTest extends EclipseTestCase { @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyCoreActivator . getDefault ( ) . setPreference ( PreferenceConstants . GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL , false ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; GroovyCoreActivator . getDefault ( ) . setPreference ( PreferenceConstants . GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL , true ) ; } public void testClassPathContainerContents ( ) throws JavaModelException { JavaModelManager javaModelManager = JavaModelManager . getJavaModelManager ( ) ; IPath containerPath = new Path ( "<STR_LIT>" ) ; IClasspathContainer container = javaModelManager . getClasspathContainer ( containerPath , testProject . getJavaProject ( ) ) ; IClasspathEntry [ ] entries = container . getClasspathEntries ( ) ; List < IClasspathEntry > groovyAllEntries = getGroovyAllEntries ( entries ) ; List < IClasspathEntry > nonPluginEntries = getNonPluginEntries ( entries ) ; assertEquals ( "<STR_LIT>" , GroovyClasspathContainer . class , container . getClass ( ) ) ; assertEquals ( "<STR_LIT>" + groovyAllEntries , <NUM_LIT:1> , groovyAllEntries . size ( ) ) ; assertEquals ( "<STR_LIT>" + nonPluginEntries , <NUM_LIT:0> , nonPluginEntries . size ( ) ) ; } private List < IClasspathEntry > getGroovyAllEntries ( IClasspathEntry [ ] entries ) { List < IClasspathEntry > groovyAllEntries = new ArrayList < IClasspathEntry > ( ) ; for ( IClasspathEntry entry : entries ) { if ( entry . getPath ( ) . toPortableString ( ) . contains ( "<STR_LIT>" ) ) { groovyAllEntries . add ( entry ) ; } } return groovyAllEntries ; } private List < IClasspathEntry > getNonPluginEntries ( IClasspathEntry [ ] entries ) { List < IClasspathEntry > nonPluginEntries = new ArrayList < IClasspathEntry > ( ) ; for ( IClasspathEntry entry : entries ) { if ( ! entry . getPath ( ) . toPortableString ( ) . contains ( "<STR_LIT>" ) ) { nonPluginEntries . add ( entry ) ; } } return nonPluginEntries ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; public class UnrecoverableErrorTests extends EclipseTestCase { private GroovySnippetCompiler compiler ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; compiler = new GroovySnippetCompiler ( testProject . getGroovyProjectFacade ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; compiler . cleanup ( ) ; } public ModuleNode compileScript ( String script ) { long start = System . currentTimeMillis ( ) ; ModuleNode result = compiler . compile ( script , "<STR_LIT:Test>" ) ; System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - start ) + "<STR_LIT>" ) ; return result ; } public void testGRE926 ( ) throws Exception { ModuleNode result = compileScript ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; assertTrue ( result . encounteredUnrecoverableError ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( "<STR_LIT>" + AllTests . class . getPackage ( ) . getName ( ) ) ; suite . addTestSuite ( ErrorRecoveryTests . class ) ; suite . addTestSuite ( AstPositionTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . jdt . internal . compiler . CompilationResult ; public class ErrorRecoveryTests extends EclipseTestCase { private GroovySnippetCompiler compiler ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; compiler = new GroovySnippetCompiler ( testProject . getGroovyProjectFacade ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; compiler . cleanup ( ) ; } public CompilationResult compileScript ( String script ) { long start = System . currentTimeMillis ( ) ; CompilationResult result = compiler . compileForErrors ( script , "<STR_LIT:Test>" ) ; System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - start ) + "<STR_LIT>" ) ; return result ; } public void testDotNothing1 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotNothing2 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotNothing3 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotNothing4 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotNothing5 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotNothing6 ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testSpreadDotNothing ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testOptionalDotNothing ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } public void testDotLBrace ( ) { CompilationResult result = compileScript ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , result . getAllProblems ( ) . length ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import java . util . List ; import junit . framework . TestCase ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . ast . stmt . Statement ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; public class AstPositionTests extends TestCase { public void testASTPositionForBlock ( ) throws Exception { String text = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; GroovySnippetParser sp = new GroovySnippetParser ( ) ; IDocument doc = new Document ( text ) ; ModuleNode module = sp . parse ( doc . get ( ) ) ; assertEquals ( text , getTextOfNode ( module , doc ) ) ; ClassNode classNode = ( ClassNode ) module . getClasses ( ) . get ( <NUM_LIT:0> ) ; MethodNode fooMethod = ( MethodNode ) classNode . getMethods ( "<STR_LIT:foo>" ) . get ( <NUM_LIT:0> ) ; assertEquals ( text , getTextOfNode ( fooMethod , doc ) ) ; BlockStatement bodyNode = ( BlockStatement ) fooMethod . getCode ( ) ; String body = getTextOfNode ( bodyNode , doc ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" , body . trim ( ) ) ; List < Statement > statements = bodyNode . getStatements ( ) ; assertEquals ( <NUM_LIT:2> , statements . size ( ) ) ; int startLine = <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < statements . size ( ) ; i ++ ) { Statement stmNode = statements . get ( i ) ; String stm = getTextOfNode ( stmNode , doc ) ; int line = startLine + i ; String lineStr = doc . get ( doc . getLineOffset ( line ) , doc . getLineLength ( line ) ) ; assertEquals ( lineStr . trim ( ) , stm . trim ( ) ) ; } } private String getTextOfNode ( ASTNode node , IDocument doc ) throws BadLocationException { return doc . get ( node . getStart ( ) , node . getLength ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completion . mock ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalFilter ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class MockProposalFilter1 implements IProposalFilter { private static boolean filterCalled = false ; public List < IGroovyProposal > filterProposals ( List < IGroovyProposal > proposals , ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { filterCalled = true ; return proposals ; } public static boolean wasFilterCalled ( ) { return filterCalled ; } public static void reset ( ) { filterCalled = false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completion . mock ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalFilter ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class MockProposalFilter2 implements IProposalFilter { private static boolean filterCalled = false ; public List < IGroovyProposal > filterProposals ( List < IGroovyProposal > proposals , ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { filterCalled = true ; return proposals ; } public static boolean wasFilterCalled ( ) { return filterCalled ; } public static void reset ( ) { filterCalled = false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completion . mock ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalProvider ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; public class MockProposalProvider2 implements IProposalProvider { private static boolean providerCalled = false ; public static boolean wasProviderCalled ( ) { return providerCalled ; } public static void reset ( ) { providerCalled = false ; } public List < IGroovyProposal > getStatementAndExpressionProposals ( ContentAssistContext context , ClassNode completionType , boolean isStatic , Set < ClassNode > categories ) { providerCalled = true ; return null ; } public List < MethodNode > getNewMethodProposals ( ContentAssistContext context ) { providerCalled = true ; return null ; } public List < String > getNewFieldProposals ( ContentAssistContext context ) { providerCalled = true ; return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completion . mock ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalProvider ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; public class MockProposalProvider1 implements IProposalProvider { private static boolean providerCalled = false ; public static boolean wasProviderCalled ( ) { return providerCalled ; } public static void reset ( ) { providerCalled = false ; } public List < IGroovyProposal > getStatementAndExpressionProposals ( ContentAssistContext context , ClassNode completionType , boolean isStatic , Set < ClassNode > categories ) { providerCalled = true ; return null ; } public List < MethodNode > getNewMethodProposals ( ContentAssistContext context ) { providerCalled = true ; return null ; } public List < String > getNewFieldProposals ( ContentAssistContext context ) { providerCalled = true ; return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class TypeCompletionTests extends CompletionTestCase { private static final String A_TEST = "<STR_LIT>" ; private static final String RUN_WITH = "<STR_LIT>" ; private static final String HTML = "<STR_LIT>" ; private static final String HTML_PROPOSAL = "<STR_LIT>" ; private static final String HTML_ANCHOR = "<STR_LIT>" ; private static final String HTML_ANCHOR_PROPOSAL = "<STR_LIT>" ; public TypeCompletionTests ( String name ) { super ( name ) ; } public void testCompletionTypesInScript ( ) throws Exception { String contents = HTML ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInScript2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInMethod2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInParameter ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInParameter2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInParameter3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInParameter4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInClassBody ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInExtends ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInImplements ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML_ANCHOR ) ) ; proposalExists ( proposals , HTML_ANCHOR_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionTypesInAnnotation1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , RUN_WITH ) ) ; proposalExists ( proposals , RUN_WITH , <NUM_LIT:1> , true ) ; } public void testCompletionTypesInAnnotation2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , A_TEST ) ) ; proposalExists ( proposals , A_TEST , <NUM_LIT:1> , true ) ; } public void testCompletionTypesInAnnotation3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; String javaContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , javaContents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCompleteFullyQualifiedTypeInScript ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompleteFullyQualifiedTypeInClass ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompleteFullyQualifiedTypeInMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompleteFullyQualifiedTypeInMethodParams ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompleteFullyQualifiedTypeInImports ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompletePackageInClass ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testCompletePackageInMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testCompletePackageInMethodParams ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testCompletePackageInImports ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testCompleteClass1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT:class>" , <NUM_LIT:1> , true ) ; } public void testCompleteClass2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testCompleteClass3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; } public void testGRECLIPSE673 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> , true ) ; } public void testAnnotation1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testAnnotation2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testAnnotation3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } public void testAnnotation4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> , true ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> , true ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; public class TypeCompletionTests2 extends CompletionTestCase { private static final String HTML = "<STR_LIT>" ; private static final String HTMLT = "<STR_LIT>" ; private static final String HTML_PROPOSAL = "<STR_LIT>" ; private static final String HTMLTableCaptionElement_PROPOSAL = "<STR_LIT>" ; public TypeCompletionTests2 ( String name ) { super ( name ) ; } public void testSimpleCompletionTypesInScript1 ( ) throws Exception { String contents = HTML ; String expected = "<STR_LIT>" ; checkProposalApplicationType ( contents , expected , getIndexOf ( contents , HTML ) , HTML_PROPOSAL ) ; } public void testSimpleCompletionTypesInScript2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationType ( contents , expected , getIndexOf ( contents , HTML ) , HTML_PROPOSAL ) ; } public void testBrokenScript1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } protected void tryInLoop ( String contents , String expected , String target , String proposal ) throws Exception { int MAX_TRIES = <NUM_LIT:5> ; Exception last = null ; int i ; for ( i = <NUM_LIT:0> ; i < MAX_TRIES ; i ++ ) { try { checkProposalApplicationType ( contents , expected , getIndexOf ( contents , target ) , proposal ) ; } catch ( Exception e ) { last = e ; } } if ( last != null && i >= MAX_TRIES ) { throw last ; } } public void testBrokenScript2 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript3 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript4 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript5 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript6 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript7 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript8 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript9 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript10 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenScript11 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String expected = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; tryInLoop ( contents , expected , HTMLT , HTMLTableCaptionElement_PROPOSAL ) ; } public void testBrokenClass1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } public void testBrokenClass2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; tryInLoop ( contents , expected , HTML , HTML_PROPOSAL ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . core . internal . resources . PreferenceInitializer ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class GroovyLikeCompletionTests extends CompletionTestCase { private static final String SCRIPTCONTENTS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; public GroovyLikeCompletionTests ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; new PreferenceInitializer ( ) . initializeDefaultPreferences ( ) ; new org . codehaus . groovy . eclipse . preferences . PreferenceInitializer ( ) . initializeDefaultPreferences ( ) ; new org . codehaus . groovy . eclipse . preferences . PreferenceInitializer ( ) . reset ( ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_PARAMETER_GUESSING , false ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; new org . codehaus . groovy . eclipse . preferences . PreferenceInitializer ( ) . reset ( ) ; } public void testMethodWithClosure ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testMethodWithNoArgs ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testMethodWith2Args ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testMethodWithClosureNotGroovyLike ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; } public void testMethodWith2ArgsNotGroovyLike ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; } public void testClosureApplication1a ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication1b ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication1c ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication1d ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication2a ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication2b ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication2c ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication2d ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication3a ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication3b ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , true ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication3c ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , true ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void testClosureApplication3d ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; createGroovy ( ) ; String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , contents . length ( ) , "<STR_LIT>" ) ; } public void _testNamedArguments1 ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , true ) ; ICompilationUnit unit = createGroovy ( ) ; doWait ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , false ) ; } public void _testNamedArguments2 ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , true ) ; ICompilationUnit unit = createGroovy ( ) ; doWait ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , false ) ; } private final static String CLOSURE_CONTENTS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private final static String CLOSURE_CONTENTS2 = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; public void testClosureCompletion1 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion2 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion3 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion4 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion5 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testClosureCompletion6 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testClosureCompletion7 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testClosureCompletion8 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion9 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion10 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosureCompletion11 ( ) throws Exception { ICompilationUnit groovyUnit = create ( CLOSURE_CONTENTS2 ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( CLOSURE_CONTENTS2 , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } protected void doWait ( ) { int x = <NUM_LIT:0> ; while ( ! Job . getJobManager ( ) . isIdle ( ) && x < <NUM_LIT:20> ) { synchronized ( this ) { try { wait ( <NUM_LIT:1000> ) ; } catch ( InterruptedException e ) { } x ++ ; } } } public void testNamedArguments3 ( ) throws Exception { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , true ) ; ICompilationUnit unit = createGroovy ( ) ; performDummySearch ( unit ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS , false ) ; } private ICompilationUnit createGroovy ( ) throws Exception { return createGroovy ( "<STR_LIT>" , SCRIPTCONTENTS ) ; } private ICompilationUnit createGroovy ( String cuName , String cuContents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , cuName , cuContents ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyExtendedCompletionContext ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . internal . core . JavaModelManager ; public class ExtendedCompletionContextTests extends CompletionTestCase { private static final String STRING_SIG = "<STR_LIT>" ; private static final String STRING_ARR_SIG = "<STR_LIT>" ; private static final String INTEGER_SIG = "<STR_LIT>" ; private static final String INTEGER_ARR_SIG = "<STR_LIT>" ; private static final String LIST_SIG = "<STR_LIT>" ; private static final String LIST_ARR_SIG = "<STR_LIT>" ; public ExtendedCompletionContextTests ( String name ) { super ( name ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; ICompilationUnit [ ] workingCopies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( null , true ) ; if ( workingCopies != null ) { for ( ICompilationUnit unit : workingCopies ) { try { unit . discardWorkingCopy ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } } public void testExtendedContextInScript1 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , INTEGER_SIG , "<STR_LIT:x>" , "<STR_LIT:a>" ) ; assertExtendedContextElements ( context , STRING_SIG , "<STR_LIT:y>" , "<STR_LIT:b>" ) ; assertExtendedContextElements ( context , LIST_SIG , "<STR_LIT>" , "<STR_LIT:c>" ) ; } public void testExtendedContextInScript2 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , INTEGER_ARR_SIG , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , STRING_ARR_SIG , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , LIST_ARR_SIG , "<STR_LIT>" ) ; } public void testExtendedContextInScript3 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" ) ; } public void testExtendedContextInScript4 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" ) ; } public void testExtendedContextInClass1 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT:foo>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" ) ; } public void testExtendedContextInClass2 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT:foo>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" ) ; } public void testExtendedContextInClass3 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT:foo>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" , "<STR_LIT:b>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT>" ) ; } public void testExtendedContextWithGenerics ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" ) ; } public void testExtendedContextWithBoxing ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , "<STR_LIT:I>" , "<STR_LIT:y>" , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:a>" , "<STR_LIT:b>" ) ; assertExtendedContextElements ( context , "<STR_LIT:Z>" , "<STR_LIT:a>" , "<STR_LIT:b>" ) ; } public void testExtendedContextWithBoxingAndArrays ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; GroovyExtendedCompletionContext context = getExtendedCoreContext ( create ( contents ) , contents . lastIndexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ) ; IJavaElement enclosing = context . getEnclosingElement ( ) ; assertEquals ( "<STR_LIT>" , enclosing . getElementName ( ) ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:y>" , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , "<STR_LIT:I>" , "<STR_LIT:y>" , "<STR_LIT:x>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT:a>" , "<STR_LIT:b>" ) ; assertExtendedContextElements ( context , "<STR_LIT:Z>" , "<STR_LIT:a>" , "<STR_LIT:b>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertExtendedContextElements ( context , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllCompletionTests { public static Test suite ( ) throws Exception { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; suite . addTestSuite ( DefaultGroovyMethodCompletionTests . class ) ; suite . addTestSuite ( LocalVariableCompletionTests . class ) ; suite . addTestSuite ( InferencingCompletionTests . class ) ; suite . addTestSuite ( FieldCompletionTests . class ) ; suite . addTestSuite ( MethodCompletionTests . class ) ; suite . addTestSuite ( TypeCompletionTests . class ) ; suite . addTestSuite ( TypeCompletionTests2 . class ) ; suite . addTestSuite ( GroovyLikeCompletionTests . class ) ; suite . addTestSuite ( InnerTypeCompletionTests . class ) ; suite . addTestSuite ( OtherCompletionTests . class ) ; suite . addTestSuite ( FindImportsRegionTests . class ) ; suite . addTestSuite ( RelevanceTests . class ) ; suite . addTestSuite ( ProposalProviderAndFilterTests . class ) ; suite . addTestSuite ( ConstructorCompletionTests . class ) ; suite . addTestSuite ( StaticImportsCompletionTests . class ) ; suite . addTestSuite ( GenericCompletionTests . class ) ; suite . addTestSuite ( ExtendedCompletionContextTests . class ) ; suite . addTestSuite ( ContentAssistLocationTests . class ) ; suite . addTestSuite ( ContextInformationTests . class ) ; suite . addTestSuite ( GuessingCompletionTests . class ) ; suite . addTestSuite ( DefaultMethodContentAssistTests . class ) ; suite . addTestSuite ( CommandChainCompletionTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import java . util . Arrays ; import java . util . Comparator ; import java . util . List ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyExtendedCompletionContext ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyJavaGuessingCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . completions . NamedParameterProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . groovy . eclipse . test . SynchronizationUtils ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . dom . AST ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . TypeNameRequestor ; import org . eclipse . jdt . core . tests . builder . BuilderTests ; import org . eclipse . jdt . core . tests . util . Util ; import org . eclipse . jdt . groovy . search . ITypeRequestor ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorFactory ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorWithRequestor ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . ui . javaeditor . EditorUtility ; import org . eclipse . jdt . internal . ui . javaeditor . JavaEditor ; import org . eclipse . jdt . internal . ui . javaeditor . JavaSourceViewer ; import org . eclipse . jdt . internal . ui . text . java . AbstractJavaCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . LazyGenericTypeProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposalComputer ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . ui . ide . IDE ; import org . eclipse . ui . internal . UIPlugin ; public abstract class CompletionTestCase extends BuilderTests { protected String defaultFileExtension ; public CompletionTestCase ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; } @ Override protected void tearDown ( ) throws Exception { UIPlugin . getDefault ( ) . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) . closeAllEditors ( false ) ; super . tearDown ( ) ; } protected IPath createGenericProject ( ) throws Exception { if ( genericProjectExists ( ) ) { return env . getProject ( "<STR_LIT>" ) . getFullPath ( ) ; } IPath projectPath = env . addProject ( "<STR_LIT>" , "<STR_LIT>" ) ; env . removePackageFragmentRoot ( projectPath , "<STR_LIT>" ) ; env . addExternalJars ( projectPath , Util . getJavaClassLibs ( ) ) ; env . addGroovyNature ( "<STR_LIT>" ) ; env . addGroovyJars ( projectPath ) ; fullBuild ( projectPath ) ; env . addPackageFragmentRoot ( projectPath , "<STR_LIT:src>" ) ; env . setOutputFolder ( projectPath , "<STR_LIT>" ) ; return projectPath ; } protected boolean genericProjectExists ( ) { return env . getProject ( "<STR_LIT>" ) != null && env . getProject ( "<STR_LIT>" ) . exists ( ) ; } protected IFile getFile ( IPath projectPath , String fileName ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getFile ( projectPath . append ( fileName ) ) ; } protected IFolder getolder ( IPath projectPath , String folderName ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getFolder ( projectPath . append ( folderName ) ) ; } protected IProject getProject ( IPath projectPath ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( projectPath . segment ( <NUM_LIT:0> ) ) ; } public ICompilationUnit getJavaCompilationUnit ( IPath sourceRootPath , String qualifiedNameWithSlashesDotJava ) { IFile file = getFile ( sourceRootPath , qualifiedNameWithSlashesDotJava ) ; return JavaCore . createCompilationUnitFrom ( file ) ; } public ICompilationUnit getCompilationUnit ( IPath fullPathName ) { IFile file = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getFile ( fullPathName ) ; return JavaCore . createCompilationUnitFrom ( file ) ; } public GroovyCompilationUnit getGroovyCompilationUnit ( IPath sourceRootPath , String qualifiedNameWithSlashesDotGroovy ) { IFile file = getFile ( sourceRootPath , qualifiedNameWithSlashesDotGroovy ) ; return ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; } protected ICompletionProposal [ ] performContentAssist ( ICompilationUnit unit , int offset , Class < ? extends IJavaCompletionProposalComputer > computerClass ) throws Exception { if ( unit instanceof GroovyCompilationUnit ) { unit . getResource ( ) . setPersistentProperty ( IDE . EDITOR_KEY , "<STR_LIT>" ) ; } JavaEditor editor = ( JavaEditor ) EditorUtility . openInEditor ( unit ) ; JavaSourceViewer viewer = ( JavaSourceViewer ) editor . getViewer ( ) ; JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext ( viewer , offset , editor ) ; IJavaCompletionProposalComputer computer = computerClass . newInstance ( ) ; List < ICompletionProposal > proposals = computer . computeCompletionProposals ( context , null ) ; return proposals . toArray ( new ICompletionProposal [ proposals . size ( ) ] ) ; } protected void proposalExists ( ICompletionProposal [ ] proposals , String name , int expectedCount ) { boolean isType = name . contains ( "<STR_LIT:U+0020-U+0020>" ) ; proposalExists ( proposals , name , expectedCount , isType ) ; } protected void proposalExists ( ICompletionProposal [ ] proposals , String name , int expectedCount , boolean isType ) { int foundCount = <NUM_LIT:0> ; for ( ICompletionProposal proposal : proposals ) { String propName = proposal . getDisplayString ( ) ; if ( propName . startsWith ( name + "<STR_LIT:U+0020>" ) ) { foundCount ++ ; } else if ( propName . startsWith ( name + "<STR_LIT:(>" ) ) { foundCount ++ ; } else if ( isType && propName . startsWith ( name ) ) { foundCount ++ ; } } if ( foundCount != expectedCount ) { StringBuffer sb = new StringBuffer ( ) ; for ( ICompletionProposal proposal : proposals ) { sb . append ( "<STR_LIT:n>" + proposal . toString ( ) ) ; } fail ( "<STR_LIT>" + name + "<STR_LIT>" + expectedCount + "<STR_LIT>" + foundCount + "<STR_LIT>" + sb ) ; } } protected int findProposal ( ICompletionProposal [ ] proposals , String name , boolean isType , int startFrom ) { for ( int i = startFrom ; i < proposals . length ; i ++ ) { ICompletionProposal proposal = proposals [ i ] ; String propName = proposal . getDisplayString ( ) ; if ( propName . startsWith ( name + "<STR_LIT:U+0020>" ) ) { return i ; } else if ( propName . startsWith ( name + "<STR_LIT:(>" ) ) { return i ; } else if ( isType && propName . startsWith ( name ) ) { return i ; } else if ( name . equals ( proposal . getDisplayString ( ) ) ) { return i ; } } return - <NUM_LIT:1> ; } protected ICompletionProposal findFirstProposal ( ICompletionProposal [ ] proposals , String name , boolean isType ) { for ( ICompletionProposal proposal : proposals ) { String propName = proposal . getDisplayString ( ) ; if ( propName . startsWith ( name + "<STR_LIT:U+0020>" ) && ! ( proposal instanceof LazyGenericTypeProposal ) ) { return proposal ; } else if ( propName . startsWith ( name + "<STR_LIT:(>" ) ) { return proposal ; } else if ( isType && propName . startsWith ( name ) ) { return proposal ; } } return null ; } protected void applyProposalAndCheck ( IDocument document , ICompletionProposal proposal , String expected ) { proposal . apply ( document ) ; assertEquals ( "<STR_LIT>" , expected , document . get ( ) ) ; } protected void checkReplacementString ( ICompletionProposal [ ] proposals , String expectedReplacement , int expectedCount ) { int foundCount = <NUM_LIT:0> ; for ( ICompletionProposal proposal : proposals ) { AbstractJavaCompletionProposal javaProposal = ( AbstractJavaCompletionProposal ) proposal ; String replacement = javaProposal . getReplacementString ( ) ; if ( replacement . equals ( expectedReplacement ) ) { foundCount ++ ; } } if ( foundCount != expectedCount ) { StringBuffer sb = new StringBuffer ( ) ; for ( ICompletionProposal proposal : proposals ) { AbstractJavaCompletionProposal javaProposal = ( AbstractJavaCompletionProposal ) proposal ; sb . append ( "<STR_LIT:n>" + javaProposal . getReplacementString ( ) ) ; } fail ( "<STR_LIT>" + expectedReplacement + "<STR_LIT>" + expectedCount + "<STR_LIT>" + foundCount + "<STR_LIT>" + sb ) ; } } protected void validateProposal ( CompletionProposal proposal , String name ) { assertEquals ( proposal . getName ( ) , name ) ; } protected int getIndexOf ( String contents , String lookFor ) { return contents . indexOf ( lookFor ) + lookFor . length ( ) ; } protected int getLastIndexOf ( String contents , String lookFor ) { return contents . lastIndexOf ( lookFor ) + lookFor . length ( ) ; } protected ICompletionProposal [ ] createProposalsAtOffset ( String contents , int completionOffset ) throws Exception { return createProposalsAtOffset ( contents , null , completionOffset ) ; } protected ICompletionProposal [ ] createProposalsAtOffset ( String contents , String javaContents , int completionOffset ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath pack = projectPath . append ( "<STR_LIT:src>" ) ; if ( javaContents != null ) { IPath pathToJavaClass = env . addClass ( pack , "<STR_LIT>" , "<STR_LIT>" + javaContents ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; unit . becomeWorkingCopy ( null ) ; } IPath pathToGroovyClass = env . addGroovyClass ( pack , "<STR_LIT>" , contents ) ; fullBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToGroovyClass ) ; unit . becomeWorkingCopy ( null ) ; return createProposalsAtOffset ( unit , completionOffset ) ; } protected ICompletionProposal [ ] createProposalsAtOffset ( ICompilationUnit unit , int completionOffset ) throws Exception { int count = <NUM_LIT:0> ; int maxCount = <NUM_LIT:15> ; ICompletionProposal [ ] proposals ; do { if ( count > <NUM_LIT:0> ) { performDummySearch ( unit . getJavaProject ( ) ) ; unit . reconcile ( AST . JLS3 , true , null , null ) ; env . fullBuild ( ) ; SynchronizationUtils . joinBackgroudActivities ( ) ; SynchronizationUtils . waitForIndexingToComplete ( ) ; } System . out . println ( "<STR_LIT>" + unit . getElementName ( ) ) ; proposals = performContentAssist ( unit , completionOffset , GroovyCompletionProposalComputer . class ) ; if ( proposals == null ) { System . out . println ( "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" + Arrays . toString ( proposals ) ) ; } count ++ ; } while ( ( proposals == null || proposals . length == <NUM_LIT:0> ) && count < maxCount ) ; return proposals ; } protected ICompletionProposal [ ] orderByRelevance ( ICompletionProposal [ ] proposals ) { Arrays . sort ( proposals , <NUM_LIT:0> , proposals . length , new Comparator < ICompletionProposal > ( ) { public int compare ( ICompletionProposal left , ICompletionProposal right ) { int initial = ( ( IJavaCompletionProposal ) right ) . getRelevance ( ) - ( ( IJavaCompletionProposal ) left ) . getRelevance ( ) ; if ( initial != <NUM_LIT:0> ) { return initial ; } else { return left . toString ( ) . compareTo ( right . toString ( ) ) ; } } } ) ; return proposals ; } protected ICompilationUnit create ( String contents ) throws Exception { return create ( "<STR_LIT>" , contents ) ; } protected ICompilationUnit create ( String cuName , String contents ) throws Exception { return create ( null , cuName , contents ) ; } protected ICompilationUnit create ( String pkg , String cuName , String contents ) throws Exception { IPath projectPath ; if ( genericProjectExists ( ) ) { projectPath = env . getProject ( "<STR_LIT>" ) . getFullPath ( ) ; } else { projectPath = createGenericProject ( ) ; } IPath pkgPath = projectPath . append ( "<STR_LIT:src>" ) ; if ( pkg != null ) { pkgPath = env . addPackage ( pkgPath , pkg ) ; } IPath pathToJavaClass = env . addGroovyClassExtension ( pkgPath , cuName , contents , defaultFileExtension ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } protected void createJava ( String cuName , String contents ) throws Exception { IPath projectPath ; if ( genericProjectExists ( ) ) { projectPath = env . getProject ( "<STR_LIT>" ) . getFullPath ( ) ; } else { projectPath = createGenericProject ( ) ; } IPath src = projectPath . append ( "<STR_LIT:src>" ) ; env . addClass ( src , cuName , contents ) ; } protected String printProposals ( ICompletionProposal [ ] proposals ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; for ( ICompletionProposal proposal : proposals ) { sb . append ( proposal . getDisplayString ( ) + "<STR_LIT:n>" ) ; } return sb . toString ( ) ; } protected void checkProposalApplicationType ( String contents , String expected , int proposalLocation , String proposalName ) throws Exception { checkProposalApplication ( contents , expected , proposalLocation , proposalName , true ) ; } protected void checkProposalApplicationNonType ( String contents , String expected , int proposalLocation , String proposalName ) throws Exception { checkProposalApplication ( contents , expected , proposalLocation , proposalName , false ) ; } protected void checkProposalApplication ( String contents , String expected , int proposalLocation , String proposalName , boolean isType ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , proposalLocation ) ; ICompletionProposal firstProposal = findFirstProposal ( proposals , proposalName , isType ) ; if ( firstProposal == null ) { fail ( "<STR_LIT>" ) ; } applyProposalAndCheck ( new Document ( contents ) , firstProposal , expected ) ; } protected void checkProposalApplication ( String contents , int proposalLocation , String [ ] expecteds , String [ ] proposalNames ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , proposalLocation ) ; for ( int i = <NUM_LIT:0> ; i < expecteds . length ; i ++ ) { ICompletionProposal firstProposal = findFirstProposal ( proposals , proposalNames [ i ] , false ) ; if ( firstProposal == null ) { fail ( "<STR_LIT>" ) ; } applyProposalAndCheck ( new Document ( contents ) , firstProposal , expecteds [ i ] ) ; } } protected void assertProposalOrdering ( ICompletionProposal [ ] proposals , String ... order ) { int startFrom = <NUM_LIT:0> ; for ( String propName : order ) { startFrom = findProposal ( proposals , propName , false , startFrom ) + <NUM_LIT:1> ; if ( startFrom == <NUM_LIT:0> ) { fail ( "<STR_LIT>" + propName + "<STR_LIT>" + printProposals ( proposals ) ) ; } } } protected void assertExtendedContextElements ( GroovyExtendedCompletionContext context , String signature , String ... expectedNames ) { IJavaElement [ ] visibleElements = context . getVisibleElements ( signature ) ; assertEquals ( "<STR_LIT>" + Arrays . toString ( expectedNames ) + "<STR_LIT>" + elementsToNames ( visibleElements ) , expectedNames . length , visibleElements . length ) ; for ( String name : expectedNames ) { boolean found = false ; for ( IJavaElement element : visibleElements ) { if ( element . getElementName ( ) . equals ( name ) ) { found = true ; break ; } } if ( ! found ) { fail ( "<STR_LIT>" + name + "<STR_LIT>" + elementsToNames ( visibleElements ) ) ; } } } private String elementsToNames ( IJavaElement [ ] visibleElements ) { String [ ] names = new String [ visibleElements . length ] ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { names [ i ] = visibleElements [ i ] . getElementName ( ) ; } return Arrays . toString ( names ) ; } protected GroovyExtendedCompletionContext getExtendedCoreContext ( ICompilationUnit unit , int invocationOffset ) throws JavaModelException { GroovyCompilationUnit gunit = ( GroovyCompilationUnit ) unit ; gunit . becomeWorkingCopy ( null ) ; GroovyCompletionProposalComputer computer = new GroovyCompletionProposalComputer ( ) ; ContentAssistContext context = computer . createContentAssistContext ( gunit , invocationOffset , new Document ( String . valueOf ( gunit . getContents ( ) ) ) ) ; TypeInferencingVisitorWithRequestor visitor = new TypeInferencingVisitorFactory ( ) . createVisitor ( gunit ) ; SearchRequestor requestor = new SearchRequestor ( context . completionNode ) ; visitor . visitCompilationUnit ( requestor ) ; return new GroovyExtendedCompletionContext ( context , requestor . currentScope ) ; } public class SearchRequestor implements ITypeRequestor { public VariableScope currentScope ; public ASTNode node ; public SearchRequestor ( ASTNode node ) { this . node = node ; } public VisitStatus acceptASTNode ( ASTNode visitorNode , TypeLookupResult visitorResult , IJavaElement enclosingElement ) { if ( node == visitorNode ) { this . currentScope = visitorResult . scope ; return VisitStatus . STOP_VISIT ; } return VisitStatus . CONTINUE ; } } protected void checkProposalChoices ( String contents , String toFind , String lookFor , String replacementString , String [ ] expectedChoices ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , toFind ) ) ; checkReplacementString ( proposals , replacementString , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , lookFor , false ) ; NamedParameterProposal guessingProposal = ( NamedParameterProposal ) proposal ; ICompletionProposal [ ] choices = guessingProposal . getChoices ( ) ; assertEquals ( expectedChoices . length , choices . length ) ; for ( int i = <NUM_LIT:0> ; i < expectedChoices . length ; i ++ ) { assertEquals ( "<STR_LIT>" , expectedChoices [ i ] , choices [ i ] . getDisplayString ( ) ) ; } } protected void checkProposalChoices ( String contents , String lookFor , String replacementString , String [ ] [ ] expectedChoices ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , lookFor ) ) ; checkReplacementString ( proposals , replacementString , <NUM_LIT:1> ) ; ICompletionProposal proposal = findFirstProposal ( proposals , lookFor , false ) ; GroovyJavaGuessingCompletionProposal guessingProposal = ( GroovyJavaGuessingCompletionProposal ) proposal ; guessingProposal . getReplacementString ( ) ; ICompletionProposal [ ] [ ] choices = guessingProposal . getChoices ( ) ; assertEquals ( expectedChoices . length , choices . length ) ; for ( int i = <NUM_LIT:0> ; i < expectedChoices . length ; i ++ ) { assertEquals ( expectedChoices [ i ] . length , choices [ i ] . length ) ; Comparator < ICompletionProposal > c = new Comparator < ICompletionProposal > ( ) { public int compare ( ICompletionProposal c1 , ICompletionProposal c2 ) { return c1 . getDisplayString ( ) . compareTo ( c2 . getDisplayString ( ) ) ; } } ; Arrays . sort ( choices [ i ] , <NUM_LIT:0> , choices [ i ] . length , c ) ; Arrays . sort ( expectedChoices [ i ] , <NUM_LIT:0> , expectedChoices [ i ] . length ) ; for ( int j = <NUM_LIT:0> ; j < expectedChoices [ i ] . length ; j ++ ) { assertEquals ( "<STR_LIT>" , expectedChoices [ i ] [ j ] , choices [ i ] [ j ] . getDisplayString ( ) ) ; } } } public void performDummySearch ( IJavaElement element ) throws Exception { JavaModelManager . getIndexManager ( ) . indexAll ( element . getJavaProject ( ) . getProject ( ) ) ; new SearchEngine ( ) . searchAllTypeNames ( null , SearchPattern . R_EXACT_MATCH , "<STR_LIT>" . toCharArray ( ) , SearchPattern . R_EXACT_MATCH , IJavaSearchConstants . CLASS , SearchEngine . createJavaSearchScope ( new IJavaElement [ ] { element } ) , new Requestor ( ) , IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH , null ) ; } private static class Requestor extends TypeNameRequestor { } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import java . util . Arrays ; import java . util . Comparator ; import junit . framework . ComparisonFailure ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class OtherCompletionTests extends CompletionTestCase { public OtherCompletionTests ( String name ) { super ( name ) ; } boolean orig ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; orig = GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . getBoolean ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_PARAMETER_GUESSING , false ) ; } @ Override protected void tearDown ( ) throws Exception { try { super . tearDown ( ) ; } finally { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , orig ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_PARAMETER_GUESSING , true ) ; } } public void testGreclipse414 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT:i>" , <NUM_LIT:1> ) ; } public void testGreclipse422 ( ) throws Exception { String javaClass = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String groovyClass = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; env . addClass ( groovyUnit . getParent ( ) . getResource ( ) . getFullPath ( ) , "<STR_LIT>" , javaClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT:bar>" , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , proposals [ <NUM_LIT:0> ] . getDisplayString ( ) ) ; proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; Arrays . sort ( proposals , new Comparator < ICompletionProposal > ( ) { public int compare ( ICompletionProposal o1 , ICompletionProposal o2 ) { return - o1 . getDisplayString ( ) . compareTo ( o2 . getDisplayString ( ) ) ; } } ) ; proposalExists ( proposals , "<STR_LIT>" , GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ? <NUM_LIT:2> : <NUM_LIT:3> ) ; assertEquals ( printProposals ( proposals ) , "<STR_LIT>" , proposals [ <NUM_LIT:0> ] . getDisplayString ( ) . toString ( ) ) ; try { } catch ( ComparisonFailure e ) { } if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT> ) { assertEquals ( printProposals ( proposals ) , "<STR_LIT>" , proposals [ <NUM_LIT:1> ] . getDisplayString ( ) . toString ( ) ) ; assertEquals ( printProposals ( proposals ) , "<STR_LIT>" , proposals [ <NUM_LIT:2> ] . getDisplayString ( ) . toString ( ) ) ; } else { assertEquals ( printProposals ( proposals ) , "<STR_LIT>" , proposals [ <NUM_LIT:1> ] . getDisplayString ( ) . toString ( ) ) ; } } public void testVisibility ( ) throws Exception { String groovyClass = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , proposals [ <NUM_LIT:0> ] . getDisplayString ( ) ) ; } public void testGString1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testContentAssistInInitializers1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testContentAssistInInitializers2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testContentAssistInStaticInitializers1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testContentAssistInStaticInitializers2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testMethodWithSpaces ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testMethodWithSpaces2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterStaticCall ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testArrayCompletion1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:x>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testArrayCompletion2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testArrayCompletion3 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testArrayCompletion4 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:x>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testListCompletion1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testListCompletion2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion1 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion2 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion3 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion4 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion5 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion6 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion7 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion8 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion9 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion10 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion11 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testSpreadCompletion12 ( ) throws Exception { String groovyClass = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( groovyClass ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getLastIndexOf ( groovyClass , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; checkReplacementString ( proposals , "<STR_LIT:value>" , <NUM_LIT:1> ) ; } public void testBeforeScript ( ) throws Exception { String script = "<STR_LIT>" ; ICompilationUnit groovyUnit = create ( script ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( groovyUnit , getIndexOf ( script , "<STR_LIT:n>" ) , GroovyCompletionProposalComputer . class ) ; assertProposalOrdering ( proposals , "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class FieldCompletionTests extends CompletionTestCase { public FieldCompletionTests ( String name ) { super ( name ) ; } public void testSafeDeferencing ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpaces1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpaces2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testSpaces3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testProperties1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties5 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; env . addClass ( env . getProject ( "<STR_LIT>" ) . getFolder ( "<STR_LIT:src>" ) . getFullPath ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties1a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties2a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties3a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties4a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties5a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; env . addClass ( env . getProject ( "<STR_LIT>" ) . getFolder ( "<STR_LIT:src>" ) . getFullPath ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties6 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties6a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testProperties7 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:x>" , <NUM_LIT:1> ) ; } public void testProperties7a ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testProperties8 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testProperties9 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testClosure1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosure2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosure3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosure4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT:b>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosure5 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosuret6 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClosuret7 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testInitializer1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:.>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class ConstructorCompletionTests extends CompletionTestCase { public ConstructorCompletionTests ( String name ) { super ( name ) ; } boolean orig ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; orig = GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . getBoolean ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS ) ; GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , false ) ; } @ Override protected void tearDown ( ) throws Exception { try { super . tearDown ( ) ; } finally { GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS , orig ) ; } } public void _testConstructorCompletion1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void _testConstructorCompletion2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void _testConstructorCompletion3 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testNoNamedArgs1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNoNamedArgs2 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testNoNamedArgs3 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testNamedArgs1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs2 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs3 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs4 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs5 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs6 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNamedArgs7 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getLastIndexOf ( contents , "<STR_LIT:(>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testParamGuessing1 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing2 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing3 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing4 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing5 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing6 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing7 ( ) throws Exception { create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] expectedChoices = new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class InnerTypeCompletionTests extends CompletionTestCase { private static final String XXX = "<STR_LIT>" ; private static final String HTML = "<STR_LIT>" ; private static final String HTML_PROPOSAL = "<STR_LIT>" ; public InnerTypeCompletionTests ( String name ) { super ( name ) ; } public void testCompletionInInnerClass1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionInInnerClass2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionInInnerClass3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionInInnerClass4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , HTML ) ) ; proposalExists ( proposals , HTML_PROPOSAL , <NUM_LIT:1> ) ; } public void testCompletionOfInnerClass1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testCompletionOfInnerClass2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testCompletionOFInnerMember1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } public void testCompletionOFInnerMember2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } public void testCompletionOFInnerMember3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } public void testCompletionOFInnerMember4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } public void testCompletionOFInnerMember5 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } public void testCompletionOFInnerMember6 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , getIndexOf ( contents , XXX ) ) ; proposalExists ( proposals , XXX , <NUM_LIT:1> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; public class GenericCompletionTests extends CompletionTestCase { public GenericCompletionTests ( String name ) { super ( name ) ; } public void testAfterArrayAccesses1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testAfterArrayAccesses2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testAfterMultipleArrayAccesses1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testAfterMultipleArrayAccesses2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class NewFieldCompletionTests extends CompletionTestCase { public NewFieldCompletionTests ( String name ) { super ( name ) ; } public void testNewFieldSimple ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testNewField1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; } public void testNewField2 ( ) throws Exception { String contents = "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; } public void testNewField3 ( ) throws Exception { String contents = "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } ) ; } public void testNewField4 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; } public void testNewField5 ( ) throws Exception { String contents = "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } ) ; } public void testNewField6 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; } public void testNewField7 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; checkProposalApplication ( contents , getIndexOf ( contents , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; } public void testNoNewField1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testNoNewField2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class CompletionTestsPlugin extends AbstractUIPlugin { public CompletionTestsPlugin ( ) { } @ Override public void start ( BundleContext context ) throws Exception { super . start ( context ) ; } @ Override public void stop ( BundleContext context ) throws Exception { super . stop ( context ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class InferencingCompletionTests extends CompletionTestCase { public InferencingCompletionTests ( ) { super ( "<STR_LIT>" ) ; } private static final String CONTENTS = "<STR_LIT>" ; private static final String CONTENTS_SCRIPT = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:U+0020U+0020}>" + "<STR_LIT:}>" ; private static final String CONTENTS_GETAT1 = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static final String CONTENTS_GETAT2 = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static final String CONTENTS_CLOSURE = "<STR_LIT>" ; public void testInferenceOfLocalStringInMethod ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS , getIndexOf ( CONTENTS , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testInferenceOfLocalString ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_SCRIPT , getIndexOf ( CONTENTS_SCRIPT , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testInferenceOfLocalString2 ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_SCRIPT , getIndexOf ( CONTENTS_SCRIPT , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testInferenceOfStringInClass ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_SCRIPT , getIndexOf ( CONTENTS_SCRIPT , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testInferenceInClosure ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_CLOSURE , getIndexOf ( CONTENTS_CLOSURE , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testGetAt1 ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_GETAT1 , getIndexOf ( CONTENTS_GETAT1 , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testGetAt2 ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_GETAT1 , getIndexOf ( CONTENTS_GETAT1 , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testGetAt3 ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_GETAT2 , getIndexOf ( CONTENTS_GETAT2 , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testGetAt4 ( ) throws Exception { ICompletionProposal [ ] proposals = createProposalsAtOffset ( CONTENTS_GETAT2 , getIndexOf ( CONTENTS_GETAT2 , "<STR_LIT>" ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class ContextInformationTests extends CompletionTestCase { public ContextInformationTests ( String name ) { super ( name ) ; } public void testMethodContext1 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testMethodContext2 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:3> , proposals , contents ) ; } public void testMethodContext3 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:3> , proposals , contents ) ; } public void testMethodContext4 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:3> , proposals , contents ) ; } public void testConstructorContext1 ( ) throws Exception { ICompilationUnit unit = create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; performDummySearch ( unit ) ; String contents = "<STR_LIT>" ; unit = create ( contents ) ; performDummySearch ( unit ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testConstructorContext1a ( ) throws Exception { ICompilationUnit unit = create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; performDummySearch ( unit ) ; String contents = "<STR_LIT>" ; unit = create ( contents ) ; performDummySearch ( unit ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testConstructorContext1b ( ) throws Exception { ICompilationUnit unit = create ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; performDummySearch ( unit ) ; String contents = "<STR_LIT>" ; unit = create ( contents ) ; performDummySearch ( unit ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testConstructorContext2 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testConstructorContext3 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; unit . becomeWorkingCopy ( null ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } public void testConstructorContext4 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; performDummySearch ( unit ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertContextInformation ( "<STR_LIT>" , <NUM_LIT:2> , proposals , contents ) ; } private void assertContextInformation ( String proposalName , int cnt , ICompletionProposal [ ] proposals , String contents ) { if ( cnt != proposals . length ) { fail ( "<STR_LIT>" + cnt + "<STR_LIT>" + proposals . length + "<STR_LIT>" + printProposals ( proposals ) ) ; } IDocument doc = new Document ( contents ) ; for ( int i = <NUM_LIT:0> ; i < proposals . length ; i ++ ) { if ( ! proposals [ i ] . getDisplayString ( ) . startsWith ( proposalName ) ) { fail ( "<STR_LIT>" + cnt + "<STR_LIT>" + printProposals ( proposals ) ) ; } if ( proposals [ i ] . getContextInformation ( ) == null ) { fail ( "<STR_LIT>" + cnt + "<STR_LIT>" + printProposals ( proposals ) ) ; } proposals [ i ] . apply ( doc ) ; assertEquals ( "<STR_LIT>" , contents , doc . get ( ) ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . completion . mock . MockProposalFilter1 ; import org . codehaus . groovy . eclipse . codeassist . completion . mock . MockProposalFilter2 ; import org . codehaus . groovy . eclipse . codeassist . completion . mock . MockProposalProvider1 ; import org . codehaus . groovy . eclipse . codeassist . completion . mock . MockProposalProvider2 ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalFilter ; import org . codehaus . groovy . eclipse . codeassist . processors . IProposalProvider ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . groovy . eclipse . test . ui . Extender1 ; import org . codehaus . groovy . eclipse . test . ui . Extender2 ; import org . eclipse . jdt . core . ICompilationUnit ; public class ProposalProviderAndFilterTests extends CompletionTestCase { public ProposalProviderAndFilterTests ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; createGenericProject ( ) ; env . addNature ( "<STR_LIT>" , Extender2 . NATURE2 ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; MockProposalFilter1 . reset ( ) ; MockProposalFilter2 . reset ( ) ; MockProposalProvider1 . reset ( ) ; MockProposalProvider2 . reset ( ) ; } public void testProvidersAndFilters1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertFalse ( "<STR_LIT>" , MockProposalProvider1 . wasProviderCalled ( ) ) ; assertFalse ( "<STR_LIT>" , MockProposalFilter1 . wasFilterCalled ( ) ) ; assertTrue ( "<STR_LIT>" , MockProposalProvider2 . wasProviderCalled ( ) ) ; assertTrue ( "<STR_LIT>" , MockProposalFilter2 . wasFilterCalled ( ) ) ; } public void testProvidersAndFilters2 ( ) throws Exception { env . addNature ( "<STR_LIT>" , Extender1 . NATURE1 ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; assertTrue ( "<STR_LIT>" , MockProposalProvider1 . wasProviderCalled ( ) ) ; assertTrue ( "<STR_LIT>" , MockProposalFilter1 . wasFilterCalled ( ) ) ; assertTrue ( "<STR_LIT>" , MockProposalProvider2 . wasProviderCalled ( ) ) ; assertTrue ( "<STR_LIT>" , MockProposalFilter2 . wasFilterCalled ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class StaticImportsCompletionTests extends CompletionTestCase { public StaticImportsCompletionTests ( String name ) { super ( name ) ; } public void testStaticImportField ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; expectingNoProblems ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testStaticImportMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testStaticStarImportField ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; expectingNoProblems ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testStaticStarImportMethod ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; fullBuild ( ) ; expectingNoProblems ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class LocalVariableCompletionTests extends CompletionTestCase { private static final String CONTENTS = "<STR_LIT>" ; private static final String SCRIPTCONTENTS = "<STR_LIT>" ; private static final String SCRIPTCONTENTS2 = "<STR_LIT>" ; private static final String SELFREFERENCINGSCRIPT = "<STR_LIT>" ; public LocalVariableCompletionTests ( String name ) { super ( name ) ; } public void testLocalVarsInJavaFile ( ) throws Exception { ICompilationUnit unit = createJava ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:0> ) ; } public void testLocalVarsInGroovyFile ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:0> ) ; } public void testLocalVarsInScript ( ) throws Exception { ICompilationUnit unit = createGroovyForScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:1> ) ; } public void testLocalVarsInClosureInScript ( ) throws Exception { ICompilationUnit unit = createGroovyForScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:1> ) ; } public void testLocalVarsInClosureInScript2 ( ) throws Exception { ICompilationUnit unit = createGroovyForScript2 ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS2 , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:0> ) ; } public void testLocalVarsInClosureInMethod ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; proposalExists ( proposals , "<STR_LIT:y>" , <NUM_LIT:1> ) ; } public void testSelfReferencingLocalVar ( ) throws Exception { ICompilationUnit unit = createGroovyForSelfReferencingScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( SELFREFERENCINGSCRIPT , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testClsoureVar1 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testClsoureVar2 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testClsoureVar3 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testClsoureVar4 ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testClsoureVar4a ( ) throws Exception { String contents = "<STR_LIT>" ; String expected = "<STR_LIT>" ; checkProposalApplicationNonType ( contents , expected , getIndexOf ( contents , "<STR_LIT>" ) , "<STR_LIT>" ) ; } public void testClsoureVar5 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:d>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } private ICompilationUnit createJava ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addClass ( src , "<STR_LIT>" , CONTENTS ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } private ICompilationUnit createGroovy ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , "<STR_LIT>" , CONTENTS ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } private ICompilationUnit createGroovyForScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , "<STR_LIT>" , SCRIPTCONTENTS ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } private ICompilationUnit createGroovyForScript2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , "<STR_LIT>" , SCRIPTCONTENTS2 ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } private ICompilationUnit createGroovyForSelfReferencingScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , "<STR_LIT>" , SELFREFERENCINGSCRIPT ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class DefaultMethodContentAssistTests extends CompletionTestCase { public DefaultMethodContentAssistTests ( String name ) { super ( name ) ; } public void testDefaultMethods1 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , contents . lastIndexOf ( '<CHAR_LIT:e>' ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:3> ) ; } public void testDefaultMethods2 ( ) throws Exception { create ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = createProposalsAtOffset ( contents , contents . lastIndexOf ( '<CHAR_LIT:e>' ) ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:4> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jface . text . Document ; public class ContentAssistLocationTests extends CompletionTestCase { public ContentAssistLocationTests ( String name ) { super ( name ) ; } public void testStatement1 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:0> , ContentAssistLocation . SCRIPT ) ; } public void testStatement2 ( ) throws Exception { assertLocation ( "<STR_LIT:a>" , <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement3 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:)>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement4 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:)>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement5 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:2> , ContentAssistLocation . SCRIPT ) ; } public void testStatement6 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:3> , ContentAssistLocation . STATEMENT ) ; } public void testStatement7 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:{>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement8 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:{>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement9 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:}>" ) , ContentAssistLocation . STATEMENT ) ; } public void testStatement10 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:}>" ) , ContentAssistLocation . STATEMENT ) ; } public void testStatement11 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:c>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement12 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:b>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement13 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:b>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement14 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:a>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement15 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:a>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testStatement16 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:)>" ) , ContentAssistLocation . STATEMENT ) ; } public void testStatement17 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:)>" ) + <NUM_LIT:1> , ContentAssistLocation . STATEMENT ) ; } public void testExpression ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:b>" ) + <NUM_LIT:1> , ContentAssistLocation . EXPRESSION ) ; } public void testMethodContext1 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext2 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext3 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext5 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext6 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext7 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext8 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext9 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext10 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext11 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext12 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext13 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext14 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext15 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002C>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext16 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:4> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext17 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002CU+0020>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext18 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext19 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testMethodContext20 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:U+002CU+0020>" ) + <NUM_LIT:1> , ContentAssistLocation . METHOD_CONTEXT ) ; } public void testExpression1 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:3> , ContentAssistLocation . EXPRESSION ) ; } public void testExpression2 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:2> , ContentAssistLocation . EXPRESSION ) ; } public void testExpression3 ( ) throws Exception { assertLocation ( "<STR_LIT>" , <NUM_LIT:3> , ContentAssistLocation . EXPRESSION ) ; } public void testExpression4 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . length ( ) , ContentAssistLocation . EXPRESSION ) ; } public void testExpression5 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> , ContentAssistLocation . EXPRESSION ) ; } public void testExpression6 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:c>" ) + <NUM_LIT:1> , ContentAssistLocation . EXPRESSION ) ; } public void testExpression7 ( ) throws Exception { String contents = "<STR_LIT>" ; assertLocation ( contents , contents . indexOf ( "<STR_LIT:b>" ) + <NUM_LIT:1> , ContentAssistLocation . EXPRESSION ) ; } public void _testImport1 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + "<STR_LIT>" . length ( ) ; assertLocation ( contents , loc , ContentAssistLocation . IMPORT ) ; } public void testImport2 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + "<STR_LIT>" . length ( ) ; assertLocation ( contents , loc , ContentAssistLocation . IMPORT ) ; } public void _testImport3 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + "<STR_LIT>" . length ( ) ; assertLocation ( contents , loc , ContentAssistLocation . IMPORT ) ; } public void testImport4 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + "<STR_LIT>" . length ( ) ; assertLocation ( contents , loc , ContentAssistLocation . PACKAGE ) ; } public void testClassBody1 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:{>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . CLASS_BODY ) ; } public void testClassBody2 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:t>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . CLASS_BODY ) ; } public void testClassBody3 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:t>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . CLASS_BODY ) ; } public void testClassBody4 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:4> ; assertLocation ( contents , loc , ContentAssistLocation . EXTENDS ) ; } public void testClassBody5 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:3> ; assertLocation ( contents , loc , ContentAssistLocation . EXTENDS ) ; } public void testClassBody6 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:6> ; assertLocation ( contents , loc , ContentAssistLocation . IMPLEMENTS ) ; } public void testClassBody7 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:3> ; assertLocation ( contents , loc , ContentAssistLocation . IMPLEMENTS ) ; } public void testClassBody8 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:3> ; assertLocation ( contents , loc , ContentAssistLocation . IMPLEMENTS ) ; } public void testClassBody9 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:n>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . CLASS_BODY ) ; } public void testParameters1 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:(>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testParameters2 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testParameters3 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:4> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testParameters4 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:=>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . STATEMENT ) ; } public void testParameters5 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . STATEMENT ) ; } public void testParameters6 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testParameters7 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testParameters8 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:y>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . PARAMETER ) ; } public void testExceptions1 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . EXCEPTIONS ) ; } public void testExceptions2 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:4> ; assertLocation ( contents , loc , ContentAssistLocation . EXCEPTIONS ) ; } public void testExceptions3 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:U+002CU+0020>" ) + <NUM_LIT:3> ; assertLocation ( contents , loc , ContentAssistLocation . EXCEPTIONS ) ; } public void testExceptions4 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . EXCEPTIONS ) ; } public void _testAnnotation1 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:@>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation2 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation2a ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation2b ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void _testAnnotation2d ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:@>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void _testAnnotation3 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:@>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation4 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void _testAnnotation5 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT:@>" ) + <NUM_LIT:1> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation6 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } public void testAnnotation7 ( ) throws Exception { String contents = "<STR_LIT>" ; int loc = contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ; assertLocation ( contents , loc , ContentAssistLocation . ANNOTATION ) ; } void assertLocation ( String contents , int offset , ContentAssistLocation location ) throws Exception { ICompilationUnit unit = create ( contents ) ; GroovyCompletionProposalComputer computer = new GroovyCompletionProposalComputer ( ) ; ContentAssistContext context = computer . createContentAssistContext ( ( GroovyCompilationUnit ) unit , offset , new Document ( unit . getBuffer ( ) . getContents ( ) ) ) ; assertEquals ( "<STR_LIT>" + offset + "<STR_LIT>" + contents , location , context . location ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . stmt . ExpressionStatement ; import org . codehaus . groovy . ast . stmt . ReturnStatement ; import org . codehaus . groovy . ast . stmt . Statement ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyMethodProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . codehaus . groovy . eclipse . test . SynchronizationUtils ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class MethodCompletionTests extends CompletionTestCase { private class MockGroovyMethodProposal extends GroovyMethodProposal { public MockGroovyMethodProposal ( MethodNode method ) { super ( method ) ; } @ Override protected char [ ] [ ] createAllParameterNames ( ICompilationUnit unit ) { return super . createAllParameterNames ( unit ) ; } } public MethodCompletionTests ( String name ) { super ( name ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; env . setAutoBuilding ( true ) ; } public void testAfterParens1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterParens2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterParens3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterParens4 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterParens5 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testAfterParens6 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testParameterNames1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ClassNode clazz = extract ( ( GroovyCompilationUnit ) unit ) ; List < MethodNode > methods = clazz . getMethods ( "<STR_LIT>" ) ; for ( MethodNode method : methods ) { if ( method . getParameters ( ) . length == <NUM_LIT:2> ) { MockGroovyMethodProposal proposal = new MockGroovyMethodProposal ( method ) ; char [ ] [ ] names = proposal . createAllParameterNames ( unit ) ; checkNames ( new char [ ] [ ] { "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) } , names ) ; } } if ( methods . size ( ) != <NUM_LIT:1> ) { fail ( "<STR_LIT>" + methods . size ( ) + "<STR_LIT>" + methods ) ; } } public void testParameterNames2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ClassNode clazz = extract ( ( GroovyCompilationUnit ) unit ) ; List < MethodNode > methods = clazz . getMethods ( "<STR_LIT:m>" ) ; for ( MethodNode method : methods ) { if ( method . getParameters ( ) . length == <NUM_LIT:1> ) { MockGroovyMethodProposal proposal = new MockGroovyMethodProposal ( method ) ; char [ ] [ ] names = proposal . createAllParameterNames ( unit ) ; checkNames ( new char [ ] [ ] { "<STR_LIT:x>" . toCharArray ( ) } , names ) ; } if ( method . getParameters ( ) . length == <NUM_LIT:2> ) { MockGroovyMethodProposal proposal = new MockGroovyMethodProposal ( method ) ; char [ ] [ ] names = proposal . createAllParameterNames ( unit ) ; checkNames ( new char [ ] [ ] { "<STR_LIT:x>" . toCharArray ( ) , "<STR_LIT:y>" . toCharArray ( ) } , names ) ; } } if ( methods . size ( ) != <NUM_LIT:2> ) { fail ( "<STR_LIT>" + methods . size ( ) + "<STR_LIT>" + methods ) ; } } public void testParameterNames3 ( ) throws Exception { env . setAutoBuilding ( false ) ; String contents = "<STR_LIT>" ; create ( contents ) ; GroovyCompilationUnit unit = ( GroovyCompilationUnit ) create ( "<STR_LIT>" , "<STR_LIT>" ) ; env . fullBuild ( ) ; expectingNoProblems ( ) ; List < MethodNode > methods = null ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:5> ; i ++ ) { methods = delegateTestParameterNames ( unit ) ; if ( methods . size ( ) == <NUM_LIT:2> ) { return ; } } fail ( "<STR_LIT>" + methods . size ( ) + "<STR_LIT>" + methods ) ; } public void testParameterNames4 ( ) throws Exception { env . setAutoBuilding ( false ) ; ICompilationUnit unit = create ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; createJava ( "<STR_LIT>" , contents ) ; env . fullBuild ( ) ; List < MethodNode > methods = null ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:5> ; i ++ ) { methods = delegateTestParameterNames ( ( GroovyCompilationUnit ) unit ) ; if ( methods . size ( ) == <NUM_LIT:2> ) { return ; } } fail ( "<STR_LIT>" + methods . size ( ) + "<STR_LIT>" + methods ) ; } public void testParensExprs1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testParensExprs2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testParensExprs3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } private List < MethodNode > delegateTestParameterNames ( GroovyCompilationUnit unit ) throws Exception { SynchronizationUtils . waitForIndexingToComplete ( ) ; ClassNode clazz = extract ( unit ) ; List < MethodNode > methods = clazz . getMethods ( "<STR_LIT:m>" ) ; for ( MethodNode method : methods ) { if ( method . getParameters ( ) . length == <NUM_LIT:1> ) { MockGroovyMethodProposal proposal = new MockGroovyMethodProposal ( method ) ; char [ ] [ ] names = proposal . createAllParameterNames ( unit ) ; checkNames ( new char [ ] [ ] { "<STR_LIT:x>" . toCharArray ( ) } , names ) ; } if ( method . getParameters ( ) . length == <NUM_LIT:2> ) { MockGroovyMethodProposal proposal = new MockGroovyMethodProposal ( method ) ; char [ ] [ ] names = proposal . createAllParameterNames ( unit ) ; checkNames ( new char [ ] [ ] { "<STR_LIT:x>" . toCharArray ( ) , "<STR_LIT:y>" . toCharArray ( ) } , names ) ; } } return methods ; } private void checkNames ( char [ ] [ ] expected , char [ ] [ ] names ) { if ( ! CharOperation . equals ( expected , names ) ) { fail ( "<STR_LIT>" + CharOperation . toString ( expected ) + "<STR_LIT>" + CharOperation . toString ( names ) ) ; } } private ClassNode extract ( GroovyCompilationUnit unit ) { Statement state = ( Statement ) unit . getModuleNode ( ) . getStatementBlock ( ) . getStatements ( ) . get ( <NUM_LIT:0> ) ; if ( state instanceof ReturnStatement ) { ReturnStatement ret = ( ReturnStatement ) state ; return ( ( Expression ) ret . getExpression ( ) ) . getType ( ) ; } else if ( state instanceof ExpressionStatement ) { ExpressionStatement expr = ( ExpressionStatement ) state ; return ( ( Expression ) expr . getExpression ( ) ) . getType ( ) ; } else { fail ( "<STR_LIT>" + state + "<STR_LIT>" ) ; return null ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; public class GuessingCompletionTests extends CompletionTestCase { public GuessingCompletionTests ( ) { super ( "<STR_LIT>" ) ; } public void testParamGuessing1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] [ ] expectedChoices = new String [ ] [ ] { new String [ ] { "<STR_LIT>" , "<STR_LIT>" } } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] [ ] expectedChoices = new String [ ] [ ] { new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] [ ] expectedChoices = new String [ ] [ ] { new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT:0>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT:false>" , "<STR_LIT:true>" } } ; checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } public void testParamGuessing4 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String [ ] [ ] expectedChoices = new String [ ] [ ] { new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } } ; try { checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } catch ( AssertionError e ) { try { checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } catch ( AssertionError e2 ) { checkProposalChoices ( contents , "<STR_LIT>" , "<STR_LIT>" , expectedChoices ) ; } } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class CommandChainCompletionTests extends CompletionTestCase { public CommandChainCompletionTests ( String name ) { super ( name ) ; } private final String INITIAL_CONTENTS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; env . setAutoBuilding ( true ) ; } public void testCommandChain1 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCommandChain2 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCommandChain3 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCommandChain4 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCommandChain5 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testCommandChain6 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testNoCommandChain1 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testNoCommandChain2 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testNoCommandChain3 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testNoCommandChain4 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } String contents = INITIAL_CONTENTS + "<STR_LIT>" ; ICompilationUnit unit = create ( contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getLastIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import java . util . Arrays ; import java . util . HashSet ; import org . codehaus . groovy . eclipse . codeassist . GroovyContentAssistActivator ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyJavaMethodCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . GroovyCompletionProposalComputer ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class DefaultGroovyMethodCompletionTests extends CompletionTestCase { private static final String CONTENTS = "<STR_LIT>" ; private static final String SCRIPTCONTENTS = "<STR_LIT>" ; private static final String CLOSURECONTENTS = "<STR_LIT>" ; private static final String LISTCONTENTS = "<STR_LIT>" ; public DefaultGroovyMethodCompletionTests ( String name ) { super ( name ) ; } public void testDGMInJavaFile ( ) throws Exception { ICompilationUnit unit = createJava ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testDGMInMethodScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGMInMethodScopeFromOther ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGMInConstructorScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGMInScriptScope ( ) throws Exception { ICompilationUnit unit = createGroovyForScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT:n>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGMInScriptOtherClassScope ( ) throws Exception { ICompilationUnit unit = createGroovyForScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGMInClassScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testDGMInMethodParamScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testDGMInConstructorParamScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testDGMInModuleScope ( ) throws Exception { ICompilationUnit unit = createGroovy ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; } public void testDGMInClosure ( ) throws Exception { ICompilationUnit unit = createGroovyForClosure ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( CLOSURECONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testDGSM ( ) throws Exception { ICompilationUnit unit = createGroovyForScript ( ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( SCRIPTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } public void testPopertyVariantOfDGM ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT:text>" , <NUM_LIT:1> ) ; } public void testDateGM ( ) throws Exception { String contents = "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } public void testProcessGM ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT:get>" ) , GroovyCompletionProposalComputer . class ) ; if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT> ) { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } else { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } } public void testXmlGM ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT> ) { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } else { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:4> ) ; } } public void testEncodingGM ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; if ( GroovyUtils . GROOVY_LEVEL >= <NUM_LIT> ) { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } else { proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } } public void testDGMFilter1 ( ) throws Exception { try { setDGMFilter ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; setDGMFilter ( ) ; proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } finally { setDGMFilter ( ) ; } } public void testDGMFilter2 ( ) throws Exception { try { setDGMFilter ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , contents ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:0> ) ; setDGMFilter ( ) ; proposals = performContentAssist ( unit , getIndexOf ( contents , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:1> ) ; } finally { setDGMFilter ( ) ; } } public void testNoDups ( ) throws Exception { ICompilationUnit unit = createGroovyWithContents ( "<STR_LIT>" , LISTCONTENTS ) ; ICompletionProposal [ ] proposals = performContentAssist ( unit , getIndexOf ( LISTCONTENTS , "<STR_LIT>" ) , GroovyCompletionProposalComputer . class ) ; proposalExists ( proposals , "<STR_LIT>" , <NUM_LIT:2> ) ; } private void setDGMFilter ( String ... filter ) { GroovyContentAssistActivator . getDefault ( ) . setFilteredDGMs ( new HashSet < String > ( Arrays . asList ( filter ) ) ) ; } private ICompilationUnit createJava ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addClass ( src , "<STR_LIT>" , CONTENTS ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } private ICompilationUnit createGroovy ( ) throws Exception { return createGroovyWithContents ( "<STR_LIT>" , CONTENTS ) ; } private ICompilationUnit createGroovyForScript ( ) throws Exception { return createGroovyWithContents ( "<STR_LIT>" , SCRIPTCONTENTS ) ; } private ICompilationUnit createGroovyForClosure ( ) throws Exception { return createGroovyWithContents ( "<STR_LIT>" , CLOSURECONTENTS ) ; } private ICompilationUnit createGroovyWithContents ( String name , String contents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath src = projectPath . append ( "<STR_LIT:src>" ) ; IPath pathToJavaClass = env . addGroovyClass ( src , name , contents ) ; incrementalBuild ( ) ; ICompilationUnit unit = getCompilationUnit ( pathToJavaClass ) ; return unit ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . tests ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class RelevanceTests extends CompletionTestCase { public RelevanceTests ( String name ) { super ( name ) ; } private static String NEWLINE = "<STR_LIT>" ; private static String THIS_TO = "<STR_LIT>" ; private static String PU = "<STR_LIT>" ; public void testParamThenFieldThenMethodThenDGM ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , NEWLINE ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT:p>" , "<STR_LIT:f>" , "<STR_LIT>" , "<STR_LIT:m>" , "<STR_LIT>" ) ; } public void testLocalVarThenFieldThenMethodThenDGM ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , NEWLINE ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT:p>" , "<STR_LIT:f>" , "<STR_LIT>" , "<STR_LIT:m>" , "<STR_LIT>" ) ; } public void testObjectMethods ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , THIS_TO ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testOverriddenObjectMethods ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , THIS_TO ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testNewMethodThenModifier ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , PU ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testFieldOfAssignedType1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testFieldOfAssignedType2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testFieldOfAssignedType3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodOfAssignedType1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodOfAssignedType2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodOfAssignedType3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodAndFieldOfAssignedType1 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodAndFieldOfAssignedType2 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testMethodAndFieldOfAssignedType3 ( ) throws Exception { String contents = "<STR_LIT>" ; ICompletionProposal [ ] proposals = orderByRelevance ( createProposalsAtOffset ( contents , getIndexOf ( contents , "<STR_LIT>" ) ) ) ; assertProposalOrdering ( proposals , "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . lang . reflect . Field ; import java . net . URL ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . Map ; import junit . framework . Assert ; import org . codehaus . groovy . activator . GroovyActivator ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTestPlugin ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Status ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . TypeNameRequestor ; import org . eclipse . jdt . core . tests . util . Util ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . util . CoreUtility ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Synchronizer ; import org . eclipse . ui . dialogs . IOverwriteQuery ; import org . osgi . framework . Bundle ; public class JavaProjectHelper { public static final IPath RT_STUBS_13 = new Path ( "<STR_LIT>" ) ; public static final IPath JUNIT_SRC = new Path ( "<STR_LIT>" ) ; public static final IPath RT_STUBS_15 = new Path ( "<STR_LIT>" ) ; public static final IPath RT_STUBS_16 = new Path ( "<STR_LIT>" ) ; public static final IPath JUNIT_SRC_381 = new Path ( "<STR_LIT>" ) ; public static final String JUNIT_SRC_ENCODING = "<STR_LIT>" ; public static final IPath MYLIB = new Path ( "<STR_LIT>" ) ; public static final IPath MYLIB_STDOUT = new Path ( "<STR_LIT>" ) ; public static final IPath MYLIB_SIG = new Path ( "<STR_LIT>" ) ; public static final IPath NLS_LIB = new Path ( "<STR_LIT>" ) ; private static final int MAX_RETRY = <NUM_LIT:5> ; public static final int COUNT_CLASSES_RT_STUBS_15 = <NUM_LIT> ; public static final int COUNT_INTERFACES_RT_STUBS_15 = <NUM_LIT> ; public static final int COUNT_CLASSES_JUNIT_SRC_381 = <NUM_LIT> ; public static final int COUNT_INTERFACES_JUNIT_SRC_381 = <NUM_LIT:8> ; public static final int COUNT_CLASSES_MYLIB = <NUM_LIT:3> ; private static final boolean ASSERT_NO_MIXED_LINE_DELIMIERS = false ; public static IJavaProject createJavaProject ( String projectName , String binFolderName ) throws CoreException { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IProject project = root . getProject ( projectName ) ; if ( ! project . exists ( ) ) { project . create ( null ) ; } else { project . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; } if ( ! project . isOpen ( ) ) { project . open ( null ) ; } IPath outputLocation ; if ( binFolderName != null && binFolderName . length ( ) > <NUM_LIT:0> ) { IFolder binFolder = project . getFolder ( binFolderName ) ; if ( ! binFolder . exists ( ) ) { CoreUtility . createFolder ( binFolder , false , true , null ) ; } outputLocation = binFolder . getFullPath ( ) ; } else { outputLocation = project . getFullPath ( ) ; } if ( ! project . hasNature ( JavaCore . NATURE_ID ) ) { addNatureToProject ( project , JavaCore . NATURE_ID , null ) ; } IJavaProject jproject = JavaCore . create ( project ) ; jproject . setOutputLocation ( outputLocation , null ) ; jproject . setRawClasspath ( new IClasspathEntry [ <NUM_LIT:0> ] , null ) ; return jproject ; } public static IJavaProject createGroovyProject ( String projectName , String binFolderName ) throws CoreException { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IProject project = root . getProject ( projectName ) ; if ( ! project . exists ( ) ) { project . create ( null ) ; } else { project . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; } if ( ! project . isOpen ( ) ) { project . open ( null ) ; } IPath outputLocation ; if ( binFolderName != null && binFolderName . length ( ) > <NUM_LIT:0> ) { IFolder binFolder = project . getFolder ( binFolderName ) ; if ( ! binFolder . exists ( ) ) { CoreUtility . createFolder ( binFolder , false , true , null ) ; } outputLocation = binFolder . getFullPath ( ) ; } else { outputLocation = project . getFullPath ( ) ; } if ( ! project . hasNature ( JavaCore . NATURE_ID ) ) { addNatureToProject ( project , JavaCore . NATURE_ID , null ) ; } if ( ! project . hasNature ( GroovyNature . GROOVY_NATURE ) ) { addNatureToProject ( project , GroovyNature . GROOVY_NATURE , null ) ; } IJavaProject jproject = JavaCore . create ( project ) ; jproject . setOutputLocation ( outputLocation , null ) ; jproject . setRawClasspath ( new IClasspathEntry [ <NUM_LIT:0> ] , null ) ; return jproject ; } public static void set15CompilerOptions ( IJavaProject project ) { Map options = project . getOptions ( false ) ; JavaProjectHelper . set15CompilerOptions ( options ) ; project . setOptions ( options ) ; } public static void set14CompilerOptions ( IJavaProject project ) { Map options = project . getOptions ( false ) ; JavaProjectHelper . set14CompilerOptions ( options ) ; project . setOptions ( options ) ; } public static void set16CompilerOptions ( Map options ) { options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_6 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_6 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_6 ) ; } public static void set15CompilerOptions ( Map options ) { options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_5 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_5 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_5 ) ; } public static void set14CompilerOptions ( Map options ) { options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_4 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . ERROR ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . WARNING ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_2 ) ; } public static void set13CompilerOptions ( Map options ) { options . put ( JavaCore . COMPILER_COMPLIANCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_PB_ASSERT_IDENTIFIER , JavaCore . WARNING ) ; options . put ( JavaCore . COMPILER_PB_ENUM_IDENTIFIER , JavaCore . WARNING ) ; options . put ( JavaCore . COMPILER_SOURCE , JavaCore . VERSION_1_3 ) ; options . put ( JavaCore . COMPILER_CODEGEN_TARGET_PLATFORM , JavaCore . VERSION_1_2 ) ; } public static void delete ( final IJavaElement elem ) throws CoreException { if ( ASSERT_NO_MIXED_LINE_DELIMIERS ) MixedLineDelimiterDetector . assertNoMixedLineDelimiters ( elem ) ; IWorkspaceRunnable runnable = new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor monitor ) throws CoreException { performDummySearch ( ) ; if ( elem instanceof IJavaProject ) { IJavaProject jproject = ( IJavaProject ) elem ; jproject . setRawClasspath ( new IClasspathEntry [ <NUM_LIT:0> ] , jproject . getProject ( ) . getFullPath ( ) , null ) ; } delete ( elem . getResource ( ) ) ; } } ; ResourcesPlugin . getWorkspace ( ) . run ( runnable , null ) ; emptyDisplayLoop ( ) ; } public static void delete ( IResource resource ) throws CoreException { for ( int i = <NUM_LIT:0> ; i < MAX_RETRY ; i ++ ) { try { resource . delete ( true , null ) ; i = MAX_RETRY ; } catch ( CoreException e ) { if ( i == MAX_RETRY - <NUM_LIT:1> ) { JavaPlugin . log ( e ) ; throw e ; } try { Thread . sleep ( <NUM_LIT:1000> ) ; } catch ( InterruptedException e1 ) { } } } } public static void clear ( final IJavaProject jproject , final IClasspathEntry [ ] entries ) throws Exception { performDummySearch ( ) ; IWorkspaceRunnable runnable = new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor monitor ) throws CoreException { jproject . setRawClasspath ( entries , null ) ; IResource [ ] resources = jproject . getProject ( ) . members ( ) ; for ( int i = <NUM_LIT:0> ; i < resources . length ; i ++ ) { if ( ! resources [ i ] . getName ( ) . startsWith ( "<STR_LIT:.>" ) ) { delete ( resources [ i ] ) ; } } } } ; ResourcesPlugin . getWorkspace ( ) . run ( runnable , null ) ; JavaProjectHelper . emptyDisplayLoop ( ) ; } public static void performDummySearch ( ) throws JavaModelException { new SearchEngine ( ) . searchAllTypeNames ( null , SearchPattern . R_EXACT_MATCH , "<STR_LIT>" . toCharArray ( ) , SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE , IJavaSearchConstants . CLASS , SearchEngine . createJavaSearchScope ( new IJavaElement [ <NUM_LIT:0> ] ) , new Requestor ( ) , IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH , null ) ; } public static IPackageFragmentRoot addSourceContainer ( IJavaProject jproject , String containerName ) throws CoreException { return addSourceContainer ( jproject , containerName , new Path [ <NUM_LIT:0> ] ) ; } public static IPackageFragmentRoot addSourceContainer ( IJavaProject jproject , String containerName , IPath [ ] exclusionFilters ) throws CoreException { return addSourceContainer ( jproject , containerName , new Path [ <NUM_LIT:0> ] , exclusionFilters ) ; } public static IPackageFragmentRoot addSourceContainer ( IJavaProject jproject , String containerName , IPath [ ] inclusionFilters , IPath [ ] exclusionFilters ) throws CoreException { return addSourceContainer ( jproject , containerName , inclusionFilters , exclusionFilters , null ) ; } public static IPackageFragmentRoot addSourceContainer ( IJavaProject jproject , String containerName , IPath [ ] inclusionFilters , IPath [ ] exclusionFilters , String outputLocation ) throws CoreException { IProject project = jproject . getProject ( ) ; IContainer container = null ; if ( containerName == null || containerName . length ( ) == <NUM_LIT:0> ) { container = project ; } else { IFolder folder = project . getFolder ( containerName ) ; if ( ! folder . exists ( ) ) { CoreUtility . createFolder ( folder , false , true , null ) ; } container = folder ; } IPackageFragmentRoot root = jproject . getPackageFragmentRoot ( container ) ; IPath outputPath = null ; if ( outputLocation != null ) { IFolder folder = project . getFolder ( outputLocation ) ; if ( ! folder . exists ( ) ) { CoreUtility . createFolder ( folder , false , true , null ) ; } outputPath = folder . getFullPath ( ) ; } IClasspathEntry cpe = JavaCore . newSourceEntry ( root . getPath ( ) , inclusionFilters , exclusionFilters , outputPath ) ; addToClasspath ( jproject , cpe ) ; return root ; } public static void removeSourceContainer ( IJavaProject jproject , String containerName ) throws CoreException { IFolder folder = jproject . getProject ( ) . getFolder ( containerName ) ; removeFromClasspath ( jproject , folder . getFullPath ( ) ) ; folder . delete ( true , null ) ; } public static IPackageFragmentRoot addLibrary ( IJavaProject jproject , IPath path ) throws JavaModelException { return addLibrary ( jproject , path , null , null ) ; } public static IPackageFragmentRoot addLibrary ( IJavaProject jproject , IPath path , IPath sourceAttachPath , IPath sourceAttachRoot ) throws JavaModelException { IClasspathEntry cpe = JavaCore . newLibraryEntry ( path , sourceAttachPath , sourceAttachRoot ) ; addToClasspath ( jproject , cpe ) ; IResource workspaceResource = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . findMember ( path ) ; if ( workspaceResource != null ) { return jproject . getPackageFragmentRoot ( workspaceResource ) ; } return jproject . getPackageFragmentRoot ( path . toString ( ) ) ; } public static IPackageFragmentRoot addLibraryWithImport ( IJavaProject jproject , IPath jarPath , IPath sourceAttachPath , IPath sourceAttachRoot ) throws IOException , CoreException { IProject project = jproject . getProject ( ) ; IFile newFile = project . getFile ( jarPath . lastSegment ( ) ) ; InputStream inputStream = null ; try { inputStream = new FileInputStream ( jarPath . toFile ( ) ) ; newFile . create ( inputStream , true , null ) ; } finally { if ( inputStream != null ) { try { inputStream . close ( ) ; } catch ( IOException e ) { } } } return addLibrary ( jproject , newFile . getFullPath ( ) , sourceAttachPath , sourceAttachRoot ) ; } public static IPackageFragmentRoot addClassFolder ( IJavaProject jproject , String containerName , IPath sourceAttachPath , IPath sourceAttachRoot ) throws CoreException { IProject project = jproject . getProject ( ) ; IContainer container = null ; if ( containerName == null || containerName . length ( ) == <NUM_LIT:0> ) { container = project ; } else { IFolder folder = project . getFolder ( containerName ) ; if ( ! folder . exists ( ) ) { CoreUtility . createFolder ( folder , false , true , null ) ; } container = folder ; } IClasspathEntry cpe = JavaCore . newLibraryEntry ( container . getFullPath ( ) , sourceAttachPath , sourceAttachRoot ) ; addToClasspath ( jproject , cpe ) ; return jproject . getPackageFragmentRoot ( container ) ; } public static IPackageFragmentRoot addRTJar ( IJavaProject jproject ) throws CoreException { return addRTJar15 ( jproject ) ; } public static IPackageFragmentRoot addGroovyJar ( IJavaProject jproject ) throws CoreException { IPath [ ] groovyJarPath = findGroovyJar ( ) ; return addLibrary ( jproject , groovyJarPath [ <NUM_LIT:0> ] , groovyJarPath [ <NUM_LIT:1> ] , groovyJarPath [ <NUM_LIT:2> ] ) ; } public static IPackageFragmentRoot addRTJar13 ( IJavaProject jproject ) throws CoreException { IPath [ ] rtJarPath = findRtJar ( RT_STUBS_13 ) ; Map options = jproject . getOptions ( false ) ; JavaProjectHelper . set13CompilerOptions ( options ) ; jproject . setOptions ( options ) ; return addLibrary ( jproject , rtJarPath [ <NUM_LIT:0> ] , rtJarPath [ <NUM_LIT:1> ] , rtJarPath [ <NUM_LIT:2> ] ) ; } public static IPackageFragmentRoot addRTJar15 ( IJavaProject jproject ) throws CoreException , JavaModelException { IPath [ ] rtJarPath = findRtJar ( RT_STUBS_15 ) ; set15CompilerOptions ( jproject ) ; return addLibrary ( jproject , rtJarPath [ <NUM_LIT:0> ] , rtJarPath [ <NUM_LIT:1> ] , rtJarPath [ <NUM_LIT:2> ] ) ; } public static IPackageFragmentRoot addRTJar16 ( IJavaProject jproject ) throws CoreException { IPath [ ] rtJarPath = findRtJar ( RT_STUBS_16 ) ; Map options = jproject . getOptions ( false ) ; JavaProjectHelper . set16CompilerOptions ( options ) ; jproject . setOptions ( options ) ; return addLibrary ( jproject , rtJarPath [ <NUM_LIT:0> ] , rtJarPath [ <NUM_LIT:1> ] , rtJarPath [ <NUM_LIT:2> ] ) ; } public static IPackageFragmentRoot addVariableEntry ( IJavaProject jproject , IPath path , IPath sourceAttachPath , IPath sourceAttachRoot ) throws JavaModelException { IClasspathEntry cpe = JavaCore . newVariableEntry ( path , sourceAttachPath , sourceAttachRoot ) ; addToClasspath ( jproject , cpe ) ; IPath resolvedPath = JavaCore . getResolvedVariablePath ( path ) ; if ( resolvedPath != null ) { return jproject . getPackageFragmentRoot ( resolvedPath . toString ( ) ) ; } return null ; } public static IPackageFragmentRoot addVariableRTJar13 ( IJavaProject jproject , String libVarName , String srcVarName , String srcrootVarName ) throws CoreException { return addVariableRTJar ( jproject , RT_STUBS_13 , libVarName , srcVarName , srcrootVarName ) ; } public static IPackageFragmentRoot addVariableRTJar ( IJavaProject jproject , String libVarName , String srcVarName , String srcrootVarName ) throws CoreException { return addVariableRTJar ( jproject , RT_STUBS_15 , libVarName , srcVarName , srcrootVarName ) ; } private static IPackageFragmentRoot addVariableRTJar ( IJavaProject jproject , IPath rtStubsPath , String libVarName , String srcVarName , String srcrootVarName ) throws CoreException { IPath [ ] rtJarPaths = findRtJar ( rtStubsPath ) ; IPath libVarPath = new Path ( libVarName ) ; IPath srcVarPath = null ; IPath srcrootVarPath = null ; JavaCore . setClasspathVariable ( libVarName , rtJarPaths [ <NUM_LIT:0> ] , null ) ; if ( srcVarName != null ) { IPath varValue = rtJarPaths [ <NUM_LIT:1> ] != null ? rtJarPaths [ <NUM_LIT:1> ] : Path . EMPTY ; JavaCore . setClasspathVariable ( srcVarName , varValue , null ) ; srcVarPath = new Path ( srcVarName ) ; } if ( srcrootVarName != null ) { IPath varValue = rtJarPaths [ <NUM_LIT:2> ] != null ? rtJarPaths [ <NUM_LIT:2> ] : Path . EMPTY ; JavaCore . setClasspathVariable ( srcrootVarName , varValue , null ) ; srcrootVarPath = new Path ( srcrootVarName ) ; } return addVariableEntry ( jproject , libVarPath , srcVarPath , srcrootVarPath ) ; } public static void addRequiredProject ( IJavaProject jproject , IJavaProject required ) throws JavaModelException { IClasspathEntry cpe = JavaCore . newProjectEntry ( required . getProject ( ) . getFullPath ( ) ) ; addToClasspath ( jproject , cpe ) ; } public static void removeFromClasspath ( IJavaProject jproject , IPath path ) throws JavaModelException { IClasspathEntry [ ] oldEntries = jproject . getRawClasspath ( ) ; int nEntries = oldEntries . length ; ArrayList list = new ArrayList ( nEntries ) ; for ( int i = <NUM_LIT:0> ; i < nEntries ; i ++ ) { IClasspathEntry curr = oldEntries [ i ] ; if ( ! path . equals ( curr . getPath ( ) ) ) { list . add ( curr ) ; } } IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) list . toArray ( new IClasspathEntry [ list . size ( ) ] ) ; jproject . setRawClasspath ( newEntries , null ) ; } public static void addToClasspath ( IJavaProject jproject , IClasspathEntry cpe ) throws JavaModelException { IClasspathEntry [ ] oldEntries = jproject . getRawClasspath ( ) ; for ( int i = <NUM_LIT:0> ; i < oldEntries . length ; i ++ ) { if ( oldEntries [ i ] . equals ( cpe ) ) { return ; } } int nEntries = oldEntries . length ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ nEntries + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , nEntries ) ; newEntries [ nEntries ] = cpe ; jproject . setRawClasspath ( newEntries , null ) ; } public static IPath [ ] findRtJar ( IPath rtStubsPath ) throws CoreException { File rtStubs = RefactoringTestPlugin . getDefault ( ) . getFileInPlugin ( rtStubsPath ) ; Assert . assertNotNull ( rtStubs ) ; Assert . assertTrue ( rtStubs . exists ( ) ) ; return new IPath [ ] { Path . fromOSString ( rtStubs . getPath ( ) ) , null , null } ; } public static IPath [ ] findGroovyJar ( ) throws CoreException { URL installURL = CompilerUtils . getExportedGroovyAllJar ( ) ; URL localURL ; try { localURL = FileLocator . toFileURL ( installURL ) ; } catch ( IOException e ) { throw new CoreException ( new Status ( IStatus . ERROR , RefactoringTestPlugin . getPluginId ( ) , "<STR_LIT>" , e ) ) ; } File groovyJarFile = new File ( localURL . getFile ( ) ) ; Assert . assertNotNull ( groovyJarFile ) ; Assert . assertTrue ( groovyJarFile . exists ( ) ) ; return new IPath [ ] { Path . fromOSString ( groovyJarFile . getPath ( ) ) , null , null } ; } private static void addNatureToProject ( IProject proj , String natureId , IProgressMonitor monitor ) throws CoreException { IProjectDescription description = proj . getDescription ( ) ; String [ ] prevNatures = description . getNatureIds ( ) ; String [ ] newNatures = new String [ prevNatures . length + <NUM_LIT:1> ] ; System . arraycopy ( prevNatures , <NUM_LIT:0> , newNatures , <NUM_LIT:0> , prevNatures . length ) ; newNatures [ prevNatures . length ] = natureId ; description . setNatureIds ( newNatures ) ; proj . setDescription ( description , monitor ) ; } public static void importResources ( IContainer importTarget , Bundle bundle , String bundleSourcePath ) throws CoreException , IOException { Enumeration entryPaths = bundle . getEntryPaths ( bundleSourcePath ) ; while ( entryPaths . hasMoreElements ( ) ) { String path = ( String ) entryPaths . nextElement ( ) ; IPath name = new Path ( path . substring ( bundleSourcePath . length ( ) ) ) ; if ( path . endsWith ( "<STR_LIT:/>" ) ) { IFolder folder = importTarget . getFolder ( name ) ; folder . create ( false , true , null ) ; importResources ( folder , bundle , path ) ; } else { URL url = bundle . getEntry ( path ) ; IFile file = importTarget . getFile ( name ) ; file . create ( url . openStream ( ) , true , null ) ; } } } private static class ImportOverwriteQuery implements IOverwriteQuery { public String queryOverwrite ( String file ) { return ALL ; } } private static class Requestor extends TypeNameRequestor { } public static void emptyDisplayLoop ( ) { boolean showDebugInfo = false ; Display display = Display . getCurrent ( ) ; if ( display != null ) { if ( showDebugInfo ) { try { Synchronizer synchronizer = display . getSynchronizer ( ) ; Field field = Synchronizer . class . getDeclaredField ( "<STR_LIT>" ) ; field . setAccessible ( true ) ; System . out . println ( "<STR_LIT>" + field . getInt ( synchronizer ) + "<STR_LIT>" ) ; } catch ( Exception e ) { System . out . println ( e ) ; } } while ( display . readAndDispatch ( ) ) { } } } public static IPackageFragmentRoot [ ] addRTJars ( IJavaProject project ) throws CoreException { String [ ] javaClassLibs = Util . getJavaClassLibs ( ) ; IPackageFragmentRoot [ ] roots = new IPackageFragmentRoot [ javaClassLibs . length ] ; for ( int i = <NUM_LIT:0> ; i < javaClassLibs . length ; i ++ ) { roots [ i ] = addLibrary ( project , Path . fromOSString ( javaClassLibs [ i ] ) , null , null ) ; } return roots ; } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import java . util . HashMap ; import java . util . Hashtable ; import java . util . Map ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jdt . internal . formatter . align . Alignment ; import org . eclipse . jdt . ui . PreferenceConstants ; import org . eclipse . jdt . internal . ui . JavaPlugin ; public class TestOptions { public static Hashtable getDefaultOptions ( ) { Hashtable result = JavaCore . getDefaultOptions ( ) ; result . put ( JavaCore . COMPILER_PB_LOCAL_VARIABLE_HIDING , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_FIELD_HIDING , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_UNUSED_PRIVATE_MEMBER , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_UNUSED_LOCAL , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_RAW_TYPE_REFERENCE , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_UNUSED_WARNING_TOKEN , JavaCore . IGNORE ) ; result . put ( JavaCore . COMPILER_PB_DEAD_CODE , JavaCore . IGNORE ) ; result . putAll ( TestFormatterOptions . getSettings ( ) ) ; return result ; } public static void initializeCodeGenerationOptions ( ) { IPreferenceStore store = JavaPlugin . getDefault ( ) . getPreferenceStore ( ) ; store . setValue ( PreferenceConstants . CODEGEN_KEYWORD_THIS , false ) ; store . setValue ( PreferenceConstants . CODEGEN_IS_FOR_GETTERS , true ) ; store . setValue ( PreferenceConstants . CODEGEN_EXCEPTION_VAR_NAME , "<STR_LIT:e>" ) ; store . setValue ( PreferenceConstants . CODEGEN_ADD_COMMENTS , true ) ; store . setValue ( PreferenceConstants . ORGIMPORTS_IMPORTORDER , "<STR_LIT>" ) ; store . setValue ( PreferenceConstants . ORGIMPORTS_ONDEMANDTHRESHOLD , <NUM_LIT> ) ; store . setValue ( PreferenceConstants . ORGIMPORTS_IGNORELOWERCASE , true ) ; } public static void initializeProjectOptions ( IJavaProject project ) { Map options = new HashMap ( ) ; JavaProjectHelper . set15CompilerOptions ( options ) ; project . setOptions ( options ) ; } } class TestFormatterOptions { public static Hashtable getSettings ( ) { TestFormatterOptions options = new TestFormatterOptions ( ) ; options . setDefaultSettings ( ) ; return options . getMap ( ) ; } public int alignment_for_arguments_in_allocation_expression ; public int alignment_for_arguments_in_explicit_constructor_call ; public int alignment_for_arguments_in_method_invocation ; public int alignment_for_arguments_in_qualified_allocation_expression ; public int alignment_for_binary_expression ; public int alignment_for_compact_if ; public int alignment_for_conditional_expression ; public int alignment_for_expressions_in_array_initializer ; public int alignment_for_multiple_fields ; public int alignment_for_parameters_in_constructor_declaration ; public int alignment_for_parameters_in_method_declaration ; public int alignment_for_selector_in_method_invocation ; public int alignment_for_superclass_in_type_declaration ; public int alignment_for_superinterfaces_in_type_declaration ; public int alignment_for_throws_clause_in_constructor_declaration ; public int alignment_for_throws_clause_in_method_declaration ; public boolean align_type_members_on_columns ; public String brace_position_for_anonymous_type_declaration ; public String brace_position_for_array_initializer ; public String brace_position_for_block ; public String brace_position_for_block_in_case ; public String brace_position_for_constructor_declaration ; public String brace_position_for_method_declaration ; public String brace_position_for_type_declaration ; public String brace_position_for_switch ; public int continuation_indentation ; public int continuation_indentation_for_array_initializer ; public int blank_lines_after_imports ; public int blank_lines_after_package ; public int blank_lines_before_field ; public int blank_lines_before_first_class_body_declaration ; public int blank_lines_before_imports ; public int blank_lines_before_member_type ; public int blank_lines_before_method ; public int blank_lines_before_new_chunk ; public int blank_lines_before_package ; public int blank_lines_between_type_declarations ; public int blank_lines_at_beginning_of_method_body ; public boolean indent_statements_compare_to_block ; public boolean indent_statements_compare_to_body ; public boolean indent_body_declarations_compare_to_type_header ; public boolean indent_breaks_compare_to_cases ; public boolean indent_switchstatements_compare_to_cases ; public boolean indent_switchstatements_compare_to_switch ; public boolean insert_new_line_after_opening_brace_in_array_initializer ; public boolean insert_new_line_after_annotation_on_member ; public boolean insert_new_line_after_annotation_on_parameter ; public boolean insert_new_line_after_annotation_on_local_variable ; public boolean insert_new_line_at_end_of_file_if_missing ; public boolean insert_new_line_before_catch_in_try_statement ; public boolean insert_new_line_before_closing_brace_in_array_initializer ; public boolean insert_new_line_before_else_in_if_statement ; public boolean insert_new_line_before_finally_in_try_statement ; public boolean insert_new_line_before_while_in_do_statement ; public boolean insert_new_line_in_empty_anonymous_type_declaration ; public boolean insert_new_line_in_empty_block ; public boolean insert_new_line_in_empty_method_body ; public boolean insert_new_line_in_empty_type_declaration ; public boolean insert_space_after_assignment_operator ; public boolean insert_space_after_binary_operator ; public boolean insert_space_after_closing_paren_in_cast ; public boolean insert_space_after_closing_brace_in_block ; public boolean insert_space_after_colon_in_assert ; public boolean insert_space_after_colon_in_case ; public boolean insert_space_after_colon_in_conditional ; public boolean insert_space_after_colon_in_labeled_statement ; public boolean insert_space_after_comma_in_allocation_expression ; public boolean insert_space_after_comma_in_array_initializer ; public boolean insert_space_after_comma_in_constructor_declaration_parameters ; public boolean insert_space_after_comma_in_constructor_declaration_throws ; public boolean insert_space_after_comma_in_explicit_constructor_call_arguments ; public boolean insert_space_after_comma_in_for_increments ; public boolean insert_space_after_comma_in_for_inits ; public boolean insert_space_after_comma_in_method_invocation_arguments ; public boolean insert_space_after_comma_in_method_declaration_parameters ; public boolean insert_space_after_comma_in_method_declaration_throws ; public boolean insert_space_after_comma_in_multiple_field_declarations ; public boolean insert_space_after_comma_in_multiple_local_declarations ; public boolean insert_space_after_comma_in_superinterfaces ; public boolean insert_space_after_opening_bracket_in_array_allocation_expression ; public boolean insert_space_after_opening_bracket_in_array_reference ; public boolean insert_space_after_opening_brace_in_array_initializer ; public boolean insert_space_after_opening_paren_in_cast ; public boolean insert_space_after_opening_paren_in_catch ; public boolean insert_space_after_opening_paren_in_constructor_declaration ; public boolean insert_space_after_opening_paren_in_for ; public boolean insert_space_after_opening_paren_in_if ; public boolean insert_space_after_opening_paren_in_method_declaration ; public boolean insert_space_after_opening_paren_in_method_invocation ; public boolean insert_space_after_opening_paren_in_parenthesized_expression ; public boolean insert_space_after_opening_paren_in_switch ; public boolean insert_space_after_opening_paren_in_synchronized ; public boolean insert_space_after_opening_paren_in_while ; public boolean insert_space_after_postfix_operator ; public boolean insert_space_after_prefix_operator ; public boolean insert_space_after_question_in_conditional ; public boolean insert_space_after_semicolon_in_for ; public boolean insert_space_after_unary_operator ; public boolean insert_space_before_assignment_operator ; public boolean insert_space_before_binary_operator ; public boolean insert_space_before_closing_brace_in_array_initializer ; public boolean insert_space_before_closing_bracket_in_array_allocation_expression ; public boolean insert_space_before_closing_bracket_in_array_reference ; public boolean insert_space_before_closing_paren_in_cast ; public boolean insert_space_before_closing_paren_in_catch ; public boolean insert_space_before_closing_paren_in_constructor_declaration ; public boolean insert_space_before_closing_paren_in_for ; public boolean insert_space_before_closing_paren_in_if ; public boolean insert_space_before_closing_paren_in_method_declaration ; public boolean insert_space_before_closing_paren_in_method_invocation ; public boolean insert_space_before_closing_paren_in_parenthesized_expression ; public boolean insert_space_before_closing_paren_in_switch ; public boolean insert_space_before_closing_paren_in_synchronized ; public boolean insert_space_before_closing_paren_in_while ; public boolean insert_space_before_colon_in_assert ; public boolean insert_space_before_colon_in_case ; public boolean insert_space_before_colon_in_conditional ; public boolean insert_space_before_colon_in_default ; public boolean insert_space_before_colon_in_labeled_statement ; public boolean insert_space_before_comma_in_allocation_expression ; public boolean insert_space_before_comma_in_array_initializer ; public boolean insert_space_before_comma_in_constructor_declaration_parameters ; public boolean insert_space_before_comma_in_constructor_declaration_throws ; public boolean insert_space_before_comma_in_explicit_constructor_call_arguments ; public boolean insert_space_before_comma_in_for_increments ; public boolean insert_space_before_comma_in_for_inits ; public boolean insert_space_before_comma_in_method_invocation_arguments ; public boolean insert_space_before_comma_in_method_declaration_parameters ; public boolean insert_space_before_comma_in_method_declaration_throws ; public boolean insert_space_before_comma_in_multiple_field_declarations ; public boolean insert_space_before_comma_in_multiple_local_declarations ; public boolean insert_space_before_comma_in_superinterfaces ; public boolean insert_space_before_opening_brace_in_anonymous_type_declaration ; public boolean insert_space_before_opening_brace_in_array_initializer ; public boolean insert_space_before_opening_brace_in_block ; public boolean insert_space_before_opening_brace_in_constructor_declaration ; public boolean insert_space_before_opening_brace_in_method_declaration ; public boolean insert_space_before_opening_brace_in_type_declaration ; public boolean insert_space_before_opening_bracket_in_array_allocation_expression ; public boolean insert_space_before_opening_bracket_in_array_reference ; public boolean insert_space_before_opening_bracket_in_array_type_reference ; public boolean insert_space_before_opening_paren_in_catch ; public boolean insert_space_before_opening_paren_in_constructor_declaration ; public boolean insert_space_before_opening_paren_in_for ; public boolean insert_space_before_opening_paren_in_if ; public boolean insert_space_before_opening_paren_in_method_invocation ; public boolean insert_space_before_opening_paren_in_method_declaration ; public boolean insert_space_before_opening_paren_in_switch ; public boolean insert_space_before_opening_brace_in_switch ; public boolean insert_space_before_opening_paren_in_synchronized ; public boolean insert_space_before_opening_paren_in_parenthesized_expression ; public boolean insert_space_before_opening_paren_in_while ; public boolean insert_space_before_postfix_operator ; public boolean insert_space_before_prefix_operator ; public boolean insert_space_before_question_in_conditional ; public boolean insert_space_before_semicolon ; public boolean insert_space_before_semicolon_in_for ; public boolean insert_space_before_unary_operator ; public boolean insert_space_between_brackets_in_array_type_reference ; public boolean insert_space_between_empty_braces_in_array_initializer ; public boolean insert_space_between_empty_brackets_in_array_allocation_expression ; public boolean insert_space_between_empty_parens_in_constructor_declaration ; public boolean insert_space_between_empty_parens_in_method_declaration ; public boolean insert_space_between_empty_parens_in_method_invocation ; public boolean compact_else_if ; public boolean keep_guardian_clause_on_one_line ; public boolean keep_else_statement_on_same_line ; public boolean keep_empty_array_initializer_on_one_line ; public boolean keep_simple_if_on_one_line ; public boolean keep_then_statement_on_same_line ; public boolean never_indent_block_comments_on_first_column ; public boolean never_indent_line_comments_on_first_column ; public int number_of_empty_lines_to_preserve ; public boolean put_empty_statement_on_new_line ; public int tab_size ; public final char filling_space = '<CHAR_LIT:U+0020>' ; public int page_width ; public boolean use_tab ; public boolean wrapBeforeBinaryOperator ; public int initial_indentation_level ; public String line_separator ; private TestFormatterOptions ( ) { } private String getAlignment ( int alignment ) { return Integer . toString ( alignment ) ; } private Hashtable getMap ( ) { Hashtable options = new Hashtable ( ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION , getAlignment ( this . alignment_for_arguments_in_allocation_expression ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL , getAlignment ( this . alignment_for_arguments_in_explicit_constructor_call ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION , getAlignment ( this . alignment_for_arguments_in_method_invocation ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION , getAlignment ( this . alignment_for_arguments_in_qualified_allocation_expression ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION , getAlignment ( this . alignment_for_binary_expression ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_COMPACT_IF , getAlignment ( this . alignment_for_compact_if ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION , getAlignment ( this . alignment_for_conditional_expression ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER , getAlignment ( this . alignment_for_expressions_in_array_initializer ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS , getAlignment ( this . alignment_for_multiple_fields ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION , getAlignment ( this . alignment_for_parameters_in_constructor_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION , getAlignment ( this . alignment_for_parameters_in_method_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION , getAlignment ( this . alignment_for_selector_in_method_invocation ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_SUPERCLASS_IN_TYPE_DECLARATION , getAlignment ( this . alignment_for_superclass_in_type_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_SUPERINTERFACES_IN_TYPE_DECLARATION , getAlignment ( this . alignment_for_superinterfaces_in_type_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_CONSTRUCTOR_DECLARATION , getAlignment ( this . alignment_for_throws_clause_in_constructor_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_METHOD_DECLARATION , getAlignment ( this . alignment_for_throws_clause_in_method_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_ALIGN_TYPE_MEMBERS_ON_COLUMNS , this . align_type_members_on_columns ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_ANONYMOUS_TYPE_DECLARATION , this . brace_position_for_anonymous_type_declaration ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER , this . brace_position_for_array_initializer ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_BLOCK , this . brace_position_for_block ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_BLOCK_IN_CASE , this . brace_position_for_block_in_case ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_CONSTRUCTOR_DECLARATION , this . brace_position_for_constructor_declaration ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION , this . brace_position_for_method_declaration ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION , this . brace_position_for_type_declaration ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BRACE_POSITION_FOR_SWITCH , this . brace_position_for_switch ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_CONTINUATION_INDENTATION , Integer . toString ( this . continuation_indentation ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER , Integer . toString ( this . continuation_indentation_for_array_initializer ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_AFTER_IMPORTS , Integer . toString ( this . blank_lines_after_imports ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_AFTER_PACKAGE , Integer . toString ( this . blank_lines_after_package ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_FIELD , Integer . toString ( this . blank_lines_before_field ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_FIRST_CLASS_BODY_DECLARATION , Integer . toString ( this . blank_lines_before_first_class_body_declaration ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_IMPORTS , Integer . toString ( this . blank_lines_before_imports ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_MEMBER_TYPE , Integer . toString ( this . blank_lines_before_member_type ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_METHOD , Integer . toString ( this . blank_lines_before_method ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_NEW_CHUNK , Integer . toString ( this . blank_lines_before_new_chunk ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BEFORE_PACKAGE , Integer . toString ( this . blank_lines_before_package ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_BETWEEN_TYPE_DECLARATIONS , Integer . toString ( this . blank_lines_between_type_declarations ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_BLANK_LINES_AT_BEGINNING_OF_METHOD_BODY , Integer . toString ( this . blank_lines_at_beginning_of_method_body ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK , this . indent_statements_compare_to_block ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BODY , this . indent_statements_compare_to_body ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_TYPE_HEADER , this . indent_body_declarations_compare_to_type_header ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES , this . indent_breaks_compare_to_cases ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES , this . indent_switchstatements_compare_to_cases ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH , this . indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER , this . insert_new_line_after_opening_brace_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER , this . insert_new_line_after_annotation_on_member ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER , this . insert_new_line_after_annotation_on_parameter ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE , this . insert_new_line_after_annotation_on_local_variable ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING , this . insert_new_line_at_end_of_file_if_missing ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT , this . insert_new_line_before_catch_in_try_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER , this . insert_new_line_before_closing_brace_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT , this . insert_new_line_before_else_in_if_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT , this . insert_new_line_before_finally_in_try_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT , this . insert_new_line_before_while_in_do_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANONYMOUS_TYPE_DECLARATION , this . insert_new_line_in_empty_anonymous_type_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK , this . insert_new_line_in_empty_block ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY , this . insert_new_line_in_empty_method_body ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION , this . insert_new_line_in_empty_type_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR , this . insert_space_after_assignment_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR , this . insert_space_after_binary_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_CLOSING_PAREN_IN_CAST , this . insert_space_after_closing_paren_in_cast ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_CLOSING_BRACE_IN_BLOCK , this . insert_space_after_closing_brace_in_block ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COLON_IN_ASSERT , this . insert_space_after_colon_in_assert ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COLON_IN_CASE , this . insert_space_after_colon_in_case ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COLON_IN_CONDITIONAL , this . insert_space_after_colon_in_conditional ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COLON_IN_LABELED_STATEMENT , this . insert_space_after_colon_in_labeled_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ALLOCATION_EXPRESSION , this . insert_space_after_comma_in_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_ARRAY_INITIALIZER , this . insert_space_after_comma_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_CONSTRUCTOR_DECLARATION_PARAMETERS , this . insert_space_after_comma_in_constructor_declaration_parameters ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_CONSTRUCTOR_DECLARATION_THROWS , this . insert_space_after_comma_in_constructor_declaration_throws ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_EXPLICIT_CONSTRUCTOR_CALL_ARGUMENTS , this . insert_space_after_comma_in_explicit_constructor_call_arguments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_FOR_INCREMENTS , this . insert_space_after_comma_in_for_increments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_FOR_INITS , this . insert_space_after_comma_in_for_inits ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_INVOCATION_ARGUMENTS , this . insert_space_after_comma_in_method_invocation_arguments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS , this . insert_space_after_comma_in_method_declaration_parameters ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_THROWS , this . insert_space_after_comma_in_method_declaration_throws ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_MULTIPLE_FIELD_DECLARATIONS , this . insert_space_after_comma_in_multiple_field_declarations ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_MULTIPLE_LOCAL_DECLARATIONS , this . insert_space_after_comma_in_multiple_local_declarations ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_SUPERINTERFACES , this . insert_space_after_comma_in_superinterfaces ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACKET_IN_ARRAY_ALLOCATION_EXPRESSION , this . insert_space_after_opening_bracket_in_array_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACKET_IN_ARRAY_REFERENCE , this . insert_space_after_opening_bracket_in_array_reference ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER , this . insert_space_after_opening_brace_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CAST , this . insert_space_after_opening_paren_in_cast ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CATCH , this . insert_space_after_opening_paren_in_catch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_CONSTRUCTOR_DECLARATION , this . insert_space_after_opening_paren_in_constructor_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_FOR , this . insert_space_after_opening_paren_in_for ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_IF , this . insert_space_after_opening_paren_in_if ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_DECLARATION , this . insert_space_after_opening_paren_in_method_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_INVOCATION , this . insert_space_after_opening_paren_in_method_invocation ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_PARENTHESIZED_EXPRESSION , this . insert_space_after_opening_paren_in_parenthesized_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_SWITCH , this . insert_space_after_opening_paren_in_switch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_SYNCHRONIZED , this . insert_space_after_opening_paren_in_synchronized ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_WHILE , this . insert_space_after_opening_paren_in_while ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_POSTFIX_OPERATOR , this . insert_space_after_postfix_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_PREFIX_OPERATOR , this . insert_space_after_prefix_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_QUESTION_IN_CONDITIONAL , this . insert_space_after_question_in_conditional ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_SEMICOLON_IN_FOR , this . insert_space_after_semicolon_in_for ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_AFTER_UNARY_OPERATOR , this . insert_space_after_unary_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR , this . insert_space_before_assignment_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR , this . insert_space_before_binary_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER , this . insert_space_before_closing_brace_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACKET_IN_ARRAY_ALLOCATION_EXPRESSION , this . insert_space_before_closing_bracket_in_array_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACKET_IN_ARRAY_REFERENCE , this . insert_space_before_closing_bracket_in_array_reference ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_CAST , this . insert_space_before_closing_paren_in_cast ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_CATCH , this . insert_space_before_closing_paren_in_catch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_CONSTRUCTOR_DECLARATION , this . insert_space_before_closing_paren_in_constructor_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_FOR , this . insert_space_before_closing_paren_in_for ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_IF , this . insert_space_before_closing_paren_in_if ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_DECLARATION , this . insert_space_before_closing_paren_in_method_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_INVOCATION , this . insert_space_before_closing_paren_in_method_invocation ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_PARENTHESIZED_EXPRESSION , this . insert_space_before_closing_paren_in_parenthesized_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_SWITCH , this . insert_space_before_closing_paren_in_switch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_SYNCHRONIZED , this . insert_space_before_closing_paren_in_synchronized ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_WHILE , this . insert_space_before_closing_paren_in_while ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_ASSERT , this . insert_space_before_colon_in_assert ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_CASE , this . insert_space_before_colon_in_case ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_CONDITIONAL , this . insert_space_before_colon_in_conditional ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_DEFAULT , this . insert_space_before_colon_in_default ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COLON_IN_LABELED_STATEMENT , this . insert_space_before_colon_in_labeled_statement ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ALLOCATION_EXPRESSION , this . insert_space_before_comma_in_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_ARRAY_INITIALIZER , this . insert_space_before_comma_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_CONSTRUCTOR_DECLARATION_PARAMETERS , this . insert_space_before_comma_in_constructor_declaration_parameters ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_CONSTRUCTOR_DECLARATION_THROWS , this . insert_space_before_comma_in_constructor_declaration_throws ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_EXPLICIT_CONSTRUCTOR_CALL_ARGUMENTS , this . insert_space_before_comma_in_explicit_constructor_call_arguments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_FOR_INCREMENTS , this . insert_space_before_comma_in_for_increments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_FOR_INITS , this . insert_space_before_comma_in_for_inits ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_INVOCATION_ARGUMENTS , this . insert_space_before_comma_in_method_invocation_arguments ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_DECLARATION_PARAMETERS , this . insert_space_before_comma_in_method_declaration_parameters ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_METHOD_DECLARATION_THROWS , this . insert_space_before_comma_in_method_declaration_throws ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_MULTIPLE_FIELD_DECLARATIONS , this . insert_space_before_comma_in_multiple_field_declarations ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_MULTIPLE_LOCAL_DECLARATIONS , this . insert_space_before_comma_in_multiple_local_declarations ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_COMMA_IN_SUPERINTERFACES , this . insert_space_before_comma_in_superinterfaces ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ANONYMOUS_TYPE_DECLARATION , this . insert_space_before_opening_brace_in_anonymous_type_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER , this . insert_space_before_opening_brace_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_BLOCK , this . insert_space_before_opening_brace_in_block ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_CONSTRUCTOR_DECLARATION , this . insert_space_before_opening_brace_in_constructor_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_METHOD_DECLARATION , this . insert_space_before_opening_brace_in_method_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_TYPE_DECLARATION , this . insert_space_before_opening_brace_in_type_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACKET_IN_ARRAY_ALLOCATION_EXPRESSION , this . insert_space_before_opening_bracket_in_array_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACKET_IN_ARRAY_REFERENCE , this . insert_space_before_opening_bracket_in_array_reference ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACKET_IN_ARRAY_TYPE_REFERENCE , this . insert_space_before_opening_bracket_in_array_type_reference ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_CATCH , this . insert_space_before_opening_paren_in_catch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_CONSTRUCTOR_DECLARATION , this . insert_space_before_opening_paren_in_constructor_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_FOR , this . insert_space_before_opening_paren_in_for ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_IF , this . insert_space_before_opening_paren_in_if ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_INVOCATION , this . insert_space_before_opening_paren_in_method_invocation ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_DECLARATION , this . insert_space_before_opening_paren_in_method_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_SWITCH , this . insert_space_before_opening_paren_in_switch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_SWITCH , this . insert_space_before_opening_brace_in_switch ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_SYNCHRONIZED , this . insert_space_before_opening_paren_in_synchronized ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_PARENTHESIZED_EXPRESSION , this . insert_space_before_opening_paren_in_parenthesized_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_WHILE , this . insert_space_before_opening_paren_in_while ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_POSTFIX_OPERATOR , this . insert_space_before_postfix_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_PREFIX_OPERATOR , this . insert_space_before_prefix_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_QUESTION_IN_CONDITIONAL , this . insert_space_before_question_in_conditional ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON , this . insert_space_before_semicolon ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON_IN_FOR , this . insert_space_before_semicolon_in_for ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BEFORE_UNARY_OPERATOR , this . insert_space_before_unary_operator ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_BRACKETS_IN_ARRAY_TYPE_REFERENCE , this . insert_space_between_brackets_in_array_type_reference ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACES_IN_ARRAY_INITIALIZER , this . insert_space_between_empty_braces_in_array_initializer ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_BRACKETS_IN_ARRAY_ALLOCATION_EXPRESSION , this . insert_space_between_empty_brackets_in_array_allocation_expression ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_CONSTRUCTOR_DECLARATION , this . insert_space_between_empty_parens_in_constructor_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_METHOD_DECLARATION , this . insert_space_between_empty_parens_in_method_declaration ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_INSERT_SPACE_BETWEEN_EMPTY_PARENS_IN_METHOD_INVOCATION , this . insert_space_between_empty_parens_in_method_invocation ? JavaCore . INSERT : JavaCore . DO_NOT_INSERT ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_COMPACT_ELSE_IF , this . compact_else_if ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_KEEP_GUARDIAN_CLAUSE_ON_ONE_LINE , this . keep_guardian_clause_on_one_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_KEEP_ELSE_STATEMENT_ON_SAME_LINE , this . keep_else_statement_on_same_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_KEEP_EMPTY_ARRAY_INITIALIZER_ON_ONE_LINE , this . keep_empty_array_initializer_on_one_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_KEEP_SIMPLE_IF_ON_ONE_LINE , this . keep_simple_if_on_one_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_KEEP_THEN_STATEMENT_ON_SAME_LINE , this . keep_then_statement_on_same_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE , Integer . toString ( this . number_of_empty_lines_to_preserve ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE , this . put_empty_statement_on_new_line ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_LINE_SPLIT , Integer . toString ( this . page_width ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , this . use_tab ? JavaCore . TAB : JavaCore . SPACE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , Integer . toString ( this . tab_size ) ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_WRAP_BEFORE_BINARY_OPERATOR , this . wrapBeforeBinaryOperator ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN , this . never_indent_block_comments_on_first_column ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN , this . never_indent_line_comments_on_first_column ? DefaultCodeFormatterConstants . TRUE : DefaultCodeFormatterConstants . FALSE ) ; return options ; } private void setDefaultSettings ( ) { this . alignment_for_arguments_in_allocation_expression = Alignment . M_COMPACT_SPLIT ; this . alignment_for_arguments_in_explicit_constructor_call = Alignment . M_COMPACT_SPLIT ; this . alignment_for_arguments_in_method_invocation = Alignment . M_COMPACT_SPLIT ; this . alignment_for_arguments_in_qualified_allocation_expression = Alignment . M_COMPACT_SPLIT ; this . alignment_for_binary_expression = Alignment . M_COMPACT_SPLIT ; this . alignment_for_compact_if = Alignment . M_ONE_PER_LINE_SPLIT | Alignment . M_INDENT_BY_ONE ; this . alignment_for_conditional_expression = Alignment . M_ONE_PER_LINE_SPLIT ; this . alignment_for_expressions_in_array_initializer = Alignment . M_COMPACT_SPLIT ; this . alignment_for_multiple_fields = Alignment . M_COMPACT_SPLIT ; this . alignment_for_parameters_in_constructor_declaration = Alignment . M_COMPACT_SPLIT ; this . alignment_for_parameters_in_method_declaration = Alignment . M_COMPACT_SPLIT ; this . alignment_for_selector_in_method_invocation = Alignment . M_COMPACT_SPLIT ; this . alignment_for_superclass_in_type_declaration = Alignment . M_NEXT_SHIFTED_SPLIT ; this . alignment_for_superinterfaces_in_type_declaration = Alignment . M_NEXT_SHIFTED_SPLIT ; this . alignment_for_throws_clause_in_constructor_declaration = Alignment . M_COMPACT_SPLIT ; this . alignment_for_throws_clause_in_method_declaration = Alignment . M_COMPACT_SPLIT ; this . align_type_members_on_columns = false ; this . brace_position_for_anonymous_type_declaration = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_array_initializer = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_block = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_block_in_case = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_constructor_declaration = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_method_declaration = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_type_declaration = DefaultCodeFormatterConstants . END_OF_LINE ; this . brace_position_for_switch = DefaultCodeFormatterConstants . END_OF_LINE ; this . continuation_indentation = <NUM_LIT:2> ; this . continuation_indentation_for_array_initializer = <NUM_LIT:2> ; this . blank_lines_after_imports = <NUM_LIT:0> ; this . blank_lines_after_package = <NUM_LIT:0> ; this . blank_lines_before_field = <NUM_LIT:0> ; this . blank_lines_before_first_class_body_declaration = <NUM_LIT:0> ; this . blank_lines_before_imports = <NUM_LIT:0> ; this . blank_lines_before_member_type = <NUM_LIT:0> ; this . blank_lines_before_method = <NUM_LIT:0> ; this . blank_lines_before_new_chunk = <NUM_LIT:0> ; this . blank_lines_before_package = <NUM_LIT:0> ; this . blank_lines_between_type_declarations = <NUM_LIT:0> ; this . blank_lines_at_beginning_of_method_body = <NUM_LIT:0> ; this . indent_statements_compare_to_block = true ; this . indent_statements_compare_to_body = true ; this . indent_body_declarations_compare_to_type_header = true ; this . indent_breaks_compare_to_cases = true ; this . indent_switchstatements_compare_to_cases = true ; this . indent_switchstatements_compare_to_switch = true ; this . insert_new_line_after_annotation_on_member = true ; this . insert_new_line_after_annotation_on_parameter = false ; this . insert_new_line_after_annotation_on_local_variable = true ; this . insert_new_line_at_end_of_file_if_missing = false ; this . insert_new_line_after_opening_brace_in_array_initializer = false ; this . insert_new_line_before_catch_in_try_statement = false ; this . insert_new_line_before_closing_brace_in_array_initializer = false ; this . insert_new_line_before_else_in_if_statement = false ; this . insert_new_line_before_finally_in_try_statement = false ; this . insert_new_line_before_while_in_do_statement = false ; this . insert_new_line_in_empty_anonymous_type_declaration = true ; this . insert_new_line_in_empty_block = true ; this . insert_new_line_in_empty_method_body = true ; this . insert_new_line_in_empty_type_declaration = true ; this . insert_space_after_assignment_operator = true ; this . insert_space_after_binary_operator = true ; this . insert_space_after_closing_paren_in_cast = true ; this . insert_space_after_closing_brace_in_block = true ; this . insert_space_after_colon_in_assert = true ; this . insert_space_after_colon_in_case = true ; this . insert_space_after_colon_in_conditional = true ; this . insert_space_after_colon_in_labeled_statement = true ; this . insert_space_after_comma_in_allocation_expression = true ; this . insert_space_after_comma_in_array_initializer = true ; this . insert_space_after_comma_in_constructor_declaration_parameters = true ; this . insert_space_after_comma_in_constructor_declaration_throws = true ; this . insert_space_after_comma_in_explicit_constructor_call_arguments = true ; this . insert_space_after_comma_in_for_increments = true ; this . insert_space_after_comma_in_for_inits = true ; this . insert_space_after_comma_in_method_invocation_arguments = true ; this . insert_space_after_comma_in_method_declaration_parameters = true ; this . insert_space_after_comma_in_method_declaration_throws = true ; this . insert_space_after_comma_in_multiple_field_declarations = true ; this . insert_space_after_comma_in_multiple_local_declarations = true ; this . insert_space_after_comma_in_superinterfaces = true ; this . insert_space_after_opening_bracket_in_array_allocation_expression = false ; this . insert_space_after_opening_bracket_in_array_reference = false ; this . insert_space_after_opening_brace_in_array_initializer = false ; this . insert_space_after_opening_paren_in_cast = false ; this . insert_space_after_opening_paren_in_catch = false ; this . insert_space_after_opening_paren_in_constructor_declaration = false ; this . insert_space_after_opening_paren_in_for = false ; this . insert_space_after_opening_paren_in_if = false ; this . insert_space_after_opening_paren_in_method_declaration = false ; this . insert_space_after_opening_paren_in_method_invocation = false ; this . insert_space_after_opening_paren_in_parenthesized_expression = false ; this . insert_space_after_opening_paren_in_switch = false ; this . insert_space_after_opening_paren_in_synchronized = false ; this . insert_space_after_opening_paren_in_while = false ; this . insert_space_after_postfix_operator = false ; this . insert_space_after_prefix_operator = false ; this . insert_space_after_question_in_conditional = true ; this . insert_space_after_semicolon_in_for = true ; this . insert_space_after_unary_operator = false ; this . insert_space_before_assignment_operator = true ; this . insert_space_before_binary_operator = true ; this . insert_space_before_closing_brace_in_array_initializer = false ; this . insert_space_before_closing_bracket_in_array_allocation_expression = false ; this . insert_space_before_closing_bracket_in_array_reference = false ; this . insert_space_before_closing_paren_in_cast = false ; this . insert_space_before_closing_paren_in_catch = false ; this . insert_space_before_closing_paren_in_constructor_declaration = false ; this . insert_space_before_closing_paren_in_for = false ; this . insert_space_before_closing_paren_in_if = false ; this . insert_space_before_closing_paren_in_method_declaration = false ; this . insert_space_before_closing_paren_in_method_invocation = false ; this . insert_space_before_closing_paren_in_parenthesized_expression = false ; this . insert_space_before_closing_paren_in_switch = false ; this . insert_space_before_closing_paren_in_synchronized = false ; this . insert_space_before_closing_paren_in_while = false ; this . insert_space_before_colon_in_assert = true ; this . insert_space_before_colon_in_case = true ; this . insert_space_before_colon_in_conditional = true ; this . insert_space_before_colon_in_default = true ; this . insert_space_before_colon_in_labeled_statement = true ; this . insert_space_before_comma_in_allocation_expression = false ; this . insert_space_before_comma_in_array_initializer = false ; this . insert_space_before_comma_in_constructor_declaration_parameters = false ; this . insert_space_before_comma_in_constructor_declaration_throws = false ; this . insert_space_before_comma_in_explicit_constructor_call_arguments = false ; this . insert_space_before_comma_in_for_increments = false ; this . insert_space_before_comma_in_for_inits = false ; this . insert_space_before_comma_in_method_invocation_arguments = false ; this . insert_space_before_comma_in_method_declaration_parameters = false ; this . insert_space_before_comma_in_method_declaration_throws = false ; this . insert_space_before_comma_in_multiple_field_declarations = false ; this . insert_space_before_comma_in_multiple_local_declarations = false ; this . insert_space_before_comma_in_superinterfaces = false ; this . insert_space_before_opening_brace_in_anonymous_type_declaration = true ; this . insert_space_before_opening_brace_in_array_initializer = false ; this . insert_space_before_opening_brace_in_block = true ; this . insert_space_before_opening_brace_in_constructor_declaration = true ; this . insert_space_before_opening_brace_in_method_declaration = true ; this . insert_space_before_opening_brace_in_switch = true ; this . insert_space_before_opening_brace_in_type_declaration = true ; this . insert_space_before_opening_bracket_in_array_allocation_expression = false ; this . insert_space_before_opening_bracket_in_array_reference = false ; this . insert_space_before_opening_bracket_in_array_type_reference = false ; this . insert_space_before_opening_paren_in_catch = true ; this . insert_space_before_opening_paren_in_constructor_declaration = false ; this . insert_space_before_opening_paren_in_for = true ; this . insert_space_before_opening_paren_in_if = true ; this . insert_space_before_opening_paren_in_method_invocation = false ; this . insert_space_before_opening_paren_in_method_declaration = false ; this . insert_space_before_opening_paren_in_switch = true ; this . insert_space_before_opening_paren_in_synchronized = true ; this . insert_space_before_opening_paren_in_parenthesized_expression = false ; this . insert_space_before_opening_paren_in_while = true ; this . insert_space_before_postfix_operator = false ; this . insert_space_before_prefix_operator = false ; this . insert_space_before_question_in_conditional = true ; this . insert_space_before_semicolon = false ; this . insert_space_before_semicolon_in_for = false ; this . insert_space_before_unary_operator = false ; this . insert_space_between_brackets_in_array_type_reference = false ; this . insert_space_between_empty_braces_in_array_initializer = false ; this . insert_space_between_empty_brackets_in_array_allocation_expression = false ; this . insert_space_between_empty_parens_in_constructor_declaration = false ; this . insert_space_between_empty_parens_in_method_declaration = false ; this . insert_space_between_empty_parens_in_method_invocation = false ; this . compact_else_if = true ; this . keep_guardian_clause_on_one_line = false ; this . keep_else_statement_on_same_line = false ; this . keep_empty_array_initializer_on_one_line = true ; this . keep_simple_if_on_one_line = false ; this . keep_then_statement_on_same_line = false ; this . number_of_empty_lines_to_preserve = <NUM_LIT:1> ; this . put_empty_statement_on_new_line = false ; this . tab_size = <NUM_LIT:4> ; this . page_width = <NUM_LIT> ; this . use_tab = true ; this . wrapBeforeBinaryOperator = true ; this . never_indent_block_comments_on_first_column = false ; this . never_indent_line_comments_on_first_column = false ; } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import java . lang . reflect . Method ; import java . util . HashSet ; import java . util . Iterator ; import java . util . Set ; import junit . framework . Test ; import junit . framework . TestCase ; import junit . framework . TestSuite ; public class OrderedTestSuite extends TestSuite { public OrderedTestSuite ( final Class testClass , String [ ] testMethods ) { super ( testClass . getName ( ) ) ; Set existingMethods = new HashSet ( ) ; Method [ ] methods = testClass . getMethods ( ) ; for ( int i = <NUM_LIT:0> ; i < methods . length ; i ++ ) { Method method = methods [ i ] ; existingMethods . add ( method . getName ( ) ) ; } for ( int i = <NUM_LIT:0> ; i < testMethods . length ; i ++ ) { final String testMethod = testMethods [ i ] ; if ( existingMethods . remove ( testMethod ) ) { addTest ( createTest ( testClass , testMethod ) ) ; } else { addTest ( error ( testMethod , new IllegalArgumentException ( "<STR_LIT>" + testClass . getName ( ) + "<STR_LIT>" + testMethod + "<STR_LIT>" ) ) ) ; } } for ( Iterator iter = existingMethods . iterator ( ) ; iter . hasNext ( ) ; ) { String existingMethod = ( String ) iter . next ( ) ; if ( existingMethod . startsWith ( "<STR_LIT:test>" ) ) { addTest ( error ( existingMethod , new IllegalArgumentException ( "<STR_LIT>" + existingMethod + "<STR_LIT>" + testClass . getName ( ) + "<STR_LIT>" ) ) ) ; } } } public static Test error ( String testMethod , Exception exception ) { final Throwable e2 = exception . fillInStackTrace ( ) ; return new TestCase ( testMethod ) { protected void runTest ( ) throws Throwable { throw e2 ; } } ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Label ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . swt . widgets . Text ; import org . eclipse . jface . dialogs . Dialog ; import org . eclipse . jface . dialogs . IDialogConstants ; import org . eclipse . jface . resource . JFaceResources ; public class FailureDialog extends Dialog { private Text _text ; private String _log ; private int SIZING_TEXT_WIDTH = <NUM_LIT> ; private int SIZING_TEXT_HEIGHT = <NUM_LIT> ; public FailureDialog ( Shell parentShell ) { super ( parentShell ) ; } protected void configureShell ( Shell newShell ) { super . configureShell ( newShell ) ; newShell . setText ( "<STR_LIT>" ) ; } protected void createButtonsForButtonBar ( Composite parent ) { createButton ( parent , IDialogConstants . OK_ID , "<STR_LIT>" , true ) ; createButton ( parent , IDialogConstants . CANCEL_ID , IDialogConstants . CANCEL_LABEL , false ) ; } protected Control createDialogArea ( Composite parent ) { Composite composite = ( Composite ) super . createDialogArea ( parent ) ; composite . setSize ( composite . computeSize ( SWT . DEFAULT , SWT . DEFAULT ) ) ; Label label = new Label ( composite , SWT . WRAP ) ; label . setText ( "<STR_LIT>" ) ; _text = new Text ( composite , SWT . MULTI | SWT . BORDER | SWT . H_SCROLL | SWT . V_SCROLL ) ; _text . setFont ( JFaceResources . getFontRegistry ( ) . get ( JFaceResources . TEXT_FONT ) ) ; GridData data = new GridData ( GridData . FILL_BOTH ) ; data . widthHint = SIZING_TEXT_WIDTH ; data . heightHint = SIZING_TEXT_HEIGHT ; _text . setLayoutData ( data ) ; return composite ; } protected void okPressed ( ) { _log = _text . getText ( ) ; super . okPressed ( ) ; } String getText ( ) { if ( _log == null ) { return "<STR_LIT>" ; } else { return _log ; } } void setText ( String text ) { _text . setText ( text ) ; } public String toString ( ) { return getText ( ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . ArrayList ; class SizingTestPass implements IDialogTestPass { private static final int CHECKLIST_SIZE = <NUM_LIT:5> ; public String title ( ) { return "<STR_LIT>" ; } public String description ( ) { return "<STR_LIT>" ; } public String label ( ) { return "<STR_LIT>" ; } public ArrayList checkListTexts ( ) { ArrayList list = new ArrayList ( CHECKLIST_SIZE ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; return list ; } public String [ ] failureTexts ( ) { String [ ] failureText = new String [ CHECKLIST_SIZE ] ; failureText [ <NUM_LIT:0> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:1> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:2> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:3> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:4> ] = "<STR_LIT>" ; return failureText ; } public String queryText ( ) { return "<STR_LIT>" ; } public int getID ( ) { return VerifyDialog . TEST_SIZING ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . Iterator ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . ShellAdapter ; import org . eclipse . swt . events . ShellEvent ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Group ; import org . eclipse . swt . widgets . Label ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . jface . dialogs . Dialog ; import org . eclipse . jface . dialogs . IDialogConstants ; import org . eclipse . jface . dialogs . TitleAreaDialog ; public class VerifyDialog extends TitleAreaDialog { private int SIZING_WIDTH = <NUM_LIT> ; private static int TEST_TYPE ; public static final int TEST_SIZING = <NUM_LIT:0> ; public static final int TEST_FOCUS = <NUM_LIT:1> ; public static final int TEST_ACCESS = <NUM_LIT:2> ; private IDialogTestPass _dialogTests [ ] = new IDialogTestPass [ <NUM_LIT:3> ] ; private Dialog _testDialog ; private Point _testDialogSize ; private Label _queryLabel ; private Button _yesButton ; private Button _checkList [ ] ; private String _failureText ; public VerifyDialog ( Shell parent ) { super ( parent ) ; if ( ! ( TEST_TYPE <= <NUM_LIT:2> ) && ! ( TEST_TYPE >= <NUM_LIT:0> ) ) { TEST_TYPE = TEST_SIZING ; } _failureText = "<STR_LIT>" ; _dialogTests [ <NUM_LIT:0> ] = new SizingTestPass ( ) ; _dialogTests [ <NUM_LIT:1> ] = new FocusTestPass ( ) ; _dialogTests [ <NUM_LIT:2> ] = new AccessibilityTestPass ( ) ; } protected void configureShell ( Shell newShell ) { super . configureShell ( newShell ) ; newShell . setText ( "<STR_LIT>" ) ; setShellStyle ( SWT . NONE ) ; } protected void createButtonsForButtonBar ( Composite parent ) { _yesButton = createButton ( parent , IDialogConstants . YES_ID , IDialogConstants . YES_LABEL , true ) ; createButton ( parent , IDialogConstants . NO_ID , IDialogConstants . NO_LABEL , false ) ; } protected void buttonPressed ( int buttonId ) { if ( IDialogConstants . YES_ID == buttonId ) { setReturnCode ( IDialogConstants . YES_ID ) ; if ( _testDialog . getShell ( ) != null ) { _testDialog . close ( ) ; } close ( ) ; } else if ( IDialogConstants . NO_ID == buttonId ) { handleFailure ( ) ; } } protected Control createDialogArea ( Composite parent ) { Composite parentComposite = ( Composite ) super . createDialogArea ( parent ) ; Composite composite = new Composite ( parentComposite , SWT . NONE ) ; composite . setSize ( SIZING_WIDTH , SWT . DEFAULT ) ; GridLayout layout = new GridLayout ( ) ; layout . marginHeight = convertVerticalDLUsToPixels ( IDialogConstants . VERTICAL_MARGIN ) ; layout . marginWidth = convertHorizontalDLUsToPixels ( IDialogConstants . HORIZONTAL_MARGIN ) ; layout . verticalSpacing = convertVerticalDLUsToPixels ( IDialogConstants . VERTICAL_SPACING ) ; layout . horizontalSpacing = convertHorizontalDLUsToPixels ( IDialogConstants . HORIZONTAL_SPACING ) ; composite . setLayout ( layout ) ; composite . setLayoutData ( new GridData ( GridData . FILL_BOTH ) ) ; createTestSelectionGroup ( composite ) ; createCheckListGroup ( composite ) ; _queryLabel = new Label ( composite , SWT . NONE ) ; _queryLabel . setLayoutData ( new GridData ( GridData . FILL_HORIZONTAL ) ) ; initializeTest ( ) ; return composite ; } private void createTestSelectionGroup ( Composite parent ) { Group group = new Group ( parent , SWT . SHADOW_NONE ) ; group . setText ( "<STR_LIT>" ) ; group . setLayout ( new GridLayout ( ) ) ; GridData data = new GridData ( GridData . FILL_HORIZONTAL ) ; group . setLayoutData ( data ) ; for ( int i = <NUM_LIT:0> ; i < _dialogTests . length ; i ++ ) { Button radio = new Button ( group , SWT . RADIO ) ; radio . setText ( _dialogTests [ i ] . label ( ) ) ; final int testID = _dialogTests [ i ] . getID ( ) ; radio . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { TEST_TYPE = testID ; initializeTest ( ) ; _yesButton . setEnabled ( true ) ; } } ) ; if ( TEST_TYPE == _dialogTests [ i ] . getID ( ) ) { radio . setSelection ( true ) ; } } } private void createCheckListGroup ( Composite parent ) { Group group = new Group ( parent , SWT . SHADOW_NONE ) ; group . setText ( "<STR_LIT>" ) ; group . setLayout ( new GridLayout ( ) ) ; GridData data = new GridData ( GridData . FILL_HORIZONTAL ) ; group . setLayoutData ( data ) ; int checkListSize = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < _dialogTests . length ; i ++ ) { int size = _dialogTests [ i ] . checkListTexts ( ) . size ( ) ; if ( size > checkListSize ) { checkListSize = size ; } } _checkList = new Button [ checkListSize ] ; SelectionAdapter selectionAdapter = new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { checkYesEnable ( ) ; } } ; for ( int i = <NUM_LIT:0> ; i < checkListSize ; i ++ ) { _checkList [ i ] = new Button ( group , SWT . CHECK ) ; _checkList [ i ] . addSelectionListener ( selectionAdapter ) ; data = new GridData ( GridData . HORIZONTAL_ALIGN_FILL ) ; data . grabExcessHorizontalSpace = true ; _checkList [ i ] . setLayoutData ( data ) ; } } private void checkYesEnable ( ) { boolean enable = true ; for ( int i = <NUM_LIT:0> ; i < _checkList . length ; i ++ ) { if ( ! _checkList [ i ] . getSelection ( ) ) { enable = false ; } } _yesButton . setEnabled ( enable ) ; } private void initializeTest ( ) { IDialogTestPass test = _dialogTests [ TEST_TYPE ] ; setTitle ( test . title ( ) ) ; setMessage ( test . description ( ) ) ; Iterator iterator = test . checkListTexts ( ) . iterator ( ) ; for ( int i = <NUM_LIT:0> ; i < _checkList . length ; i ++ ) { if ( iterator . hasNext ( ) ) { _checkList [ i ] . setText ( iterator . next ( ) . toString ( ) ) ; _checkList [ i ] . setVisible ( true ) ; _checkList [ i ] . update ( ) ; } else { _checkList [ i ] . setVisible ( false ) ; _checkList [ i ] . update ( ) ; } _checkList [ i ] . setSelection ( true ) ; } _queryLabel . setText ( test . queryText ( ) ) ; } public String getFailureText ( ) { return _failureText ; } public int open ( ) { _failureText = "<STR_LIT>" ; return IDialogConstants . NO_ID ; } public int open ( Dialog testDialog ) { if ( getShell ( ) == null ) { create ( ) ; } getShell ( ) . setLocation ( <NUM_LIT:0> , <NUM_LIT:0> ) ; getShell ( ) . setSize ( Math . max ( SIZING_WIDTH , getShell ( ) . getSize ( ) . x ) , getShell ( ) . getSize ( ) . y ) ; _testDialog = testDialog ; if ( _testDialog . getShell ( ) == null ) { _testDialog . create ( ) ; } _testDialogSize = _testDialog . getShell ( ) . getSize ( ) ; openNewTestDialog ( ) ; return super . open ( ) ; } private void openNewTestDialog ( ) { if ( _testDialog . getShell ( ) == null ) { _testDialog . create ( ) ; } _testDialog . setBlockOnOpen ( false ) ; _testDialog . getShell ( ) . setLocation ( getShell ( ) . getSize ( ) . x + <NUM_LIT:1> , <NUM_LIT:0> ) ; _testDialog . getShell ( ) . setSize ( _testDialogSize ) ; _testDialog . getShell ( ) . addShellListener ( new ShellAdapter ( ) { public void shellClosed ( ShellEvent e ) { e . doit = false ; } } ) ; _testDialog . open ( ) ; } private void handleFailure ( ) { IDialogTestPass test = _dialogTests [ TEST_TYPE ] ; StringBuffer text = new StringBuffer ( ) ; String label = test . label ( ) ; label = label . substring ( <NUM_LIT:0> , label . indexOf ( "<STR_LIT:&>" ) ) + label . substring ( label . indexOf ( "<STR_LIT:&>" ) + <NUM_LIT:1> ) ; text . append ( label ) . append ( "<STR_LIT>" ) . append ( SWT . getPlatform ( ) ) . append ( "<STR_LIT>" ) ; String failureMessages [ ] = test . failureTexts ( ) ; for ( int i = <NUM_LIT:0> ; i < test . checkListTexts ( ) . size ( ) ; i ++ ) { if ( ! _checkList [ i ] . getSelection ( ) ) { text . append ( "<STR_LIT>" ) . append ( failureMessages [ i ] ) . append ( "<STR_LIT:n>" ) ; } } FailureDialog dialog = new FailureDialog ( getShell ( ) ) ; dialog . create ( ) ; dialog . setText ( text . toString ( ) ) ; if ( dialog . open ( ) == IDialogConstants . OK_ID ) { _failureText = dialog . toString ( ) ; setReturnCode ( IDialogConstants . NO_ID ) ; if ( _testDialog . getShell ( ) != null ) { _testDialog . close ( ) ; } close ( ) ; } } protected void handleShellCloseEvent ( ) { handleFailure ( ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . ArrayList ; public class FocusTestPass implements IDialogTestPass { private static final int CHECKLIST_SIZE = <NUM_LIT:1> ; public String title ( ) { return "<STR_LIT>" ; } public String description ( ) { return "<STR_LIT>" ; } public String label ( ) { return "<STR_LIT>" ; } public ArrayList checkListTexts ( ) { ArrayList list = new ArrayList ( CHECKLIST_SIZE ) ; list . add ( "<STR_LIT>" ) ; return list ; } public String [ ] failureTexts ( ) { String [ ] failureText = new String [ CHECKLIST_SIZE ] ; failureText [ <NUM_LIT:0> ] = "<STR_LIT>" ; return failureText ; } public String queryText ( ) { return "<STR_LIT>" ; } public int getID ( ) { return VerifyDialog . TEST_FOCUS ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . ArrayList ; public class AccessibilityTestPass implements IDialogTestPass { private static final int CHECKLIST_SIZE = <NUM_LIT:5> ; public String title ( ) { return "<STR_LIT>" ; } public String description ( ) { return "<STR_LIT>" ; } public String label ( ) { return "<STR_LIT>" ; } public ArrayList checkListTexts ( ) { ArrayList list = new ArrayList ( CHECKLIST_SIZE ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; list . add ( "<STR_LIT>" ) ; return list ; } public String [ ] failureTexts ( ) { String [ ] failureText = new String [ CHECKLIST_SIZE ] ; failureText [ <NUM_LIT:0> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:1> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:2> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:3> ] = "<STR_LIT>" ; failureText [ <NUM_LIT:4> ] = "<STR_LIT>" ; return failureText ; } public String queryText ( ) { return "<STR_LIT>" ; } public int getID ( ) { return VerifyDialog . TEST_ACCESS ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Label ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . jface . dialogs . Dialog ; import org . eclipse . jface . dialogs . IDialogConstants ; import org . eclipse . ui . PlatformUI ; public class DialogCheck { private DialogCheck ( ) { } private static VerifyDialog _verifyDialog ; public static void assertDialog ( Dialog dialog ) { Assert . assertNotNull ( dialog ) ; if ( _verifyDialog . getShell ( ) == null ) { getShell ( ) ; } if ( _verifyDialog . open ( dialog ) == IDialogConstants . NO_ID ) { Assert . assertTrue ( _verifyDialog . getFailureText ( ) , false ) ; } } public static void assertDialogTexts ( Dialog dialog ) { Assert . assertNotNull ( dialog ) ; dialog . setBlockOnOpen ( false ) ; dialog . open ( ) ; Shell shell = dialog . getShell ( ) ; verifyCompositeText ( shell ) ; dialog . close ( ) ; } public static Shell getShell ( ) { Shell shell = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getShell ( ) ; _verifyDialog = new VerifyDialog ( shell ) ; _verifyDialog . create ( ) ; return _verifyDialog . getShell ( ) ; } private static void verifyCompositeText ( Composite composite ) { Control children [ ] = composite . getChildren ( ) ; for ( int i = <NUM_LIT:0> ; i < children . length ; i ++ ) { try { verifyButtonText ( ( Button ) children [ i ] ) ; } catch ( ClassCastException exNotButton ) { try { verifyLabelText ( ( Label ) children [ i ] ) ; } catch ( ClassCastException exNotLabel ) { try { verifyCompositeText ( ( Composite ) children [ i ] ) ; } catch ( ClassCastException exNotComposite ) { } } } } } private static void verifyButtonText ( Button button ) { String widget = button . toString ( ) ; Point size = button . getSize ( ) ; Point preferred = button . computeSize ( SWT . DEFAULT , SWT . DEFAULT ) ; if ( preferred . y * size . y > <NUM_LIT:0> ) { preferred . y /= countLines ( button . getText ( ) ) ; if ( size . y / preferred . y > <NUM_LIT:1> ) { preferred . x /= ( size . y / preferred . y ) ; } } String message = new StringBuffer ( "<STR_LIT>" ) . append ( widget ) . append ( "<STR_LIT>" ) . append ( size . x ) . append ( "<STR_LIT>" ) . append ( preferred . x ) . toString ( ) ; if ( preferred . x > size . x ) { button . getShell ( ) . dispose ( ) ; Assert . assertTrue ( message . toString ( ) , false ) ; } } private static void verifyLabelText ( Label label ) { String widget = label . toString ( ) ; Point size = label . getSize ( ) ; Point preferred = label . computeSize ( SWT . DEFAULT , SWT . DEFAULT ) ; if ( preferred . y * size . y > <NUM_LIT:0> ) { preferred . y /= countLines ( label . getText ( ) ) ; if ( size . y / preferred . y > <NUM_LIT:1> ) { preferred . x /= ( size . y / preferred . y ) ; } } String message = new StringBuffer ( "<STR_LIT>" ) . append ( widget ) . append ( "<STR_LIT>" ) . append ( size . x ) . append ( "<STR_LIT>" ) . append ( preferred . x ) . toString ( ) ; if ( preferred . x > size . x ) { label . getShell ( ) . dispose ( ) ; Assert . assertTrue ( message . toString ( ) , false ) ; } } private static int countLines ( String text ) { int newLines = <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < text . length ( ) ; i ++ ) { if ( text . charAt ( i ) == '<STR_LIT:\n>' ) { newLines ++ ; } } return newLines ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . logging . Level ; import java . util . logging . Logger ; import junit . framework . Assert ; import org . eclipse . swt . widgets . Display ; public abstract class DisplayHelper { private static final boolean DISABLE_TIMEOUT = false ; protected DisplayHelper ( ) { } public final boolean waitForCondition ( Display display , long timeout ) { if ( condition ( ) ) return true ; if ( timeout < <NUM_LIT:0> ) return false ; driveEventQueue ( display ) ; if ( condition ( ) ) return true ; if ( timeout == <NUM_LIT:0> ) return false ; DisplayWaiter waiter = new DisplayWaiter ( display ) ; DisplayWaiter . Timeout timeoutState = waiter . start ( timeout ) ; boolean condition ; try { do { if ( display . sleep ( ) ) driveEventQueue ( display ) ; condition = condition ( ) ; } while ( ! condition && ! timeoutState . hasTimedOut ( ) ) ; } finally { waiter . stop ( ) ; } return condition ; } public static void sleep ( Display display , long millis ) { new DisplayHelper ( ) { public boolean condition ( ) { return false ; } } . waitForCondition ( display , millis ) ; } protected abstract boolean condition ( ) ; private static boolean driveEventQueue ( Display display ) { boolean events = false ; while ( display . readAndDispatch ( ) ) { events = true ; } return events ; } public final boolean waitForCondition ( Display display , long timeout , long interval ) { if ( condition ( ) ) return true ; if ( timeout < <NUM_LIT:0> ) return false ; driveEventQueue ( display ) ; if ( condition ( ) ) return true ; if ( timeout == <NUM_LIT:0> ) return false ; DisplayWaiter waiter = new DisplayWaiter ( display , true ) ; long currentTimeMillis = System . currentTimeMillis ( ) ; long finalTimeout = timeout + currentTimeMillis ; if ( finalTimeout < currentTimeMillis ) finalTimeout = Long . MAX_VALUE ; boolean condition ; try { do { waiter . restart ( interval ) ; if ( display . sleep ( ) ) driveEventQueue ( display ) ; condition = condition ( ) ; } while ( ! condition && ( DISABLE_TIMEOUT || finalTimeout > System . currentTimeMillis ( ) ) ) ; } finally { waiter . stop ( ) ; } return condition ; } } final class DisplayWaiter { public final class Timeout { private boolean fTimeoutState = false ; public boolean hasTimedOut ( ) { synchronized ( fMutex ) { return fTimeoutState ; } } void setTimedOut ( boolean timedOut ) { fTimeoutState = timedOut ; } Timeout ( boolean initialState ) { fTimeoutState = initialState ; } } private final Display fDisplay ; private final Object fMutex = new Object ( ) ; private final boolean fKeepRunningOnTimeout ; private static final int RUNNING = <NUM_LIT:1> << <NUM_LIT:1> ; private static final int STOPPED = <NUM_LIT:1> << <NUM_LIT:2> ; private static final int IDLE = <NUM_LIT:1> << <NUM_LIT:3> ; private int fState ; private long fNextTimeout ; private Thread fCurrentThread ; private Timeout fCurrentTimeoutState ; public DisplayWaiter ( Display display ) { this ( display , false ) ; } public DisplayWaiter ( Display display , boolean keepRunning ) { Assert . assertNotNull ( display ) ; fDisplay = display ; fState = STOPPED ; fKeepRunningOnTimeout = keepRunning ; } public Timeout start ( long delay ) { Assert . assertTrue ( delay > <NUM_LIT:0> ) ; synchronized ( fMutex ) { switch ( fState ) { case STOPPED : startThread ( ) ; setNextTimeout ( delay ) ; break ; case IDLE : unhold ( ) ; setNextTimeout ( delay ) ; break ; } return fCurrentTimeoutState ; } } private void setNextTimeout ( long delay ) { long currentTimeMillis = System . currentTimeMillis ( ) ; long next = currentTimeMillis + delay ; if ( next > currentTimeMillis ) fNextTimeout = next ; else fNextTimeout = Long . MAX_VALUE ; } public Timeout restart ( long delay ) { Assert . assertTrue ( delay > <NUM_LIT:0> ) ; synchronized ( fMutex ) { switch ( fState ) { case STOPPED : startThread ( ) ; break ; case IDLE : unhold ( ) ; break ; } setNextTimeout ( delay ) ; return fCurrentTimeoutState ; } } public void stop ( ) { synchronized ( fMutex ) { if ( tryTransition ( RUNNING | IDLE , STOPPED ) ) fMutex . notifyAll ( ) ; } } public void hold ( ) { synchronized ( fMutex ) { if ( tryTransition ( RUNNING , IDLE ) ) fMutex . notifyAll ( ) ; } } private void unhold ( ) { checkedTransition ( IDLE , RUNNING ) ; fCurrentTimeoutState = new Timeout ( false ) ; fMutex . notifyAll ( ) ; } private void startThread ( ) { checkedTransition ( STOPPED , RUNNING ) ; fCurrentTimeoutState = new Timeout ( false ) ; fCurrentThread = new Thread ( ) { final class ThreadChangedException extends Exception { private static final long serialVersionUID = <NUM_LIT:1L> ; } public void run ( ) { try { run2 ( ) ; } catch ( InterruptedException e ) { Logger . global . log ( Level . FINE , "<STR_LIT>" , e ) ; } catch ( ThreadChangedException e ) { Logger . global . log ( Level . FINE , "<STR_LIT>" , e ) ; synchronized ( fMutex ) { fMutex . notifyAll ( ) ; } } } private void run2 ( ) throws InterruptedException , ThreadChangedException { synchronized ( fMutex ) { checkThread ( ) ; tryHold ( ) ; assertStates ( STOPPED | RUNNING ) ; while ( isState ( RUNNING ) ) { waitForTimeout ( ) ; if ( isState ( RUNNING ) ) timedOut ( ) ; assertStates ( STOPPED | IDLE ) ; tryHold ( ) ; assertStates ( STOPPED | RUNNING ) ; } assertStates ( STOPPED ) ; } } private void checkThread ( ) throws ThreadChangedException { if ( fCurrentThread != this ) throw new ThreadChangedException ( ) ; } private void waitForTimeout ( ) throws InterruptedException , ThreadChangedException { long delta ; while ( isState ( RUNNING ) && ( delta = fNextTimeout - System . currentTimeMillis ( ) ) > <NUM_LIT:0> ) { delta = Math . max ( delta , <NUM_LIT> ) ; Logger . global . finest ( "<STR_LIT>" + delta + "<STR_LIT>" ) ; fMutex . wait ( delta ) ; checkThread ( ) ; } } private void timedOut ( ) { Logger . global . finer ( "<STR_LIT>" ) ; fCurrentTimeoutState . setTimedOut ( true ) ; fDisplay . wake ( ) ; if ( fKeepRunningOnTimeout ) checkedTransition ( RUNNING , IDLE ) ; else checkedTransition ( RUNNING , STOPPED ) ; } private void tryHold ( ) throws InterruptedException , ThreadChangedException { while ( isState ( IDLE ) ) { fMutex . wait ( <NUM_LIT:0> ) ; checkThread ( ) ; } assertStates ( STOPPED | RUNNING ) ; } } ; fCurrentThread . start ( ) ; } private boolean tryTransition ( int possibleStates , int nextState ) { if ( isState ( possibleStates ) ) { Logger . global . finer ( name ( fState ) + "<STR_LIT>" + name ( nextState ) + "<STR_LIT:U+0020(>" + name ( possibleStates ) + "<STR_LIT:)>" ) ; fState = nextState ; return true ; } Logger . global . finest ( "<STR_LIT>" + name ( fState ) + "<STR_LIT>" + name ( nextState ) + "<STR_LIT:U+0020(>" + name ( possibleStates ) + "<STR_LIT:)>" ) ; return false ; } private void checkedTransition ( int possibleStates , int nextState ) { assertStates ( possibleStates ) ; Logger . global . finer ( name ( fState ) + "<STR_LIT>" + name ( nextState ) ) ; fState = nextState ; } private void assertStates ( int states ) { Assert . assertTrue ( "<STR_LIT>" , isState ( states ) ) ; } private boolean isState ( int states ) { return ( states & fState ) == fState ; } private String name ( int states ) { StringBuffer buf = new StringBuffer ( ) ; boolean comma = false ; if ( ( states & RUNNING ) == RUNNING ) { buf . append ( "<STR_LIT>" ) ; comma = true ; } if ( ( states & STOPPED ) == STOPPED ) { if ( comma ) buf . append ( "<STR_LIT:U+002C>" ) ; buf . append ( "<STR_LIT>" ) ; comma = true ; } if ( ( states & IDLE ) == IDLE ) { if ( comma ) buf . append ( "<STR_LIT:U+002C>" ) ; buf . append ( "<STR_LIT>" ) ; } return buf . toString ( ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . util ; import java . util . ArrayList ; public interface IDialogTestPass { public String title ( ) ; public String description ( ) ; public String label ( ) ; public ArrayList checkListTexts ( ) ; public String [ ] failureTexts ( ) ; public String queryText ( ) ; public int getID ( ) ; } </s>
|
<s> package org . eclipse . jdt . testplugin . test ; import junit . framework . Test ; import junit . framework . TestCase ; import junit . framework . TestSuite ; import org . eclipse . jdt . testplugin . JavaProjectHelper ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; public class JavaTestCase extends TestCase { private IJavaProject fJavaProject ; public JavaTestCase ( String name ) { super ( name ) ; } public static Test suite ( ) { TestSuite suite = new TestSuite ( ) ; suite . addTest ( new JavaTestCase ( "<STR_LIT>" ) ) ; return suite ; } protected void setUp ( ) throws Exception { fJavaProject = JavaProjectHelper . createJavaProject ( "<STR_LIT>" , "<STR_LIT>" ) ; IPackageFragmentRoot root = JavaProjectHelper . addSourceContainer ( fJavaProject , "<STR_LIT:src>" ) ; IPackageFragment pack = root . createPackageFragment ( "<STR_LIT>" , true , null ) ; ICompilationUnit cu = pack . getCompilationUnit ( "<STR_LIT>" ) ; IType type = cu . createType ( "<STR_LIT>" , null , true , null ) ; type . createMethod ( "<STR_LIT>" , null , true , null ) ; type . createMethod ( "<STR_LIT>" , null , true , null ) ; } protected void tearDown ( ) throws Exception { JavaProjectHelper . delete ( fJavaProject ) ; } public void doTest1 ( ) throws Exception { String name = "<STR_LIT>" ; ICompilationUnit cu = ( ICompilationUnit ) fJavaProject . findElement ( new Path ( name ) ) ; assertTrue ( "<STR_LIT>" , cu != null ) ; IType type = cu . getType ( "<STR_LIT:A>" ) ; assertTrue ( "<STR_LIT>" , type != null ) ; System . out . println ( "<STR_LIT>" ) ; IMethod [ ] methods = type . getMethods ( ) ; for ( int i = <NUM_LIT:0> ; i < methods . length ; i ++ ) { System . out . println ( methods [ i ] . getElementName ( ) ) ; } assertTrue ( "<STR_LIT>" , methods . length == <NUM_LIT:2> ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin . test ; import junit . framework . Test ; import junit . framework . TestCase ; import junit . framework . TestSuite ; import org . eclipse . jdt . testplugin . JavaProjectHelper ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IClassFile ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; public class HelloWorld extends TestCase { private IJavaProject fJProject ; public static Test suite ( ) { TestSuite suite = new TestSuite ( ) ; suite . addTest ( new HelloWorld ( "<STR_LIT:test1>" ) ) ; return suite ; } public HelloWorld ( String name ) { super ( name ) ; } protected void setUp ( ) throws Exception { fJProject = JavaProjectHelper . createJavaProject ( "<STR_LIT>" , "<STR_LIT>" ) ; } protected void tearDown ( ) throws Exception { JavaProjectHelper . delete ( fJProject ) ; } public void test1 ( ) throws Exception { if ( JavaProjectHelper . addRTJar ( fJProject ) == null ) { assertTrue ( "<STR_LIT>" , false ) ; return ; } String name = "<STR_LIT>" ; IClassFile classfile = ( IClassFile ) fJProject . findElement ( new Path ( name ) ) ; assertTrue ( "<STR_LIT>" , classfile != null ) ; IType type = classfile . getType ( ) ; System . out . println ( "<STR_LIT>" ) ; IMethod [ ] methods = type . getMethods ( ) ; for ( int i = <NUM_LIT:0> ; i < methods . length ; i ++ ) { System . out . println ( methods [ i ] . getElementName ( ) ) ; } } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . StringReader ; import java . util . ArrayList ; import java . util . Arrays ; import junit . framework . Assert ; public class StringAsserts { public StringAsserts ( ) { super ( ) ; } private static int getDiffPos ( String str1 , String str2 ) { int len1 = Math . min ( str1 . length ( ) , str2 . length ( ) ) ; int diffPos = - <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < len1 ; i ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) { diffPos = i ; break ; } } if ( diffPos == - <NUM_LIT:1> && str1 . length ( ) != str2 . length ( ) ) { diffPos = len1 ; } return diffPos ; } private static final int printRange = <NUM_LIT:6> ; public static void assertEqualString ( String actual , String expected ) { if ( actual == null || expected == null ) { if ( actual == expected ) { return ; } if ( actual == null ) { Assert . assertTrue ( "<STR_LIT>" + expected , false ) ; } else { Assert . assertTrue ( "<STR_LIT>" + actual , false ) ; } } int diffPos = getDiffPos ( actual , expected ) ; if ( diffPos != - <NUM_LIT:1> ) { int diffAhead = Math . max ( <NUM_LIT:0> , diffPos - printRange ) ; int diffAfter = Math . min ( actual . length ( ) , diffPos + printRange ) ; String diffStr = actual . substring ( diffAhead , diffPos ) + '<CHAR_LIT>' + actual . substring ( diffPos , diffAfter ) ; String message = "<STR_LIT>" + actual + "<STR_LIT>" + diffPos + "<STR_LIT::U+0020>" + diffStr + "<STR_LIT>" + expected ; Assert . assertEquals ( message , expected , actual ) ; } } public static void assertEqualStringIgnoreDelim ( String actual , String expected ) throws IOException { if ( actual == null || expected == null ) { if ( actual == expected ) { return ; } if ( actual == null ) { Assert . assertTrue ( "<STR_LIT>" + expected , false ) ; } else { Assert . assertTrue ( "<STR_LIT>" + actual , false ) ; } } BufferedReader read1 = new BufferedReader ( new StringReader ( actual ) ) ; BufferedReader read2 = new BufferedReader ( new StringReader ( expected ) ) ; int line = <NUM_LIT:1> ; do { String s1 = read1 . readLine ( ) ; String s2 = read2 . readLine ( ) ; if ( s1 == null || ! s1 . equals ( s2 ) ) { if ( s1 == null && s2 == null ) { return ; } String diffStr = ( s1 == null ) ? s2 : s1 ; String message = "<STR_LIT>" + actual + "<STR_LIT>" + line + "<STR_LIT::U+0020>" + diffStr + "<STR_LIT>" + expected ; Assert . assertEquals ( message , expected , actual ) ; } line ++ ; } while ( true ) ; } public static void assertEqualStringsIgnoreOrder ( String [ ] actuals , String [ ] expecteds ) { ArrayList list1 = new ArrayList ( Arrays . asList ( actuals ) ) ; ArrayList list2 = new ArrayList ( Arrays . asList ( expecteds ) ) ; for ( int i = list1 . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { if ( list2 . remove ( list1 . get ( i ) ) ) { list1 . remove ( i ) ; } } int n1 = list1 . size ( ) ; int n2 = list2 . size ( ) ; if ( n1 + n2 > <NUM_LIT:0> ) { if ( n1 == <NUM_LIT:1> && n2 == <NUM_LIT:1> ) { assertEqualString ( ( String ) list1 . get ( <NUM_LIT:0> ) , ( String ) list2 . get ( <NUM_LIT:0> ) ) ; } StringBuffer buf = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < n1 ; i ++ ) { String s1 = ( String ) list1 . get ( i ) ; if ( s1 != null ) { buf . append ( s1 ) ; buf . append ( "<STR_LIT:n>" ) ; } } String actual = buf . toString ( ) ; buf = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < n2 ; i ++ ) { String s2 = ( String ) list2 . get ( i ) ; if ( s2 != null ) { buf . append ( s2 ) ; buf . append ( "<STR_LIT:n>" ) ; } } String expected = buf . toString ( ) ; String message = "<STR_LIT>" + actual + "<STR_LIT>" + expected ; Assert . assertEquals ( message , expected , actual ) ; } } public static void assertExpectedExistInProposals ( String [ ] actuals , String [ ] expecteds ) { ArrayList list1 = new ArrayList ( Arrays . asList ( actuals ) ) ; ArrayList list2 = new ArrayList ( Arrays . asList ( expecteds ) ) ; for ( int i = list1 . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { if ( list2 . remove ( list1 . get ( i ) ) ) { list1 . remove ( i ) ; } } int n1 = list1 . size ( ) ; int n2 = list2 . size ( ) ; if ( n2 > <NUM_LIT:0> ) { if ( n1 == <NUM_LIT:1> && n2 == <NUM_LIT:1> ) { assertEqualString ( ( String ) list1 . get ( <NUM_LIT:0> ) , ( String ) list2 . get ( <NUM_LIT:0> ) ) ; } StringBuffer buf = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < n1 ; i ++ ) { String s1 = ( String ) list1 . get ( i ) ; if ( s1 != null ) { buf . append ( s1 ) ; buf . append ( "<STR_LIT:n>" ) ; } } String actual = buf . toString ( ) ; buf = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < n2 ; i ++ ) { String s2 = ( String ) list2 . get ( i ) ; if ( s2 != null ) { buf . append ( s2 ) ; buf . append ( "<STR_LIT:n>" ) ; } } String expected = buf . toString ( ) ; String message = "<STR_LIT>" + actual + "<STR_LIT>" + expected ; Assert . assertEquals ( message , expected , actual ) ; } } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import junit . extensions . TestSetup ; import junit . framework . Test ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . internal . ui . JavaPlugin ; public class TestOptionsSetup extends TestSetup { public TestOptionsSetup ( Test test ) { super ( test ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; JavaCore . setOptions ( TestOptions . getDefaultOptions ( ) ) ; TestOptions . initializeCodeGenerationOptions ( ) ; JavaPlugin . getDefault ( ) . getCodeTemplateStore ( ) . load ( ) ; } } </s>
|
<s> package org . eclipse . jdt . testplugin ; import junit . framework . Assert ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; public class MixedLineDelimiterDetector { public static void assertNoMixedLineDelimiters ( IJavaElement elem ) { IResource resource ; if ( elem instanceof IJavaProject ) resource = ( ( IJavaProject ) elem ) . getProject ( ) ; else resource = elem . getResource ( ) ; assertNoMixedLineDelimiters ( resource ) ; } public static void assertNoMixedLineDelimiters ( IResource resource ) { IResource [ ] mixedResources = findFilesWithMixedLineDelimiters ( resource ) ; Assert . assertTrue ( mixedResources == null || mixedResources . length == <NUM_LIT:0> ) ; } private static IResource [ ] findFilesWithMixedLineDelimiters ( final IResource resource ) { Assert . fail ( "<STR_LIT>" ) ; return new IResource [ <NUM_LIT:0> ] ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import junit . framework . Test ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . testplugin . JavaProjectHelper ; public class RefactoringTestSetup extends AbstractRefactoringTestSetup { public RefactoringTestSetup ( Test test ) { super ( test ) ; } public static final String CONTAINER = "<STR_LIT:src>" ; private static IPackageFragmentRoot fgRoot ; private static IPackageFragment fgPackageP ; private static IJavaProject fgJavaTestProject ; private static IPackageFragmentRoot [ ] fgJRELibraries ; private static IPackageFragmentRoot fgGroovyLibrary ; public static IPackageFragmentRoot getDefaultSourceFolder ( ) throws Exception { if ( fgRoot != null ) return fgRoot ; throw new Exception ( RefactoringTestSetup . class . getName ( ) + "<STR_LIT>" ) ; } public static IPackageFragmentRoot [ ] getJRELibraries ( ) throws Exception { if ( fgJRELibraries != null ) return fgJRELibraries ; throw new Exception ( RefactoringTestSetup . class . getName ( ) + "<STR_LIT>" ) ; } public static IClasspathEntry [ ] getJRELibrariesAsRawClasspathEntry ( ) throws Exception { if ( fgJRELibraries != null ) { IClasspathEntry [ ] entries = new IClasspathEntry [ fgJRELibraries . length ] ; for ( int i = <NUM_LIT:0> ; i < fgJRELibraries . length ; i ++ ) { entries [ i ] = fgJRELibraries [ i ] . getRawClasspathEntry ( ) ; } return entries ; } throw new Exception ( RefactoringTestSetup . class . getName ( ) + "<STR_LIT>" ) ; } public static IJavaProject getProject ( ) throws Exception { if ( fgJavaTestProject != null ) return fgJavaTestProject ; throw new Exception ( RefactoringTestSetup . class . getName ( ) + "<STR_LIT>" ) ; } public static IPackageFragment getPackageP ( ) throws Exception { if ( fgPackageP != null ) return fgPackageP ; throw new Exception ( RefactoringTestSetup . class . getName ( ) + "<STR_LIT>" ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; if ( fgJavaTestProject != null && fgJavaTestProject . exists ( ) ) { int breakpointTarget = <NUM_LIT:0> ; breakpointTarget ++ ; } fgJavaTestProject = JavaProjectHelper . createGroovyProject ( "<STR_LIT>" + System . currentTimeMillis ( ) , "<STR_LIT>" ) ; fgJRELibraries = addRTJars ( fgJavaTestProject ) ; fgGroovyLibrary = addGroovyJar ( fgJavaTestProject ) ; JavaProjectHelper . removeFromClasspath ( fgJavaTestProject , fgJavaTestProject . getProject ( ) . getFullPath ( ) ) ; fgRoot = JavaProjectHelper . addSourceContainer ( fgJavaTestProject , CONTAINER ) ; fgPackageP = fgRoot . createPackageFragment ( "<STR_LIT:p>" , true , null ) ; } public IPackageFragmentRoot getGroovyLibrary ( ) { return fgGroovyLibrary ; } protected IPackageFragmentRoot [ ] addRTJars ( IJavaProject project ) throws CoreException { return JavaProjectHelper . addRTJars ( project ) ; } protected IPackageFragmentRoot addGroovyJar ( IJavaProject project ) throws CoreException { return JavaProjectHelper . addGroovyJar ( project ) ; } protected void tearDown ( ) throws Exception { JavaProjectHelper . delete ( fgJavaTestProject ) ; super . tearDown ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extractMethod ; import java . io . File ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . refactoring . core . extract . ExtractGroovyMethodRefactoring ; import org . codehaus . groovy . eclipse . refactoring . test . TestPrefInitializer ; import org . codehaus . groovy . eclipse . test . TestProject ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . objectweb . asm . Opcodes ; public class ExtractMethodTestCase extends RefactoringTestCase { private ExtractGroovyMethodRefactoring refactoring ; private TestProject testProject ; private GroovyCompilationUnit unit ; public ExtractMethodTestCase ( String arg0 , File arg1 ) { super ( arg0 , arg1 ) ; } @ Override public void preAction ( ) { try { testProject = new TestProject ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , getOrigin ( ) . get ( ) ) ) ; unit . becomeWorkingCopy ( null ) ; RefactoringStatus status = new RefactoringStatus ( ) ; refactoring = new ExtractGroovyMethodRefactoring ( unit , getUserSelection ( ) . getOffset ( ) , getUserSelection ( ) . getLength ( ) , status ) ; refactoring . setPreferences ( TestPrefInitializer . initializePreferences ( getFileProperties ( ) ) ) ; if ( status . getSeverity ( ) != RefactoringStatus . OK ) { fail ( "<STR_LIT>" + status ) ; } } catch ( CoreException e ) { throw new RuntimeException ( e ) ; } } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; unit . discardWorkingCopy ( ) ; testProject . dispose ( ) ; } @ Override public RefactoringStatus checkInitialCondition ( ) throws OperationCanceledException , CoreException { return refactoring . checkInitialConditions ( new NullProgressMonitor ( ) ) ; } @ Override public void simulateUserInput ( ) { int modifier = <NUM_LIT:0> ; String newMethodName = "<STR_LIT>" ; try { newMethodName = properties . get ( "<STR_LIT>" ) ; String mod = properties . get ( "<STR_LIT>" ) ; if ( mod . equals ( "<STR_LIT>" ) ) modifier = Opcodes . ACC_PRIVATE ; if ( mod . equals ( "<STR_LIT>" ) ) modifier = Opcodes . ACC_PUBLIC ; if ( mod . equals ( "<STR_LIT>" ) ) modifier = Opcodes . ACC_PROTECTED ; } catch ( Exception e ) { e . printStackTrace ( ) ; fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } refactoring . setModifier ( modifier ) ; refactoring . setNewMethodname ( newMethodName ) ; setMoveParameter ( refactoring ) ; setRenameParameter ( refactoring ) ; } @ Override public RefactoringStatus checkFinalCondition ( ) throws OperationCanceledException , CoreException { return refactoring . checkFinalConditions ( new NullProgressMonitor ( ) ) ; } @ Override public Change createChange ( ) throws OperationCanceledException , CoreException { return refactoring . createChange ( new NullProgressMonitor ( ) ) ; } @ Override public void finalAssert ( ) { getDocument ( ) . set ( String . valueOf ( unit . getContents ( ) ) ) ; super . finalAssert ( ) ; } private void setRenameParameter ( ExtractGroovyMethodRefactoring provider ) { String variableToRename = properties . get ( "<STR_LIT>" ) ; Map < String , String > variablesToRename = null ; if ( variableToRename != null ) { variablesToRename = new HashMap < String , String > ( ) ; String [ ] renameMappings = variableToRename . split ( "<STR_LIT:;>" ) ; for ( int i = <NUM_LIT:0> ; i < renameMappings . length ; i ++ ) { String [ ] singleRenames = renameMappings [ i ] . split ( "<STR_LIT::>" ) ; if ( singleRenames . length == <NUM_LIT:2> ) { variablesToRename . put ( singleRenames [ <NUM_LIT:0> ] , singleRenames [ <NUM_LIT:1> ] ) ; } } provider . setParameterRename ( variablesToRename ) ; } } private void setMoveParameter ( ExtractGroovyMethodRefactoring provider ) { String moveSettings = properties . get ( "<STR_LIT>" ) ; if ( moveSettings != null ) { boolean upEvent = false ; int sortOfMoveCharPosition = moveSettings . indexOf ( '<CHAR_LIT>' ) ; if ( sortOfMoveCharPosition == - <NUM_LIT:1> ) { upEvent = true ; sortOfMoveCharPosition = moveSettings . indexOf ( '<CHAR_LIT:->' ) ; } String varName = moveSettings . substring ( <NUM_LIT:0> , sortOfMoveCharPosition ) ; int numberOfMoves = Integer . valueOf ( moveSettings . substring ( sortOfMoveCharPosition + <NUM_LIT:1> , moveSettings . length ( ) ) ) ; provider . setMoveParameter ( varName , upEvent , numberOfMoves ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extractMethod ; import java . io . File ; import junit . framework . AssertionFailedError ; import org . codehaus . groovy . eclipse . refactoring . test . BaseTestCase ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . RefactoringStatusEntry ; public abstract class RefactoringTestCase extends BaseTestCase { public RefactoringTestCase ( String name , File file ) { super ( name , file ) ; setName ( "<STR_LIT>" ) ; } public void testRefactoring ( ) throws Throwable { try { preAction ( ) ; RefactoringStatus rs = checkInitialCondition ( ) ; simulateUserInput ( ) ; rs . merge ( checkFinalCondition ( ) ) ; if ( analyseRefactoringStatus ( rs ) ) { Change change = createChange ( ) ; change . perform ( new NullProgressMonitor ( ) ) ; } finalAssert ( ) ; } catch ( Exception e ) { if ( e . getCause ( ) instanceof AssertionFailedError ) { throw e . getCause ( ) ; } throw e ; } } private boolean analyseRefactoringStatus ( RefactoringStatus state ) { RefactoringStatusEntry [ ] entries = state . getEntries ( ) ; if ( shouldFail && ( entries . length == <NUM_LIT:0> ) ) { fail ( "<STR_LIT>" + properties . get ( "<STR_LIT>" ) ) ; } for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { RefactoringStatusEntry entry = entries [ i ] ; if ( ( entry . isError ( ) || entry . isFatalError ( ) ) && shouldFail == false ) { fail ( "<STR_LIT>" + entry . getMessage ( ) ) ; } else { if ( shouldFail && properties . get ( "<STR_LIT>" ) != null ) { assertEquals ( properties . get ( "<STR_LIT>" ) , entry . getMessage ( ) ) ; } } if ( entry . isFatalError ( ) ) { return false ; } } return true ; } public abstract void preAction ( ) ; public abstract RefactoringStatus checkInitialCondition ( ) throws OperationCanceledException , CoreException ; public abstract void simulateUserInput ( ) ; public abstract RefactoringStatus checkFinalCondition ( ) throws OperationCanceledException , CoreException ; public abstract Change createChange ( ) throws OperationCanceledException , CoreException ; } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extractMethod ; import java . io . File ; import java . util . List ; import org . codehaus . groovy . eclipse . refactoring . test . BaseTestSuite ; import junit . framework . TestSuite ; public class ExtractMethodTestSuite extends BaseTestSuite { public static TestSuite suite ( ) { TestSuite ts = new TestSuite ( "<STR_LIT>" ) ; List < File > files = getFileList ( "<STR_LIT>" , "<STR_LIT>" ) ; for ( File file : files ) { ts . addTest ( new ExtractMethodTestCase ( file . getName ( ) , file ) ) ; } return ts ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extract ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . refactoring . core . extract . ExtractGroovyLocalRefactoring ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTest ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTestSetup ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public class ExtractLocalTests extends RefactoringTest { private static final Class < ExtractLocalTests > clazz = ExtractLocalTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public ExtractLocalTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new RefactoringTestSetup ( new TestSuite ( clazz ) ) ; } public static Test setUpTest ( Test test ) { return new RefactoringTestSetup ( test ) ; } @ Override protected String getRefactoringPath ( ) { return REFACTORING_PATH ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; fIsPreDeltaTest = true ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } public void test1 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest1In ( ) , ExtractLocalTestsData . getTest1Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT:test1>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test2 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest2In ( ) , ExtractLocalTestsData . getTest2Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test3 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest3In ( ) , ExtractLocalTestsData . getTest3Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test4 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest4In ( ) , ExtractLocalTestsData . getTest4Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , false ) ; } public void test5 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest5In ( ) , ExtractLocalTestsData . getTest5Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test6 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest6In ( ) , ExtractLocalTestsData . getTest6Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test7 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest7In ( ) , ExtractLocalTestsData . getTest7Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test8 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest8In ( ) , ExtractLocalTestsData . getTest8Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test9 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest9In ( ) , ExtractLocalTestsData . getTest9Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test10 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest10In ( ) , ExtractLocalTestsData . getTest10Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test10a ( ) throws Exception { helper ( ExtractLocalTestsData . getTest10In ( ) , ExtractLocalTestsData . getTest10Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test10b ( ) throws Exception { helper ( ExtractLocalTestsData . getTest10In ( ) , ExtractLocalTestsData . getTest10Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test11 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest11In ( ) , ExtractLocalTestsData . getTest11Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } public void test12 ( ) throws Exception { helper ( ExtractLocalTestsData . getTest12In ( ) , ExtractLocalTestsData . getTest12Out ( ) , ExtractLocalTestsData . findLocation ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , true ) ; } private void helper ( String before , String expected , int offset , int length , boolean replaceAllOccurrences ) throws Exception { GroovyCompilationUnit cu = ( GroovyCompilationUnit ) createCU ( getPackageP ( ) , "<STR_LIT>" , before ) ; try { ExtractGroovyLocalRefactoring refactoring = new ExtractGroovyLocalRefactoring ( cu , offset , length ) ; refactoring . setReplaceAllOccurrences ( replaceAllOccurrences ) ; refactoring . setLocalName ( refactoring . guessLocalNames ( ) [ <NUM_LIT:0> ] ) ; RefactoringStatus result = performRefactoring ( refactoring , false ) ; assertTrue ( "<STR_LIT>" , result == null || result . isOK ( ) ) ; assertEqualLines ( "<STR_LIT>" , expected , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , before , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , expected , cu . getSource ( ) ) ; } finally { performDummySearch ( ) ; cu . delete ( true , null ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extract ; import java . io . IOException ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . refactoring . core . extract . ExtractGroovyConstantRefactoring ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTest ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTestSetup ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public class ExtractConstantTests extends RefactoringTest { private static final String FOO_BAR = "<STR_LIT>" ; private static final String FOO_BAR_FRAX = "<STR_LIT>" ; private static final Class < ExtractConstantTests > clazz = ExtractConstantTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public ExtractConstantTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new RefactoringTestSetup ( new TestSuite ( clazz ) ) ; } public static Test setUpTest ( Test test ) { return new RefactoringTestSetup ( test ) ; } @ Override protected String getRefactoringPath ( ) { return REFACTORING_PATH ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; fIsPreDeltaTest = true ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } public void test1 ( ) throws Exception { helper ( indexOf ( FOO_BAR ) , FOO_BAR . length ( ) , true , false ) ; } public void test2 ( ) throws Exception { helper ( indexOf ( FOO_BAR ) , FOO_BAR . length ( ) , true , false ) ; } public void test3 ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , true , false ) ; } public void test4 ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , true , false ) ; } public void test5a ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , true , false ) ; } public void test6a ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , true , false ) ; } public void testNoReplaceOccurrences1 ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , false , false ) ; } public void testQualifiedReplace1 ( ) throws Exception { helper ( indexOf ( FOO_BAR_FRAX ) , FOO_BAR_FRAX . length ( ) , true , true ) ; } private int indexOf ( String str ) throws IOException { return getFileContents ( getInputTestFileName ( "<STR_LIT:A>" ) ) . indexOf ( str ) ; } private void helper ( int offset , int length , boolean replaceAllOccurrences , boolean useQualifiedReplace ) throws Exception { GroovyCompilationUnit cu = ( GroovyCompilationUnit ) createCUfromTestFile ( getPackageP ( ) , "<STR_LIT:A>" ) ; try { ExtractGroovyConstantRefactoring refactoring = new ExtractGroovyConstantRefactoring ( cu , offset , length ) ; refactoring . setReplaceAllOccurrences ( replaceAllOccurrences ) ; refactoring . setQualifyReferencesWithDeclaringClassName ( useQualifiedReplace ) ; refactoring . setConstantName ( refactoring . guessConstantName ( ) ) ; RefactoringStatus result = performRefactoring ( refactoring , false ) ; assertTrue ( "<STR_LIT>" , result == null || result . isOK ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getInputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; } finally { performDummySearch ( ) ; cu . delete ( true , null ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extract ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . codebrowsing . tests . AbstractCheckerTests ; import org . codehaus . groovy . eclipse . refactoring . core . extract . StaticExpressionChecker ; import org . eclipse . core . runtime . CoreException ; public class StaticFragmentCheckerTests extends AbstractCheckerTests { public StaticFragmentCheckerTests ( ) { super ( StaticFragmentCheckerTests . class . getName ( ) ) ; } public void testStaticExpressionChecker1 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker2 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker3 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker4 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker5 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker6 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker7 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker8 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } private void checkIsStatic ( String text ) throws CoreException { ModuleNode module = createModuleFromText ( text ) ; StaticExpressionChecker checker = new StaticExpressionChecker ( ) ; boolean result = checker . doVisit ( getLastExpression ( module ) ) ; assertTrue ( "<STR_LIT>" + text + "<STR_LIT>" , result ) ; } private void checkIsNotStatic ( String text ) throws CoreException { ModuleNode module = createModuleFromText ( text ) ; StaticExpressionChecker checker = new StaticExpressionChecker ( ) ; boolean result = checker . doVisit ( getLastExpression ( module ) ) ; assertFalse ( "<STR_LIT>" + text + "<STR_LIT>" , result ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extract ; import java . util . List ; import junit . framework . AssertionFailedError ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . refactoring . core . extract . ConvertGroovyLocalToFieldRefactoring ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTest ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTestSetup ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public class ConvertLocalToFieldTests extends RefactoringTest { private static final Class < ConvertLocalToFieldTests > clazz = ConvertLocalToFieldTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public ConvertLocalToFieldTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new RefactoringTestSetup ( new TestSuite ( clazz ) ) ; } public static Test setUpTest ( Test test ) { return new RefactoringTestSetup ( test ) ; } @ Override protected String getRefactoringPath ( ) { return REFACTORING_PATH ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; fIsPreDeltaTest = true ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } public void testMethodToModule ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testClosureToModule ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testDeclarationWithDef ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testDeclarationWithType ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testReference ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testTupleDeclaration ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testRename ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testInitialization ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testVariableConflict ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testFieldConflict ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testFieldReference ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testException ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testForLoop ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testPostfix ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testPrefix ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testMethodInvocation ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testParameterList ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testArgumentList ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testInnerClass ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testInnerFieldConflict ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testFakeField ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testClosure ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testClosureVariableConflict ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testClosureParameterList ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } public void testClosureImplicitIt ( ) throws Exception { ConvertLocalToFieldTestsData . TestCase testCase = ConvertLocalToFieldTestsData . getTestCases ( ) . get ( "<STR_LIT>" ) ; helper ( testCase ) ; } private void helper ( ConvertLocalToFieldTestsData . TestCase testCase ) throws Exception { GroovyCompilationUnit cu = ( GroovyCompilationUnit ) createCU ( getPackageP ( ) , "<STR_LIT>" , testCase . getInput ( ) ) ; try { ConvertGroovyLocalToFieldRefactoring refactoring = new ConvertGroovyLocalToFieldRefactoring ( cu , testCase . getSelectionOffset ( ) , testCase . getSelectionLength ( ) ) ; refactoring . setFieldName ( testCase . getFieldName ( ) ) ; RefactoringStatus result = null ; try { result = performRefactoring ( refactoring , false ) ; } catch ( AssertionFailedError e ) { if ( testCase . getExpected ( ) == null ) { return ; } else { throw e ; } } if ( testCase . isExpectWarning ( ) ) { assertTrue ( "<STR_LIT>" , result . hasWarning ( ) ) ; } else { assertTrue ( "<STR_LIT>" , result . isOK ( ) ) ; assertEqualLines ( "<STR_LIT>" , testCase . getExpected ( ) , cu . getSource ( ) ) ; } assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , testCase . getInput ( ) , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , testCase . getExpected ( ) , cu . getSource ( ) ) ; } finally { performDummySearch ( ) ; cu . delete ( true , null ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . extract ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . codebrowsing . tests . AbstractCheckerTests ; import org . codehaus . groovy . eclipse . refactoring . core . extract . StaticFragmentChecker ; import org . eclipse . core . runtime . CoreException ; public class StaticExpressionCheckerTests extends AbstractCheckerTests { public StaticExpressionCheckerTests ( ) { super ( StaticExpressionCheckerTests . class . getName ( ) ) ; } public void testStaticExpressionChecker1 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker2 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker3 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker4 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker5 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker6 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker7 ( ) throws Exception { checkIsStatic ( "<STR_LIT>" ) ; } public void testStaticExpressionChecker8 ( ) throws Exception { checkIsNotStatic ( "<STR_LIT>" ) ; } private void checkIsStatic ( String text ) throws CoreException { ModuleNode module = createModuleFromText ( text ) ; StaticFragmentChecker checker = new StaticFragmentChecker ( ) ; boolean result = checker . mayNotBeStatic ( getLastFragment ( module ) ) ; assertTrue ( "<STR_LIT>" + text + "<STR_LIT>" , result ) ; } private void checkIsNotStatic ( String text ) throws CoreException { ModuleNode module = createModuleFromText ( text ) ; StaticFragmentChecker checker = new StaticFragmentChecker ( ) ; boolean result = checker . mayNotBeStatic ( getLastFragment ( module ) ) ; assertFalse ( "<STR_LIT>" + text + "<STR_LIT>" , result ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . io . File ; import java . io . FilenameFilter ; import java . io . IOException ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestSuite ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Platform ; public class BaseTestSuite extends TestSuite { private static class PatternFilter implements FilenameFilter { public PatternFilter ( final String findPattern ) { this . findPattern = "<STR_LIT>" + findPattern + "<STR_LIT>" ; } private String findPattern ; public boolean accept ( final File dir , final String name ) { return name . matches ( findPattern ) ; } } public static List < File > getFileList ( final String search ) { return createFileList ( search , "<STR_LIT>" ) ; } public static List < File > getFileList ( final String subFolder , final String search ) { return createFileList ( search , subFolder ) ; } private static List < File > createFileList ( final String search , final String subFolder ) { final String TEST_FILES = getPathToTestFiles ( ) ; final File dir = new File ( TEST_FILES + subFolder ) ; if ( ! dir . isDirectory ( ) ) { throw new RuntimeException ( "<STR_LIT>" + dir . getAbsolutePath ( ) + "<STR_LIT>" ) ; } final ArrayList < File > fl = new ArrayList < File > ( ) ; for ( final File f : dir . listFiles ( new PatternFilter ( search ) ) ) { fl . add ( f ) ; } return fl ; } private static String getPluginDirectoryPath ( ) { try { URL platformURL = Platform . getBundle ( "<STR_LIT>" ) . getEntry ( "<STR_LIT:/>" ) ; return new File ( FileLocator . toFileURL ( platformURL ) . getFile ( ) ) . getAbsolutePath ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return null ; } public static String getPathToTestFiles ( ) { final String systemSeparator = String . valueOf ( IPath . SEPARATOR ) ; String folders = "<STR_LIT>" ; folders = folders . replaceAll ( "<STR_LIT:/>" , systemSeparator ) ; return getPluginDirectoryPath ( ) + folders ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . Collection ; import java . util . Iterator ; import java . util . List ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IImportDeclaration ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; public final class DebugUtils { private DebugUtils ( ) { } public static void dumpCharCharArray ( String msg , char [ ] [ ] o ) { dump ( "<STR_LIT>" + msg ) ; for ( int i = <NUM_LIT:0> ; i < o . length ; i ++ ) { dump ( new String ( o [ i ] ) ) ; } } public static void dumpArray ( String msg , Object [ ] refs ) { System . out . println ( "<STR_LIT>" + msg ) ; if ( refs == null ) { System . out . println ( "<STR_LIT:null>" ) ; return ; } for ( int i = <NUM_LIT:0> ; i < refs . length ; i ++ ) System . out . println ( refs [ i ] . toString ( ) ) ; } public static void dumpCollectionCollection ( String msg , Collection c ) { for ( Iterator iter = c . iterator ( ) ; iter . hasNext ( ) ; ) { dumpCollection ( "<STR_LIT>" , ( List ) iter . next ( ) ) ; } } public static void dumpCollection ( String msg , Collection c ) { System . out . println ( "<STR_LIT>" + msg ) ; if ( c == null ) { System . out . println ( "<STR_LIT:null>" ) ; return ; } for ( Iterator iter = c . iterator ( ) ; iter . hasNext ( ) ; ) { System . out . println ( iter . next ( ) . toString ( ) ) ; } } public static void dumpIMethod ( IMethod method ) { try { if ( method == null ) { System . out . println ( "<STR_LIT>" ) ; return ; } System . out . println ( "<STR_LIT>" + method . getElementName ( ) + "<STR_LIT>" + method . getSignature ( ) + "<STR_LIT>" + method . getDeclaringType ( ) . getFullyQualifiedName ( '<CHAR_LIT:.>' ) + "<STR_LIT>" + method . getReturnType ( ) ) ; dumpArray ( "<STR_LIT>" , method . getParameterTypes ( ) ) ; dumpArray ( "<STR_LIT>" , method . getExceptionTypes ( ) ) ; } catch ( JavaModelException e ) { System . out . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public static void dumpIMethodList ( String msg , List l ) { System . out . println ( "<STR_LIT>" + msg ) ; if ( l == null ) { System . out . println ( "<STR_LIT:null>" ) ; return ; } Iterator iter = l . iterator ( ) ; while ( iter . hasNext ( ) ) { dumpIMethod ( ( IMethod ) iter . next ( ) ) ; } } public static void dumpIType ( String msg , IType type ) { System . out . println ( "<STR_LIT>" + msg ) ; System . out . println ( "<STR_LIT>" + type . exists ( ) ) ; try { System . out . println ( "<STR_LIT>" + type . getCorrespondingResource ( ) ) ; System . out . println ( "<STR_LIT>" + type . getUnderlyingResource ( ) ) ; System . out . println ( "<STR_LIT>" + type . getSource ( ) ) ; System . out . println ( "<STR_LIT>" + type . getCompilationUnit ( ) . getSource ( ) ) ; } catch ( JavaModelException e ) { System . out . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public static void dumpIResource ( String msg , IResource res ) { System . out . println ( "<STR_LIT>" + msg ) ; System . out . println ( "<STR_LIT>" + res . getFullPath ( ) . toString ( ) ) ; System . out . println ( "<STR_LIT>" + res . exists ( ) ) ; } public static void dump ( Object o ) { if ( o == null ) dump ( "<STR_LIT:null>" ) ; else dump ( o . toString ( ) ) ; } public static void dump ( String msg ) { System . out . println ( "<STR_LIT>" + msg ) ; } public static void dumpImports ( ICompilationUnit cu ) throws JavaModelException { IImportDeclaration [ ] imports = cu . getImports ( ) ; if ( imports == null ) return ; DebugUtils . dump ( "<STR_LIT>" + cu . getElementName ( ) ) ; for ( int k = <NUM_LIT:0> ; k < imports . length ; k ++ ) { DebugUtils . dump ( "<STR_LIT>" + imports [ k ] . getElementName ( ) + "<STR_LIT>" + imports [ k ] . isOnDemand ( ) ) ; } } public static void dumpImports ( IPackageFragment pack ) throws JavaModelException { ICompilationUnit [ ] cus = pack . getCompilationUnits ( ) ; if ( cus == null ) return ; for ( int j = <NUM_LIT:0> ; j < cus . length ; j ++ ) { dumpImports ( cus [ j ] ) ; } } public static void dumpImports ( IJavaProject project ) throws JavaModelException { IPackageFragment [ ] packages = project . getPackageFragments ( ) ; if ( packages == null ) return ; for ( int i = <NUM_LIT:0> ; i < packages . length ; i ++ ) { dumpImports ( packages [ i ] ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . codebrowsing . tests . FindAllOccurrencesVisitorTests ; import org . codehaus . groovy . eclipse . codebrowsing . tests . IsSameExpressionTests ; import org . codehaus . groovy . eclipse . refactoring . test . extract . ExtractConstantTests ; import org . codehaus . groovy . eclipse . refactoring . test . extract . ExtractLocalTests ; import org . codehaus . groovy . eclipse . refactoring . test . extract . StaticExpressionCheckerTests ; import org . codehaus . groovy . eclipse . refactoring . test . extract . StaticFragmentCheckerTests ; import org . codehaus . groovy . eclipse . refactoring . test . extractMethod . ExtractMethodTestSuite ; import org . codehaus . groovy . eclipse . refactoring . test . formatter . FormatterTestSuite ; import org . codehaus . groovy . eclipse . refactoring . test . formatter . SemicolonRemoverTests ; import org . codehaus . groovy . eclipse . refactoring . test . formatter . WhitespaceRemoverTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . MoveCURefactoringTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . RenameFieldTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . RenameLocalTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . RenameMethodTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . RenameTypeTests ; import org . codehaus . groovy . eclipse . refactoring . test . rename . SyntheticAccessorRenamingTests ; public class AllRefactoringTests { public static Test suite ( ) { final TestSuite suite = new TestSuite ( "<STR_LIT>" + AllRefactoringTests . class . getPackage ( ) . getName ( ) ) ; suite . addTest ( RenameTypeTests . suite ( ) ) ; suite . addTest ( RenameMethodTests . suite ( ) ) ; suite . addTest ( RenameFieldTests . suite ( ) ) ; suite . addTest ( RenameLocalTests . suite ( ) ) ; suite . addTest ( new TestSuite ( MoveCURefactoringTests . class ) ) ; suite . addTest ( new TestSuite ( SyntheticAccessorRenamingTests . class ) ) ; suite . addTest ( new TestSuite ( StaticExpressionCheckerTests . class ) ) ; suite . addTest ( new TestSuite ( StaticFragmentCheckerTests . class ) ) ; suite . addTest ( new TestSuite ( IsSameExpressionTests . class ) ) ; suite . addTest ( new TestSuite ( FindAllOccurrencesVisitorTests . class ) ) ; suite . addTest ( ExtractConstantTests . suite ( ) ) ; suite . addTest ( ExtractLocalTests . suite ( ) ) ; suite . addTest ( ExtractMethodTestSuite . suite ( ) ) ; suite . addTest ( FormatterTestSuite . suite ( ) ) ; suite . addTest ( new TestSuite ( SemicolonRemoverTests . class ) ) ; suite . addTest ( new TestSuite ( WhitespaceRemoverTests . class ) ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . Hashtable ; import junit . extensions . TestSetup ; import junit . framework . Test ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility ; import org . eclipse . jdt . internal . corext . template . java . CodeTemplateContextType ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . util . CoreUtility ; import org . eclipse . jdt . testplugin . TestOptions ; public class AbstractRefactoringTestSetup extends TestSetup { private boolean fWasAutobuild ; private Hashtable fWasOptions ; public AbstractRefactoringTestSetup ( Test test ) { super ( test ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; fWasOptions = JavaCore . getOptions ( ) ; fWasAutobuild = CoreUtility . setAutoBuilding ( false ) ; Hashtable options = TestOptions . getDefaultOptions ( ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , JavaCore . TAB ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE , "<STR_LIT:0>" ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , "<STR_LIT:4>" ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_LINE_SPLIT , String . valueOf ( <NUM_LIT> ) ) ; JavaCore . setOptions ( options ) ; TestOptions . initializeCodeGenerationOptions ( ) ; JavaPlugin . getDefault ( ) . getCodeTemplateStore ( ) . load ( ) ; StringBuffer comment = new StringBuffer ( ) ; comment . append ( "<STR_LIT>" ) ; comment . append ( "<STR_LIT>" ) ; comment . append ( "<STR_LIT>" ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . CONSTRUCTORCOMMENT_ID , comment . toString ( ) , null ) ; } protected void tearDown ( ) throws Exception { if ( fWasOptions != null ) { JavaCore . setOptions ( fWasOptions ) ; } CoreUtility . setAutoBuilding ( fWasAutobuild ) ; super . tearDown ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . net . URL ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Plugin ; import org . eclipse . core . runtime . Status ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; public class RefactoringTestPlugin extends Plugin { public static String PLUGIN_ID = "<STR_LIT>" ; private static RefactoringTestPlugin fgDefault ; public RefactoringTestPlugin ( ) { fgDefault = this ; } public static RefactoringTestPlugin getDefault ( ) { return fgDefault ; } public static IWorkspace getWorkspace ( ) { return ResourcesPlugin . getWorkspace ( ) ; } public InputStream getTestResourceStream ( String fileName ) throws IOException { IPath path = new Path ( "<STR_LIT>" ) . append ( fileName ) ; URL url = new URL ( getBundle ( ) . getEntry ( "<STR_LIT:/>" ) , path . toString ( ) ) ; return url . openStream ( ) ; } public File getFileInPlugin ( IPath path ) throws CoreException { try { URL installURL = new URL ( getBundle ( ) . getEntry ( "<STR_LIT:/>" ) , path . toString ( ) ) ; URL localURL = FileLocator . toFileURL ( installURL ) ; return new File ( localURL . getFile ( ) ) ; } catch ( IOException e ) { throw new CoreException ( new Status ( IStatus . ERROR , getPluginId ( ) , IStatus . ERROR , e . getMessage ( ) , e ) ) ; } } public static String getPluginId ( ) { return PLUGIN_ID ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import junit . framework . Assert ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . resources . IResource ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . CheckConditionsContext ; import org . eclipse . ltk . core . refactoring . participants . RenameArguments ; import org . eclipse . ltk . core . refactoring . participants . RenameParticipant ; import org . eclipse . jdt . core . IJavaElement ; public class TestRenameParticipantSingle extends RenameParticipant { private static List fgInstances = new ArrayList ( ) ; private Object fElement ; private String fHandle ; public boolean initialize ( Object element ) { fgInstances . add ( this ) ; fElement = element ; ref ( fElement ) ; if ( fElement instanceof IJavaElement ) { fHandle = ( ( IJavaElement ) fElement ) . getHandleIdentifier ( ) ; } else { fHandle = ( ( IResource ) fElement ) . getFullPath ( ) . toString ( ) ; } return true ; } public String getName ( ) { return getClass ( ) . getName ( ) ; } public RefactoringStatus checkConditions ( IProgressMonitor pm , CheckConditionsContext context ) { return new RefactoringStatus ( ) ; } public Change createChange ( IProgressMonitor pm ) throws CoreException { return null ; } public static void testNumberOfInstances ( int instances ) { Assert . assertEquals ( instances , fgInstances . size ( ) ) ; } public static void testElements ( String [ ] handles ) { testNumberOfInstances ( handles . length ) ; List l1 = new ArrayList ( Arrays . asList ( handles ) ) ; for ( int i = <NUM_LIT:0> ; i < l1 . size ( ) ; i ++ ) { Assert . assertTrue ( l1 . contains ( getInstance ( i ) . fHandle ) ) ; } } public static void testArguments ( RenameArguments [ ] args ) { testNumberOfInstances ( args . length ) ; for ( int i = <NUM_LIT:0> ; i < args . length ; i ++ ) { RenameArguments expected = args [ i ] ; RenameArguments actual = getInstance ( i ) . getArguments ( ) ; Assert . assertEquals ( expected . getNewName ( ) , actual . getNewName ( ) ) ; Assert . assertEquals ( expected . getUpdateReferences ( ) , actual . getUpdateReferences ( ) ) ; } } public static void reset ( ) { fgInstances = new ArrayList ( ) ; } private static TestRenameParticipantSingle getInstance ( int i ) { return ( ( TestRenameParticipantSingle ) fgInstances . get ( i ) ) ; } void ref ( Object element ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import junit . framework . Assert ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . resources . IResource ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . CheckConditionsContext ; import org . eclipse . ltk . core . refactoring . participants . ISharableParticipant ; import org . eclipse . ltk . core . refactoring . participants . RefactoringArguments ; import org . eclipse . ltk . core . refactoring . participants . RenameArguments ; import org . eclipse . ltk . core . refactoring . participants . RenameParticipant ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . refactoring . IJavaElementMapper ; import org . eclipse . jdt . core . refactoring . RenameTypeArguments ; public class TestRenameParticipantShared extends RenameParticipant implements ISharableParticipant { static TestRenameParticipantShared fgInstance ; List fElements = new ArrayList ( <NUM_LIT:3> ) ; List fHandles = new ArrayList ( <NUM_LIT:3> ) ; List fArguments = new ArrayList ( <NUM_LIT:3> ) ; Map fSimilarToHandle = new HashMap ( ) ; Map fSimilarToNewName = new HashMap ( ) ; public boolean initialize ( Object element ) { fgInstance = this ; fElements . add ( element ) ; fArguments . add ( getArguments ( ) ) ; if ( element instanceof IJavaElement ) fHandles . add ( ( ( IJavaElement ) element ) . getHandleIdentifier ( ) ) ; else fHandles . add ( ( ( IResource ) element ) . getFullPath ( ) . toString ( ) ) ; IJavaElementMapper updating = ( IJavaElementMapper ) getProcessor ( ) . getAdapter ( IJavaElementMapper . class ) ; if ( ( updating != null ) && getArguments ( ) instanceof RenameTypeArguments ) { RenameTypeArguments arguments = ( RenameTypeArguments ) getArguments ( ) ; if ( arguments . getUpdateSimilarDeclarations ( ) ) { IJavaElement [ ] elements = arguments . getSimilarDeclarations ( ) ; for ( int i = <NUM_LIT:0> ; i < elements . length ; i ++ ) { IJavaElement updated = updating . getRefactoredJavaElement ( elements [ i ] ) ; if ( updated != null ) { fSimilarToHandle . put ( elements [ i ] . getHandleIdentifier ( ) , getKey ( updated ) ) ; fSimilarToNewName . put ( elements [ i ] . getHandleIdentifier ( ) , updated . getElementName ( ) ) ; } } } } return true ; } private String getKey ( IJavaElement updated ) { if ( updated instanceof IType ) return ( ( IType ) updated ) . getKey ( ) ; else if ( updated instanceof IMethod ) return ( ( IMethod ) updated ) . getKey ( ) ; else if ( updated instanceof IField ) return ( ( IField ) updated ) . getKey ( ) ; return "<STR_LIT>" ; } public void addElement ( Object element , RefactoringArguments args ) { fElements . add ( element ) ; fArguments . add ( args ) ; if ( element instanceof IJavaElement ) fHandles . add ( ( ( IJavaElement ) element ) . getHandleIdentifier ( ) ) ; else fHandles . add ( ( ( IResource ) element ) . getFullPath ( ) . toString ( ) ) ; } public String getName ( ) { return getClass ( ) . getName ( ) ; } public RefactoringStatus checkConditions ( IProgressMonitor pm , CheckConditionsContext context ) { return new RefactoringStatus ( ) ; } public Change createChange ( IProgressMonitor pm ) throws CoreException { return null ; } public static void testNumberOfElements ( int expected ) { if ( expected == <NUM_LIT:0> ) { Assert . assertTrue ( fgInstance == null ) ; } else { Assert . assertEquals ( expected , fgInstance . fElements . size ( ) ) ; Assert . assertEquals ( expected , fgInstance . fArguments . size ( ) ) ; } } public static void testArguments ( RenameArguments [ ] args ) { testNumberOfElements ( args . length ) ; for ( int i = <NUM_LIT:0> ; i < args . length ; i ++ ) { RenameArguments expected = args [ i ] ; RenameArguments actual = ( RenameArguments ) fgInstance . fArguments . get ( i ) ; Assert . assertEquals ( expected . getNewName ( ) , actual . getNewName ( ) ) ; Assert . assertEquals ( expected . getUpdateReferences ( ) , actual . getUpdateReferences ( ) ) ; } } public static void reset ( ) { fgInstance = null ; } public static void testNumberOfSimilarElements ( int expected ) { if ( expected == <NUM_LIT:0> ) Assert . assertTrue ( fgInstance == null ) ; else Assert . assertEquals ( expected , fgInstance . fSimilarToHandle . size ( ) ) ; } public static void testSimilarElements ( List similarList , List similarNewNameList , List similarNewHandleList ) { for ( int i = <NUM_LIT:0> ; i < similarList . size ( ) ; i ++ ) { String handle = ( String ) similarList . get ( i ) ; String newHandle = ( String ) similarNewHandleList . get ( i ) ; String newName = ( String ) similarNewNameList . get ( i ) ; String actualNewHandle = ( String ) fgInstance . fSimilarToHandle . get ( handle ) ; String actualNewName = ( String ) fgInstance . fSimilarToNewName . get ( handle ) ; Assert . assertEquals ( "<STR_LIT>" , newHandle , actualNewHandle ) ; Assert . assertEquals ( "<STR_LIT>" , newName , actualNewName ) ; } Assert . assertEquals ( similarList . size ( ) , fgInstance . fSimilarToHandle . size ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . IOException ; import java . util . HashMap ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . refactoring . core . utils . ASTTools ; import org . codehaus . groovy . eclipse . refactoring . core . utils . FilePartReader ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . TextSelection ; public abstract class BaseTestCase extends TestCase { protected File file ; private final String newLine ; private final Pattern origRegExp , expRegExp , propertiesRegExp ; private final String name ; private final IDocument doc ; protected boolean shouldFail = false ; protected HashMap < String , String > properties ; protected TextSelection selection ; protected BaseTestCase ( String name , File fileToTest ) { setFile ( fileToTest ) ; this . name = name ; newLine = FilePartReader . getLineDelimiter ( file ) ; origRegExp = Pattern . compile ( "<STR_LIT>" + newLine + "<STR_LIT>" + newLine + "<STR_LIT>" , Pattern . DOTALL ) ; expRegExp = Pattern . compile ( "<STR_LIT>" + newLine + "<STR_LIT>" + newLine + "<STR_LIT>" , Pattern . DOTALL ) ; propertiesRegExp = Pattern . compile ( "<STR_LIT>" + newLine + "<STR_LIT>" + newLine + "<STR_LIT>" , Pattern . DOTALL ) ; properties = getFileProperties ( ) ; doc = getOrigin ( ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; selection = getUserSelection ( ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } protected void setFile ( File file ) { this . file = file ; } @ Override public String getName ( ) { return name ; } public IDocument getOrigin ( ) { return getArea ( origRegExp ) ; } public IDocument getExpected ( ) { return getArea ( expRegExp ) ; } public IDocument getArea ( Pattern regExpression ) { String filecontent = getContents ( file ) ; Matcher match = regExpression . matcher ( filecontent ) ; if ( match . find ( ) ) { String fileContent = match . group ( <NUM_LIT:1> ) ; return ASTTools . getDocumentWithSystemLineBreak ( fileContent ) ; } return new Document ( ) ; } public TextSelection getUserSelection ( ) { try { selection = getSelection ( ) ; } catch ( Exception e ) { fail ( e . getMessage ( ) ) ; } return selection ; } private TextSelection getSelection ( ) { try { int startLine = getInt ( "<STR_LIT>" ) ; int startColumn = getInt ( "<STR_LIT>" ) ; int endLine = getInt ( "<STR_LIT>" ) ; int endColumn = getInt ( "<STR_LIT>" ) ; IRegion startRegion = getDocument ( ) . getLineInformation ( startLine - <NUM_LIT:1> ) ; int offset = startRegion . getOffset ( ) + startColumn - <NUM_LIT:1> ; IRegion endRegion = getDocument ( ) . getLineInformation ( endLine - <NUM_LIT:1> ) ; int end = endRegion . getOffset ( ) + endColumn - <NUM_LIT:1> ; return new TextSelection ( offset , end - offset ) ; } catch ( BadLocationException e ) { return new TextSelection ( <NUM_LIT:0> , getDocument ( ) . getLength ( ) ) ; } } private int getInt ( String startLine ) { try { return Integer . valueOf ( properties . get ( startLine ) ) ; } catch ( NumberFormatException e ) { return - <NUM_LIT:1> ; } } public HashMap < String , String > getFileProperties ( ) { HashMap < String , String > properties = new HashMap < String , String > ( ) ; Matcher propertiesSection = propertiesRegExp . matcher ( getContents ( file ) ) ; if ( propertiesSection . find ( ) ) { String [ ] reults = propertiesSection . group ( <NUM_LIT:1> ) . split ( FilePartReader . getLineDelimiter ( file ) ) ; for ( String line : reults ) { String [ ] prop = line . split ( "<STR_LIT:=>" ) ; if ( prop . length != <NUM_LIT:2> ) fail ( "<STR_LIT>" ) ; properties . put ( prop [ <NUM_LIT:0> ] , prop [ <NUM_LIT:1> ] ) ; } try { if ( properties . get ( "<STR_LIT>" ) != null && properties . get ( "<STR_LIT>" ) . equals ( "<STR_LIT:true>" ) ) shouldFail = true ; } catch ( Exception e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } return properties ; } public IDocument getDocument ( ) { return doc ; } public void finalAssert ( ) { String expected = getExpected ( ) . get ( ) ; String content = getDocument ( ) . get ( ) ; assertEquals ( "<STR_LIT>" + file + "<STR_LIT:U+0020>" , expected , content ) ; } static public String getContents ( File aFile ) { StringBuilder contents = new StringBuilder ( ) ; try { BufferedReader input = new BufferedReader ( new FileReader ( aFile ) ) ; try { String line = null ; while ( ( line = input . readLine ( ) ) != null ) { contents . append ( line ) ; contents . append ( FilePartReader . getLineDelimiter ( aFile ) ) ; } } finally { input . close ( ) ; } } catch ( IOException ex ) { ex . printStackTrace ( ) ; } return contents . toString ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . HashMap ; import org . codehaus . groovy . eclipse . refactoring . PreferenceConstants ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . preference . PreferenceStore ; public class TestPrefInitializer { public static IPreferenceStore initializePreferences ( HashMap < String , String > properties ) { IPreferenceStore pref = new PreferenceStore ( ) ; String indentation = properties . get ( "<STR_LIT>" ) ; if ( indentation != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_INDENTATION , indentation ) ; } String tabsize = properties . get ( "<STR_LIT>" ) ; if ( tabsize != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_INDENTATION_SIZE , Integer . parseInt ( tabsize ) ) ; pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_TAB_SIZE , Integer . parseInt ( tabsize ) ) ; } String indentsize = properties . get ( "<STR_LIT>" ) ; if ( indentsize != null ) { if ( "<STR_LIT>" . equals ( indentation ) ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_TAB_SIZE , Integer . parseInt ( indentsize ) ) ; } else { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_INDENTATION_SIZE , Integer . parseInt ( indentsize ) ) ; } } String multiInd = properties . get ( "<STR_LIT>" ) ; if ( multiInd != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_MULTILINE_INDENTATION , Integer . parseInt ( multiInd ) ) ; } String bracesStart = properties . get ( "<STR_LIT>" ) ; if ( bracesStart != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_BRACES_START , bracesStart ) ; } String bracesEnd = properties . get ( "<STR_LIT>" ) ; if ( bracesEnd != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_BRACES_END , bracesEnd ) ; } String maxLineLength = properties . get ( "<STR_LIT>" ) ; if ( maxLineLength != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_MAX_LINELENGTH , Integer . parseInt ( maxLineLength ) ) ; } String longListLength = properties . get ( "<STR_LIT>" ) ; if ( longListLength != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_LONG_LIST_LENGTH , Integer . parseInt ( longListLength ) ) ; } String indentEmptyLines = properties . get ( "<STR_LIT>" ) ; if ( indentEmptyLines != null ) { pref . setValue ( DefaultCodeFormatterConstants . FORMATTER_INDENT_EMPTY_LINES , indentEmptyLines ) ; } String removeUnnecessarySemicolons = properties . get ( "<STR_LIT>" ) ; if ( removeUnnecessarySemicolons != null ) { pref . setValue ( PreferenceConstants . GROOVY_FORMATTER_REMOVE_UNNECESSARY_SEMICOLONS , removeUnnecessarySemicolons ) ; } return pref ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . CompilationUnit ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . CheckConditionsOperation ; import org . eclipse . ltk . core . refactoring . CreateChangeOperation ; import org . eclipse . ltk . core . refactoring . IUndoManager ; import org . eclipse . ltk . core . refactoring . PerformChangeOperation ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringDescriptor ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . RefactoringStatusEntry ; public abstract class AbstractRefactoringTest extends EclipseTestCase { @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; testProject . addNature ( GroovyNature . GROOVY_NATURE ) ; testProject . createPackage ( "<STR_LIT:p>" ) ; } protected ICompilationUnit [ ] createUnits ( String [ ] packages , String [ ] cuNames , String [ ] cuContents ) throws CoreException { return testProject . createUnits ( packages , cuNames , cuContents ) ; } protected ICompilationUnit createUnit ( String pkg , String cuName , String cuContents ) throws CoreException { return testProject . createUnit ( pkg , cuName , cuContents ) ; } protected void assertContents ( ICompilationUnit [ ] existingUnits , String [ ] expectedContents ) throws JavaModelException { StringBuffer sb = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < existingUnits . length ; i ++ ) { if ( expectedContents [ i ] != null ) { char [ ] contents = extractContents ( existingUnits [ i ] ) ; String actualContents = String . valueOf ( contents ) ; if ( ! actualContents . equals ( expectedContents [ i ] ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( expectedContents [ i ] ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( actualContents ) ; } } else { if ( existingUnits [ i ] . exists ( ) ) { sb . append ( "<STR_LIT>" + existingUnits [ i ] . getElementName ( ) + "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( extractContents ( existingUnits [ i ] ) ) ; } } } if ( sb . length ( ) > <NUM_LIT:0> ) { fail ( "<STR_LIT>" + sb . toString ( ) ) ; } } public char [ ] extractContents ( ICompilationUnit unit ) throws JavaModelException { return ( ( CompilationUnit ) unit ) . getContents ( ) ; } protected void assertContents ( ICompilationUnit existingUnits , String expectedContents ) throws JavaModelException { StringBuffer sb = new StringBuffer ( ) ; char [ ] contents ; contents = extractContents ( existingUnits ) ; String actualContents = String . valueOf ( contents ) ; if ( ! actualContents . equals ( expectedContents ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( expectedContents ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( actualContents ) ; } if ( sb . length ( ) > <NUM_LIT:0> ) { fail ( "<STR_LIT>" + sb . toString ( ) ) ; } } protected RefactoringStatus performRefactoring ( Refactoring ref , boolean providesUndo , boolean performOnFail ) throws Exception { super . fullProjectBuild ( ) ; performDummySearch ( ) ; IUndoManager undoManager = getUndoManager ( ) ; final CreateChangeOperation create = new CreateChangeOperation ( new CheckConditionsOperation ( ref , CheckConditionsOperation . ALL_CONDITIONS ) , RefactoringStatus . FATAL ) ; final PerformChangeOperation perform = new PerformChangeOperation ( create ) ; perform . setUndoManager ( undoManager , ref . getName ( ) ) ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; executePerformOperation ( perform , workspace ) ; RefactoringStatus status = create . getConditionCheckingStatus ( ) ; assertTrue ( "<STR_LIT>" , perform . changeExecuted ( ) || ! perform . changeExecutionFailed ( ) ) ; Change undo = perform . getUndoChange ( ) ; if ( providesUndo ) { assertNotNull ( "<STR_LIT>" , undo ) ; assertTrue ( "<STR_LIT>" , undoManager . anythingToUndo ( ) ) ; } else { assertNull ( "<STR_LIT>" , undo ) ; } return status ; } protected RefactoringStatus ignoreKnownErrors ( RefactoringStatus result ) { if ( result . getSeverity ( ) != RefactoringStatus . ERROR ) { return result ; } RefactoringStatusEntry [ ] entries = result . getEntries ( ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { if ( ! checkStringForKnownErrors ( entries [ i ] . getMessage ( ) ) && entries [ i ] . isError ( ) ) { return result ; } } return new RefactoringStatus ( ) ; } private boolean checkStringForKnownErrors ( String resultString ) { return resultString . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> || resultString . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> || resultString . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> || resultString . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> || resultString . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> ; } protected void performDummySearch ( ) throws Exception { RefactoringTest . performDummySearch ( testProject . getJavaProject ( ) . findPackageFragment ( new Path ( "<STR_LIT>" ) ) ) ; } protected final Refactoring createRefactoring ( RefactoringDescriptor descriptor ) throws CoreException { RefactoringStatus status = new RefactoringStatus ( ) ; Refactoring refactoring = descriptor . createRefactoring ( status ) ; assertNotNull ( "<STR_LIT>" , refactoring ) ; assertTrue ( "<STR_LIT>" + status , status . isOK ( ) ) ; return refactoring ; } protected IUndoManager getUndoManager ( ) { IUndoManager undoManager = RefactoringCore . getUndoManager ( ) ; undoManager . flush ( ) ; return undoManager ; } protected void executePerformOperation ( final PerformChangeOperation perform , IWorkspace workspace ) throws CoreException { workspace . run ( perform , new NullProgressMonitor ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . io . BufferedReader ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . refactoring . core . rename . ForcePreviewParticipant ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMember ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . ISourceManipulation ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . refactoring . descriptors . JavaRefactoringDescriptor ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . TypeNameRequestor ; import org . eclipse . jdt . internal . corext . refactoring . util . JavaElementUtil ; import org . eclipse . jdt . internal . corext . util . Strings ; import org . eclipse . jdt . testplugin . JavaProjectHelper ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . ChangeDescriptor ; import org . eclipse . ltk . core . refactoring . CheckConditionsOperation ; import org . eclipse . ltk . core . refactoring . CreateChangeOperation ; import org . eclipse . ltk . core . refactoring . IUndoManager ; import org . eclipse . ltk . core . refactoring . PerformChangeOperation ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringChangeDescriptor ; import org . eclipse . ltk . core . refactoring . RefactoringContribution ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringDescriptor ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public abstract class RefactoringTest extends TestCase { private static final boolean DESCRIPTOR_TEST = false ; private IPackageFragmentRoot fRoot ; private IPackageFragment fPackageP ; public boolean fIsPreDeltaTest = false ; public static final String TEST_PATH_PREFIX = "<STR_LIT>" ; protected static final String TEST_INPUT_INFIX = "<STR_LIT>" ; protected static final String TEST_OUTPUT_INFIX = "<STR_LIT>" ; protected static final String CONTAINER = "<STR_LIT:src>" ; protected static final List PROJECT_RESOURCE_CHILDREN = Arrays . asList ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; public RefactoringTest ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { fRoot = RefactoringTestSetup . getDefaultSourceFolder ( ) ; fPackageP = RefactoringTestSetup . getPackageP ( ) ; fIsPreDeltaTest = false ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getClass ( ) + "<STR_LIT:.>" + getName ( ) ) ; RefactoringCore . getUndoManager ( ) . flush ( ) ; ForcePreviewParticipant . mute ( ) ; } protected void performDummySearch ( ) throws Exception { performDummySearch ( getPackageP ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { try { refreshFromLocal ( ) ; performDummySearch ( ) ; if ( getPackageP ( ) . exists ( ) ) { tryDeletingAllJavaChildren ( getPackageP ( ) ) ; tryDeletingAllNonJavaChildResources ( getPackageP ( ) ) ; } if ( getRoot ( ) . exists ( ) ) { IJavaElement [ ] packages = getRoot ( ) . getChildren ( ) ; for ( int i = <NUM_LIT:0> ; i < packages . length ; i ++ ) { IPackageFragment pack = ( IPackageFragment ) packages [ i ] ; if ( ! pack . equals ( getPackageP ( ) ) && pack . exists ( ) && ! pack . isReadOnly ( ) ) if ( pack . isDefaultPackage ( ) ) pack . delete ( true , null ) ; else JavaProjectHelper . delete ( pack . getResource ( ) ) ; } } restoreTestProject ( ) ; } finally { TestRenameParticipantShared . reset ( ) ; TestRenameParticipantSingle . reset ( ) ; ForcePreviewParticipant . unmute ( ) ; } } private void restoreTestProject ( ) throws Exception { IJavaProject javaProject = getRoot ( ) . getJavaProject ( ) ; if ( javaProject . exists ( ) ) { IClasspathEntry srcEntry = getRoot ( ) . getRawClasspathEntry ( ) ; try { IClasspathEntry [ ] jreEntries = RefactoringTestSetup . getJRELibrariesAsRawClasspathEntry ( ) ; IClasspathEntry [ ] cpes = javaProject . getRawClasspath ( ) ; ArrayList newCPEs = new ArrayList ( ) ; boolean cpChanged = false ; for ( int i = <NUM_LIT:0> ; i < cpes . length ; i ++ ) { IClasspathEntry cpe = cpes [ i ] ; boolean isJREEntry = false ; for ( int j = <NUM_LIT:0> ; j < jreEntries . length ; j ++ ) { if ( cpe . equals ( jreEntries [ j ] ) ) { isJREEntry = true ; break ; } } if ( cpe . equals ( srcEntry ) || isJREEntry ) { newCPEs . add ( cpe ) ; } else { cpChanged = true ; } } if ( cpChanged ) { IClasspathEntry [ ] newCPEsArray = ( IClasspathEntry [ ] ) newCPEs . toArray ( new IClasspathEntry [ newCPEs . size ( ) ] ) ; javaProject . setRawClasspath ( newCPEsArray , null ) ; } } catch ( JavaModelException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } Object [ ] nonJavaResources = javaProject . getNonJavaResources ( ) ; for ( int i = <NUM_LIT:0> ; i < nonJavaResources . length ; i ++ ) { Object kid = nonJavaResources [ i ] ; if ( kid instanceof IResource ) { IResource resource = ( IResource ) kid ; if ( ! PROJECT_RESOURCE_CHILDREN . contains ( resource . getName ( ) ) ) { JavaProjectHelper . delete ( resource ) ; } } } } } private void refreshFromLocal ( ) throws CoreException { if ( getRoot ( ) . exists ( ) ) getRoot ( ) . getResource ( ) . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; else if ( getPackageP ( ) . exists ( ) ) getPackageP ( ) . getResource ( ) . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; } private static void tryDeletingAllNonJavaChildResources ( IPackageFragment pack ) throws CoreException { Object [ ] nonJavaKids = pack . getNonJavaResources ( ) ; for ( int i = <NUM_LIT:0> ; i < nonJavaKids . length ; i ++ ) { if ( nonJavaKids [ i ] instanceof IResource ) { IResource resource = ( IResource ) nonJavaKids [ i ] ; JavaProjectHelper . delete ( resource ) ; } } } private static void tryDeletingAllJavaChildren ( IPackageFragment pack ) throws CoreException { IJavaElement [ ] kids = pack . getChildren ( ) ; for ( int i = <NUM_LIT:0> ; i < kids . length ; i ++ ) { if ( kids [ i ] instanceof ISourceManipulation ) { if ( kids [ i ] . exists ( ) && ! kids [ i ] . isReadOnly ( ) ) JavaProjectHelper . delete ( kids [ i ] ) ; } } } protected IPackageFragmentRoot getRoot ( ) { return fRoot ; } protected IPackageFragment getPackageP ( ) { return fPackageP ; } protected IJavaProject getProject ( ) { return fRoot . getJavaProject ( ) ; } protected final RefactoringStatus performRefactoring ( RefactoringDescriptor descriptor ) throws Exception { return performRefactoring ( descriptor , true ) ; } protected final RefactoringStatus performRefactoring ( RefactoringDescriptor descriptor , boolean providesUndo ) throws Exception { Refactoring refactoring = createRefactoring ( descriptor ) ; return performRefactoring ( refactoring , providesUndo ) ; } protected final Refactoring createRefactoring ( RefactoringDescriptor descriptor ) throws CoreException { RefactoringStatus status = new RefactoringStatus ( ) ; Refactoring refactoring = descriptor . createRefactoring ( status ) ; assertNotNull ( "<STR_LIT>" , refactoring ) ; assertTrue ( "<STR_LIT>" , status . isOK ( ) ) ; return refactoring ; } protected final RefactoringStatus performRefactoring ( Refactoring ref , boolean performOnFail ) throws Exception { return performRefactoring ( ref , true , performOnFail ) ; } protected final RefactoringStatus performRefactoring ( Refactoring ref , boolean providesUndo , boolean performOnFail ) throws Exception { performDummySearch ( ) ; IUndoManager undoManager = getUndoManager ( ) ; if ( DESCRIPTOR_TEST ) { final CreateChangeOperation create = new CreateChangeOperation ( new CheckConditionsOperation ( ref , CheckConditionsOperation . ALL_CONDITIONS ) , RefactoringStatus . FATAL ) ; create . run ( new NullProgressMonitor ( ) ) ; RefactoringStatus checkingStatus = create . getConditionCheckingStatus ( ) ; if ( checkingStatus . hasError ( ) ) return checkingStatus ; Change change = create . getChange ( ) ; ChangeDescriptor descriptor = change . getDescriptor ( ) ; if ( descriptor instanceof RefactoringChangeDescriptor ) { RefactoringChangeDescriptor rcd = ( RefactoringChangeDescriptor ) descriptor ; RefactoringDescriptor refactoringDescriptor = rcd . getRefactoringDescriptor ( ) ; if ( refactoringDescriptor instanceof JavaRefactoringDescriptor ) { JavaRefactoringDescriptor jrd = ( JavaRefactoringDescriptor ) refactoringDescriptor ; RefactoringStatus validation = jrd . validateDescriptor ( ) ; if ( validation . hasError ( ) && ! performOnFail ) return validation ; RefactoringStatus refactoringStatus = new RefactoringStatus ( ) ; Class expected = jrd . getClass ( ) ; RefactoringContribution contribution = RefactoringCore . getRefactoringContribution ( jrd . getID ( ) ) ; jrd = ( JavaRefactoringDescriptor ) contribution . createDescriptor ( jrd . getID ( ) , jrd . getProject ( ) , jrd . getDescription ( ) , jrd . getComment ( ) , contribution . retrieveArgumentMap ( jrd ) , jrd . getFlags ( ) ) ; assertEquals ( expected , jrd . getClass ( ) ) ; ref = jrd . createRefactoring ( refactoringStatus ) ; if ( refactoringStatus . hasError ( ) && ! performOnFail ) return refactoringStatus ; TestRenameParticipantSingle . reset ( ) ; } } } final CreateChangeOperation create = new CreateChangeOperation ( new CheckConditionsOperation ( ref , CheckConditionsOperation . ALL_CONDITIONS ) , RefactoringStatus . FATAL ) ; final PerformChangeOperation perform = new PerformChangeOperation ( create ) ; perform . setUndoManager ( undoManager , ref . getName ( ) ) ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; executePerformOperation ( perform , workspace ) ; RefactoringStatus status = create . getConditionCheckingStatus ( ) ; if ( ! status . hasError ( ) && ! performOnFail ) return status ; assertTrue ( "<STR_LIT>" , perform . changeExecuted ( ) ) ; Change undo = perform . getUndoChange ( ) ; if ( providesUndo ) { assertNotNull ( "<STR_LIT>" , undo ) ; assertTrue ( "<STR_LIT>" , undoManager . anythingToUndo ( ) ) ; } else { assertNull ( "<STR_LIT>" , undo ) ; } return null ; } protected void executePerformOperation ( final PerformChangeOperation perform , IWorkspace workspace ) throws CoreException { workspace . run ( perform , new NullProgressMonitor ( ) ) ; } public RefactoringStatus performRefactoringWithStatus ( Refactoring ref , boolean performOnFail ) throws Exception , CoreException { RefactoringStatus status = performRefactoring ( ref , performOnFail ) ; if ( status == null ) return new RefactoringStatus ( ) ; return status ; } protected final Change performChange ( Refactoring refactoring , boolean storeUndo ) throws Exception { CreateChangeOperation create = new CreateChangeOperation ( refactoring ) ; PerformChangeOperation perform = new PerformChangeOperation ( create ) ; if ( storeUndo ) { perform . setUndoManager ( getUndoManager ( ) , refactoring . getName ( ) ) ; } ResourcesPlugin . getWorkspace ( ) . run ( perform , new NullProgressMonitor ( ) ) ; assertTrue ( "<STR_LIT>" , perform . changeExecuted ( ) ) ; return perform . getUndoChange ( ) ; } protected final Change performChange ( final Change change ) throws Exception { PerformChangeOperation perform = new PerformChangeOperation ( change ) ; ResourcesPlugin . getWorkspace ( ) . run ( perform , new NullProgressMonitor ( ) ) ; assertTrue ( "<STR_LIT>" , perform . changeExecuted ( ) ) ; return perform . getUndoChange ( ) ; } protected IUndoManager getUndoManager ( ) { IUndoManager undoManager = RefactoringCore . getUndoManager ( ) ; undoManager . flush ( ) ; return undoManager ; } protected IType getType ( ICompilationUnit cu , String name ) throws JavaModelException { IType [ ] types = cu . getAllTypes ( ) ; for ( int i = <NUM_LIT:0> ; i < types . length ; i ++ ) if ( types [ i ] . getTypeQualifiedName ( '<CHAR_LIT:.>' ) . equals ( name ) || types [ i ] . getElementName ( ) . equals ( name ) ) return types [ i ] ; return null ; } protected String getRefactoringPath ( ) { return "<STR_LIT>" ; } protected String getTestPath ( ) { return TEST_PATH_PREFIX + getRefactoringPath ( ) ; } protected String createTestFileName ( String cuName , String infix ) { return getTestPath ( ) + getName ( ) + infix + cuName + "<STR_LIT>" ; } protected String getInputTestFileName ( String cuName ) { return createTestFileName ( cuName , TEST_INPUT_INFIX ) ; } protected String getInputTestFileName ( String cuName , String subDirName ) { return createTestFileName ( cuName , TEST_INPUT_INFIX + subDirName ) ; } protected String getOutputTestFileName ( String cuName ) { return createTestFileName ( cuName , TEST_OUTPUT_INFIX ) ; } protected String getOutputTestFileName ( String cuName , String subDirName ) { return createTestFileName ( cuName , TEST_OUTPUT_INFIX + subDirName ) ; } protected ICompilationUnit createCUfromTestFile ( IPackageFragment pack , String cuName ) throws Exception { return createCUfromTestFile ( pack , cuName , true ) ; } protected ICompilationUnit createCUfromTestFile ( IPackageFragment pack , String cuName , String subDirName ) throws Exception { return createCUfromTestFile ( pack , cuName , subDirName , true ) ; } protected ICompilationUnit createCUfromTestFile ( IPackageFragment pack , String cuName , boolean input ) throws Exception { String contents = input ? getFileContents ( getInputTestFileName ( cuName ) ) : getFileContents ( getOutputTestFileName ( cuName ) ) ; return createCU ( pack , cuName + "<STR_LIT>" , contents ) ; } protected ICompilationUnit createCUfromTestFile ( IPackageFragment pack , String cuName , String subDirName , boolean input ) throws Exception { String contents = input ? getFileContents ( getInputTestFileName ( cuName , subDirName ) ) : getFileContents ( getOutputTestFileName ( cuName , subDirName ) ) ; return createCU ( pack , cuName + "<STR_LIT>" , contents ) ; } protected void printTestDisabledMessage ( String explanation ) { System . out . println ( "<STR_LIT:n>" + getClass ( ) . getName ( ) + "<STR_LIT>" + getName ( ) + "<STR_LIT>" + explanation + "<STR_LIT:)>" ) ; } public static InputStream getStream ( String content ) { return new ByteArrayInputStream ( content . getBytes ( ) ) ; } public static IPackageFragmentRoot getSourceFolder ( IJavaProject javaProject , String name ) throws JavaModelException { IPackageFragmentRoot [ ] roots = javaProject . getPackageFragmentRoots ( ) ; for ( int i = <NUM_LIT:0> ; i < roots . length ; i ++ ) { if ( ! roots [ i ] . isArchive ( ) && roots [ i ] . getElementName ( ) . equals ( name ) ) return roots [ i ] ; } return null ; } public String getFileContents ( String fileName ) throws IOException { return getContents ( getFileInputStream ( fileName ) ) ; } public static String getContents ( IFile file ) throws IOException , CoreException { return getContents ( file . getContents ( ) ) ; } public static ICompilationUnit createCU ( IPackageFragment pack , String name , String contents ) throws Exception { assertTrue ( ! pack . getCompilationUnit ( name ) . exists ( ) ) ; ICompilationUnit cu = pack . createCompilationUnit ( name , contents , true , null ) ; cu . save ( null , true ) ; return cu ; } public static String getContents ( InputStream in ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; StringBuffer sb = new StringBuffer ( <NUM_LIT> ) ; try { int read = <NUM_LIT:0> ; while ( ( read = br . read ( ) ) != - <NUM_LIT:1> ) sb . append ( ( char ) read ) ; } finally { br . close ( ) ; } return sb . toString ( ) ; } public static InputStream getFileInputStream ( String fileName ) throws IOException { return RefactoringTestPlugin . getDefault ( ) . getTestResourceStream ( fileName ) ; } public static String removeExtension ( String fileName ) { return fileName . substring ( <NUM_LIT:0> , fileName . lastIndexOf ( '<CHAR_LIT:.>' ) ) ; } public static void performDummySearch ( IJavaElement element ) throws Exception { new SearchEngine ( ) . searchAllTypeNames ( null , SearchPattern . R_EXACT_MATCH , "<STR_LIT>" . toCharArray ( ) , SearchPattern . R_EXACT_MATCH , IJavaSearchConstants . CLASS , SearchEngine . createJavaSearchScope ( new IJavaElement [ ] { element } ) , new Requestor ( ) , IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH , null ) ; } public static IMember [ ] merge ( IMember [ ] a1 , IMember [ ] a2 , IMember [ ] a3 ) { return JavaElementUtil . merge ( JavaElementUtil . merge ( a1 , a2 ) , a3 ) ; } public static IMember [ ] merge ( IMember [ ] a1 , IMember [ ] a2 ) { return JavaElementUtil . merge ( a1 , a2 ) ; } public static IField [ ] getFields ( IType type , String [ ] names ) { if ( names == null ) return new IField [ <NUM_LIT:0> ] ; Set fields = new HashSet ( ) ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { IField field = type . getField ( names [ i ] ) ; assertTrue ( "<STR_LIT>" + field . getElementName ( ) + "<STR_LIT>" , field . exists ( ) ) ; fields . add ( field ) ; } return ( IField [ ] ) fields . toArray ( new IField [ fields . size ( ) ] ) ; } public static IType [ ] getMemberTypes ( IType type , String [ ] names ) { if ( names == null ) return new IType [ <NUM_LIT:0> ] ; Set memberTypes = new HashSet ( ) ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { IType memberType ; if ( names [ i ] . indexOf ( '<CHAR_LIT:.>' ) != - <NUM_LIT:1> ) { String [ ] path = names [ i ] . split ( "<STR_LIT:\\.>" ) ; memberType = type . getType ( path [ <NUM_LIT:0> ] ) ; for ( int j = <NUM_LIT:1> ; j < path . length ; j ++ ) { memberType = memberType . getType ( path [ j ] ) ; } } else memberType = type . getType ( names [ i ] ) ; assertTrue ( "<STR_LIT>" + memberType . getElementName ( ) + "<STR_LIT>" , memberType . exists ( ) ) ; memberTypes . add ( memberType ) ; } return ( IType [ ] ) memberTypes . toArray ( new IType [ memberTypes . size ( ) ] ) ; } public static IMethod [ ] getMethods ( IType type , String [ ] names , String [ ] [ ] signatures ) { if ( names == null || signatures == null ) return new IMethod [ <NUM_LIT:0> ] ; List methods = new ArrayList ( names . length ) ; for ( int i = <NUM_LIT:0> ; i < names . length ; i ++ ) { IMethod method = type . getMethod ( names [ i ] , signatures [ i ] ) ; assertTrue ( "<STR_LIT>" + method . getElementName ( ) + "<STR_LIT>" , method . exists ( ) ) ; if ( ! methods . contains ( method ) ) methods . add ( method ) ; } return ( IMethod [ ] ) methods . toArray ( new IMethod [ methods . size ( ) ] ) ; } public static IType [ ] findTypes ( IType [ ] types , String [ ] namesOfTypesToPullUp ) { List found = new ArrayList ( types . length ) ; for ( int i = <NUM_LIT:0> ; i < types . length ; i ++ ) { IType type = types [ i ] ; for ( int j = <NUM_LIT:0> ; j < namesOfTypesToPullUp . length ; j ++ ) { String name = namesOfTypesToPullUp [ j ] ; if ( type . getElementName ( ) . equals ( name ) ) found . add ( type ) ; } } return ( IType [ ] ) found . toArray ( new IType [ found . size ( ) ] ) ; } public static IField [ ] findFields ( IField [ ] fields , String [ ] namesOfFieldsToPullUp ) { List found = new ArrayList ( fields . length ) ; for ( int i = <NUM_LIT:0> ; i < fields . length ; i ++ ) { IField field = fields [ i ] ; for ( int j = <NUM_LIT:0> ; j < namesOfFieldsToPullUp . length ; j ++ ) { String name = namesOfFieldsToPullUp [ j ] ; if ( field . getElementName ( ) . equals ( name ) ) found . add ( field ) ; } } return ( IField [ ] ) found . toArray ( new IField [ found . size ( ) ] ) ; } public static IMethod [ ] findMethods ( IMethod [ ] selectedMethods , String [ ] namesOfMethods , String [ ] [ ] signaturesOfMethods ) { List found = new ArrayList ( selectedMethods . length ) ; for ( int i = <NUM_LIT:0> ; i < selectedMethods . length ; i ++ ) { IMethod method = selectedMethods [ i ] ; String [ ] paramTypes = method . getParameterTypes ( ) ; for ( int j = <NUM_LIT:0> ; j < namesOfMethods . length ; j ++ ) { String methodName = namesOfMethods [ j ] ; if ( ! methodName . equals ( method . getElementName ( ) ) ) continue ; String [ ] methodSig = signaturesOfMethods [ j ] ; if ( ! areSameSignatures ( paramTypes , methodSig ) ) continue ; found . add ( method ) ; } } return ( IMethod [ ] ) found . toArray ( new IMethod [ found . size ( ) ] ) ; } private static boolean areSameSignatures ( String [ ] s1 , String [ ] s2 ) { if ( s1 . length != s2 . length ) return false ; for ( int i = <NUM_LIT:0> ; i < s1 . length ; i ++ ) { if ( ! s1 [ i ] . equals ( s2 [ i ] ) ) return false ; } return true ; } public static void assertEqualLines ( String expected , String actual ) { assertEqualLines ( "<STR_LIT>" , expected , actual ) ; } public static void assertEqualLines ( String message , String expected , String actual ) { String [ ] expectedLines = Strings . convertIntoLines ( expected ) ; String [ ] actualLines = Strings . convertIntoLines ( actual ) ; String expected2 = ( expectedLines == null ? null : Strings . concatenate ( expectedLines , "<STR_LIT:n>" ) ) ; String actual2 = ( actualLines == null ? null : Strings . concatenate ( actualLines , "<STR_LIT:n>" ) ) ; assertEquals ( message , expected2 , actual2 ) ; } private static class Requestor extends TypeNameRequestor { } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test ; import java . util . ArrayList ; import java . util . List ; import junit . framework . Assert ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . internal . corext . util . JavaElementResourceMapping ; import org . eclipse . ltk . core . refactoring . participants . CopyArguments ; import org . eclipse . ltk . core . refactoring . participants . MoveArguments ; import org . eclipse . ltk . core . refactoring . participants . RenameArguments ; public class ParticipantTesting { public static void reset ( ) { TestRenameParticipantShared . reset ( ) ; TestRenameParticipantSingle . reset ( ) ; } public static String [ ] createHandles ( Object object ) { return createHandles ( new Object [ ] { object } ) ; } public static String [ ] createHandles ( Object obj1 , Object obj2 ) { return createHandles ( new Object [ ] { obj1 , obj2 } ) ; } public static String [ ] createHandles ( Object obj1 , Object obj2 , Object obj3 ) { return createHandles ( new Object [ ] { obj1 , obj2 , obj3 } ) ; } public static String [ ] createHandles ( Object obj1 , Object obj2 , Object obj3 , Object obj4 ) { return createHandles ( new Object [ ] { obj1 , obj2 , obj3 , obj4 } ) ; } public static String [ ] createHandles ( Object [ ] elements ) { List result = new ArrayList ( ) ; for ( int i = <NUM_LIT:0> ; i < elements . length ; i ++ ) { Object element = elements [ i ] ; if ( element instanceof IJavaElement ) { result . add ( ( ( IJavaElement ) element ) . getHandleIdentifier ( ) ) ; } else if ( element instanceof IResource ) { result . add ( ( ( IResource ) element ) . getFullPath ( ) . toString ( ) ) ; } else if ( element instanceof JavaElementResourceMapping ) { result . add ( ( ( JavaElementResourceMapping ) element ) . getJavaElement ( ) . getHandleIdentifier ( ) + "<STR_LIT>" ) ; } } return ( String [ ] ) result . toArray ( new String [ result . size ( ) ] ) ; } public static void testRename ( String [ ] expectedHandles , RenameArguments [ ] args ) { Assert . assertEquals ( expectedHandles . length , args . length ) ; if ( expectedHandles . length == <NUM_LIT:0> ) { TestRenameParticipantShared . testNumberOfElements ( <NUM_LIT:0> ) ; TestRenameParticipantSingle . testNumberOfInstances ( <NUM_LIT:0> ) ; } else { testElementsShared ( expectedHandles , TestRenameParticipantShared . fgInstance . fHandles ) ; TestRenameParticipantShared . testArguments ( args ) ; TestRenameParticipantSingle . testNumberOfInstances ( expectedHandles . length ) ; TestRenameParticipantSingle . testElements ( expectedHandles ) ; TestRenameParticipantSingle . testArguments ( args ) ; } } public static void testSimilarElements ( List similarList , List similarNewNameList , List similarNewHandleList ) { Assert . assertEquals ( similarList . size ( ) , similarNewNameList . size ( ) ) ; if ( similarList . size ( ) == <NUM_LIT:0> ) { TestRenameParticipantShared . testNumberOfSimilarElements ( <NUM_LIT:0> ) ; } else { TestRenameParticipantShared . testSimilarElements ( similarList , similarNewNameList , similarNewHandleList ) ; } } private static void testElementsShared ( String [ ] expected , List actual ) { for ( int i = <NUM_LIT:0> ; i < expected . length ; i ++ ) { String handle = expected [ i ] ; Assert . assertTrue ( "<STR_LIT>" + handle , actual . contains ( handle ) ) ; } testNumberOfElements ( expected . length , actual ) ; } private static void testNumberOfElements ( int expected , List actual ) { if ( expected == <NUM_LIT:0> && actual == null ) return ; Assert . assertEquals ( expected , actual . size ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; import java . util . ArrayList ; import java . util . List ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . refactoring . test . ParticipantTesting ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTest ; import org . codehaus . groovy . eclipse . refactoring . test . RefactoringTestSetup ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . IAnnotatable ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . refactoring . IJavaRefactorings ; import org . eclipse . jdt . core . refactoring . descriptors . RenameJavaElementDescriptor ; import org . eclipse . jdt . internal . core . refactoring . descriptors . RefactoringSignatureDescriptorFactory ; import org . eclipse . jdt . internal . corext . refactoring . rename . RenameFieldProcessor ; import org . eclipse . jdt . internal . corext . util . JdtFlags ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . RenameArguments ; import org . eclipse . ltk . core . refactoring . participants . RenameRefactoring ; public class RenameFieldTests extends RefactoringTest { private static final Class < RenameFieldTests > clazz = RenameFieldTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public RenameFieldTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new RefactoringTestSetup ( new TestSuite ( clazz ) ) ; } public static Test setUpTest ( Test test ) { return new RefactoringTestSetup ( test ) ; } protected String getRefactoringPath ( ) { return REFACTORING_PATH ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; fIsPreDeltaTest = true ; } protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } private void helper2_0 ( String typeName , String fieldName , String newFieldName , boolean updateReferences , boolean createDelegates , boolean renameGetter , boolean renameSetter , boolean performOnError ) throws Exception { ICompilationUnit cu = createCUfromTestFile ( getPackageP ( ) , "<STR_LIT:A>" ) ; try { IType classA = getType ( cu , typeName ) ; if ( classA == null ) { classA = cu . getJavaProject ( ) . findType ( typeName ) ; } IField field = classA . getField ( fieldName ) ; boolean isEnum = JdtFlags . isEnum ( field ) ; String id = isEnum ? IJavaRefactorings . RENAME_ENUM_CONSTANT : IJavaRefactorings . RENAME_FIELD ; RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory . createRenameJavaElementDescriptor ( id ) ; descriptor . setUpdateReferences ( updateReferences ) ; descriptor . setJavaElement ( field ) ; descriptor . setNewName ( newFieldName ) ; if ( ! isEnum ) { descriptor . setRenameGetters ( renameGetter ) ; descriptor . setRenameSetters ( renameSetter ) ; descriptor . setKeepOriginal ( createDelegates ) ; descriptor . setDeprecateDelegate ( true ) ; } RenameRefactoring refactoring = ( RenameRefactoring ) createRefactoring ( descriptor ) ; RenameFieldProcessor processor = ( RenameFieldProcessor ) refactoring . getProcessor ( ) ; List < IAnnotatable > elements = new ArrayList < IAnnotatable > ( ) ; elements . add ( field ) ; List < RenameArguments > args = new ArrayList < RenameArguments > ( ) ; args . add ( new RenameArguments ( newFieldName , updateReferences ) ) ; if ( renameGetter ) { elements . add ( processor . getGetter ( ) ) ; args . add ( new RenameArguments ( processor . getNewGetterName ( ) , updateReferences ) ) ; } if ( renameSetter ) { elements . add ( processor . getSetter ( ) ) ; args . add ( new RenameArguments ( processor . getNewSetterName ( ) , updateReferences ) ) ; } String [ ] renameHandles = ParticipantTesting . createHandles ( elements . toArray ( ) ) ; RefactoringStatus result = performRefactoring ( refactoring , performOnError ) ; assertTrue ( "<STR_LIT>" , result == null || result . isOK ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; ParticipantTesting . testRename ( renameHandles , ( RenameArguments [ ] ) args . toArray ( new RenameArguments [ args . size ( ) ] ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getInputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( "<STR_LIT:A>" ) ) , cu . getSource ( ) ) ; } finally { performDummySearch ( ) ; cu . delete ( true , null ) ; } } private void helper2 ( boolean updateReferences ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:f>" , "<STR_LIT>" , updateReferences , false , false , false , false ) ; } private void helperPerformOnError ( boolean updateReferences ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:f>" , "<STR_LIT>" , updateReferences , false , false , false , true ) ; } private void helperScript ( ) throws Exception { helper2_0 ( "<STR_LIT:B>" , "<STR_LIT:f>" , "<STR_LIT>" , true , false , false , false , false ) ; } private void helper2 ( ) throws Exception { helper2 ( true ) ; } public void testInitializer1 ( ) throws Exception { helper2 ( ) ; } public void testInitializer2 ( ) throws Exception { helper2 ( ) ; } public void testInitializer3 ( ) throws Exception { helper2 ( ) ; } public void test1 ( ) throws Exception { helper2 ( ) ; } public void test2 ( ) throws Exception { helper2 ( ) ; } public void test3 ( ) throws Exception { helper2 ( ) ; } public void test4 ( ) throws Exception { helper2 ( ) ; } public void test5 ( ) throws Exception { helperPerformOnError ( true ) ; } public void test6 ( ) throws Exception { helper2 ( ) ; } public void test7 ( ) throws Exception { helperPerformOnError ( true ) ; } public void test8 ( ) throws Exception { helper2 ( ) ; } public void test9 ( ) throws Exception { helper2 ( ) ; } public void test10 ( ) throws Exception { helper2 ( ) ; } public void test11 ( ) throws Exception { createCU ( ( ( IPackageFragmentRoot ) getPackageP ( ) . getParent ( ) ) . createPackageFragment ( "<STR_LIT>" , true , null ) , "<STR_LIT>" , "<STR_LIT>" ) ; helper2_0 ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , true , false , false , false , false ) ; } public void testScript1 ( ) throws Exception { helperScript ( ) ; } public void testScript2 ( ) throws Exception { helperScript ( ) ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.