text
stringlengths 30
1.67M
|
|---|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . refactoring . core . rename . JavaRefactoringDispatcher ; 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 . ICompilationUnit ; import org . eclipse . jdt . core . ILocalVariable ; import org . eclipse . jdt . core . refactoring . descriptors . RenameJavaElementDescriptor ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . RenameRefactoring ; public class RenameLocalTests extends RefactoringTest { private static final Class < RenameLocalTests > clazz = RenameLocalTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public RenameLocalTests ( 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 helper ( String initial , String expected ) throws Exception { RefactoringStatus result = helper ( "<STR_LIT:A>" , initial , expected , "<STR_LIT>" , initial . indexOf ( "<STR_LIT>" ) , false ) ; assertTrue ( "<STR_LIT>" + result , result . isOK ( ) ) ; } private void helperExpectWarning ( String initial , String expected ) throws Exception { RefactoringStatus result = helper ( "<STR_LIT:A>" , initial , expected , "<STR_LIT>" , initial . indexOf ( "<STR_LIT>" ) , true ) ; assertTrue ( "<STR_LIT>" + result , result . hasWarning ( ) && ! result . hasError ( ) ) ; } private RefactoringStatus helper ( String unitNameNoExtension , String initial , String expected , String newVariableName , int refactorLocation , boolean expectingWarning ) throws Exception { ICompilationUnit cu = createCU ( getPackageP ( ) , "<STR_LIT>" , initial ) ; try { ILocalVariable toRename = ( ILocalVariable ) cu . codeSelect ( refactorLocation , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ; JavaRefactoringDispatcher dispatcher = new JavaRefactoringDispatcher ( toRename ) ; dispatcher . setNewName ( newVariableName ) ; RenameJavaElementDescriptor descriptor = dispatcher . createDescriptorForLocalVariable ( ) ; RenameRefactoring refactoring = ( RenameRefactoring ) createRefactoring ( descriptor ) ; RefactoringStatus result = performRefactoring ( refactoring , ! expectingWarning ) ; assertTrue ( "<STR_LIT>" , result == null || result . isOK ( ) || result . hasWarning ( ) ) ; 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>" , initial , 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 ( ) ) ; return result != null ? result : new RefactoringStatus ( ) ; } finally { performDummySearch ( ) ; cu . delete ( true , null ) ; } } public void test0 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test1 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test2 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test3 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test4 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test5 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test6 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test6a ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test6c ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test7 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test8 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void test9 ( ) throws Exception { helper ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testWarning0 ( ) throws Exception { helperExpectWarning ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testWarning1 ( ) throws Exception { helperExpectWarning ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testWarning2 ( ) throws Exception { helperExpectWarning ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testWarning3 ( ) throws Exception { helperExpectWarning ( "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; 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 . resources . IFile ; import org . eclipse . jdt . core . ICompilationUnit ; 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 . IType ; import org . eclipse . jdt . core . JavaCore ; 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 . RenameTypeProcessor ; import org . eclipse . jdt . internal . corext . refactoring . tagging . INameUpdating ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . RenameRefactoring ; public class RenameTypeTests extends RefactoringTest { private static final Class < RenameTypeTests > clazz = RenameTypeTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public RenameTypeTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return new RefactoringTestSetup ( new TestSuite ( clazz ) ) ; } public static Test setUpTest ( Test someTest ) { return new RefactoringTestSetup ( someTest ) ; } protected String getRefactoringPath ( ) { return REFACTORING_PATH ; } private RenameJavaElementDescriptor createRefactoringDescriptor ( IType type , String newName ) { RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory . createRenameJavaElementDescriptor ( IJavaRefactorings . RENAME_TYPE ) ; descriptor . setJavaElement ( type ) ; descriptor . setNewName ( newName ) ; descriptor . setUpdateReferences ( true ) ; return descriptor ; } private String [ ] helperWithTextual ( String oldCuName , String oldName , String newName , String newCUName , boolean updateReferences , boolean updateTextualMatches ) throws Exception { ICompilationUnit cu = createCUfromTestFile ( getPackageP ( ) , oldCuName ) ; IType classA = getType ( cu , oldName ) ; IJavaElement [ ] classAMembers = classA . getChildren ( ) ; IPackageFragment pack = ( IPackageFragment ) cu . getParent ( ) ; String [ ] renameHandles = null ; if ( classA . getDeclaringType ( ) == null && cu . getElementName ( ) . startsWith ( classA . getElementName ( ) ) ) { renameHandles = ParticipantTesting . createHandles ( classA , cu , cu . getResource ( ) ) ; } else { renameHandles = ParticipantTesting . createHandles ( classA ) ; } RenameJavaElementDescriptor descriptor = createRefactoringDescriptor ( classA , newName ) ; descriptor . setUpdateReferences ( updateReferences ) ; descriptor . setUpdateTextualOccurrences ( updateTextualMatches ) ; Refactoring refactoring = createRefactoring ( descriptor ) ; RefactoringStatus result = performRefactoring ( refactoring , false ) ; assertTrue ( "<STR_LIT>" , result == null || result . isOK ( ) ) ; ICompilationUnit newcu = pack . getCompilationUnit ( newCUName + "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" + newcu . getElementName ( ) + "<STR_LIT>" , newcu . exists ( ) ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( newCUName ) ) , newcu . getSource ( ) ) ; INameUpdating nameUpdating = ( ( INameUpdating ) refactoring . getAdapter ( INameUpdating . class ) ) ; IType newElement = ( IType ) nameUpdating . getNewElement ( ) ; assertTrue ( "<STR_LIT>" + newElement . toString ( ) , newElement . exists ( ) ) ; checkMappers ( refactoring , classA , newCUName + "<STR_LIT>" , classAMembers ) ; return renameHandles ; } private String [ ] helper2_0 ( String oldName , String newName , String newCUName , boolean updateReferences ) throws Exception { return helperWithTextual ( oldName , oldName , newName , newCUName , updateReferences , false ) ; } private String [ ] helper2 ( String oldName , String newName ) throws Exception { return helper2_0 ( oldName , newName , newName , true ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; setSomeFieldOptions ( getPackageP ( ) . getJavaProject ( ) , "<STR_LIT:f>" , "<STR_LIT>" , false ) ; setSomeFieldOptions ( getPackageP ( ) . getJavaProject ( ) , "<STR_LIT>" , "<STR_LIT>" , true ) ; setSomeLocalOptions ( getPackageP ( ) . getJavaProject ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; setSomeArgumentOptions ( getPackageP ( ) . getJavaProject ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; fIsPreDeltaTest = true ; } private void setSomeFieldOptions ( IJavaProject project , String prefixes , String suffixes , boolean forStatic ) { if ( forStatic ) { project . setOption ( JavaCore . CODEASSIST_STATIC_FIELD_PREFIXES , prefixes ) ; project . setOption ( JavaCore . CODEASSIST_STATIC_FIELD_SUFFIXES , suffixes ) ; } else { project . setOption ( JavaCore . CODEASSIST_FIELD_PREFIXES , prefixes ) ; project . setOption ( JavaCore . CODEASSIST_FIELD_SUFFIXES , suffixes ) ; } } private void setSomeLocalOptions ( IJavaProject project , String prefixes , String suffixes ) { project . setOption ( JavaCore . CODEASSIST_LOCAL_PREFIXES , prefixes ) ; project . setOption ( JavaCore . CODEASSIST_LOCAL_SUFFIXES , suffixes ) ; } private void setSomeArgumentOptions ( IJavaProject project , String prefixes , String suffixes ) { project . setOption ( JavaCore . CODEASSIST_ARGUMENT_PREFIXES , prefixes ) ; project . setOption ( JavaCore . CODEASSIST_ARGUMENT_SUFFIXES , suffixes ) ; } private void checkMappers ( Refactoring refactoring , IType type , String newCUName , IJavaElement [ ] someClassMembers ) { RenameTypeProcessor rtp = ( RenameTypeProcessor ) ( ( RenameRefactoring ) refactoring ) . getProcessor ( ) ; ICompilationUnit newUnit = ( ICompilationUnit ) rtp . getRefactoredJavaElement ( type . getCompilationUnit ( ) ) ; assertTrue ( newUnit . exists ( ) ) ; assertTrue ( newUnit . getElementName ( ) . equals ( newCUName ) ) ; IFile newFile = ( IFile ) rtp . getRefactoredResource ( type . getResource ( ) ) ; assertTrue ( newFile . exists ( ) ) ; assertTrue ( newFile . getName ( ) . equals ( newCUName ) ) ; if ( ( type . getParent ( ) . getElementType ( ) == IJavaElement . COMPILATION_UNIT ) && type . getCompilationUnit ( ) . getElementName ( ) . equals ( type . getElementName ( ) + "<STR_LIT>" ) ) { assertFalse ( type . getCompilationUnit ( ) . exists ( ) ) ; assertFalse ( type . getResource ( ) . exists ( ) ) ; } IPackageFragment oldPackage = ( IPackageFragment ) type . getCompilationUnit ( ) . getParent ( ) ; IPackageFragment newPackage = ( IPackageFragment ) rtp . getRefactoredJavaElement ( oldPackage ) ; assertEquals ( oldPackage , newPackage ) ; for ( int i = <NUM_LIT:0> ; i < someClassMembers . length ; i ++ ) { IMember member = ( IMember ) someClassMembers [ i ] ; IJavaElement refactoredMember = rtp . getRefactoredJavaElement ( member ) ; if ( member instanceof IMethod && member . getElementName ( ) . equals ( type . getElementName ( ) ) ) continue ; assertTrue ( refactoredMember . exists ( ) ) ; assertEquals ( member . getElementName ( ) , refactoredMember . getElementName ( ) ) ; assertFalse ( refactoredMember . equals ( member ) ) ; } } public void test1 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test2 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test3 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test4 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test5 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test6 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test7 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test8 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test9 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test10 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test11 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test12 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void test13 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testAnnotation1 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testAnnotation2 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testAnnotation3 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testAlias1 ( ) throws Exception { IPackageFragment p2 = getRoot ( ) . createPackageFragment ( "<STR_LIT>" , true , null ) ; String folder = "<STR_LIT>" ; String type = "<STR_LIT:A>" ; ICompilationUnit cu = createCUfromTestFile ( p2 , type , folder ) ; helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( type , folder ) ) , cu . getSource ( ) ) ; } public void testEnum1 ( ) throws Exception { IPackageFragment p2 = getRoot ( ) . createPackageFragment ( "<STR_LIT>" , true , null ) ; String folder = "<STR_LIT>" ; String type = "<STR_LIT:A>" ; ICompilationUnit cu = createCUfromTestFile ( p2 , type , folder ) ; helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; assertEqualLines ( "<STR_LIT>" , getFileContents ( getOutputTestFileName ( type , folder ) ) , cu . getSource ( ) ) ; } public void testEnum2 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testGenerics1 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testGenerics2 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testGenerics3 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testGenerics4 ( ) throws Exception { helper2 ( "<STR_LIT:A>" , "<STR_LIT:B>" ) ; } public void testInner1 ( ) throws Exception { helperWithTextual ( "<STR_LIT>" , "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT>" , true , false ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; import org . codehaus . groovy . eclipse . refactoring . test . AbstractRefactoringTest ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . refactoring . descriptors . MoveDescriptor ; import org . eclipse . jdt . internal . core . refactoring . descriptors . RefactoringSignatureDescriptorFactory ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public class MoveCURefactoringTests extends AbstractRefactoringTest { public void testSimpleMove1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } ) ; } public void testSimpleMove2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , } ) ; } public void testSimpleMove3 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testQualifiedMove1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testSimpleMove4 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testQualifiedMove2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testNonPrimaryMove1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testNonPrimaryQualifiedMove1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void testMoveBack1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void _testInnerMove1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void _testInnerMove2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void _testInnerMove3 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } public void _testInnerMove4 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:p>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , } ) ; } private void performRefactoringAndUndo ( String newPackageName , String [ ] packNames , String [ ] cuNames , String [ ] initialContents , String [ ] finalContents ) throws Exception { IPackageFragment newPackage = testProject . createPackage ( newPackageName ) ; ICompilationUnit [ ] units = createUnits ( packNames , cuNames , initialContents ) ; MoveDescriptor descriptor = RefactoringSignatureDescriptorFactory . createMoveDescriptor ( ) ; descriptor . setDestination ( newPackage ) ; descriptor . setUpdateReferences ( true ) ; descriptor . setProject ( testProject . getProject ( ) . getName ( ) ) ; descriptor . setUpdateQualifiedNames ( true ) ; descriptor . setMoveResources ( new IFile [ <NUM_LIT:0> ] , new IFolder [ <NUM_LIT:0> ] , new ICompilationUnit [ ] { units [ <NUM_LIT:0> ] } ) ; Refactoring refactoring = createRefactoring ( descriptor ) ; RefactoringStatus result = performRefactoring ( refactoring , true , true ) ; result = ignoreKnownErrors ( result ) ; assertTrue ( "<STR_LIT>" + result , result . isOK ( ) ) ; ICompilationUnit newUnit = getNewUnit ( newPackageName , cuNames [ <NUM_LIT:0> ] ) ; ICompilationUnit origUnit = units [ <NUM_LIT:0> ] ; units [ <NUM_LIT:0> ] = newUnit ; assertContents ( units , finalContents ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; units [ <NUM_LIT:0> ] = origUnit ; assertContents ( units , initialContents ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; units [ <NUM_LIT:0> ] = newUnit ; assertContents ( units , finalContents ) ; } private ICompilationUnit getNewUnit ( String newPackName , String name ) throws JavaModelException { int dotIndex = name . indexOf ( '<CHAR_LIT:.>' ) ; String typeName = name . substring ( <NUM_LIT:0> , dotIndex ) ; String qualName = newPackName . length ( ) > <NUM_LIT:0> ? newPackName + "<STR_LIT:.>" + typeName : typeName ; return testProject . getJavaProject ( ) . findType ( qualName ) . getCompilationUnit ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; import org . codehaus . groovy . eclipse . refactoring . core . rename . SyntheticAccessorsRenameParticipant ; import org . codehaus . groovy . eclipse . refactoring . test . AbstractRefactoringTest ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IMember ; 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 . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . participants . RenameRefactoring ; public class SyntheticAccessorRenamingTests extends AbstractRefactoringTest { public void testSingleFileRename1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" } , new String [ ] { "<STR_LIT>" } , new String [ ] { "<STR_LIT>" + "<STR_LIT>" + "<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>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" } ) ; } public void testSingleFileRename2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" } , new String [ ] { "<STR_LIT>" } , new String [ ] { "<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:}>" } , new String [ ] { "<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:}>" } ) ; } public void testMultiFileRename1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<STR_LIT>" + "<STR_LIT>" + "<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:}>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ) ; } public void testMultiFileRename2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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>" } , new String [ ] { "<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>" } ) ; } public void testJavaRename1 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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:}>" } , new String [ ] { "<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:}>" } ) ; } public void testJavaRename2 ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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:}>" } , new String [ ] { "<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:}>" } ) ; } public void testGetterOnly ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" , "<STR_LIT:r>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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>" } , new String [ ] { "<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>" } ) ; } public void testIsserOnly ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" , "<STR_LIT:r>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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>" } , new String [ ] { "<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>" } ) ; } public void testSetterOnly ( ) throws Exception { performRefactoringAndUndo ( "<STR_LIT>" , new String [ ] { "<STR_LIT:p>" , "<STR_LIT:q>" , "<STR_LIT:r>" } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , new String [ ] { "<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>" } , new String [ ] { "<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 void performRefactoringAndUndo ( String newName , String [ ] packNames , String [ ] cuNames , String [ ] initialContents , String [ ] finalContents ) throws Exception { performRefactoringAndUndo ( newName , true , true , packNames , cuNames , initialContents , finalContents ) ; } private void performRefactoringAndUndo ( String newName , boolean updateReferences , boolean performOnError , String [ ] packNames , String [ ] cuNames , String [ ] initialContents , String [ ] finalContents ) throws Exception { ICompilationUnit [ ] units = createUnits ( packNames , cuNames , initialContents ) ; IMember toRename = ( IMember ) units [ <NUM_LIT:0> ] . getTypes ( ) [ <NUM_LIT:0> ] . getChildren ( ) [ <NUM_LIT:0> ] ; String id = toRename instanceof IField ? IJavaRefactorings . RENAME_FIELD : IJavaRefactorings . RENAME_METHOD ; RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory . createRenameJavaElementDescriptor ( id ) ; descriptor . setUpdateReferences ( updateReferences ) ; descriptor . setJavaElement ( toRename ) ; descriptor . setNewName ( newName ) ; descriptor . setRenameGetters ( false ) ; descriptor . setRenameSetters ( false ) ; descriptor . setProject ( testProject . getProject ( ) . getName ( ) ) ; RenameRefactoring refactoring = ( RenameRefactoring ) createRefactoring ( descriptor ) ; RefactoringStatus result = performRefactoring ( refactoring , true , performOnError ) ; if ( ! performOnError ) { assertTrue ( "<STR_LIT>" + result , result . isOK ( ) ) ; } assertContents ( units , finalContents ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performUndo ( null , new NullProgressMonitor ( ) ) ; assertContents ( units , initialContents ) ; assertTrue ( "<STR_LIT>" , ! RefactoringCore . getUndoManager ( ) . anythingToUndo ( ) ) ; assertTrue ( "<STR_LIT>" , RefactoringCore . getUndoManager ( ) . anythingToRedo ( ) ) ; RefactoringCore . getUndoManager ( ) . performRedo ( null , new NullProgressMonitor ( ) ) ; assertContents ( units , finalContents ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . rename ; import junit . framework . Test ; import junit . framework . TestSuite ; 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 . ICompilationUnit ; import org . eclipse . jdt . core . IMethod ; 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 . ltk . core . refactoring . RefactoringCore ; public class RenameMethodTests extends RefactoringTest { private static final Class < RenameMethodTests > clazz = RenameMethodTests . class ; private static final String REFACTORING_PATH = "<STR_LIT>" ; public RenameMethodTests ( 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 ; } private void helper2_0 ( String typeName , String methodName , String newMethodName , String [ ] signatures , boolean updateReferences , boolean createDelegate ) throws Exception { ICompilationUnit cu = createCUfromTestFile ( getPackageP ( ) , "<STR_LIT:A>" ) ; try { IType classA = getType ( cu , typeName ) ; if ( classA == null ) { classA = cu . getJavaProject ( ) . findType ( typeName ) ; } IMethod method = classA . getMethod ( methodName , signatures ) ; RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory . createRenameJavaElementDescriptor ( IJavaRefactorings . RENAME_METHOD ) ; descriptor . setUpdateReferences ( updateReferences ) ; descriptor . setJavaElement ( method ) ; descriptor . setNewName ( newMethodName ) ; descriptor . setKeepOriginal ( createDelegate ) ; descriptor . setDeprecateDelegate ( true ) ; assertEquals ( "<STR_LIT>" , null , performRefactoring ( descriptor ) ) ; 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 ) ; } } private void helperDelegate ( ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ <NUM_LIT:0> ] , true , true ) ; } private void helper2 ( boolean updateReferences ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ <NUM_LIT:0> ] , updateReferences , false ) ; } private void helper2 ( ) throws Exception { helper2 ( true ) ; } public void test1 ( ) throws Exception { helper2 ( ) ; } public void test2 ( ) throws Exception { helper2 ( ) ; } public void test3 ( ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , true , false ) ; } public void test4 ( ) throws Exception { helper2 ( ) ; } public void test5 ( ) throws Exception { helper2 ( ) ; } public void test6 ( ) throws Exception { helper2 ( ) ; } public void test7 ( ) throws Exception { helper2 ( ) ; } public void test8 ( ) throws Exception { helper2_0 ( "<STR_LIT:B>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ ] { } , true , false ) ; } public void test9 ( ) throws Exception { helper2 ( ) ; } public void test10 ( ) throws Exception { createCU ( ( ( IPackageFragmentRoot ) getPackageP ( ) . getParent ( ) ) . createPackageFragment ( "<STR_LIT>" , true , null ) , "<STR_LIT>" , "<STR_LIT>" ) ; helper2_0 ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ <NUM_LIT:0> ] , true , false ) ; } public void testInitializer1 ( ) throws Exception { helper2 ( ) ; } public void testInitializer2 ( ) throws Exception { helper2 ( ) ; } public void testInitializer3 ( ) throws Exception { helper2 ( ) ; } public void testDelegate1 ( ) throws Exception { helperDelegate ( ) ; } public void testDelegate2 ( ) throws Exception { helperDelegate ( ) ; } public void testOverload1 ( ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , true , false ) ; } public void testOverload2 ( ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , true , false ) ; } public void testOverload3 ( ) throws Exception { helper2_0 ( "<STR_LIT:A>" , "<STR_LIT:m>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , true , false ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . formatter ; import java . io . File ; import org . codehaus . groovy . eclipse . refactoring . formatter . DefaultGroovyFormatter ; import org . codehaus . groovy . eclipse . refactoring . formatter . FormatterPreferencesOnStore ; import org . codehaus . groovy . eclipse . refactoring . test . BaseTestCase ; import org . codehaus . groovy . eclipse . refactoring . test . TestPrefInitializer ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . text . edits . MalformedTreeException ; public class FormatterTestCase extends BaseTestCase { public FormatterTestCase ( String arg0 , File arg1 ) { super ( arg0 , arg1 ) ; setName ( "<STR_LIT>" ) ; } public void testFormatter ( ) { doTest ( ) ; } private void doTest ( ) { boolean indentendOnly = false ; IPreferenceStore pref = null ; if ( properties . get ( "<STR_LIT>" ) != null && properties . get ( "<STR_LIT>" ) . equals ( "<STR_LIT:true>" ) ) { try { pref = TestPrefInitializer . initializePreferences ( properties ) ; String indOnly = properties . get ( "<STR_LIT>" ) ; if ( indOnly != null && indOnly . equals ( "<STR_LIT:true>" ) ) { indentendOnly = true ; } } catch ( Exception e ) { e . printStackTrace ( ) ; fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } DefaultGroovyFormatter formatter = new DefaultGroovyFormatter ( selection , getDocument ( ) , new FormatterPreferencesOnStore ( pref ) , indentendOnly ) ; try { formatter . format ( ) . apply ( getDocument ( ) ) ; } catch ( MalformedTreeException e ) { e . printStackTrace ( ) ; } catch ( BadLocationException e ) { e . printStackTrace ( ) ; } finalAssert ( ) ; } @ Override public void finalAssert ( ) { String expected = getExpected ( ) . get ( ) ; String content = getDocument ( ) . get ( ) ; assertEquals ( "<STR_LIT>" + file + "<STR_LIT:U+0020>" , expected , content ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . formatter ; import java . util . Hashtable ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . preferences . FormatterPreferenceInitializer ; import org . codehaus . groovy . eclipse . preferences . FormatterPreferencesPage ; import org . codehaus . groovy . eclipse . refactoring . PreferenceConstants ; import org . codehaus . groovy . eclipse . refactoring . formatter . FormatterPreferences ; import org . codehaus . groovy . eclipse . refactoring . formatter . IFormatterPreferences ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . ui . preferences . ScopedPreferenceStore ; public class TestFormatterPreferences extends EclipseTestCase { private static final String TAB_SIZE = DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE ; private static final String INDENT_SIZE = DefaultCodeFormatterConstants . FORMATTER_INDENTATION_SIZE ; private static final String TAB_CHAR = DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR ; private static final String INDENT_EMPTY_LINES = DefaultCodeFormatterConstants . FORMATTER_INDENT_EMPTY_LINES ; private static final String BRACES_START = PreferenceConstants . GROOVY_FORMATTER_BRACES_START ; private static final String BRACES_END = PreferenceConstants . GROOVY_FORMATTER_BRACES_END ; private static final String SMART_PASTE = org . eclipse . jdt . ui . PreferenceConstants . EDITOR_SMART_PASTE ; private GroovyCompilationUnit gunit ; private Hashtable saveJavaOptions ; @ Override public void setUp ( ) throws Exception { super . setUp ( ) ; saveJavaOptions = JavaCore . getOptions ( ) ; if ( ! hasGroovyNature ( ) ) GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; pack = testProject . createPackage ( "<STR_LIT>" ) ; gunit = ( GroovyCompilationUnit ) pack . createCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" , true , new NullProgressMonitor ( ) ) ; new FormatterPreferenceInitializer ( ) . initializeDefaultPreferences ( ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; JavaCore . setOptions ( saveJavaOptions ) ; new FormatterPreferenceInitializer ( ) . initializeDefaultPreferences ( ) ; } public void testBracesPrefs ( ) throws Exception { FormatterPreferencesPage preferencesPage = new FormatterPreferencesPage ( ) ; IPreferenceStore groovyPrefs = preferencesPage . getPreferenceStore ( ) ; assertTrue ( "<STR_LIT>" , groovyPrefs . contains ( BRACES_START ) ) ; assertTrue ( "<STR_LIT>" , groovyPrefs . contains ( BRACES_END ) ) ; groovyPrefs . setValue ( BRACES_START , PreferenceConstants . NEXT ) ; FormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . getBracesStart ( ) == PreferenceConstants . NEXT_LINE ) ; groovyPrefs . setValue ( BRACES_START , PreferenceConstants . SAME ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . getBracesStart ( ) == PreferenceConstants . SAME_LINE ) ; groovyPrefs . setValue ( BRACES_END , PreferenceConstants . NEXT ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . getBracesEnd ( ) == PreferenceConstants . NEXT_LINE ) ; groovyPrefs . setValue ( BRACES_END , PreferenceConstants . SAME ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . getBracesEnd ( ) == PreferenceConstants . SAME_LINE ) ; } public void testTabRelatedPrefs ( ) throws Exception { IPreferenceStore projectPrefs = new ScopedPreferenceStore ( new ProjectScope ( testProject . getProject ( ) ) , JavaCore . PLUGIN_ID ) ; assertTrue ( "<STR_LIT>" , projectPrefs . contains ( TAB_CHAR ) ) ; assertTrue ( "<STR_LIT>" , projectPrefs . contains ( TAB_SIZE ) ) ; projectPrefs . setValue ( TAB_CHAR , JavaCore . SPACE ) ; IFormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . useTabs ( ) == false ) ; projectPrefs . setValue ( TAB_CHAR , JavaCore . TAB ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . useTabs ( ) == true ) ; projectPrefs . setValue ( TAB_SIZE , <NUM_LIT> ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT> , formatPrefs . getTabSize ( ) ) ; projectPrefs . setValue ( TAB_CHAR , JavaCore . TAB ) ; projectPrefs . setValue ( TAB_SIZE , <NUM_LIT:11> ) ; projectPrefs . setValue ( INDENT_SIZE , <NUM_LIT:5> ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT:11> , formatPrefs . getIndentationSize ( ) ) ; assertEquals ( <NUM_LIT:11> , formatPrefs . getTabSize ( ) ) ; projectPrefs . setValue ( TAB_CHAR , DefaultCodeFormatterConstants . MIXED ) ; projectPrefs . setValue ( TAB_SIZE , <NUM_LIT:11> ) ; projectPrefs . setValue ( INDENT_SIZE , <NUM_LIT:5> ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT:5> , formatPrefs . getIndentationSize ( ) ) ; assertEquals ( <NUM_LIT:11> , formatPrefs . getTabSize ( ) ) ; } public void testIndentEmptyLinesPrefs ( ) throws Exception { IPreferenceStore projectPrefs = new ScopedPreferenceStore ( new ProjectScope ( testProject . getProject ( ) ) , JavaCore . PLUGIN_ID ) ; assertTrue ( "<STR_LIT>" , projectPrefs . contains ( INDENT_EMPTY_LINES ) ) ; projectPrefs . setValue ( INDENT_EMPTY_LINES , DefaultCodeFormatterConstants . TRUE ) ; IFormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . isIndentEmptyLines ( ) ) ; projectPrefs . setValue ( INDENT_EMPTY_LINES , DefaultCodeFormatterConstants . FALSE ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertFalse ( formatPrefs . isIndentEmptyLines ( ) ) ; } public void testIndentEmptyLinesFromCore ( ) throws Exception { setJavaPreference ( INDENT_EMPTY_LINES , DefaultCodeFormatterConstants . TRUE ) ; IFormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . isIndentEmptyLines ( ) ) ; } public void testTabRelatedPrefsFromCore ( ) throws Exception { setJavaPreference ( TAB_SIZE , "<STR_LIT>" + <NUM_LIT> ) ; IFormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT> , formatPrefs . getTabSize ( ) ) ; } public void testRefreshPrefsFromCore ( ) throws Exception { setJavaPreference ( TAB_SIZE , "<STR_LIT>" + <NUM_LIT> ) ; FormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT> , formatPrefs . getTabSize ( ) ) ; setJavaPreference ( TAB_SIZE , "<STR_LIT>" + <NUM_LIT:7> ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertEquals ( <NUM_LIT:7> , formatPrefs . getTabSize ( ) ) ; } public void testSmartPaste ( ) throws Exception { IPreferenceStore uiprefs = JavaPlugin . getDefault ( ) . getPreferenceStore ( ) ; boolean org = uiprefs . getBoolean ( SMART_PASTE ) ; try { assertEquals ( org , new FormatterPreferences ( gunit ) . isSmartPaste ( ) ) ; uiprefs . setValue ( SMART_PASTE , ! org ) ; assertEquals ( ! org , new FormatterPreferences ( gunit ) . isSmartPaste ( ) ) ; uiprefs . setValue ( SMART_PASTE , org ) ; assertEquals ( org , new FormatterPreferences ( gunit ) . isSmartPaste ( ) ) ; } finally { uiprefs . setValue ( SMART_PASTE , org ) ; } } public void testSemicolonPrefs ( ) throws Exception { FormatterPreferencesPage preferencesPage = new FormatterPreferencesPage ( ) ; IPreferenceStore groovyPrefs = preferencesPage . getPreferenceStore ( ) ; assertTrue ( "<STR_LIT>" , groovyPrefs . contains ( PreferenceConstants . GROOVY_FORMATTER_REMOVE_UNNECESSARY_SEMICOLONS ) ) ; groovyPrefs . setValue ( PreferenceConstants . GROOVY_FORMATTER_REMOVE_UNNECESSARY_SEMICOLONS , true ) ; FormatterPreferences formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . isRemoveUnnecessarySemicolons ( ) == true ) ; groovyPrefs . setValue ( PreferenceConstants . GROOVY_FORMATTER_REMOVE_UNNECESSARY_SEMICOLONS , false ) ; formatPrefs = new FormatterPreferences ( gunit ) ; assertTrue ( formatPrefs . isRemoveUnnecessarySemicolons ( ) == false ) ; } protected void setJavaPreference ( String name , String value ) { Hashtable options = JavaCore . getOptions ( ) ; options . put ( name , value ) ; JavaCore . setOptions ( options ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . formatter ; import java . util . HashMap ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . refactoring . formatter . DefaultGroovyFormatter ; import org . codehaus . groovy . eclipse . refactoring . formatter . FormatterPreferencesOnStore ; import org . codehaus . groovy . eclipse . refactoring . test . TestPrefInitializer ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . text . Document ; public class FindIndentsTests extends TestCase { DefaultGroovyFormatter formatter ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; HashMap < String , String > props = new HashMap < String , String > ( ) ; props . put ( "<STR_LIT>" , "<STR_LIT:3>" ) ; IPreferenceStore pref = TestPrefInitializer . initializePreferences ( props ) ; formatter = new DefaultGroovyFormatter ( new Document ( ) , new FormatterPreferencesOnStore ( pref ) , <NUM_LIT:0> ) ; } public void testIndent1 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:3> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent2 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:3> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent3 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:3> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent4 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:3> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent5 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:3> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent6 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:4> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent7 ( ) throws Exception { String line = "<STR_LIT:f>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:0> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent8 ( ) throws Exception { String line = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:0> , formatter . computeIndentLevel ( line ) ) ; } public void testIndent9 ( ) throws Exception { String line = "<STR_LIT:n>" ; assertEquals ( "<STR_LIT>" + line + "<STR_LIT:\">" , <NUM_LIT:0> , formatter . computeIndentLevel ( line ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . formatter ; import java . io . File ; import java . util . List ; import org . codehaus . groovy . eclipse . refactoring . test . BaseTestSuite ; import junit . framework . TestSuite ; public class FormatterTestSuite 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 FormatterTestCase ( file . getName ( ) , file ) ) ; } ts . addTestSuite ( FindIndentsTests . class ) ; ts . addTestSuite ( TestFormatterPreferences . class ) ; ts . addTestSuite ( GroovyDocumentScannerTests . class ) ; return ts ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . refactoring . test . formatter ; import java . util . List ; import junit . framework . TestCase ; import org . codehaus . greclipse . GroovyTokenTypeBridge ; import org . codehaus . groovy . eclipse . refactoring . formatter . GroovyDocumentScanner ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import antlr . Token ; public class GroovyDocumentScannerTests extends TestCase { private Document editDoc ; private int caret = <NUM_LIT:0> ; public void testGetTokenBefore ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" ) ; IDocument doc = getDocument ( ) ; GroovyDocumentScanner scanner = new GroovyDocumentScanner ( doc ) ; String [ ] expected = new String [ ] { "<STR_LIT>" , "<STR_LIT:f>" , "<STR_LIT:e>" , "<STR_LIT:d>" , "<STR_LIT>" , "<STR_LIT:c>" , "<STR_LIT:b>" , "<STR_LIT:a>" } ; int expect = <NUM_LIT:0> ; Token token = scanner . getLastToken ( ) ; assertEquals ( GroovyTokenTypeBridge . EOF , token . getType ( ) ) ; while ( token != null ) { assertEquals ( expected [ expect ++ ] , token . getText ( ) ) ; token = scanner . getLastTokenBefore ( token ) ; } assertEquals ( expected . length , expect ) ; scanner . dispose ( ) ; } public void testGetLineTokens ( ) throws Exception { String text = "<STR_LIT>" + "<STR_LIT>" ; makeEditor ( text ) ; IDocument doc = getDocument ( ) ; GroovyDocumentScanner scanner = new GroovyDocumentScanner ( doc ) ; List < Token > tokens = scanner . getLineTokensUpto ( text . indexOf ( "<STR_LIT:c>" ) ) ; assertTokens ( new String [ ] { "<STR_LIT:a>" , "<STR_LIT:b>" } , tokens ) ; tokens = scanner . getLineTokensUpto ( text . indexOf ( "<STR_LIT:f>" ) ) ; assertTokens ( new String [ ] { "<STR_LIT:d>" , "<STR_LIT:e>" } , tokens ) ; scanner . dispose ( ) ; } public void testGetEmptyLineTokens ( ) throws Exception { String text = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; makeEditor ( text ) ; IDocument doc = getDocument ( ) ; GroovyDocumentScanner scanner = new GroovyDocumentScanner ( doc ) ; List < Token > tokens = scanner . getLineTokens ( <NUM_LIT:0> ) ; assertTokens ( new String [ ] { "<STR_LIT:class>" , "<STR_LIT>" , "<STR_LIT:{>" , "<STR_LIT>" } , tokens ) ; tokens = scanner . getLineTokens ( <NUM_LIT:1> ) ; assertTokens ( new String [ ] { } , tokens ) ; tokens = scanner . getLineTokens ( <NUM_LIT:2> ) ; assertTokens ( new String [ ] { } , tokens ) ; tokens = scanner . getLineTokens ( <NUM_LIT:3> ) ; assertTokens ( new String [ ] { "<STR_LIT:}>" } , tokens ) ; scanner . dispose ( ) ; } public void testDocumentEdits ( ) throws Exception { String text = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; makeEditor ( text ) ; IDocument doc = getDocument ( ) ; GroovyDocumentScanner scanner = new GroovyDocumentScanner ( doc ) ; List < Token > tokens = scanner . getLineTokens ( <NUM_LIT:1> ) ; assertTokens ( new String [ ] { "<STR_LIT>" , "<STR_LIT:a>" , "<STR_LIT:=>" , "<STR_LIT>" } , tokens ) ; send ( "<STR_LIT>" ) ; tokens = scanner . getLineTokens ( <NUM_LIT:1> ) ; assertTokens ( new String [ ] { "<STR_LIT>" , "<STR_LIT:a>" , "<STR_LIT:=>" , "<STR_LIT:3>" , "<STR_LIT:+>" , "<STR_LIT:4>" , "<STR_LIT>" } , tokens ) ; scanner . dispose ( ) ; } private IDocument getDocument ( ) { return editDoc ; } private void makeEditor ( String string ) { caret = string . indexOf ( "<STR_LIT>" ) ; if ( caret < <NUM_LIT:0> ) { caret = <NUM_LIT:0> ; } else { string = string . substring ( <NUM_LIT:0> , caret ) + string . substring ( caret + "<STR_LIT>" . length ( ) ) ; } editDoc = new Document ( string ) ; } private void send ( String insertionText ) throws BadLocationException { editDoc . replace ( caret , <NUM_LIT:0> , insertionText ) ; caret = caret + insertionText . length ( ) ; } private void assertTokens ( String [ ] expected , List < Token > tokens ) { assertEquals ( expected . length , tokens . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < expected . length ; i ++ ) { assertEquals ( expected [ i ] , tokens . get ( i ) . getText ( ) ) ; } } } </s>
|
<s> package org . codehaus . groovy . alltests ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . codeassist . tests . AllCompletionTests ; import org . codehaus . groovy . eclipse . codebrowsing . tests . AllBrowsingTests ; import org . codehaus . groovy . eclipse . core . AllCoreTests ; import org . codehaus . groovy . eclipse . dsl . tests . AllDSLTests ; import org . codehaus . groovy . eclipse . junit . test . AllJUnitTests ; import org . codehaus . groovy . eclipse . quickfix . test . AllQuickFixTests ; import org . codehaus . groovy . eclipse . refactoring . test . AllRefactoringTests ; import org . codehaus . groovy . eclipse . test . AllUITests ; public class AllGroovyTests { public static Test suite ( ) throws Exception { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; suite . addTestSuite ( SanityTest . class ) ; suite . addTest ( AllUITests . suite ( ) ) ; suite . addTest ( AllCoreTests . suite ( ) ) ; suite . addTest ( AllJUnitTests . suite ( ) ) ; suite . addTest ( AllCompletionTests . suite ( ) ) ; suite . addTest ( AllBrowsingTests . suite ( ) ) ; suite . addTest ( AllRefactoringTests . suite ( ) ) ; suite . addTest ( AllQuickFixTests . suite ( ) ) ; suite . addTest ( AllDSLTests . suite ( ) ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . alltests ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . frameworkadapter . util . CompilerLevelUtils ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; import org . osgi . framework . Version ; public class SanityTest extends TestCase { private Version getEclipseVersion ( ) { Bundle jdtcore = Platform . getBundle ( "<STR_LIT>" ) ; assertNotNull ( "<STR_LIT>" , jdtcore ) ; return jdtcore . getVersion ( ) ; } private Version getGroovyCompilerVersion ( ) { return CompilerUtils . getActiveGroovyBundle ( ) . getVersion ( ) ; } public void testCompilerVersion ( ) throws Exception { Version jdtVersion = getEclipseVersion ( ) ; Version groovyVersion = getGroovyCompilerVersion ( ) ; if ( jdtVersion . getMinor ( ) == <NUM_LIT:8> ) { assertEquals ( <NUM_LIT:2> , groovyVersion . getMajor ( ) ) ; assertEquals ( <NUM_LIT:0> , groovyVersion . getMinor ( ) ) ; } else if ( jdtVersion . getMinor ( ) == <NUM_LIT:7> ) { assertEquals ( <NUM_LIT:1> , groovyVersion . getMajor ( ) ) ; assertEquals ( <NUM_LIT:8> , groovyVersion . getMinor ( ) ) ; } } } </s>
|
<s> package org . codehaus . groovy . alltests ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . eclipse . jdt . core . groovy . tests . builder . BasicGroovyBuildTests ; import org . eclipse . jdt . core . groovy . tests . builder . FullProjectTests ; import org . eclipse . jdt . core . groovy . tests . compiler . ScriptFolderTests ; import org . eclipse . jdt . core . groovy . tests . locations . ASTConverterTests ; import org . eclipse . jdt . core . groovy . tests . locations . ASTNodeSourceLocationsTests ; import org . eclipse . jdt . core . groovy . tests . locations . LocationSupportTests ; import org . eclipse . jdt . core . groovy . tests . locations . SourceLocationsTests ; import org . eclipse . jdt . core . groovy . tests . model . AnnotationsTests ; import org . eclipse . jdt . core . groovy . tests . model . GroovyClassFileTests ; import org . eclipse . jdt . core . groovy . tests . model . GroovyCompilationUnitTests ; import org . eclipse . jdt . core . groovy . tests . model . GroovyContentTypeTests ; import org . eclipse . jdt . core . groovy . tests . model . GroovyPartialModelTests ; import org . eclipse . jdt . core . groovy . tests . model . MoveRenameCopyTests ; import org . eclipse . jdt . core . groovy . tests . search . AllSearchTests ; import org . eclipse . jdt . groovy . core . tests . basic . GroovySimpleTest ; public class GroovyJDTTests { public static Test suite ( ) throws Exception { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; suite . addTest ( AnnotationsTests . suite ( ) ) ; suite . addTest ( GroovyCompilationUnitTests . suite ( ) ) ; suite . addTest ( GroovyClassFileTests . suite ( ) ) ; suite . addTest ( GroovyContentTypeTests . suite ( ) ) ; suite . addTest ( MoveRenameCopyTests . suite ( ) ) ; suite . addTest ( GroovyPartialModelTests . suite ( ) ) ; suite . addTest ( BasicGroovyBuildTests . suite ( ) ) ; suite . addTest ( FullProjectTests . suite ( ) ) ; suite . addTestSuite ( LocationSupportTests . class ) ; suite . addTestSuite ( SourceLocationsTests . class ) ; suite . addTestSuite ( ASTNodeSourceLocationsTests . class ) ; suite . addTestSuite ( ASTConverterTests . class ) ; suite . addTest ( GroovySimpleTest . suite ( ) ) ; suite . addTest ( ScriptFolderTests . suite ( ) ) ; suite . addTest ( AllSearchTests . suite ( ) ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . eclipse . jdt . core . SourceRange ; public class CodeSelectStaticImportsTest extends BrowsingTestCase { public CodeSelectStaticImportsTest ( ) { super ( CodeSelectStaticImportsTest . class . getName ( ) ) ; } public void testStaticImport1 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; String toLookFor = "<STR_LIT>" ; assertCodeSelect ( contents , new SourceRange ( contents . indexOf ( toLookFor ) , toLookFor . length ( ) ) , toLookFor ) ; } public void testStaticImport2 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; String toLookFor = "<STR_LIT>" ; assertCodeSelect ( contents , new SourceRange ( contents . indexOf ( toLookFor ) , toLookFor . length ( ) ) , toLookFor ) ; } public void testStaticImport3 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; String toLookFor = "<STR_LIT>" ; assertCodeSelect ( contents , new SourceRange ( contents . lastIndexOf ( toLookFor ) , toLookFor . length ( ) ) , toLookFor ) ; } public void testStaticImport4 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; String toLookFor = "<STR_LIT>" ; assertCodeSelect ( contents , new SourceRange ( contents . lastIndexOf ( toLookFor ) , toLookFor . length ( ) ) , toLookFor ) ; } public void testStaticImport5 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; String toLookFor = "<STR_LIT>" ; assertCodeSelect ( contents , new SourceRange ( contents . lastIndexOf ( toLookFor ) , toLookFor . length ( ) ) , toLookFor ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; public class CodeSelectFieldsPropertiesTest extends BrowsingTestCase { public CodeSelectFieldsPropertiesTest ( ) { super ( CodeSelectFieldsPropertiesTest . class . getName ( ) ) ; } public void testGettersAndField1 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = toFind ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField2 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = toFind ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField3 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField4 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField5 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = toFind ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField6 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = toFind ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField7 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testGettersAndField8 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } public void testIsGetter1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( null , null , contents , toFind , elementName ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import java . util . List ; import org . codehaus . groovy . ast . ModuleNode ; 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 . codebrowsing . fragments . ASTFragmentFactory ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . core . compiler . GroovySnippetCompiler ; import org . codehaus . groovy . eclipse . test . TestProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . tests . junit . extension . TestCase ; public class AbstractCheckerTests extends TestCase { private TestProject testProject ; private GroovySnippetCompiler compiler ; public AbstractCheckerTests ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; testProject = new TestProject ( ) ; compiler = new GroovySnippetCompiler ( testProject . getGroovyProjectFacade ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; compiler . cleanup ( ) ; testProject . dispose ( ) ; } protected IASTFragment getLastFragment ( ModuleNode module ) { Expression expr = getLastExpression ( module ) ; if ( expr != null ) { ASTFragmentFactory factory = new ASTFragmentFactory ( ) ; return factory . createFragment ( expr ) ; } else { return null ; } } protected Expression getLastExpression ( ModuleNode module ) { List < Statement > statements = module . getStatementBlock ( ) . getStatements ( ) ; Statement last = statements . get ( statements . size ( ) - <NUM_LIT:1> ) ; if ( last instanceof ReturnStatement ) { return ( ( ReturnStatement ) last ) . getExpression ( ) ; } else if ( last instanceof ExpressionStatement ) { return ( ( ExpressionStatement ) last ) . getExpression ( ) ; } else { fail ( "<STR_LIT>" ) ; } return null ; } protected ModuleNode createModuleFromText ( String text ) throws CoreException { return compiler . compile ( text ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; public class CodeSelectLocalTest extends BrowsingTestCase { public CodeSelectLocalTest ( ) { super ( CodeSelectLocalTest . class . getName ( ) ) ; } public void testLocalVar1 ( ) throws Exception { assertSelection ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testLocalVar2 ( ) throws Exception { assertSelection ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testLocalVar3 ( ) throws Exception { assertSelection ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testLocalVar4 ( ) throws Exception { String contents = "<STR_LIT>" ; assertSelection ( contents , "<STR_LIT>" ) ; assertSelection ( contents , "<STR_LIT>" ) ; } public void testLocalVar5 ( ) throws Exception { String contents = "<STR_LIT>" ; assertSelection ( contents , "<STR_LIT:i>" ) ; } public void testLocalVar6 ( ) throws Exception { String contents = "<STR_LIT>" ; assertSelection ( contents , "<STR_LIT:i>" , "<STR_LIT>" ) ; } void assertSelection ( String contents , String varName ) throws Exception { assertSelection ( contents , varName , varName ) ; } void assertSelection ( String contents , String varName , String selectionText ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( selectionText ) , selectionText . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , varName , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; public class CodeSelectTypesTest extends BrowsingTestCase { public CodeSelectTypesTest ( ) { super ( CodeSelectTypesTest . class . getName ( ) ) ; } public void testSelectSuperClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contentsSuper = "<STR_LIT>" ; String contentsSub = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contentsSuper ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contentsSub ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contentsSub . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectSuperClass2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contentsSuper = "<STR_LIT>" ; String contentsSub = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contentsSuper ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contentsSub ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contentsSub . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectThisClass ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectFieldType ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectMethodType ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectMethodParamType ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectLocalVarType ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectLocalVarTypeInClosure ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectLocalVarTypeInScript ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectTypeInAnnotation1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectTypeInAnnotation2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String javaContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; env . addClass ( root , "<STR_LIT>" , javaContents ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectTypeInAnnotation3 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String javaContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; env . addClass ( root , "<STR_LIT>" , javaContents ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectThis1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectThis2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectSuper1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectSuper2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType2 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType3 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType4 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType5 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testSelectInnerType6 ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testAnnotationOnImport ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyCompilationUnit unit = createCompilationUnit ( contents ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } private GroovyCompilationUnit createCompilationUnit ( String contents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; return unit ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . selection . FindAllOccurrencesVisitor ; import org . codehaus . groovy . eclipse . codebrowsing . selection . IsSameExpression ; import org . eclipse . core . runtime . CoreException ; public class IsSameExpressionTests extends AbstractCheckerTests { public IsSameExpressionTests ( ) { super ( IsSameExpressionTests . class . getName ( ) ) ; } public void testIsSame1 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame2 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , false ) ; } public void testIsSame3 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame4 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame5 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , false ) ; } public void testIsSame6 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame7 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame8 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame9 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , true ) ; } public void testIsSame10 ( ) throws Exception { checkTwoExpressions ( "<STR_LIT>" , "<STR_LIT>" , false ) ; } private void checkTwoExpressions ( String first , String second , boolean isSame ) throws CoreException { Expression firstExpr = getLastExpression ( createModuleFromText ( first ) ) ; Expression secondExpr = getLastExpression ( createModuleFromText ( second ) ) ; assertEquals ( createMsg ( first , second , isSame ) , isSame , new IsSameExpression ( ) . isSame ( firstExpr , secondExpr ) ) ; } private String createMsg ( String first , String second , boolean isSame ) { String end = "<STR_LIT>" + first + "<STR_LIT>" + second ; return ( isSame ? "<STR_LIT>" : "<STR_LIT>" ) + end ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; public class CodeSelectFieldsTest extends BrowsingTestCase { public CodeSelectFieldsTest ( ) { super ( CodeSelectFieldsTest . class . getName ( ) ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; } public void testCodeSelectVarInScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectFieldInClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectFieldInOtherClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT:p>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; IPath hello2Path = env . addGroovyClass ( root , "<STR_LIT:p>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( hello2Path ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectFieldInSuperClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT:p>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; IPath hello2Path = env . addGroovyClass ( root , "<STR_LIT:p>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( hello2Path ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticFieldInClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticFieldInOtherClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:t>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectInClosure2Params ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:t>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectLocalVarInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:y>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectFieldInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:y>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectFieldFromSuperInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:y>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticFieldInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:y>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticFieldFromOtherInClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:y>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectInFieldInitializer ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectInStaticFieldInitializer ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectOfGeneratedGetter ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectOfGeneratedSetter ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectInsideGString1 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:foo>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectInsideGString2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:foo>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectInsideGString3 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectInsideGString4 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) + <NUM_LIT:1> , <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:foo>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } public void testCodeSelectInsideGString5 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertTrue ( "<STR_LIT>" , elt [ <NUM_LIT:0> ] . exists ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; 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 . CoreException ; import org . eclipse . core . runtime . IPath ; 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 . SourceRange ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; 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 . internal . core . DefaultWorkingCopyOwner ; import org . eclipse . jdt . internal . core . ResolvedBinaryField ; import org . eclipse . jdt . internal . core . ResolvedBinaryMethod ; import org . eclipse . jdt . internal . core . ResolvedBinaryType ; import org . eclipse . jdt . internal . core . ResolvedSourceField ; import org . eclipse . jdt . internal . core . ResolvedSourceMethod ; import org . eclipse . jdt . internal . core . ResolvedSourceType ; public abstract class BrowsingTestCase extends BuilderTests { public BrowsingTestCase ( String name ) { super ( name ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; ICompilationUnit [ ] wcs = new ICompilationUnit [ <NUM_LIT:0> ] ; int i = <NUM_LIT:0> ; do { wcs = JavaCore . getWorkingCopies ( DefaultWorkingCopyOwner . PRIMARY ) ; for ( ICompilationUnit workingCopy : wcs ) { try { workingCopy . discardWorkingCopy ( ) ; workingCopy . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } i ++ ; if ( i > <NUM_LIT:20> ) { fail ( "<STR_LIT>" + wcs ) ; } } while ( wcs . length > <NUM_LIT:0> ) ; } protected IPath createGenericProject ( ) throws Exception { IPath projectPath ; if ( ! ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( "<STR_LIT>" ) . exists ( ) ) { 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>" ) ; } else { projectPath = env . getJavaProject ( "<STR_LIT>" ) . getPath ( ) ; } return projectPath ; } protected IFile getFile ( IPath projectPath , String fileName ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getFile ( projectPath . append ( fileName ) ) ; } protected IFile getFile ( IPath filePath ) { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getFile ( filePath ) ; } protected IFolder getFolder ( 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 GroovyCompilationUnit getGroovyCompilationUnit ( IPath sourceRootPath , String qualifiedNameWithSlashesDotGroovy ) throws Exception { IFile file = getFile ( sourceRootPath , qualifiedNameWithSlashesDotGroovy ) ; waitUntilIndexesReady ( ) ; GroovyCompilationUnit unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; unit . becomeWorkingCopy ( null ) ; return unit ; } public GroovyCompilationUnit getGroovyCompilationUnit ( IPath pathToCU ) throws Exception { IFile file = getFile ( pathToCU ) ; waitUntilIndexesReady ( ) ; GroovyCompilationUnit unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; unit . becomeWorkingCopy ( null ) ; return unit ; } protected GroovyCompilationUnit getCompilationUnitFor ( String contents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; return getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; } protected void assertCodeSelect ( String structureContents , String groovyContents , String toFind ) throws Exception , JavaModelException { assertCodeSelect ( structureContents , null , groovyContents , toFind ) ; } protected void assertCodeSelect ( String structureContents , String javaContents , String groovyContents , String toFind ) throws Exception , JavaModelException { assertCodeSelect ( structureContents , javaContents , groovyContents , toFind , toFind ) ; } protected void assertCodeSelect ( String structureContents , String javaContents , String groovyContents , String toFind , String elementName ) throws Exception , JavaModelException { assertCodeSelect ( structureContents , javaContents , groovyContents , toFind , elementName , false ) ; } protected void assertGroovyCodeSelect ( String structureContents , String javaContents , String groovyContents , String toFind ) throws Exception , JavaModelException { assertCodeSelect ( structureContents , javaContents , groovyContents , toFind , toFind , true ) ; } protected void assertCodeSelect ( String structureContents , String javaContents , String groovyContents , String toFind , String elementName , boolean isGroovy ) throws Exception , JavaModelException { assertCodeSelect ( structureContents , javaContents , groovyContents , toFind , new SourceRange ( groovyContents . lastIndexOf ( toFind ) , toFind . length ( ) ) , elementName , isGroovy ) ; } protected void assertCodeSelect ( String groovyContents , SourceRange selectRange , String elementName ) throws Exception , JavaModelException { assertCodeSelect ( null , null , groovyContents , null , selectRange , elementName , true ) ; } protected void assertCodeSelect ( String structureContents , String javaContents , String groovyContents , String toFind , SourceRange selectRegion , String elementName , boolean isGroovy ) throws Exception , JavaModelException { if ( structureContents != null ) { if ( javaContents != null ) { if ( isGroovy ) { createUnit ( "<STR_LIT>" , structureContents ) ; } else { createJavaUnit ( "<STR_LIT>" , structureContents ) ; } } else { if ( isGroovy ) { createJavaUnit ( "<STR_LIT>" , structureContents ) ; } else { createJavaUnit ( "<STR_LIT>" , structureContents ) ; } } } GroovyCompilationUnit groovyUnit = createUnit ( groovyContents ) ; ICompilationUnit javaUnit = null ; if ( javaContents != null ) { javaUnit = createJavaUnit ( "<STR_LIT>" , javaContents ) ; } incrementalBuild ( ) ; expectingNoProblems ( ) ; IJavaElement [ ] eltFromGroovy = groovyUnit . codeSelect ( selectRegion . getOffset ( ) , selectRegion . getLength ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , eltFromGroovy . length ) ; assertEquals ( "<STR_LIT>" + elementName , elementName , eltFromGroovy [ <NUM_LIT:0> ] . getElementName ( ) ) ; if ( javaUnit != null ) { IJavaElement [ ] eltFromJava = javaUnit . codeSelect ( javaContents . lastIndexOf ( toFind ) , toFind . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , eltFromJava . length ) ; assertEquals ( "<STR_LIT>" + elementName , elementName , eltFromJava [ <NUM_LIT:0> ] . getElementName ( ) ) ; String groovyUniqueKey = getUniqueKey ( eltFromGroovy [ <NUM_LIT:0> ] ) ; String javaUniqueKey = getUniqueKey ( eltFromJava [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" , javaUniqueKey , groovyUniqueKey ) ; } } protected String getUniqueKey ( IJavaElement elt ) { if ( elt instanceof ResolvedSourceField ) { return ( ( ResolvedSourceField ) elt ) . getKey ( ) ; } else if ( elt instanceof ResolvedSourceMethod ) { return ( ( ResolvedSourceMethod ) elt ) . getKey ( ) ; } else if ( elt instanceof ResolvedSourceType ) { return ( ( ResolvedSourceType ) elt ) . getKey ( ) ; } if ( elt instanceof ResolvedBinaryField ) { return ( ( ResolvedBinaryField ) elt ) . getKey ( ) ; } else if ( elt instanceof ResolvedBinaryMethod ) { return ( ( ResolvedBinaryMethod ) elt ) . getKey ( ) ; } else if ( elt instanceof ResolvedBinaryType ) { return ( ( ResolvedBinaryType ) elt ) . getKey ( ) ; } fail ( "<STR_LIT>" + elt + "<STR_LIT>" ) ; return null ; } protected GroovyCompilationUnit createUnit ( String contents ) throws Exception { return createUnit ( "<STR_LIT:Hello>" , contents ) ; } protected GroovyCompilationUnit createUnit ( String name , String contents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , name , contents ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , name + "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; return unit ; } protected ICompilationUnit createJavaUnit ( String className , String contents ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addClass ( root , "<STR_LIT>" , className , contents ) ; ICompilationUnit unit = getJavaCompilationUnit ( root , className + "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; return unit ; } public static void waitUntilIndexesReady ( ) { SearchEngine engine = new SearchEngine ( ) ; IJavaSearchScope scope = SearchEngine . createWorkspaceScope ( ) ; try { engine . searchAllTypeNames ( null , SearchPattern . R_EXACT_MATCH , "<STR_LIT>" . toCharArray ( ) , SearchPattern . R_PATTERN_MATCH | SearchPattern . R_CASE_SENSITIVE , IJavaSearchConstants . CLASS , scope , new TypeNameRequestor ( ) { @ Override public void acceptType ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path ) { } } , IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH , null ) ; } catch ( CoreException e ) { } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import java . util . Arrays ; import java . util . Collections ; import java . util . List ; import java . util . Stack ; 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 . codebrowsing . fragments . ASTFragmentFactory ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . ASTFragmentKind ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . BinaryExpressionFragment ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . FragmentVisitor ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . MethodCallFragment ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . PropertyExpressionFragment ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . SimpleExpressionASTFragment ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . JavaCore ; public class ASTFragmentTests extends BrowsingTestCase { @ Override protected void setUp ( ) throws Exception { System . out . println ( JavaCore . getWorkingCopies ( null ) ) ; super . setUp ( ) ; } private class TestFragmentVisitor extends FragmentVisitor { private Stack < ASTFragmentKind > expectedKinds ; void checkExpectedKinds ( IASTFragment fragment , ASTFragmentKind ... expectedKindsArr ) { this . expectedKinds = new Stack < ASTFragmentKind > ( ) ; List < ASTFragmentKind > list = Arrays . asList ( expectedKindsArr ) ; Collections . reverse ( list ) ; this . expectedKinds . addAll ( list ) ; fragment . accept ( this ) ; if ( ! expectedKinds . isEmpty ( ) ) { fail ( ) ; } } @ Override public boolean visit ( BinaryExpressionFragment fragment ) { if ( this . expectedKinds . isEmpty ( ) ) { fail ( ) ; } if ( this . expectedKinds . pop ( ) != fragment . kind ( ) ) { fail ( ) ; } return super . visit ( fragment ) ; } @ Override public boolean visit ( MethodCallFragment fragment ) { if ( this . expectedKinds . isEmpty ( ) ) { fail ( ) ; } if ( this . expectedKinds . pop ( ) != fragment . kind ( ) ) { fail ( ) ; } return super . visit ( fragment ) ; } @ Override public boolean visit ( PropertyExpressionFragment fragment ) { if ( this . expectedKinds . isEmpty ( ) ) { fail ( ) ; } if ( this . expectedKinds . pop ( ) != fragment . kind ( ) ) { fail ( ) ; } return super . visit ( fragment ) ; } @ Override public boolean visit ( SimpleExpressionASTFragment fragment ) { if ( this . expectedKinds . isEmpty ( ) ) { fail ( ) ; } if ( this . expectedKinds . pop ( ) != fragment . kind ( ) ) { fail ( ) ; } return super . visit ( fragment ) ; } } public ASTFragmentTests ( ) { super ( ASTFragmentTests . class . getName ( ) ) ; } public void testASTFragment1 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT:a>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT:a>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:1> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment2 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:2> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . BINARY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment3 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:2> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment4 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:2> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . METHOD_POINTER , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment5 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:3> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment6 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:3> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL ) ; } public void testASTFragment7 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:4> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment8 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:2> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL ) ; } public void testASTFragment9 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:8> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTFragment10 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment second = createFragmentFromText ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" + first , <NUM_LIT:8> , first . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment1a ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:0> , contents . indexOf ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment1b ( ) throws Exception { System . out . println ( JavaCore . getWorkingCopies ( null ) ) ; IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:2> , contents . indexOf ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentDifferent ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment2a ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:0> , contents . indexOf ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment2b ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:2> , contents . indexOf ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentDifferent ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( first , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . PROPERTY , ASTFragmentKind . PROPERTY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment3 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:4> , contents . indexOf ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . BINARY , ASTFragmentKind . BINARY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment4 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:4> , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:2> ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . BINARY , ASTFragmentKind . BINARY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testASTSubFragment5 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , <NUM_LIT:0> , contents . indexOf ( "<STR_LIT:)>" ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:2> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . PROPERTY , ASTFragmentKind . METHOD_CALL ) ; } public void testASTSubFragment6 ( ) throws Exception { IASTFragment first = createFragmentFromText ( "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; IASTFragment second = createFragmentFromText ( contents , contents . indexOf ( "<STR_LIT:c>" ) , contents . length ( ) ) ; assertEquals ( "<STR_LIT>" + second , <NUM_LIT:3> , second . fragmentLength ( ) ) ; assertFragmentSame ( first , second ) ; new TestFragmentVisitor ( ) . checkExpectedKinds ( second , ASTFragmentKind . BINARY , ASTFragmentKind . BINARY , ASTFragmentKind . SIMPLE_EXPRESSION ) ; } public void testMatchSubFragment1 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment2 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment3 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT:a>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT:b>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment4 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT:a>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment5 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT:b>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment6 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT:a>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment7 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment8 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment9 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment10 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment11 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment12 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment13 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment14 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment15 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment16 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } public void testMatchSubFragment17 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertIsEmptyFragment ( matched ) ; } public void testMatchSubFragment18 ( ) throws Exception { IASTFragment fragment = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment toMatch = createFragmentFromText ( "<STR_LIT>" ) ; IASTFragment matched = fragment . findMatchingSubFragment ( toMatch ) ; assertFragmentSame ( toMatch , matched ) ; } private void assertIsEmptyFragment ( IASTFragment fragment ) { assertEquals ( "<STR_LIT>" + fragment , ASTFragmentKind . EMPTY , fragment . kind ( ) ) ; } private void assertFragmentSame ( IASTFragment first , IASTFragment second ) { if ( ! first . matches ( second ) ) { fail ( "<STR_LIT>" + first + "<STR_LIT:n>" + second ) ; } } private void assertFragmentDifferent ( IASTFragment first , IASTFragment second ) { if ( first . matches ( second ) ) { fail ( "<STR_LIT>" + first + "<STR_LIT:n>" + second ) ; } } private IASTFragment createFragmentFromText ( String contents ) throws Exception { GroovyCompilationUnit unit = getCompilationUnitFor ( contents ) ; Statement statement = ( Statement ) unit . getModuleNode ( ) . getStatementBlock ( ) . getStatements ( ) . get ( <NUM_LIT:0> ) ; Expression expr = statement instanceof ReturnStatement ? ( ( ReturnStatement ) statement ) . getExpression ( ) : ( ( ExpressionStatement ) statement ) . getExpression ( ) ; IASTFragment fragment = new ASTFragmentFactory ( ) . createFragment ( expr ) ; unit . discardWorkingCopy ( ) ; return fragment ; } private IASTFragment createFragmentFromText ( String contents , int start , int end ) throws Exception { GroovyCompilationUnit unit = getCompilationUnitFor ( contents ) ; return new ASTFragmentFactory ( ) . createFragment ( ( ( ReturnStatement ) unit . getModuleNode ( ) . getStatementBlock ( ) . getStatements ( ) . get ( <NUM_LIT:0> ) ) . getExpression ( ) , start , end ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . eclipse . jdt . core . SourceRange ; public class CodeSelectGenericsTest extends BrowsingTestCase { public CodeSelectGenericsTest ( ) { super ( CodeSelectGenericsTest . class . getName ( ) ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; } public void testGRECLIPSE1050a ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testGRECLIPSE1050b ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectGenericField1 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericField2 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericField3 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericMethod1 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericMethod2 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericMethod3 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericMethod4 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericMethod5 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericType1 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndField1 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndField2 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndField3 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT:field>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndMethod1 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndMethod2 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndMethod3 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndMethod4 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectGenericTypeAndMethod5 ( ) throws Exception { String structureContents = "<STR_LIT>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } private static final String XX = "<STR_LIT>" ; public void testCodeSelectArray1 ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectArray2 ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectArray3 ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( XX , groovyContents , toFind ) ; } public void testCodeSelectArray4 ( ) throws Exception { String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertCodeSelect ( XX , groovyContents , toFind ) ; } public void testCodeSelectArray5 ( ) throws Exception { String groovyContents = "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectArray6 ( ) throws Exception { String groovyContents = "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectArray7 ( ) throws Exception { String groovyContents = "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } public void testCodeSelectArray8 ( ) throws Exception { String groovyContents = "<STR_LIT>" + "<STR_LIT>" ; String toFind = "<STR_LIT>" ; String elementName = "<STR_LIT>" ; assertCodeSelect ( XX , null , groovyContents , toFind , elementName ) ; } private static final String GENERICS_CLASS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; private int find ( int toFind ) { String lookFor = "<STR_LIT>" + toFind + "<STR_LIT>" ; int index = GENERICS_CLASS . indexOf ( lookFor ) ; return index < <NUM_LIT:0> ? index : index + lookFor . length ( ) ; } public void testCodeSelectTypeParam0 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:0> ) , len ) , name ) ; } public void testCodeSelectTypeParam1 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:1> ) , len ) , name ) ; } public void testCodeSelectTypeParam2 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:2> ) , len ) , name ) ; } public void testCodeSelectTypeParam3 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:3> ) , len ) , name ) ; } public void testCodeSelectTypeParam4 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:4> ) , len ) , name ) ; } public void testCodeSelectTypeParam5 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:5> ) , len ) , name ) ; } public void testCodeSelectTypeParam6 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:6> ) , len ) , name ) ; } public void testCodeSelectTypeParam7 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:7> ) , len ) , name ) ; } public void testCodeSelectTypeParam8 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:8> ) , len ) , name ) ; } public void testCodeSelectTypeParam9 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:9> ) , len ) , name ) ; } public void testCodeSelectTypeParam10 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:10> ) , len ) , name ) ; } public void testCodeSelectTypeParam11 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:11> ) , len ) , name ) ; } public void testCodeSelectTypeParam12 ( ) throws Exception { String name = "<STR_LIT>" ; int len = name . length ( ) ; assertCodeSelect ( GENERICS_CLASS , new SourceRange ( find ( <NUM_LIT:12> ) , len ) , name ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import java . util . Arrays ; import java . util . List ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . codebrowsing . selection . FindAllOccurrencesVisitor ; import org . eclipse . core . runtime . CoreException ; public class FindAllOccurrencesVisitorTests extends AbstractCheckerTests { public FindAllOccurrencesVisitorTests ( ) { super ( FindAllOccurrencesVisitorTests . class . getName ( ) ) ; } public void testFindAllOccurrences1 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences2 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) , moduleText . lastIndexOf ( exprText ) ) ; } public void testFindAllOccurrences3 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences4 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) , moduleText . lastIndexOf ( exprText ) ) ; } public void testFindAllOccurrences5 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences6 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) , moduleText . lastIndexOf ( exprText ) ) ; } public void testFindAllOccurrences7 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) , moduleText . lastIndexOf ( exprText ) ) ; } public void testFindAllOccurrences8 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences9 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences10 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences11 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences12 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; assertOccurrences ( exprText , moduleText , moduleText . indexOf ( exprText ) ) ; } public void testFindAllOccurrences13 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; int second = moduleText . indexOf ( exprText , first + <NUM_LIT:2> ) ; int third = moduleText . indexOf ( exprText , second + <NUM_LIT:2> ) ; assertOccurrences ( exprText , moduleText , first , second , third ) ; } public void testFindAllOccurrences14 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; int second = moduleText . indexOf ( exprText , moduleText . indexOf ( '<CHAR_LIT>' ) ) ; assertOccurrences ( exprText , moduleText , first , second ) ; } public void testFindAllOccurrences15 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; int second = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first , second ) ; } public void testFindAllOccurrences16 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences17 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; int second = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first , second ) ; } public void testFindAllOccurrences18 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences19 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences20 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences21 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences21a ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first ) ; } public void testFindAllOccurrences22 ( ) throws Exception { String moduleText = "<STR_LIT>" ; String exprText = "<STR_LIT>" ; int first = moduleText . indexOf ( exprText ) ; int second = moduleText . lastIndexOf ( exprText ) ; assertOccurrences ( exprText , moduleText , first , second ) ; } private void assertOccurrences ( String exprToFindText , String moduleText , int ... startLocations ) throws CoreException { IASTFragment exprToFind = getLastFragment ( createModuleFromText ( exprToFindText ) ) ; ModuleNode module = createModuleFromText ( moduleText ) ; FindAllOccurrencesVisitor visitor = new FindAllOccurrencesVisitor ( module ) ; List < IASTFragment > foundExprs = visitor . findOccurrences ( exprToFind ) ; assertEquals ( createMsg ( foundExprs , startLocations , exprToFindText , moduleText ) , startLocations . length , foundExprs . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < startLocations . length ; i ++ ) { assertEquals ( createMsg ( foundExprs , startLocations , exprToFindText , moduleText ) , foundExprs . get ( i ) . getStart ( ) , startLocations [ i ] ) ; } } private String createMsg ( List < IASTFragment > foundExprs , int [ ] startLocations , String exprToFindText , String moduleText ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" + moduleText + "<STR_LIT>" + exprToFindText + "<STR_LIT>" + Arrays . toString ( startLocations ) + "<STR_LIT>" + getStarts ( foundExprs ) + "<STR_LIT>" ) ; return sb . toString ( ) ; } private String getStarts ( List < IASTFragment > foundExprs ) { StringBuilder sb = new StringBuilder ( ) ; for ( IASTFragment foundExpr : foundExprs ) { sb . append ( foundExpr . getStart ( ) ) . append ( "<STR_LIT:U+002CU+0020>" ) ; } if ( sb . length ( ) > <NUM_LIT:0> ) { sb . replace ( sb . length ( ) - <NUM_LIT:2> , sb . length ( ) , "<STR_LIT>" ) ; } return sb . toString ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllBrowsingTests { public static Test suite ( ) throws Exception { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; suite . addTestSuite ( CodeSelectMethodsTest . class ) ; suite . addTestSuite ( CodeSelectFieldsTest . class ) ; suite . addTestSuite ( CodeSelectTypesTest . class ) ; suite . addTestSuite ( CodeSelectCategoriesTest . class ) ; suite . addTestSuite ( CodeSelectGenericsTest . class ) ; suite . addTestSuite ( FindSurroundingNodeTests . class ) ; suite . addTestSuite ( FindAllOccurrencesVisitorTests . class ) ; suite . addTestSuite ( ASTFragmentTests . class ) ; suite . addTestSuite ( IsSameExpressionTests . class ) ; suite . addTestSuite ( PartialVisitTest . class ) ; suite . addTestSuite ( CodeSelectFieldsPropertiesTest . class ) ; suite . addTestSuite ( CodeSelectLocalTest . class ) ; suite . addTestSuite ( CodeSelectStaticImportsTest . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Set ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . CodeSelectHelper ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . CodeSelectRequestor ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; public class PartialVisitTest extends BrowsingTestCase { private class PartialCodeSelectRequestor extends CodeSelectRequestor { Set < String > skippedElements = new HashSet < String > ( ) ; public PartialCodeSelectRequestor ( ASTNode nodeToLookFor , GroovyCompilationUnit unit ) { super ( nodeToLookFor , unit ) ; } @ Override public VisitStatus acceptASTNode ( ASTNode node , TypeLookupResult result , IJavaElement enclosingElement ) { VisitStatus status = super . acceptASTNode ( node , result , enclosingElement ) ; if ( status == VisitStatus . CANCEL_MEMBER ) { if ( skippedElements . contains ( enclosingElement ) ) { fail ( "<STR_LIT>" + enclosingElement ) ; } skippedElements . add ( enclosingElement . getElementName ( ) ) ; } return status ; } } class PartialCodeSelectHelper extends CodeSelectHelper { Set < String > skippedElements = new HashSet < String > ( ) ; @ Override protected CodeSelectRequestor createRequestor ( GroovyCompilationUnit unit , ASTNode nodeToLookFor ) { PartialCodeSelectRequestor partialCodeSelectRequestor = new PartialCodeSelectRequestor ( nodeToLookFor , unit ) ; skippedElements = partialCodeSelectRequestor . skippedElements ; return partialCodeSelectRequestor ; } @ Override public IJavaElement [ ] select ( GroovyCompilationUnit unit , int start , int length ) { helper . skippedElements . clear ( ) ; return super . select ( unit , start , length ) ; } @ Override public ASTNode selectASTNode ( GroovyCompilationUnit unit , int start , int length ) { helper . skippedElements . clear ( ) ; return super . selectASTNode ( unit , start , length ) ; } } PartialCodeSelectHelper helper = new PartialCodeSelectHelper ( ) ; public PartialVisitTest ( String name ) { super ( name ) ; } public void testSimple ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , indexOf ( contents , "<STR_LIT:x>" ) , "<STR_LIT:x>" , "<STR_LIT:Hello>" , "<STR_LIT>" ) ; } public void testSimple2 ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:x>" ) , "<STR_LIT:x>" , "<STR_LIT:Hello>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testSimple3 ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:x>" ) , "<STR_LIT:x>" , "<STR_LIT:x>" ) ; } public void testFieldInitializer ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:y>" ) , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT:y>" ) ; } public void testStaticFieldInitializer ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:y>" ) , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:y>" ) ; } public void testInnerClass ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:y>" ) , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testInnerClass2 ( ) throws Exception { String contents = "<STR_LIT>" ; assertCodeSelectWithSkippedNames ( contents , lastIndexOf ( contents , "<STR_LIT:y>" ) , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT>" ) ; } private Region indexOf ( String contents , String string ) { return new Region ( contents . indexOf ( string ) , string . length ( ) ) ; } private Region lastIndexOf ( String contents , String string ) { return new Region ( contents . lastIndexOf ( string ) , string . length ( ) ) ; } private void assertCodeSelectWithSkippedNames ( String contents , Region region , String expectedElementName , String ... skippedElementNames ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; env . incrementalBuild ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = helper . select ( unit , region . getOffset ( ) , region . getLength ( ) ) ; assertEquals ( "<STR_LIT>" + Arrays . toString ( elt ) , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , expectedElementName , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; for ( String skipped : skippedElementNames ) { assertTrue ( "<STR_LIT>" + skipped + "<STR_LIT>" + Arrays . toString ( skippedElementNames ) + "<STR_LIT>" + helper . skippedElements , helper . skippedElements . contains ( skipped ) ) ; } assertEquals ( "<STR_LIT>" + Arrays . toString ( skippedElementNames ) + "<STR_LIT>" + helper . skippedElements , skippedElementNames . length , helper . skippedElements . size ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . codebrowsing . selection . FindSurroundingNode ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; public class FindSurroundingNodeTests extends BrowsingTestCase { public FindSurroundingNodeTests ( ) { super ( FindSurroundingNodeTests . class . getName ( ) ) ; } public void testFindSurrounding1 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . indexOf ( '<CHAR_LIT:c>' ) , "<STR_LIT>" . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding2 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT:A>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( <NUM_LIT:0> , "<STR_LIT>" . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding3 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . indexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; checkRegion ( contents , unit , initialRegion , expectedRegion ) ; } public void testFindSurrounding4 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . indexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void _testFindSurrounding5 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; Region expectedRegion = new Region ( contents . indexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding5a ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding6 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . indexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding7 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding8a ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding8b ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding8c ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:foo>" ) , "<STR_LIT:foo>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding9a ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT:9>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding9b ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT:1>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:1>" ) , "<STR_LIT:1>" . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; checkRegion ( contents , initialRegion , expectedRegion ) ; } public void _testFindSurrounding10 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT:a>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:a>" ) , "<STR_LIT:a>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void _testFindSurrounding10a ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT:a>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:a>" ) , "<STR_LIT:a>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } public void testFindSurrounding11 ( ) throws Exception { String contents = "<STR_LIT>" ; Region initialRegion = new Region ( contents . lastIndexOf ( '<CHAR_LIT:a>' ) , <NUM_LIT:0> ) ; Region expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT:a>" ) , "<STR_LIT:a>" . length ( ) ) ; GroovyCompilationUnit unit = checkRegion ( contents , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; unit = checkRegion ( contents , unit , initialRegion , expectedRegion ) ; initialRegion = expectedRegion ; expectedRegion = new Region ( <NUM_LIT:0> , contents . length ( ) ) ; unit = checkRegion ( contents , initialRegion , expectedRegion ) ; } private GroovyCompilationUnit checkRegion ( String contents , Region initialRegion , Region expectedRegion ) throws Exception { GroovyCompilationUnit unit = getCompilationUnitFor ( contents ) ; return checkRegion ( contents , unit , initialRegion , expectedRegion ) ; } private GroovyCompilationUnit checkRegion ( String contents , GroovyCompilationUnit unit , Region initialRegion , Region expectedRegion ) { FindSurroundingNode finder = new FindSurroundingNode ( initialRegion ) ; IASTFragment result = finder . doVisitSurroundingNode ( unit . getModuleNode ( ) ) ; Region actualRegion = new Region ( result ) ; assertEquals ( "<STR_LIT>" + getRegionText ( expectedRegion , contents ) + "<STR_LIT>" + "<STR_LIT>" + getRegionText ( actualRegion , contents ) + "<STR_LIT>" , expectedRegion , actualRegion ) ; return unit ; } private String getRegionText ( Region region , String sourceString ) { return sourceString . substring ( region . getOffset ( ) , region . getEnd ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; public class CodeSelectCategoriesTest extends BrowsingTestCase { public CodeSelectCategoriesTest ( ) { super ( CodeSelectCategoriesTest . class . getName ( ) ) ; } public void testDGM ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testGroovyCategory ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents2 ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . tests ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; public class CodeSelectMethodsTest extends BrowsingTestCase { public CodeSelectMethodsTest ( ) { super ( CodeSelectMethodsTest . class . getName ( ) ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; } public void testCodeSelectDefaultParams1 ( ) throws Exception { String structureContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertGroovyCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectDefaultParams2 ( ) throws Exception { String structureContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertGroovyCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectDefaultParams3 ( ) throws Exception { String structureContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertGroovyCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectDefaultParams4 ( ) throws Exception { String structureContents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String javaContents = "<STR_LIT>" ; String groovyContents = "<STR_LIT>" ; String toFind = "<STR_LIT>" ; assertGroovyCodeSelect ( structureContents , javaContents , groovyContents , toFind ) ; } public void testCodeSelectClosure ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectInt ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectReAssign ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectMethodInClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectMethodInOtherClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectMethodInSuperClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; assertTrue ( "<STR_LIT>" , unit . exists ( ) ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectMethodInScriptFromScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectMethodInClassFromScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethodFromClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethodFromScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT:x>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethodInOtherClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethodInOtherClass2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( projectPath ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethodInSuperClass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; String contents2 = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents2 ) ; incrementalBuild ( ) ; env . waitForAutoBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents2 . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticInScript ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticMethod1 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT:p>" ) , "<STR_LIT:p>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getParent ( ) . getElementName ( ) ) ; } public void testCodeSelectStaticMethod2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . lastIndexOf ( "<STR_LIT:p>" ) , "<STR_LIT:p>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getParent ( ) . getElementName ( ) ) ; } public void testCodeSelectStaticProperty1 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticProperty2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectStaticProperty3 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; } public void testCodeSelectOverloadedMethod1 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , ( ( IMethod ) elt [ <NUM_LIT:0> ] ) . getParameterTypes ( ) . length ) ; } public void testCodeSelectOverloadedMethod2 ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; String contents = "<STR_LIT>" ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , contents ) ; incrementalBuild ( ) ; expectingNoProblems ( ) ; GroovyCompilationUnit unit = getGroovyCompilationUnit ( root , "<STR_LIT>" ) ; unit . becomeWorkingCopy ( null ) ; IJavaElement [ ] elt = unit . codeSelect ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , elt . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , elt [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , ( ( IMethod ) elt [ <NUM_LIT:0> ] ) . getParameterTypes ( ) . length ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test ; import java . lang . reflect . InvocationTargetException ; import org . codehaus . groovy . eclipse . quickassist . AbstractGroovyCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . AssignStatementToNewLocalProposal ; import org . codehaus . groovy . eclipse . quickassist . ConvertToClosureCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . ConvertToMethodCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . ConvertToMultiLineStringCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . ConvertToSingleLineStringCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . RemoveUnnecessarySemicolonsCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . SplitAssigmentCompletionProposal ; import org . codehaus . groovy . eclipse . quickassist . SwapOperandsCompletionProposal ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . core . CompilationUnit ; import org . eclipse . jdt . internal . ui . text . correction . AssistContext ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; public class QuickAssistTests extends EclipseTestCase { public void testConvertToClosure1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure2 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure3 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure4 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure5 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure6 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure7 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure8 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure9 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure10 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToClosure11 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToClosureCompletionProposal . class ) ; } public void testConvertToMethod1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod3 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod4 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod5 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod6 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod7 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod8 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod9 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod10 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMethod11 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" , ConvertToMethodCompletionProposal . class ) ; } public void testConvertToMultiLine1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:f>" , ConvertToMultiLineStringCompletionProposal . class ) ; } public void testConvertToMultiLine2 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:f>" , ConvertToMultiLineStringCompletionProposal . class ) ; } public void testConvertToSingleLine1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:f>" , ConvertToSingleLineStringCompletionProposal . class ) ; } public void testConvertToSingleLine2 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:f>" , ConvertToSingleLineStringCompletionProposal . class ) ; } public void testRemoveUnnecessarySemicolons1 ( ) throws Exception { String original = "<STR_LIT>" ; assertConversion ( original , "<STR_LIT>" , original , RemoveUnnecessarySemicolonsCompletionProposal . class ) ; } public void testRemoveUnnecessarySemicolons2 ( ) throws Exception { String original = "<STR_LIT>" ; String expected = "<STR_LIT>" ; assertConversion ( original , expected , null , RemoveUnnecessarySemicolonsCompletionProposal . class ) ; } public void testSwapOperands1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:7> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands2 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands3 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:7> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands4 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:7> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands5 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands6 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:12> , <NUM_LIT:1> , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands7 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , SwapOperandsCompletionProposal . class ) ; } public void testSwapOperands8 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , SwapOperandsCompletionProposal . class ) ; } public void testSplitAssignment1 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:=>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment2 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment3 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:=>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment4 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment5 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:=>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment6 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:=>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment7 ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment7a ( ) throws Exception { assertConversion ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , SplitAssigmentCompletionProposal . class ) ; } public void testSplitAssignment8 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" , "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" , "<STR_LIT>" , SplitAssigmentCompletionProposal . class ) ; } public void testAssignStatementToLocalRefactoring1 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring2 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring3 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring4 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:false>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring5 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring6 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT:2>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring7 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } public void testAssignStatementToLocalRefactoring8 ( ) throws Exception { assertConversion ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , "<STR_LIT>" , AssignStatementToNewLocalProposal . class ) ; } private void assertConversion ( String original , String expected , String searchFor , Class < ? extends AbstractGroovyCompletionProposal > proposalClass ) throws Exception , SecurityException , InstantiationException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { int start = searchFor == null ? <NUM_LIT:0> : original . indexOf ( searchFor ) ; int length = searchFor == null ? <NUM_LIT:0> : searchFor . length ( ) ; assertConversion ( original , expected , start , length , proposalClass ) ; } private void assertConversion ( String original , String expected , int offset , int length , Class < ? extends AbstractGroovyCompletionProposal > proposalClass ) throws Exception , SecurityException , InstantiationException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { ICompilationUnit unit = testProject . createUnit ( "<STR_LIT>" , "<STR_LIT>" , original ) ; IInvocationContext context = new AssistContext ( unit , offset , length ) ; AbstractGroovyCompletionProposal proposal = proposalClass . getConstructor ( IInvocationContext . class ) . newInstance ( context ) ; assertTrue ( "<STR_LIT>" + proposal . getDisplayString ( ) + "<STR_LIT:'>" , proposal . hasProposals ( ) ) ; IDocument document = new Document ( String . valueOf ( ( ( CompilationUnit ) unit ) . getContents ( ) ) ) ; proposal . apply ( document ) ; assertEquals ( "<STR_LIT>" , expected , document . get ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class GroovyQuickFixPlugin extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static GroovyQuickFixPlugin plugin ; public GroovyQuickFixPlugin ( ) { } 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 GroovyQuickFixPlugin getDefault ( ) { return plugin ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test . resolvers ; import java . util . List ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddMissingGroovyImportsResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ConvertToGroovyFileResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . IQuickFixResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemType ; import org . eclipse . core . resources . IMarker ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; public class GroovyProjectJavaQuickFixTest extends GroovyProjectQuickFixHarness { public void testNoGroovyAddImportQuickFix ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createJavaTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( typeToImport , unit ) ; assertNull ( "<STR_LIT>" + typeToImport + "<STR_LIT>" + unit . getResource ( ) . getName ( ) + "<STR_LIT>" , resolver ) ; } public void testConverToGroovyQuickFixMissingSemiColon ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createJavaTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; ConvertToGroovyFileResolver resolver = getConvertToGroovyQuickFixResolver ( unit ) ; assertNotNull ( "<STR_LIT>" , resolver ) ; String expectedDisplayString = "<STR_LIT>" ; List < IJavaCompletionProposal > proposals = resolver . getQuickFixProposals ( ) ; assertTrue ( "<STR_LIT>" , proposals != null && proposals . size ( ) > <NUM_LIT:0> ) ; IJavaCompletionProposal firstProposal = proposals . get ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , expectedDisplayString , firstProposal . getDisplayString ( ) ) ; } public void testConverToGroovyQuickFixMissingSemiColonVariant ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createJavaTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; ConvertToGroovyFileResolver resolver = getConvertToGroovyQuickFixResolver ( unit ) ; assertNotNull ( "<STR_LIT>" , resolver ) ; String expectedDisplayString = "<STR_LIT>" ; List < IJavaCompletionProposal > proposals = resolver . getQuickFixProposals ( ) ; assertTrue ( "<STR_LIT>" , proposals != null && proposals . size ( ) > <NUM_LIT:0> ) ; IJavaCompletionProposal firstProposal = proposals . get ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , expectedDisplayString , firstProposal . getDisplayString ( ) ) ; } protected ConvertToGroovyFileResolver getConvertToGroovyQuickFixResolver ( ICompilationUnit unit ) throws Exception { IMarker [ ] markers = getCompilationUnitJDTFailureMarkers ( unit ) ; List < IQuickFixResolver > resolvers = getAllQuickFixResolversForType ( markers , ProblemType . MISSING_SEMI_COLON_TYPE , unit ) ; assertNotNull ( resolvers ) ; assertTrue ( resolvers . size ( ) > <NUM_LIT:0> ) ; for ( IQuickFixResolver resolver : resolvers ) { if ( resolver instanceof ConvertToGroovyFileResolver ) { return ( ConvertToGroovyFileResolver ) resolver ; } } return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test . resolvers ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . eclipse . quickfix . processors . GroovyQuickFixProcessor ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddMissingGroovyImportsResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddMissingGroovyImportsResolver . AddMissingImportProposal ; import org . codehaus . groovy . eclipse . quickfix . proposals . GroovyQuickFixResolverRegistry ; import org . codehaus . groovy . eclipse . quickfix . proposals . IQuickFixResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemDescriptor ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemType ; import org . codehaus . groovy . eclipse . quickfix . proposals . QuickFixProblemContext ; import org . codehaus . groovy . eclipse . quickfix . test . GroovyProjectTestCase ; import org . eclipse . core . resources . IMarker ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . internal . ui . text . correction . AssistContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; public class GroovyProjectQuickFixHarness extends GroovyProjectTestCase { protected void testSelectImportGroovyTypeFromNewPackage ( String typeToImportSimple , String typeToImportFullyQualified , String expectedQuickFixDisplay , String typeToAddImport , String typeToAddImportContent ) throws Exception { ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( typeToImportSimple , unit ) ; assertNotNull ( "<STR_LIT>" + typeToImportSimple , resolver ) ; AddMissingImportProposal proposal = getAddMissingImportsProposal ( expectedQuickFixDisplay , resolver ) ; assertNotNull ( "<STR_LIT>" + typeToImportSimple , proposal ) ; assertEquals ( "<STR_LIT>" + expectedQuickFixDisplay , expectedQuickFixDisplay , proposal . getDisplayString ( ) ) ; IType proposedJavaType = proposal . getSuggestedJavaType ( ) ; assertEquals ( "<STR_LIT>" + typeToImportFullyQualified , getDotForm ( proposedJavaType . getFullyQualifiedName ( ) ) , typeToImportFullyQualified ) ; } protected void testMultipleProposalsSameTypeName ( String typeToImportSimple , Map < String , String > expectedQuickFixes , String typeToAddImport , String typeToAddImportContent ) throws Exception { assertTrue ( "<STR_LIT>" , expectedQuickFixes != null && expectedQuickFixes . size ( ) > <NUM_LIT:0> ) ; ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( typeToImportSimple , unit ) ; assertNotNull ( "<STR_LIT>" + typeToImportSimple , resolver ) ; List < IJavaCompletionProposal > proposals = resolver . getQuickFixProposals ( ) ; Map < String , IJavaCompletionProposal > proposalsMap = new HashMap < String , IJavaCompletionProposal > ( ) ; for ( IJavaCompletionProposal proposal : proposals ) { proposalsMap . put ( proposal . getDisplayString ( ) , proposal ) ; } assertEquals ( "<STR_LIT>" , proposalsMap . size ( ) , expectedQuickFixes . size ( ) ) ; for ( Entry < String , String > entry : expectedQuickFixes . entrySet ( ) ) { String expectedDisplay = entry . getKey ( ) ; String expectedFullyQualifiedName = entry . getValue ( ) ; IJavaCompletionProposal actualProposal = proposalsMap . get ( expectedDisplay ) ; assertNotNull ( "<STR_LIT>" + expectedFullyQualifiedName , actualProposal ) ; assertEquals ( "<STR_LIT>" + expectedDisplay , expectedDisplay , actualProposal . getDisplayString ( ) ) ; String actualFullyQualifiedType = ( ( AddMissingImportProposal ) actualProposal ) . getSuggestedJavaType ( ) . getFullyQualifiedName ( ) ; assertEquals ( "<STR_LIT>" + expectedFullyQualifiedName , expectedFullyQualifiedName , getDotForm ( actualFullyQualifiedType ) ) ; } } protected String getDotForm ( String fullyQualifiedName ) { return fullyQualifiedName . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; } protected List < IQuickFixResolver > getAllQuickFixResolversForType ( IMarker [ ] markers , ProblemType type , ICompilationUnit unit ) throws Exception { if ( markers == null ) { return null ; } List < IQuickFixResolver > totalResolvers = new ArrayList < IQuickFixResolver > ( ) ; for ( IMarker marker : markers ) { QuickFixProblemContext context = getSimpleProblemContext ( marker , unit , type ) ; if ( context != null ) { List < IQuickFixResolver > resolvers = new GroovyQuickFixResolverRegistry ( context ) . getQuickFixResolvers ( ) ; assertTrue ( "<STR_LIT>" + context . getProblemDescriptor ( ) . getMarkerMessages ( ) [ <NUM_LIT:0> ] , resolvers != null && resolvers . size ( ) > <NUM_LIT:0> ) ; totalResolvers . addAll ( resolvers ) ; } } return ! totalResolvers . isEmpty ( ) ? totalResolvers : null ; } protected IJavaCompletionProposal getCompletionProposal ( String quickFixDisplay , IQuickFixResolver resolver ) { List < IJavaCompletionProposal > proposals = resolver . getQuickFixProposals ( ) ; if ( proposals == null ) { return null ; } for ( IJavaCompletionProposal proposal : proposals ) { if ( proposal . getDisplayString ( ) . equals ( quickFixDisplay ) ) { return proposal ; } } return null ; } protected AddMissingImportProposal getAddMissingImportsProposal ( String quickFixDisplay , IQuickFixResolver resolver ) { IJavaCompletionProposal proposal = getCompletionProposal ( quickFixDisplay , resolver ) ; if ( proposal instanceof AddMissingImportProposal ) { return ( AddMissingImportProposal ) proposal ; } return null ; } protected QuickFixProblemContext getSimpleProblemContext ( IMarker marker , ICompilationUnit unit , ProblemType problemType ) throws Exception { if ( ! marker . getResource ( ) . equals ( unit . getResource ( ) ) ) { return null ; } if ( ( ( Integer ) marker . getAttribute ( IMarker . SEVERITY ) ) . intValue ( ) == IMarker . SEVERITY_ERROR ) { String [ ] markerMessages = getMarkerMessages ( marker ) ; int problemID = ( ( Integer ) marker . getAttribute ( "<STR_LIT:id>" ) ) . intValue ( ) ; ProblemDescriptor descriptor = new GroovyQuickFixProcessor ( ) . getProblemDescriptor ( problemID , marker . getType ( ) , markerMessages ) ; if ( descriptor != null && descriptor . getType ( ) == problemType ) { int offset = ( ( Integer ) marker . getAttribute ( IMarker . CHAR_START ) ) ; int length = ( ( Integer ) marker . getAttribute ( IMarker . CHAR_END ) ) ; return new QuickFixProblemContext ( descriptor , new AssistContext ( unit , offset , length ) , null ) ; } } return null ; } protected AddMissingGroovyImportsResolver getAddMissingImportsResolver ( String unresolvedSimpleName , ICompilationUnit unit ) throws Exception { IMarker [ ] markers = getCompilationUnitJDTFailureMarkers ( unit ) ; List < IQuickFixResolver > resolvers = getAllQuickFixResolversForType ( markers , ProblemType . MISSING_IMPORTS_TYPE , unit ) ; if ( resolvers == null ) { return null ; } for ( IQuickFixResolver resolver : resolvers ) { if ( resolver instanceof AddMissingGroovyImportsResolver ) { AddMissingGroovyImportsResolver importResolver = ( AddMissingGroovyImportsResolver ) resolver ; List < IJavaCompletionProposal > proposals = importResolver . getQuickFixProposals ( ) ; if ( proposals != null ) { for ( IJavaCompletionProposal proposal : proposals ) { if ( proposal instanceof AddMissingImportProposal ) { AddMissingImportProposal importProposal = ( AddMissingImportProposal ) proposal ; if ( importProposal . getSuggestedJavaType ( ) . getElementName ( ) . equals ( unresolvedSimpleName ) ) { return importResolver ; } } } } } } return null ; } protected ProblemType [ ] getGroovyProblemTypes ( ) { return ProblemType . values ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test . resolvers ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddGroovyRuntimeResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddMissingGroovyImportsResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . IQuickFixResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemType ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IPackageFragment ; public class GroovyProjectGroovyQuickFixTest extends GroovyProjectQuickFixHarness { private static final String SUBTEST = "<STR_LIT>" ; private static final String SUBSUBTEST = "<STR_LIT>" ; private ICompilationUnit topLevelUnit ; protected void setUp ( ) throws Exception { super . setUp ( ) ; init ( ) ; } protected void init ( ) throws Exception { IPackageFragment subtestPackFrag = testProject . createPackage ( SUBTEST ) ; assertNotNull ( subtestPackFrag ) ; String topLeveLContent = "<STR_LIT>" ; createGroovyType ( subtestPackFrag , "<STR_LIT>" , topLeveLContent ) ; subtestPackFrag = testProject . createPackage ( SUBSUBTEST ) ; assertNotNull ( subtestPackFrag ) ; topLevelUnit = createGroovyType ( subtestPackFrag , "<STR_LIT>" , topLeveLContent ) ; } public void testAddImportField ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testBasicAddImportInnerType ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String innerFullyQualified = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , innerFullyQualified , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testBasicAddImportInnerType2 ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String typeToImportFullyQualified = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , typeToImportFullyQualified , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testBasicAddImportInnerInnerType ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String typeToImportFullyQualified = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , typeToImportFullyQualified , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportReturnType ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportMethodParameter ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportGeneric ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportSubclassing ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportLocalVariable ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportMultipleLocations ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportMultipleUnresolved ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String expectedQuickFixDisplay = "<STR_LIT>" ; String fullQualifiedTypeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; testSelectImportGroovyTypeFromNewPackage ( typeToImport , fullQualifiedTypeToImport , expectedQuickFixDisplay , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportMultipleProposalsForSameType ( ) throws Exception { String typeToImport = "<STR_LIT>" ; String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; Map < String , String > expectedQuickFixes = new HashMap < String , String > ( ) ; expectedQuickFixes . put ( "<STR_LIT>" , "<STR_LIT>" ) ; expectedQuickFixes . put ( "<STR_LIT>" , "<STR_LIT>" ) ; testMultipleProposalsSameTypeName ( typeToImport , expectedQuickFixes , typeToAddImport , typeToAddImportContent ) ; } public void testAddImportNoProposals ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String nonExistantType = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( nonExistantType , unit ) ; assertNull ( "<STR_LIT>" + nonExistantType , resolver ) ; } public void testAddGroovyRuntime ( ) throws Exception { GroovyRuntime . removeGroovyClasspathContainer ( testProject . getJavaProject ( ) ) ; testProject . getProject ( ) . build ( IncrementalProjectBuilder . FULL_BUILD , null ) ; assertNotNull ( "<STR_LIT>" , testProject . getProblems ( ) ) ; IMarker [ ] markers = getCompilationUnitJDTFailureMarkers ( topLevelUnit ) ; List < IQuickFixResolver > resolvers = getAllQuickFixResolversForType ( markers , ProblemType . MISSING_CLASSPATH_CONTAINER_TYPE , topLevelUnit ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , resolvers . size ( ) ) ; assertEquals ( "<STR_LIT>" , AddGroovyRuntimeResolver . class , resolvers . get ( <NUM_LIT:0> ) . getClass ( ) ) ; resolvers . get ( <NUM_LIT:0> ) . getQuickFixProposals ( ) . get ( <NUM_LIT:0> ) . apply ( null ) ; testProject . getProject ( ) . build ( IncrementalProjectBuilder . FULL_BUILD , null ) ; assertNull ( "<STR_LIT>" , testProject . getProblems ( ) ) ; } public void testUnrecognisedErrorNoProposals ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; IMarker [ ] markers = getCompilationUnitJDTFailureMarkers ( unit ) ; ProblemType [ ] knownProblemTypes = getGroovyProblemTypes ( ) ; assertTrue ( "<STR_LIT>" , knownProblemTypes != null && knownProblemTypes . length > <NUM_LIT:0> ) ; for ( ProblemType type : getGroovyProblemTypes ( ) ) { List < IQuickFixResolver > resolvers = getAllQuickFixResolversForType ( markers , type , unit ) ; assertTrue ( "<STR_LIT>" , resolvers == null || resolvers . isEmpty ( ) ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test . resolvers ; import java . util . List ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . quickfix . proposals . AddMissingGroovyImportsResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . IQuickFixResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemType ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IMarker ; import org . eclipse . jdt . core . ICompilationUnit ; public class NonGroovyProjectQuickFixTest extends GroovyProjectQuickFixHarness { protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . removeGroovyNature ( testProject . getProject ( ) ) ; } public void testIsNonGroovyProject ( ) throws Exception { assertFalse ( "<STR_LIT>" , GroovyNature . hasGroovyNature ( testProject . getProject ( ) ) ) ; } public void testNoGroovyAddImportQuickFix ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createJavaTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( typeToImport , unit ) ; assertNull ( "<STR_LIT>" + typeToImport + "<STR_LIT>" + unit . getResource ( ) . getName ( ) + "<STR_LIT>" , resolver ) ; } public void testNoGroovyQuickFixNonGroovyProject1 ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; IMarker [ ] markers = getCompilationUnitJDTFailureMarkers ( unit ) ; ProblemType [ ] knownProblemTypes = getGroovyProblemTypes ( ) ; assertTrue ( "<STR_LIT>" , knownProblemTypes != null && knownProblemTypes . length > <NUM_LIT:0> ) ; for ( ProblemType type : getGroovyProblemTypes ( ) ) { List < IQuickFixResolver > resolvers = getAllQuickFixResolversForType ( markers , type , unit ) ; assertTrue ( "<STR_LIT>" , resolvers == null || resolvers . isEmpty ( ) ) ; } } public void testNoGroovyQuickFixNonGroovyProject2 ( ) throws Exception { String typeToAddImport = "<STR_LIT>" ; String unresolvedType = "<STR_LIT>" ; String typeToAddImportContent = "<STR_LIT>" ; ICompilationUnit unit = createGroovyTypeInTestPackage ( typeToAddImport + "<STR_LIT>" , typeToAddImportContent ) ; AddMissingGroovyImportsResolver resolver = getAddMissingImportsResolver ( unresolvedType , unit ) ; assertNull ( "<STR_LIT>" , resolver ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaModelMarker ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . JavaCore ; public class GroovyProjectTestCase extends EclipseTestCase { public static final String PACKAGE = "<STR_LIT>" ; private IPackageFragment packageFrag ; protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; packageFrag = testProject . createPackage ( PACKAGE ) ; } protected ICompilationUnit createGroovyTypeInTestPackage ( String fileName , String contents ) throws Exception { return createGroovyType ( packageFrag , fileName , contents ) ; } protected ICompilationUnit createGroovyType ( IPackageFragment pack , String fileName , String contents ) throws Exception { IFile file = testProject . createGroovyType ( pack , fileName , contents ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; fullProjectBuild ( ) ; waitForIndexes ( ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; return unit ; } protected ICompilationUnit createJavaTypeInTestPackage ( String fileName , String contents ) throws Exception { ICompilationUnit unit = testProject . createJavaType ( packageFrag , fileName , contents ) . getCompilationUnit ( ) ; fullProjectBuild ( ) ; waitForIndexes ( ) ; IFile file = ( IFile ) unit . getResource ( ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; return unit ; } protected IProject getTestProject ( ) { return testProject . getProject ( ) ; } protected IPackageFragment getTestPackage ( ) { return packageFrag ; } protected IMarker [ ] getProjectJDTFailureMarkers ( ) throws CoreException { return getTestProject ( ) . findMarkers ( IJavaModelMarker . JAVA_MODEL_PROBLEM_MARKER , false , IResource . DEPTH_INFINITE ) ; } protected String [ ] getMarkerMessages ( IMarker marker ) throws Exception { String message = ( String ) marker . getAttribute ( IMarker . MESSAGE ) ; return new String [ ] { message } ; } protected IMarker [ ] getCompilationUnitJDTFailureMarkers ( ICompilationUnit unit ) throws Exception { return unit . getResource ( ) . findMarkers ( IJavaModelMarker . JAVA_MODEL_PROBLEM_MARKER , false , IResource . DEPTH_INFINITE ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . test ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . quickfix . test . resolvers . GroovyProjectGroovyQuickFixTest ; import org . codehaus . groovy . eclipse . quickfix . test . resolvers . GroovyProjectJavaQuickFixTest ; import org . codehaus . groovy . eclipse . quickfix . test . resolvers . NonGroovyProjectQuickFixTest ; public class AllQuickFixTests { public static Test suite ( ) throws Exception { final TestSuite suite = new TestSuite ( AllQuickFixTests . class . getName ( ) ) ; suite . addTestSuite ( GroovyProjectGroovyQuickFixTest . class ) ; suite . addTestSuite ( GroovyProjectJavaQuickFixTest . class ) ; suite . addTestSuite ( NonGroovyProjectQuickFixTest . class ) ; suite . addTestSuite ( QuickAssistTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . DEPRECATED ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . FIELD ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . REGEX ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . METHOD ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . STATIC_METHOD ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . STATIC_FIELD ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . UNKNOWN ; import static org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition . HighlightKind . NUMBER ; import java . util . Arrays ; import java . util . Comparator ; import org . codehaus . groovy . eclipse . editor . highlighting . GatherSemanticReferences ; import org . codehaus . groovy . eclipse . editor . highlighting . HighlightedTypedPosition ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . ui . PartInitException ; public class SemanticHighlightingTests extends EclipseTestCase { @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; testProject . addNature ( GroovyNature . GROOVY_NATURE ) ; testProject . createJavaTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testStaticFieldRanges ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , STATIC_FIELD ) , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) , METHOD ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , STATIC_FIELD ) ) ; } public void testStaticMethodRanges ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , STATIC_METHOD ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , STATIC_METHOD ) ) ; } public void testRegex ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , REGEX ) ) ; } public void testUnknown ( ) throws Exception { String contents = "<STR_LIT:unknown>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT:unknown>" ) , "<STR_LIT:unknown>" . length ( ) , UNKNOWN ) ) ; } public void testDeprecated ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , DEPRECATED ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , DEPRECATED ) , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , DEPRECATED ) ) ; } public void testDeprecated2 ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , DEPRECATED ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT>" ) , "<STR_LIT>" . length ( ) , DEPRECATED ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) , FIELD ) ) ; } public void testDeprecated3 ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) , DEPRECATED ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT:y>" ) , "<STR_LIT:y>" . length ( ) , METHOD ) , new HighlightedTypedPosition ( contents . lastIndexOf ( "<STR_LIT:x>" ) , "<STR_LIT:x>" . length ( ) , DEPRECATED ) ) ; } public void testNumberWithSuffix ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; } public void testOctal ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; } public void testHex ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; } public void testExponent ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; } public void testDecimal ( ) throws Exception { String contents = "<STR_LIT>" ; assertHighlighting ( contents , new HighlightedTypedPosition ( <NUM_LIT:0> , contents . length ( ) , NUMBER ) ) ; } public void testMultipleStaticMethods ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; int first = contents . indexOf ( "<STR_LIT:f>" ) ; int second = contents . indexOf ( "<STR_LIT:f>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT:f>" , second + <NUM_LIT:1> ) ; assertHighlighting ( contents , new HighlightedTypedPosition ( first , "<STR_LIT:f>" . length ( ) , STATIC_METHOD ) , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT:1>" ) , "<STR_LIT:1>" . length ( ) , NUMBER ) , new HighlightedTypedPosition ( contents . indexOf ( "<STR_LIT:2>" ) , "<STR_LIT:2>" . length ( ) , NUMBER ) , new HighlightedTypedPosition ( second , "<STR_LIT:f>" . length ( ) , STATIC_METHOD ) , new HighlightedTypedPosition ( third , "<STR_LIT:f>" . length ( ) , STATIC_METHOD ) ) ; } private void assertHighlighting ( String contents , HighlightedTypedPosition ... expectedPositions ) throws Exception { GroovyCompilationUnit unit = openFile ( contents ) ; checkStyles ( unit , expectedPositions ) ; } private GroovyCompilationUnit openFile ( String contents ) throws CoreException , PartInitException { IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; return ( GroovyCompilationUnit ) JavaCore . create ( file ) ; } private void checkStyles ( GroovyCompilationUnit unit , HighlightedTypedPosition [ ] expectedPositions ) { GatherSemanticReferences references = new GatherSemanticReferences ( unit ) ; HighlightedTypedPosition [ ] actualPositions = ( HighlightedTypedPosition [ ] ) references . findSemanticHighlightingReferences ( ) . toArray ( new HighlightedTypedPosition [ <NUM_LIT:0> ] ) ; Arrays . sort ( actualPositions , new Comparator < HighlightedTypedPosition > ( ) { public int compare ( HighlightedTypedPosition h1 , HighlightedTypedPosition h2 ) { if ( h1 . offset == h2 . offset ) { return h1 . kind . ordinal ( ) - h2 . kind . ordinal ( ) ; } return h1 . offset - h2 . offset ; } } ) ; assertEquals ( "<STR_LIT>" + Arrays . toString ( expectedPositions ) + "<STR_LIT>" + Arrays . toString ( actualPositions ) , expectedPositions . length , actualPositions . length ) ; for ( int i = <NUM_LIT:0> ; i < actualPositions . length ; i ++ ) { assertEquals ( "<STR_LIT>" + Arrays . toString ( expectedPositions ) + "<STR_LIT>" + Arrays . toString ( actualPositions ) , expectedPositions [ i ] , actualPositions [ i ] ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . editor . outline . GroovyOutlinePage ; import org . codehaus . groovy . eclipse . editor . outline . IOJavaElement ; import org . codehaus . groovy . eclipse . editor . outline . IOutlineExtender ; import org . codehaus . groovy . eclipse . editor . outline . OCompilationUnit ; import org . codehaus . groovy . eclipse . editor . outline . OField ; import org . codehaus . groovy . eclipse . editor . outline . OMethod ; import org . codehaus . groovy . eclipse . editor . outline . OType ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectNature ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IMember ; public class OutlineExtender1 implements IOutlineExtender , IProjectNature { public static final String NATURE = "<STR_LIT>" ; public void configure ( ) throws CoreException { } public void deconfigure ( ) throws CoreException { } IProject p ; public IProject getProject ( ) { return p ; } public void setProject ( IProject project ) { this . p = project ; } public GroovyOutlinePage getGroovyOutlinePageForEditor ( String contextMenuID , GroovyEditor editor ) { TCompilationUnit ounit = new TCompilationUnit ( this , editor . getGroovyCompilationUnit ( ) ) ; return new TGroovyOutlinePage ( null , editor , ounit ) ; } public boolean appliesTo ( GroovyCompilationUnit unit ) { return new String ( unit . getFileName ( ) ) . contains ( "<STR_LIT:X>" ) ; } public static class TGroovyOutlinePage extends GroovyOutlinePage { public TGroovyOutlinePage ( String contextMenuID , GroovyEditor editor , OCompilationUnit unit ) { super ( contextMenuID , editor , unit ) ; } public JavaOutlineViewer getViewer ( ) { return getOutlineViewer ( ) ; } } public static class TCompilationUnit extends OCompilationUnit { public OutlineExtender1 outlineExtender ; public TType type ; public TCompilationUnit ( OutlineExtender1 outlineExtender , GroovyCompilationUnit unit ) { super ( unit ) ; this . outlineExtender = outlineExtender ; } @ Override public IMember [ ] refreshChildren ( ) { type = new TType ( this , getElementName ( ) ) ; return new IMember [ ] { type } ; } @ Override public IMember getOutlineElementAt ( int caretOffset ) { return type ; } } public static class TType extends OType { public TType ( IOJavaElement parent , String name ) { super ( parent , new ConstantExpression ( name ) , name ) ; this . name = name ; } @ Override public ASTNode getElementNameNode ( ) { return getNode ( ) ; } public TType addTestType ( String name ) { TType t = new TType ( this , name ) ; addChild ( t ) ; return t ; } public TMethod addTestMethod ( String name , String returnType ) { TMethod m = new TMethod ( this , name , returnType ) ; addChild ( m ) ; return m ; } public TField addTestField ( String name , String typeSignature ) { TField f = new TField ( this , name , typeSignature ) ; addChild ( f ) ; return f ; } } public static class TMethod extends OMethod { private String returnType ; public TMethod ( OType parent , String name , String returnType ) { super ( parent , new ConstantExpression ( name ) , name ) ; this . name = name ; this . returnType = returnType ; } @ Override public ASTNode getElementNameNode ( ) { return getNode ( ) ; } @ Override public String getReturnTypeName ( ) { return returnType ; } } public static class TField extends OField { private String typeSignature ; public TField ( OType parent , String name , String typeSignature ) { super ( parent , new ConstantExpression ( name ) , name ) ; this . name = name ; this . typeSignature = typeSignature ; } @ Override public ASTNode getElementNameNode ( ) { return getNode ( ) ; } @ Override public String getTypeSignature ( ) { return typeSignature ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . editor . GroovyPartitionScanner ; import org . eclipse . jdt . ui . text . IJavaPartitions ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . rules . IToken ; public class GroovyPartitionScannerTests extends TestCase { GroovyPartitionScanner scanner ; @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; scanner = new GroovyPartitionScanner ( ) ; } public void testSingleQuotes ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testSingleQuotes2 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testSingleQuotes3 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDoubleQuotes ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDoubleQuotes2 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDoubleQuotes3 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDollarSlash1 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDollarSlash2 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testDollarSlash3 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , GroovyPartitionScanner . GROOVY_MULTILINE_STRINGS ) ; } public void testNone ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , IJavaPartitions . JAVA_STRING ) ; } public void testNone2 ( ) throws Exception { tryString ( "<STR_LIT>" , <NUM_LIT:0> , IJavaPartitions . JAVA_STRING ) ; } public void testComment ( ) throws Exception { tryString ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , <NUM_LIT:0> , IJavaPartitions . JAVA_MULTI_LINE_COMMENT ) ; } public void testJavaDoc ( ) throws Exception { tryString ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , <NUM_LIT:0> , IJavaPartitions . JAVA_DOC ) ; } private void tryString ( String string , int start , String expectedContentType ) { IDocument doc = new Document ( string ) ; scanner . setRange ( doc , start , string . length ( ) ) ; IToken token = scanner . nextToken ( ) ; assertEquals ( "<STR_LIT>" + string + "<STR_LIT:'>" , expectedContentType , token . getData ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . editor . GroovyTagScanner ; import org . codehaus . groovy . eclipse . editor . GroovyTextTools ; import org . codehaus . groovy . eclipse . preferences . PreferenceInitializer ; import org . eclipse . jdt . ui . text . IColorManager ; public class GroovyTagScannerTests extends TestCase { GroovyTagScanner scanner ; @ SuppressWarnings ( "<STR_LIT:deprecation>" ) @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; System . out . println ( "<STR_LIT>" ) ; super . setUp ( ) ; new PreferenceInitializer ( ) . initializeDefaultPreferences ( ) ; GroovyTextTools textTools = GroovyPlugin . getDefault ( ) . getTextTools ( ) ; IColorManager colorManager = textTools . getColorManager ( ) ; scanner = new GroovyTagScanner ( colorManager ) ; } public void testNoColor ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testGJDKColor ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testJavaTypeColor ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testJavaKeywordColor ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void testStringColor ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . Arrays ; import java . util . List ; import org . codehaus . groovy . eclipse . editor . highlighting . IHighlightingExtender ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectNature ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jface . text . rules . IRule ; import org . eclipse . jface . text . rules . IWordDetector ; import org . eclipse . jface . text . rules . WordRule ; public class Extender2 implements IHighlightingExtender , IProjectNature { public static final String NATURE2 = "<STR_LIT>" ; public static final IRule RULE = new WordRule ( new IWordDetector ( ) { public boolean isWordStart ( char c ) { return false ; } public boolean isWordPart ( char c ) { return false ; } } ) ; public List < String > getAdditionalGJDKKeywords ( ) { return null ; } public List < String > getAdditionalGroovyKeywords ( ) { return null ; } public List < IRule > getAdditionalRules ( ) { return Arrays . asList ( RULE ) ; } public void configure ( ) throws CoreException { } public void deconfigure ( ) throws CoreException { } IProject p ; public IProject getProject ( ) { return p ; } public void setProject ( IProject project ) { this . p = project ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . internal . ui . javaeditor . EditorUtility ; import org . eclipse . jface . text . IDocument ; import org . eclipse . swt . SWT ; import org . eclipse . swt . custom . StyledText ; import org . eclipse . swt . dnd . Clipboard ; import org . eclipse . swt . dnd . TextTransfer ; import org . eclipse . swt . dnd . Transfer ; import org . eclipse . swt . widgets . Event ; public abstract class GroovyEditorTest extends EclipseTestCase { protected static final String CARET = "<STR_LIT>" ; protected GroovyEditor editor ; @ Override protected void tearDown ( ) throws Exception { GroovyPlugin . getActiveWorkbenchWindow ( ) . getActivePage ( ) . closeAllEditors ( false ) ; editor = null ; super . tearDown ( ) ; } protected void makeEditor ( String contents ) throws CoreException { int cursor = <NUM_LIT:0> ; if ( contents . contains ( CARET ) ) { cursor = contents . indexOf ( CARET ) ; contents = contents . replace ( CARET , "<STR_LIT>" ) ; } IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , contents ) ; editor = ( GroovyEditor ) EditorUtility . openInEditor ( file ) ; editor . setHighlightRange ( cursor , <NUM_LIT:0> , true ) ; editor . setFocus ( ) ; } protected void send ( String text ) { for ( char c : text . toCharArray ( ) ) { send ( c ) ; } } protected void send ( char c ) { Event e = new Event ( ) ; e . character = c ; e . doit = true ; e . widget = editor . getViewer ( ) . getTextWidget ( ) ; e . widget . notifyListeners ( SWT . KeyDown , e ) ; } protected void sendBackTab ( ) { Event e = new Event ( ) ; e . character = '<STR_LIT:\t>' ; e . stateMask = SWT . SHIFT ; e . doit = true ; e . widget = editor . getViewer ( ) . getTextWidget ( ) ; e . widget . notifyListeners ( SWT . KeyDown , e ) ; } protected void sendPaste ( String pasted ) { StyledText widget = editor . getViewer ( ) . getTextWidget ( ) ; Clipboard clipboard = new Clipboard ( editor . getViewer ( ) . getTextWidget ( ) . getDisplay ( ) ) ; TextTransfer plainTextTransfer = TextTransfer . getInstance ( ) ; clipboard . setContents ( new Object [ ] { pasted } , new Transfer [ ] { plainTextTransfer } ) ; widget . paste ( ) ; clipboard . dispose ( ) ; } protected String getText ( ) { return getDocument ( ) . get ( ) ; } protected IDocument getDocument ( ) { return editor . getViewer ( ) . getDocument ( ) ; } protected void assertEditorContents ( String expected ) { String actual = getText ( ) ; if ( expected . contains ( CARET ) ) { int cursor = getCaret ( ) ; actual = actual . substring ( <NUM_LIT:0> , cursor ) + CARET + actual . substring ( cursor ) ; } assertEquals ( expected , actual ) ; } private int getCaret ( ) { return editor . getCaretOffset ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . List ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . editor . highlighting . HighlightingExtenderRegistry ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . jface . text . rules . IRule ; public class HighlightingExtenderTests extends EclipseTestCase { private HighlightingExtenderRegistry registry ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; registry = GroovyPlugin . getDefault ( ) . getTextTools ( ) . getHighlightingExtenderRegistry ( ) ; registry . initialize ( ) ; } public void testHighlightingExtender1 ( ) throws Exception { testProject . addNature ( Extender1 . NATURE1 ) ; testProject . addNature ( Extender2 . NATURE2 ) ; List < IRule > extraRules = registry . getAdditionalRulesForProject ( testProject . getProject ( ) ) ; assertEquals ( Extender2 . RULE , extraRules . get ( <NUM_LIT:0> ) ) ; } public void testHighlightingExtender2 ( ) throws Exception { testProject . addNature ( Extender1 . NATURE1 ) ; testProject . addNature ( Extender2 . NATURE2 ) ; List < String > extraKeywords = registry . getExtraGJDKKeywordsForProject ( testProject . getProject ( ) ) ; assertEquals ( Extender1 . GJDK_KEYWORD , extraKeywords . get ( <NUM_LIT:0> ) ) ; } public void testHighlightingExtender3 ( ) throws Exception { testProject . addNature ( Extender1 . NATURE1 ) ; testProject . addNature ( Extender2 . NATURE2 ) ; List < String > extraKeywords = registry . getExtraGroovyKeywordsForProject ( testProject . getProject ( ) ) ; assertEquals ( Extender1 . GROOVY_KEYWORD , extraKeywords . get ( <NUM_LIT:0> ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . internal . ui . javaeditor . EditorUtility ; import org . eclipse . swt . events . VerifyEvent ; import org . eclipse . swt . widgets . Event ; public class BracketInserterTests extends EclipseTestCase { public void testInsertDQuote1 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:0> ) ; } public void testInsertDQuote2 ( ) throws Exception { assertClosing ( "<STR_LIT:\">" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:1> ) ; } public void testInsertDQuote3 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:2> ) ; } public void testInsertDQuote4 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:3> ) ; } public void testInsertDQuote5 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:7> ) ; } public void testInsertDQuote6 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:8> ) ; } public void testInsertDQuote7 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:\">' , <NUM_LIT:1> ) ; } public void testInsertSQuote1 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:0> ) ; } public void testInsertSQuote2 ( ) throws Exception { assertClosing ( "<STR_LIT:'>" , "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:1> ) ; } public void testInsertSQuote3 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:2> ) ; } public void testInsertSQuote4 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:3> ) ; } public void testInsertParen ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<CHAR_LIT:(>' , <NUM_LIT:0> ) ; } public void testInsertSquare ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT:[]>" , '<CHAR_LIT:[>' , <NUM_LIT:0> ) ; } public void testInsertAngle ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<CHAR_LIT>' , <NUM_LIT:0> ) ; } public void testInsertBraces1 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<CHAR_LIT>' , <NUM_LIT:2> ) ; } public void testInsertBraces2 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<CHAR_LIT>' , <NUM_LIT:4> ) ; } public void testInsertBraces3 ( ) throws Exception { assertClosing ( "<STR_LIT:$>" , "<STR_LIT>" , '<CHAR_LIT>' , <NUM_LIT:1> ) ; } public void testInsertBraces4 ( ) throws Exception { assertClosing ( "<STR_LIT>" , "<STR_LIT>" , '<CHAR_LIT>' , <NUM_LIT:5> ) ; } private void assertClosing ( String initialDoc , String expectedDoc , char inserted , int location ) throws Exception { initialDoc += "<STR_LIT:n>" ; expectedDoc += "<STR_LIT>" ; IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , initialDoc + "<STR_LIT:U+0020>" ) ; GroovyEditor editor = ( GroovyEditor ) EditorUtility . openInEditor ( file ) ; try { Event e = new Event ( ) ; e . character = inserted ; e . doit = true ; e . widget = editor . getViewer ( ) . getTextWidget ( ) ; VerifyEvent ve = new VerifyEvent ( e ) ; editor . getViewer ( ) . setSelectedRange ( location , <NUM_LIT:0> ) ; editor . getGroovyBracketInserter ( ) . verifyKey ( ve ) ; if ( ve . doit ) { editor . getViewer ( ) . getDocument ( ) . replace ( location , <NUM_LIT:0> , Character . toString ( inserted ) ) ; } String actual = editor . getViewer ( ) . getDocument ( ) . get ( ) ; assertEquals ( "<STR_LIT>" + inserted + "<STR_LIT>" + location , expectedDoc , actual ) ; } finally { GroovyPlugin . getActiveWorkbenchWindow ( ) . getActivePage ( ) . closeAllEditors ( false ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . Stack ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . editor . outline . GroovyOutlinePage ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . IMember ; public class OutlineExtender2 extends OutlineExtender1 { public static final String NATURE = "<STR_LIT>" ; public boolean appliesTo ( GroovyCompilationUnit unit ) { return new String ( unit . getFileName ( ) ) . contains ( "<STR_LIT:Y>" ) ; } public GroovyOutlinePage getGroovyOutlinePageForEditor ( String contextMenuID , GroovyEditor editor ) { TCompilationUnit2 ounit = new TCompilationUnit2 ( this , editor . getGroovyCompilationUnit ( ) ) ; return new TGroovyOutlinePage ( null , editor , ounit ) ; } public static class TCompilationUnit2 extends TCompilationUnit { public TCompilationUnit2 ( OutlineExtender2 outlineExtender , GroovyCompilationUnit unit ) { super ( outlineExtender , unit ) ; } @ Override public IMember [ ] refreshChildren ( ) { type = new TType ( this , getElementName ( ) . substring ( <NUM_LIT:0> , getElementName ( ) . indexOf ( '<CHAR_LIT:.>' ) ) ) ; ModuleNode moduleNode = ( ModuleNode ) getNode ( ) ; if ( moduleNode != null ) { new Finder ( moduleNode , type ) . execute ( ) ; } return new IMember [ ] { type } ; } @ Override public void refresh ( ) { super . refresh ( ) ; } } public static class Finder extends ASTNodeFinder { private ModuleNode moduleNode ; private Stack < TType > methodStack = new Stack < TType > ( ) ; public Finder ( ModuleNode moduleNode , TType rootType ) { super ( new Region ( moduleNode ) ) ; this . moduleNode = moduleNode ; methodStack . push ( rootType ) ; } public void execute ( ) { doVisit ( moduleNode ) ; } @ Override public void visitMethodCallExpression ( MethodCallExpression methodCall ) { if ( methodCall . getLineNumber ( ) < <NUM_LIT:0> ) { super . visitMethodCallExpression ( methodCall ) ; return ; } TType parentType = methodStack . peek ( ) ; TType t = parentType . addTestType ( methodCall . getMethodAsString ( ) ) ; methodStack . push ( t ) ; super . visitMethodCallExpression ( methodCall ) ; methodStack . pop ( ) ; } @ Override public void visitMethod ( MethodNode method ) { if ( method . getLineNumber ( ) <= <NUM_LIT:1> ) { super . visitMethod ( method ) ; return ; } TType parentType = methodStack . peek ( ) ; parentType . addTestMethod ( method . getName ( ) , method . getReturnType ( ) . getNameWithoutPackage ( ) ) ; super . visitMethod ( method ) ; } @ Override public void visitVariableExpression ( VariableExpression variable ) { if ( variable . getLineNumber ( ) < <NUM_LIT:0> ) { super . visitVariableExpression ( variable ) ; return ; } TType parentType = methodStack . peek ( ) ; parentType . addTestField ( variable . getName ( ) , variable . getType ( ) . getNameWithoutPackage ( ) ) ; super . visitVariableExpression ( variable ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . editor . outline . GroovyOutlinePage ; import org . codehaus . groovy . eclipse . editor . outline . GroovyScriptOutlineExtender ; import org . codehaus . groovy . eclipse . editor . outline . OCompilationUnit ; import org . codehaus . groovy . eclipse . editor . outline . OField ; import org . codehaus . groovy . eclipse . editor . outline . OMethod ; import org . codehaus . groovy . eclipse . editor . outline . OType ; import org . codehaus . groovy . eclipse . editor . outline . OutlineExtenderRegistry ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . groovy . eclipse . test . ui . OutlineExtender1 . TCompilationUnit ; import org . codehaus . groovy . eclipse . test . ui . OutlineExtender1 . TGroovyOutlinePage ; import org . codehaus . groovy . eclipse . test . ui . OutlineExtender1 . TType ; import org . codehaus . groovy . eclipse . test . ui . OutlineExtender2 . TCompilationUnit2 ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . ui . javaeditor . EditorUtility ; import org . eclipse . jdt . internal . ui . javaeditor . JavaSourceViewer ; import org . eclipse . ui . PartInitException ; import org . eclipse . ui . internal . Workbench ; public class OutlineExtenderTests extends EclipseTestCase { private OutlineExtenderRegistry registry ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyNature ( testProject . getProject ( ) ) ; registry = GroovyPlugin . getDefault ( ) . getOutlineTools ( ) . getOutlineExtenderRegistry ( ) ; registry . initialize ( ) ; } @ Override protected void tearDown ( ) throws Exception { Workbench . getInstance ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) . closeAllEditors ( false ) ; super . tearDown ( ) ; } public void testStandardOutlineIfNoExtender ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT:X>" , contents ) ; assertNull ( outline ) ; } public void testStandardOutlineIfUnitNotApplyToExtender ( ) throws Exception { testProject . addNature ( OutlineExtender1 . NATURE ) ; String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT:Z>" , contents ) ; assertNull ( outline ) ; } public void testOutlineActivated ( ) throws Exception { testProject . addNature ( OutlineExtender1 . NATURE ) ; String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT:X>" , contents ) ; assertNotNull ( outline ) ; } public void testFirstDeclaredWins1 ( ) throws Exception { testProject . addNature ( OutlineExtender1 . NATURE ) ; testProject . addNature ( OutlineExtender2 . NATURE ) ; String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; TCompilationUnit tu = ( TCompilationUnit ) outline . getOutlineCompilationUnit ( ) ; assertTrue ( tu . outlineExtender . getClass ( ) == OutlineExtender1 . class ) ; } public void testFirstDeclaredWins2 ( ) throws Exception { testProject . addNature ( OutlineExtender2 . NATURE ) ; testProject . addNature ( OutlineExtender1 . NATURE ) ; String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; TCompilationUnit tu = ( TCompilationUnit ) outline . getOutlineCompilationUnit ( ) ; assertTrue ( tu . outlineExtender . getClass ( ) == OutlineExtender2 . class ) ; } public void testOutlineTreeConsistency1 ( ) throws Exception { testProject . addNature ( OutlineExtender2 . NATURE ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; TGroovyOutlinePage outline = ( TGroovyOutlinePage ) openFile ( "<STR_LIT>" , contents ) ; TCompilationUnit2 tu = ( TCompilationUnit2 ) outline . getOutlineCompilationUnit ( ) ; TType tx = ( TType ) tu . getChildren ( ) [ <NUM_LIT:0> ] ; assertEquals ( <NUM_LIT:4> , tx . getChildren ( ) . length ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:1> ] , "<STR_LIT>" , "<STR_LIT:String>" ) ; assertIsMethod ( tx . getChildren ( ) [ <NUM_LIT:2> ] , "<STR_LIT>" , "<STR_LIT>" ) ; assertIsMethod ( tx . getChildren ( ) [ <NUM_LIT:3> ] , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testOutlineTreeConsistency2 ( ) throws Exception { testProject . addNature ( OutlineExtender2 . NATURE ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; TCompilationUnit2 tu = ( TCompilationUnit2 ) outline . getOutlineCompilationUnit ( ) ; TType yTest = ( TType ) tu . getChildren ( ) [ <NUM_LIT:0> ] ; TType inline1 = ( TType ) yTest . getChildren ( ) [ <NUM_LIT:0> ] ; assertEquals ( <NUM_LIT:1> , inline1 . getChildren ( ) . length ) ; assertIsType ( inline1 . getChildren ( ) [ <NUM_LIT:0> ] , "<STR_LIT>" ) ; TType inline2 = ( TType ) inline1 . getChildren ( ) [ <NUM_LIT:0> ] ; assertEquals ( <NUM_LIT:1> , inline2 . getChildren ( ) . length ) ; assertIsField ( inline2 . getChildren ( ) [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) ; } public void testOutlineTreeSynchronized ( ) throws Exception { testProject . addNature ( OutlineExtender2 . NATURE ) ; String contents = "<STR_LIT>" + "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; TCompilationUnit2 tu = ( TCompilationUnit2 ) outline . getOutlineCompilationUnit ( ) ; TType tx = ( TType ) tu . getChildren ( ) [ <NUM_LIT:0> ] ; assertEquals ( <NUM_LIT:2> , tx . getChildren ( ) . length ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:1> ] , "<STR_LIT>" , "<STR_LIT:String>" ) ; GroovyEditor editor = getGroovyEditor ( tu ) ; JavaSourceViewer viewer = ( JavaSourceViewer ) editor . getViewer ( ) ; viewer . getTextWidget ( ) . setSelection ( <NUM_LIT:0> ) ; viewer . getTextWidget ( ) . insert ( "<STR_LIT>" ) ; fullProjectBuild ( ) ; waitForIndexes ( ) ; tu . refresh ( ) ; tx = ( TType ) tu . getChildren ( ) [ <NUM_LIT:0> ] ; assertEquals ( <NUM_LIT:3> , tx . getChildren ( ) . length ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:1> ] , "<STR_LIT>" , "<STR_LIT>" ) ; assertIsField ( tx . getChildren ( ) [ <NUM_LIT:2> ] , "<STR_LIT>" , "<STR_LIT:String>" ) ; editor . close ( false ) ; } public void testUseGroovyScriptOutline ( ) throws Exception { testProject . addNature ( OutlineExtender1 . NATURE ) ; String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT:Z>" , contents ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , outline . getOutlineCompilationUnit ( ) . getClass ( ) . getName ( ) ) ; } public void testGroovyScriptOutline1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; OCompilationUnit unit = outline . getOutlineCompilationUnit ( ) ; IJavaElement [ ] children = unit . getChildren ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:6> , children . length ) ; assertEquals ( "<STR_LIT>" , children [ <NUM_LIT:0> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , children [ <NUM_LIT:1> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , children [ <NUM_LIT:2> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , children [ <NUM_LIT:3> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT:Y>" , children [ <NUM_LIT:4> ] . getElementName ( ) ) ; assertEquals ( "<STR_LIT>" , children [ <NUM_LIT:5> ] . getElementName ( ) ) ; assertEquals ( IJavaElement . IMPORT_CONTAINER , children [ <NUM_LIT:0> ] . getElementType ( ) ) ; assertEquals ( IJavaElement . FIELD , children [ <NUM_LIT:1> ] . getElementType ( ) ) ; assertEquals ( IJavaElement . FIELD , children [ <NUM_LIT:2> ] . getElementType ( ) ) ; assertEquals ( IJavaElement . FIELD , children [ <NUM_LIT:3> ] . getElementType ( ) ) ; assertEquals ( IJavaElement . TYPE , children [ <NUM_LIT:4> ] . getElementType ( ) ) ; assertEquals ( IJavaElement . METHOD , children [ <NUM_LIT:5> ] . getElementType ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IField ) children [ <NUM_LIT:1> ] ) . getTypeSignature ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IField ) children [ <NUM_LIT:2> ] ) . getTypeSignature ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( IField ) children [ <NUM_LIT:3> ] ) . getTypeSignature ( ) ) ; assertEquals ( contents . indexOf ( "<STR_LIT>" ) , ( ( IField ) children [ <NUM_LIT:1> ] ) . getNameRange ( ) . getOffset ( ) ) ; assertEquals ( contents . indexOf ( "<STR_LIT>" ) , ( ( IField ) children [ <NUM_LIT:2> ] ) . getNameRange ( ) . getOffset ( ) ) ; assertEquals ( contents . indexOf ( "<STR_LIT>" ) , ( ( IField ) children [ <NUM_LIT:3> ] ) . getNameRange ( ) . getOffset ( ) ) ; assertEquals ( <NUM_LIT:3> , ( ( IField ) children [ <NUM_LIT:1> ] ) . getNameRange ( ) . getLength ( ) ) ; assertEquals ( <NUM_LIT:3> , ( ( IField ) children [ <NUM_LIT:2> ] ) . getNameRange ( ) . getLength ( ) ) ; assertEquals ( <NUM_LIT:3> , ( ( IField ) children [ <NUM_LIT:3> ] ) . getNameRange ( ) . getLength ( ) ) ; } public void testStructureUnknown ( ) throws Exception { String contents = "<STR_LIT>" ; GroovyOutlinePage outline = openFile ( "<STR_LIT>" , contents ) ; OCompilationUnit unit = outline . getOutlineCompilationUnit ( ) ; IJavaElement [ ] children = unit . getChildren ( ) ; assertEquals ( <NUM_LIT:1> , children . length ) ; assertEquals ( "<STR_LIT>" + GroovyScriptOutlineExtender . NO_STRUCTURE_FOUND , children [ <NUM_LIT:0> ] . getElementName ( ) ) ; } private GroovyOutlinePage openFile ( String className , String contents ) throws Exception { IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , className + "<STR_LIT>" , contents ) ; GroovyCompilationUnit unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; unit . becomeWorkingCopy ( null ) ; unit . reconcile ( true , null ) ; GroovyEditor editor = getGroovyEditor ( unit ) ; GroovyOutlinePage outline = editor . getOutlinePage ( ) ; if ( ! unit . isWorkingCopy ( ) ) { fail ( "<STR_LIT>" ) ; } if ( unit . getModuleNode ( ) == null ) { fail ( "<STR_LIT>" ) ; } if ( outline != null ) { outline . refresh ( ) ; return outline ; } return null ; } private GroovyEditor getGroovyEditor ( GroovyCompilationUnit unit ) throws PartInitException { return ( GroovyEditor ) EditorUtility . openInEditor ( unit ) ; } private void assertIsField ( IJavaElement element , String name , String typeSignature ) throws JavaModelException { assertTrue ( "<STR_LIT>" + element . getElementName ( ) + "<STR_LIT>" , element instanceof OField ) ; OField field = ( OField ) element ; assertTrue ( "<STR_LIT>" + field . getElementName ( ) + "<STR_LIT>" + name + "<STR_LIT:'>" , name . equals ( field . getElementName ( ) ) ) ; assertTrue ( "<STR_LIT>" + field . getTypeSignature ( ) + "<STR_LIT>" + name + "<STR_LIT:'>" , typeSignature . equals ( field . getTypeSignature ( ) ) ) ; } private void assertIsMethod ( IJavaElement element , String name , String returnType ) throws JavaModelException { assertTrue ( "<STR_LIT>" + element . getElementName ( ) + "<STR_LIT>" , element instanceof OMethod ) ; OMethod method = ( OMethod ) element ; assertTrue ( "<STR_LIT>" + method . getElementName ( ) + "<STR_LIT>" + name + "<STR_LIT:'>" , name . equals ( method . getElementName ( ) ) ) ; if ( returnType != null ) { assertTrue ( "<STR_LIT>" + method . getReturnTypeName ( ) + "<STR_LIT>" + returnType + "<STR_LIT:'>" , returnType . equals ( method . getReturnTypeName ( ) ) ) ; } } private void assertIsType ( IJavaElement element , String name ) throws JavaModelException { assertTrue ( "<STR_LIT>" + element . getElementName ( ) + "<STR_LIT>" , element instanceof OType ) ; OType type = ( OType ) element ; assertTrue ( "<STR_LIT>" + type . getElementName ( ) + "<STR_LIT>" + name + "<STR_LIT:'>" , name . equals ( type . getElementName ( ) ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . Arrays ; import java . util . List ; import org . codehaus . groovy . eclipse . editor . highlighting . IHighlightingExtender ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectNature ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jface . text . rules . IRule ; public class Extender1 implements IHighlightingExtender , IProjectNature { public static final String NATURE1 = "<STR_LIT>" ; public static final String GJDK_KEYWORD = "<STR_LIT>" ; public static final String GROOVY_KEYWORD = "<STR_LIT>" ; public List < String > getAdditionalGJDKKeywords ( ) { return Arrays . asList ( GJDK_KEYWORD ) ; } public List < String > getAdditionalGroovyKeywords ( ) { return Arrays . asList ( GROOVY_KEYWORD ) ; } public List < IRule > getAdditionalRules ( ) { return null ; } public void configure ( ) throws CoreException { } public void deconfigure ( ) throws CoreException { } IProject p ; public IProject getProject ( ) { return p ; } public void setProject ( IProject project ) { this . p = project ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . Hashtable ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; public class GroovyAutoIndenterTests extends GroovyEditorTest { @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , JavaCore . TAB ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , "<STR_LIT:4>" ) ; ProjectScope projectPrefScope = new ProjectScope ( testProject . getProject ( ) ) ; projectPrefScope . getNode ( JavaCore . PLUGIN_ID ) . clear ( ) ; } public void testScaffolding ( ) throws Exception { makeEditor ( "<STR_LIT>" ) ; send ( '<CHAR_LIT:a>' ) ; assertEquals ( "<STR_LIT:a>" , getText ( ) ) ; assertEditorContents ( "<STR_LIT>" ) ; } public void test1 ( ) throws Exception { makeEditor ( "<STR_LIT>" ) ; send ( "<STR_LIT>" ) ; assertEditorContents ( "<STR_LIT>" ) ; } public void test2 ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } public void test3 ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } public void testGRE631 ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; send ( "<STR_LIT>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; } public void testSpaces ( ) throws Exception { setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , JavaCore . SPACE ) ; makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } public void testPasteInMultiLineString ( ) throws Exception { String initial = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; makeEditor ( initial ) ; String pasteString = "<STR_LIT>" ; sendPaste ( pasteString ) ; assertEditorContents ( initial . replace ( CARET , pasteString + CARET ) ) ; } public void testSpacesOptionSetAfterOpen ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , JavaCore . SPACE ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } public void testMixedTabsAndSpaces ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , DefaultCodeFormatterConstants . MIXED ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , "<STR_LIT>" ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_INDENTATION_SIZE , "<STR_LIT:4>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } public void testMixedTabsAndSpaces2 ( ) throws Exception { makeEditor ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , DefaultCodeFormatterConstants . MIXED ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , "<STR_LIT>" ) ; setJavaPreference ( DefaultCodeFormatterConstants . FORMATTER_INDENTATION_SIZE , "<STR_LIT:4>" ) ; send ( "<STR_LIT:n>" ) ; assertEditorContents ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } protected void setJavaPreference ( String name , String value ) { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Hashtable options = JavaCore . getOptions ( ) ; options . put ( name , value ) ; JavaCore . setOptions ( options ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . ui ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . ui . IViewPart ; import org . eclipse . ui . internal . Workbench ; import org . eclipse . ui . internal . views . log . AbstractEntry ; import org . eclipse . ui . internal . views . log . LogEntry ; import org . eclipse . ui . internal . views . log . LogView ; public class ErrorLogTest extends TestCase { @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; } private static final String [ ] KNOWN_MSGS = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private boolean canIgnoreMessage ( String msg ) { for ( String ignore : KNOWN_MSGS ) { if ( msg . contains ( ignore ) ) { return true ; } } return false ; } public void testNoWarningsOnStartup ( ) throws Exception { IViewPart view = Workbench . getInstance ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) . getActivePart ( ) . getSite ( ) . getPage ( ) . showView ( "<STR_LIT>" ) ; if ( view instanceof LogView ) { LogView logView = ( LogView ) view ; AbstractEntry [ ] logs = logView . getElements ( ) ; List < AbstractEntry > errorsAndWarnings = new ArrayList < AbstractEntry > ( ) ; for ( int i = <NUM_LIT:0> ; i < logs . length ; i ++ ) { LogEntry entry = ( LogEntry ) logs [ i ] ; if ( entry . getSeverity ( ) == IStatus . ERROR || entry . getSeverity ( ) == IStatus . WARNING ) { String msg = entry . getMessage ( ) ; if ( ! canIgnoreMessage ( msg ) ) { errorsAndWarnings . add ( logs [ i ] ) ; } } } if ( errorsAndWarnings . size ( ) > <NUM_LIT:0> ) { StringBuffer errors = new StringBuffer ( ) ; boolean ignore = false ; for ( AbstractEntry element : errorsAndWarnings ) { LogEntry log = ( LogEntry ) element ; errors . append ( log . getMessage ( ) ) ; errors . append ( "<STR_LIT:U+0020(>" + log . getPluginId ( ) + "<STR_LIT>" ) ; if ( element . hasChildren ( ) ) { Object [ ] sub = element . getChildren ( null ) ; for ( int i = <NUM_LIT:0> ; i < sub . length ; i ++ ) { if ( sub [ i ] instanceof LogEntry ) { LogEntry s = ( LogEntry ) sub [ i ] ; String msg = s . getMessage ( ) ; errors . append ( "<STR_LIT:U+0020U+0020U+0020U+0020>" + msg ) ; errors . append ( "<STR_LIT:U+0020(>" + s . getPluginId ( ) + "<STR_LIT>" ) ; errors . append ( "<STR_LIT>" + s . getStack ( ) + "<STR_LIT>" ) ; ignore = false ; } } } } if ( ! ignore ) { fail ( "<STR_LIT>" + errors . toString ( ) ) ; } } } else { fail ( "<STR_LIT>" ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . debug ; import org . eclipse . debug . ui . console . IConsole ; import org . eclipse . debug . ui . console . IConsoleLineTrackerExtension ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IRegion ; public class ConsoleLineTracker implements IConsoleLineTrackerExtension { private static IConsoleLineTrackerExtension fDelegate ; private static IConsole fConsole ; public static void setDelegate ( IConsoleLineTrackerExtension tracker ) { fDelegate = tracker ; fConsole = null ; } public void dispose ( ) { if ( fDelegate != null ) { fDelegate . dispose ( ) ; } fConsole = null ; } public synchronized void init ( IConsole console ) { fConsole = console ; if ( fDelegate != null ) { fDelegate . init ( console ) ; } } public static IDocument getDocument ( ) { return fConsole . getDocument ( ) ; } public void lineAppended ( IRegion line ) { if ( fDelegate != null ) { fDelegate . lineAppended ( line ) ; } } public void consoleClosed ( ) { if ( fDelegate != null && fConsole != null ) { fDelegate . consoleClosed ( ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . debug ; import java . io . ByteArrayInputStream ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . eclipse . launchers . GroovyConsoleLineTracker ; import org . codehaus . groovy . eclipse . launchers . GroovyConsoleLineTracker . AmbiguousFileLink ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; import org . eclipse . debug . core . model . IProcess ; import org . eclipse . debug . core . model . IStreamMonitor ; import org . eclipse . debug . core . model . IStreamsProxy ; import org . eclipse . debug . ui . console . FileLink ; import org . eclipse . debug . ui . console . IConsole ; import org . eclipse . debug . ui . console . IConsoleHyperlink ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . Region ; import org . eclipse . ui . console . IHyperlink ; import org . eclipse . ui . console . IOConsoleOutputStream ; import org . eclipse . ui . console . IPatternMatchListener ; @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public class ConsoleLineTrackerTests extends EclipseTestCase { MockConsole console ; GroovyConsoleLineTracker lineTracker ; IDocument doc ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; doc = new Document ( ) ; console = new MockConsole ( doc ) ; lineTracker = new GroovyConsoleLineTracker ( ) ; lineTracker . init ( console ) ; testProject . addNature ( GroovyNature . GROOVY_NATURE ) ; } public void testNoLink ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT:f>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; doc . set ( contents ) ; lineTracker . lineAppended ( new Region ( <NUM_LIT:0> , contents . length ( ) ) ) ; assertNull ( "<STR_LIT>" , console . getLastLink ( ) ) ; } public void testLink ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT:f>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" ; doc . set ( contents ) ; lineTracker . lineAppended ( new Region ( <NUM_LIT:0> , contents . length ( ) ) ) ; assertNotNull ( "<STR_LIT>" , console . getLastLink ( ) ) ; FileLink link = ( FileLink ) console . getLastLink ( ) ; IFile file = ( IFile ) ReflectionUtils . getPrivateField ( FileLink . class , "<STR_LIT>" , link ) ; assertTrue ( "<STR_LIT>" , file . isAccessible ( ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , file . getName ( ) ) ; } public void testAmbiguousLink ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT:f>" , "<STR_LIT>" , "<STR_LIT>" ) ; testProject . createOtherSourceFolder ( ) ; testProject . getProject ( ) . getFolder ( "<STR_LIT>" ) . create ( true , true , null ) ; testProject . getProject ( ) . getFile ( "<STR_LIT>" ) . create ( new ByteArrayInputStream ( new byte [ <NUM_LIT:0> ] ) , true , null ) ; String contents = "<STR_LIT>" ; doc . set ( contents ) ; lineTracker . lineAppended ( new Region ( <NUM_LIT:0> , contents . length ( ) ) ) ; assertNotNull ( "<STR_LIT>" , console . getLastLink ( ) ) ; FileLink link = ( FileLink ) console . getLastLink ( ) ; Object file = ReflectionUtils . getPrivateField ( FileLink . class , "<STR_LIT>" , link ) ; assertNull ( "<STR_LIT>" , file ) ; IFile [ ] files = ( IFile [ ] ) ReflectionUtils . getPrivateField ( AmbiguousFileLink . class , "<STR_LIT>" , link ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , files . length ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , files [ <NUM_LIT:0> ] . getName ( ) ) ; assertEquals ( "<STR_LIT>" , "<STR_LIT>" , files [ <NUM_LIT:1> ] . getName ( ) ) ; } } class MockConsole implements IConsole { private Map < IHyperlink , IRegion > regionLinkMap = new HashMap < IHyperlink , IRegion > ( ) ; private IHyperlink lastLink = null ; private IDocument doc ; public MockConsole ( IDocument doc ) { this . doc = doc ; } public void addLink ( @ SuppressWarnings ( "<STR_LIT:deprecation>" ) IConsoleHyperlink link , int offset , int length ) { } public void connect ( IStreamsProxy streamsProxy ) { } public void connect ( IStreamMonitor streamMonitor , String streamIdentifer ) { } public IDocument getDocument ( ) { return doc ; } public IProcess getProcess ( ) { return null ; } public IRegion getRegion ( @ SuppressWarnings ( "<STR_LIT:deprecation>" ) IConsoleHyperlink link ) { return null ; } public void addLink ( IHyperlink link , int offset , int length ) { regionLinkMap . put ( link , new Region ( offset , length ) ) ; lastLink = link ; } public void addPatternMatchListener ( IPatternMatchListener matchListener ) { } public IRegion getRegion ( IHyperlink link ) { return regionLinkMap . get ( link ) ; } public IHyperlink getLastLink ( ) { return lastLink ; } public IOConsoleOutputStream getStream ( String streamIdentifier ) { return null ; } public void removePatternMatchListener ( IPatternMatchListener matchListener ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . debug ; import java . io . File ; import java . net . URL ; import java . util . Map ; import junit . framework . AssertionFailedError ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . launchers . GroovyScriptLaunchShortcut ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . groovy . eclipse . test . TestProject ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . debug . core . ILaunch ; import org . eclipse . debug . core . ILaunchConfiguration ; import org . eclipse . debug . internal . ui . DebugUIPlugin ; import org . eclipse . debug . internal . ui . IInternalDebugUIConstants ; import org . eclipse . debug . internal . ui . preferences . IDebugPreferenceConstants ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . debug . ui . launchConfigurations . JavaApplicationLaunchShortcut ; import org . eclipse . jface . dialogs . MessageDialogWithToggle ; public class GroovyLauncherShortcutTests extends EclipseTestCase { class MockGroovyScriptLaunchShortcut extends GroovyScriptLaunchShortcut { @ Override protected Map < String , String > createLaunchProperties ( IType runType , IJavaProject javaProject ) { return super . createLaunchProperties ( runType , javaProject ) ; } @ Override protected String generateClasspath ( IJavaProject javaProject ) { return super . generateClasspath ( javaProject ) ; } } class MockJavaApplicationLaunchShortcut extends JavaApplicationLaunchShortcut { @ Override protected ILaunchConfiguration createConfiguration ( IType type ) { return super . createConfiguration ( type ) ; } } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; DebugUIPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( IInternalDebugUIConstants . PREF_WAIT_FOR_BUILD , MessageDialogWithToggle . NEVER ) ; DebugUIPlugin . getDefault ( ) . getPreferenceStore ( ) . setValue ( IDebugPreferenceConstants . CONSOLE_OPEN_ON_OUT , false ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; } public GroovyLauncherShortcutTests ( ) { super ( GroovyLauncherShortcutTests . class . getCanonicalName ( ) ) ; } public void testScriptLaunch1 ( ) throws Exception { ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch2 ( ) throws Exception { createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch3 ( ) throws Exception { createJavaCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch4 ( ) throws Exception { IPackageFragmentRoot newRoot = createSourceFolder ( ) ; IPackageFragment newFrag = createFragment ( newRoot ) ; createGroovyCompilationUnit ( newFrag , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch5 ( ) throws Exception { IPackageFragmentRoot newRoot = createSourceFolder ( ) ; IPackageFragment newFrag = createFragment ( newRoot ) ; createJavaCompilationUnit ( newFrag , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch6 ( ) throws Exception { IPackageFragmentRoot newRoot = createSourceFolder ( ) ; IPackageFragment newFrag = createFragment ( newRoot ) ; createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( newFrag , "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch7 ( ) throws Exception { IPackageFragmentRoot newRoot = createSourceFolder ( "<STR_LIT>" ) ; IPackageFragment newFrag = createFragment ( newRoot ) ; createGroovyCompilationUnit ( newFrag , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch8 ( ) throws Exception { IPackageFragmentRoot newRoot = createSourceFolder ( "<STR_LIT>" ) ; IPackageFragment newFrag = createFragment ( newRoot ) ; createJavaCompilationUnit ( newFrag , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } public void testScriptLaunch9 ( ) throws Exception { TestProject otherProject = new TestProject ( "<STR_LIT>" ) ; try { GroovyRuntime . addGroovyRuntime ( otherProject . getProject ( ) ) ; testProject . addProjectReference ( otherProject . getJavaProject ( ) ) ; otherProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } finally { otherProject . dispose ( ) ; } } public void testScriptLaunch10 ( ) throws Exception { TestProject otherProject = new TestProject ( "<STR_LIT>" ) ; try { testProject . addProjectReference ( otherProject . getJavaProject ( ) ) ; otherProject . createJavaTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; ICompilationUnit unit = createGroovyCompilationUnit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; IType launchType = unit . getType ( "<STR_LIT>" ) ; launchScriptAndAssertExitValue ( launchType ) ; } finally { otherProject . dispose ( ) ; } } public void testClasspathGeneration1 ( ) throws Exception { TestProject p4 = new TestProject ( "<STR_LIT>" ) ; p4 . createSourceFolder ( "<STR_LIT>" , "<STR_LIT>" ) ; TestProject p3 = new TestProject ( "<STR_LIT>" ) ; p3 . addProjectReference ( p4 . getJavaProject ( ) ) ; p3 . createSourceFolder ( "<STR_LIT>" , "<STR_LIT>" ) ; TestProject p2 = new TestProject ( "<STR_LIT>" ) ; p2 . addProjectReference ( p4 . getJavaProject ( ) ) ; p2 . addProjectReference ( p3 . getJavaProject ( ) ) ; TestProject p1 = new TestProject ( "<STR_LIT>" ) ; p1 . addProjectReference ( p4 . getJavaProject ( ) ) ; p1 . addProjectReference ( p3 . getJavaProject ( ) ) ; p1 . addProjectReference ( p2 . getJavaProject ( ) ) ; String classpath = new MockGroovyScriptLaunchShortcut ( ) . generateClasspath ( p1 . getJavaProject ( ) ) ; assertEquals ( "<STR_LIT>" , createClassPathString1 ( ) , classpath ) ; p1 . dispose ( ) ; p2 . dispose ( ) ; p3 . dispose ( ) ; p4 . dispose ( ) ; } public void testClasspathGeneration2 ( ) throws Exception { TestProject p1 = new TestProject ( "<STR_LIT>" ) ; URL groovyURL = CompilerUtils . getExportedGroovyAllJar ( ) ; IPath runtimeJarPath = new Path ( groovyURL . getPath ( ) ) ; p1 . addJarFileToClasspath ( runtimeJarPath ) ; IFile f1 = p1 . createFile ( "<STR_LIT>" , "<STR_LIT>" ) ; p1 . addJarFileToClasspath ( f1 . getFullPath ( ) ) ; TestProject p2 = new TestProject ( "<STR_LIT>" ) ; IFile f2 = p2 . createFile ( "<STR_LIT>" , "<STR_LIT>" ) ; p1 . addJarFileToClasspath ( f2 . getFullPath ( ) ) ; String classpath = new MockGroovyScriptLaunchShortcut ( ) . generateClasspath ( p1 . getJavaProject ( ) ) ; assertEquals ( "<STR_LIT>" , createClassPathString2 ( runtimeJarPath . toPortableString ( ) ) , classpath ) ; p1 . dispose ( ) ; p2 . dispose ( ) ; } private String createClassPathString1 ( ) { String classpath = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; if ( File . separatorChar == '<CHAR_LIT:/>' ) { classpath = classpath . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } return classpath ; } private String createClassPathString2 ( String groovyRuntimePath ) { String classpath = "<STR_LIT>" + "<STR_LIT>" + groovyRuntimePath + "<STR_LIT::>" + "<STR_LIT>" ; if ( File . separatorChar == '<CHAR_LIT:/>' ) { classpath = classpath . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } return classpath ; } private IPackageFragment createFragment ( IPackageFragmentRoot newRoot ) throws Exception { return newRoot . createPackageFragment ( "<STR_LIT>" , true , null ) ; } private IPackageFragmentRoot createSourceFolder ( ) throws Exception { return testProject . createOtherSourceFolder ( ) ; } private IPackageFragmentRoot createSourceFolder ( String outFolder ) throws Exception { return testProject . createOtherSourceFolder ( outFolder ) ; } private ICompilationUnit createGroovyCompilationUnit ( IPackageFragment frag , String unitName , String contents ) throws CoreException { IFile file = testProject . createGroovyType ( frag , unitName , contents ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; return unit ; } private ICompilationUnit createGroovyCompilationUnit ( String unitName , String contents ) throws CoreException { return createGroovyCompilationUnit ( "<STR_LIT>" , unitName , contents ) ; } private ICompilationUnit createGroovyCompilationUnit ( String packageName , String unitName , String contents ) throws CoreException { IFile file = testProject . createGroovyTypeAndPackage ( packageName , unitName , contents ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; return unit ; } private IType createJavaCompilationUnit ( String unitName , String contents ) throws CoreException { return testProject . createJavaTypeAndPackage ( "<STR_LIT>" , unitName , contents ) ; } private IType createJavaCompilationUnit ( IPackageFragment frag , String unitName , String contents ) throws CoreException { return testProject . createJavaType ( frag , unitName , contents ) ; } protected void launchScriptAndAssertExitValue ( IType launchType ) throws InterruptedException , CoreException { launchScriptAndAssertExitValue ( launchType , <NUM_LIT:20> ) ; } protected void launchScriptAndAssertExitValue ( final IType launchType , final int timeoutSeconds ) throws InterruptedException , CoreException { String problems = testProject . getProblems ( ) ; if ( problems != null ) { fail ( "<STR_LIT>" + problems ) ; } Runnable runner = new Runnable ( ) { public void run ( ) { try { MockGroovyScriptLaunchShortcut shortcut = new MockGroovyScriptLaunchShortcut ( ) ; ILaunchConfiguration config = shortcut . findOrCreateLaunchConfig ( shortcut . createLaunchProperties ( launchType , launchType . getJavaProject ( ) ) , launchType . getFullyQualifiedName ( ) ) ; assertTrue ( launchType . exists ( ) ) ; ILaunch launch = config . launch ( "<STR_LIT>" , new NullProgressMonitor ( ) ) ; synchronized ( launch ) { int i = <NUM_LIT:0> ; System . out . println ( "<STR_LIT>" + i + "<STR_LIT>" ) ; while ( ! launch . isTerminated ( ) && i < timeoutSeconds ) { i ++ ; System . out . println ( "<STR_LIT>" + i + "<STR_LIT>" ) ; launch . wait ( <NUM_LIT:1000> ) ; } } if ( launch . isTerminated ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( launch . getProcesses ( ) [ <NUM_LIT:0> ] . getStreamsProxy ( ) . getOutputStreamMonitor ( ) . getContents ( ) ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( launch . getProcesses ( ) [ <NUM_LIT:0> ] . getStreamsProxy ( ) . getErrorStreamMonitor ( ) . getContents ( ) ) ; System . out . println ( "<STR_LIT>" ) ; } assertTrue ( "<STR_LIT>" , launch . isTerminated ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , launch . getProcesses ( ) [ <NUM_LIT:0> ] . getExitValue ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } } ; AssertionFailedError currentException = null ; for ( int attempt = <NUM_LIT:0> ; attempt < <NUM_LIT:4> ; attempt ++ ) { try { runner . run ( ) ; return ; } catch ( AssertionFailedError e ) { currentException = e ; System . out . println ( "<STR_LIT>" + attempt + "<STR_LIT>" ) ; } } if ( currentException != null ) { throw currentException ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . debug ; import java . io . InputStream ; import java . net . URL ; import junit . framework . AssertionFailedError ; import org . apache . commons . io . IOUtils ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . debug . ui . ToggleBreakpointAdapter ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . groovy . eclipse . test . Activator ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . groovy . eclipse . test . SynchronizationUtils ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . debug . core . DebugPlugin ; import org . eclipse . debug . core . IBreakpointManager ; import org . eclipse . debug . core . model . IBreakpoint ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . internal . debug . ui . actions . ActionDelegateHelper ; import org . eclipse . jdt . internal . ui . javaeditor . EditorUtility ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . ITextSelection ; import org . eclipse . jface . text . TextSelection ; public class DebugBreakpointsTests extends EclipseTestCase { private static final String BREAKPOINT_SCRIPT_NAME = "<STR_LIT>" ; private ToggleBreakpointAdapter adapter ; private ICompilationUnit unit ; private GroovyEditor editor ; private String text ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; InputStream input = null ; final URL url = Activator . bundle ( ) . getEntry ( "<STR_LIT>" + BREAKPOINT_SCRIPT_NAME ) ; try { input = url . openStream ( ) ; IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , BREAKPOINT_SCRIPT_NAME , input ) ; unit = JavaCore . createCompilationUnitFrom ( file ) ; } finally { IOUtils . closeQuietly ( input ) ; } try { input = url . openStream ( ) ; text = IOUtils . toString ( input ) ; } finally { IOUtils . closeQuietly ( input ) ; } adapter = new ToggleBreakpointAdapter ( ) ; editor = ( GroovyEditor ) EditorUtility . openInEditor ( unit ) ; ReflectionUtils . setPrivateField ( ActionDelegateHelper . class , "<STR_LIT>" , ActionDelegateHelper . getDefault ( ) , editor ) ; unit . becomeWorkingCopy ( null ) ; unit . makeConsistent ( null ) ; SynchronizationUtils . joinBackgroudActivities ( ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; unit . discardWorkingCopy ( ) ; editor . close ( false ) ; SynchronizationUtils . joinBackgroudActivities ( ) ; } public void testBreakpointInScript1 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:1> ) ; } public void testBreakpointInScript2 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:2> ) ; } public void testBreakpointInScript3 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:3> ) ; } public void testBreakpointInScript4 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:4> ) ; } public void testBreakpointInScript5 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:5> ) ; } public void testBreakpointInScript6 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:6> ) ; } public void testBreakpointInScript7 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:7> ) ; } public void testBreakpointInScript8 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:8> ) ; } public void testBreakpointInScript9 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:9> ) ; } public void testBreakpointInScript10 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:10> ) ; } public void testBreakpointInScript11 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:11> ) ; } public void testBreakpointInScript12 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:12> ) ; } public void testBreakpointInScript13 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript14 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript15 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:15> ) ; } public void testBreakpointInScript16 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:16> ) ; } public void testBreakpointInScript17 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript18 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript19 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript20 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:20> ) ; } public void testBreakpointInScript21 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript22 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript23 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } private void doBreakpointTest ( int i ) throws Exception { int count = <NUM_LIT:0> ; int maxCount = <NUM_LIT:5> ; while ( count <= maxCount ) { count ++ ; try { innerDoBreakpointTest ( i ) ; } catch ( AssertionFailedError err ) { if ( count >= maxCount ) { throw err ; } } } } private void innerDoBreakpointTest ( int i ) throws CoreException { ITextSelection selection = new TextSelection ( new Document ( text ) , text . indexOf ( "<STR_LIT>" + i ) - <NUM_LIT:3> , <NUM_LIT:3> ) ; boolean canToggle = adapter . canToggleLineBreakpoints ( editor , selection ) ; assertTrue ( "<STR_LIT>" + i , canToggle ) ; int initialNumBreakpoints ; IBreakpointManager breakpointManager = DebugPlugin . getDefault ( ) . getBreakpointManager ( ) ; IBreakpoint [ ] breakpoints = breakpointManager . getBreakpoints ( ) ; initialNumBreakpoints = breakpoints . length ; try { adapter . toggleLineBreakpoints ( editor , selection ) ; SynchronizationUtils . joinBackgroudActivities ( ) ; } finally { IBreakpoint [ ] newBreakpoints = breakpointManager . getBreakpoints ( ) ; assertEquals ( "<STR_LIT>" , initialNumBreakpoints + <NUM_LIT:1> , newBreakpoints . length ) ; for ( IBreakpoint breakpoint : newBreakpoints ) { breakpointManager . removeBreakpoint ( breakpoint , true ) ; } assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , breakpointManager . getBreakpoints ( ) . length ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . debug ; import java . io . InputStream ; import java . net . URL ; import org . apache . commons . io . IOUtils ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . debug . ui . ValidBreakpointLocationFinder ; import org . codehaus . groovy . eclipse . test . Activator ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jface . text . Document ; import org . eclipse . jface . text . IDocument ; public class BreakpointLocationTests extends EclipseTestCase { private static final String BREAKPOINT_SCRIPT_NAME = "<STR_LIT>" ; private GroovyCompilationUnit unit ; private IDocument document ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; InputStream input = null ; final URL url = Activator . bundle ( ) . getEntry ( "<STR_LIT>" + BREAKPOINT_SCRIPT_NAME ) ; try { input = url . openStream ( ) ; IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , BREAKPOINT_SCRIPT_NAME , input ) ; unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; } finally { IOUtils . closeQuietly ( input ) ; } String text ; try { input = url . openStream ( ) ; text = IOUtils . toString ( input ) ; } finally { IOUtils . closeQuietly ( input ) ; } document = new Document ( text ) ; unit . becomeWorkingCopy ( null ) ; unit . makeConsistent ( null ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; unit . discardWorkingCopy ( ) ; } public void testBreakpointInScript1 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:1> ) ; } public void testBreakpointInScript2 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:2> ) ; } public void testBreakpointInScript3 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:3> ) ; } public void testBreakpointInScript4 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:4> ) ; } public void testBreakpointInScript5 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:5> ) ; } public void testBreakpointInScript6 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:6> ) ; } public void testBreakpointInScript7 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:7> ) ; } public void testBreakpointInScript8 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:8> ) ; } public void testBreakpointInScript9 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:9> ) ; } public void testBreakpointInScript10 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:10> ) ; } public void testBreakpointInScript11 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:11> ) ; } public void testBreakpointInScript12 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:12> ) ; } public void testBreakpointInScript13 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript14 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript15 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:15> ) ; } public void testBreakpointInScript16 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:16> ) ; } public void testBreakpointInScript17 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript18 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript19 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript20 ( ) throws Exception { doBreakpointTest ( <NUM_LIT:20> ) ; } public void testBreakpointInScript21 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript22 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } public void testBreakpointInScript23 ( ) throws Exception { doBreakpointTest ( <NUM_LIT> ) ; } private void doBreakpointTest ( int i ) throws Exception { int location = document . get ( ) . indexOf ( "<STR_LIT>" + i ) - <NUM_LIT:3> ; int line = document . getLineOfOffset ( location ) + <NUM_LIT:1> ; ValidBreakpointLocationFinder finder = new ValidBreakpointLocationFinder ( line ) ; ASTNode node = finder . findValidBreakpointLocation ( unit . getModuleNode ( ) ) ; assertNotNull ( "<STR_LIT>" + line , node ) ; assertEquals ( "<STR_LIT>" , line , node . getLineNumber ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . core . util ; import org . codehaus . groovy . eclipse . core . ISourceBuffer ; import org . codehaus . groovy . eclipse . core . impl . StringSourceBuffer ; import org . codehaus . groovy . eclipse . core . util . ExpressionFinder ; import junit . framework . * ; public class ExpressionFinderTestCase extends TestCase { @ Override protected void setUp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; super . setUp ( ) ; } public void test_identifierExpression ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_parenExpression ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_arrayElementExpressionInParen ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_arrayElementExpression ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_parenInParenExpression ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_parenInParenExpression2 ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_stringExpression ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_stringExpressionAfterOtherExpressionAndNewLine ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_stringExpressionAfterOtherExpressionAndSemi ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionInGString ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionInParenAfterNewLine ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionAfterNewLine ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_noExpression1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; } public void test_noExpression2 ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_noExpression3 ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionAfterNumber ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionAfterStringLiteral ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( null , expression ) ; } public void test_expressionInParenAfterSemi ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } public void test_expressionForNewGenericType ( ) throws Exception { ExpressionFinder finder = new ExpressionFinder ( ) ; String source = "<STR_LIT>" ; String completionLocation = "<STR_LIT>" ; ISourceBuffer sourceBuffer = new StringSourceBuffer ( source ) ; String expression = finder . findForCompletions ( sourceBuffer , completionLocation . length ( ) - <NUM_LIT:1> ) ; Assert . assertEquals ( "<STR_LIT>" , expression ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . actions ; import org . codehaus . groovy . eclipse . editor . actions . RenameToGroovyAction ; import org . codehaus . groovy . eclipse . editor . actions . RenameToGroovyOrJavaAction ; import org . codehaus . groovy . eclipse . editor . actions . RenameToJavaAction ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . jdt . core . IType ; import org . eclipse . jface . viewers . StructuredSelection ; import org . eclipse . ui . IActionDelegate ; public class ConvertToJavaOrGroovyActionTest extends EclipseTestCase { @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; testProject . addNature ( GroovyNature . GROOVY_NATURE ) ; } public void testRenameToGroovy ( ) throws Exception { IType type = testProject . createJavaTypeAndPackage ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) ; IResource file = type . getCompilationUnit ( ) . getResource ( ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; StructuredSelection ss = new StructuredSelection ( file ) ; IActionDelegate action = new RenameToGroovyAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; } public void testRenameToJava ( ) throws Exception { IResource file = testProject . createGroovyTypeAndPackage ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; StructuredSelection ss = new StructuredSelection ( file ) ; IActionDelegate action = new RenameToJavaAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; } public void testRenameToGroovyAndBack ( ) throws Exception { IType type = testProject . createJavaTypeAndPackage ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) ; IResource file = type . getCompilationUnit ( ) . getResource ( ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; StructuredSelection ss = new StructuredSelection ( file ) ; IActionDelegate action = new RenameToGroovyAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; ss = new StructuredSelection ( file ) ; action = new RenameToJavaAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; } public void testRenameToJavaAndBack ( ) throws Exception { IResource file = testProject . createGroovyTypeAndPackage ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; StructuredSelection ss = new StructuredSelection ( file ) ; IActionDelegate action = new RenameToJavaAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; ss = new StructuredSelection ( file ) ; action = new RenameToGroovyAction ( ) ; action . selectionChanged ( null , ss ) ; action . run ( null ) ; waitForJobAndRefresh ( file ) ; assertFalse ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; file = file . getParent ( ) . getFile ( new Path ( "<STR_LIT>" ) ) ; assertTrue ( file . getName ( ) + "<STR_LIT>" , file . exists ( ) ) ; } private void waitForJobAndRefresh ( IResource file ) throws InterruptedException , CoreException { Job . getJobManager ( ) . join ( RenameToGroovyOrJavaAction . class , null ) ; file . getParent ( ) . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . actions ; import org . codehaus . groovy . eclipse . refactoring . actions . DelegatingCleanUpPostSaveListener ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . jdt . internal . corext . fix . CleanUpPostSaveListener ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . javaeditor . saveparticipant . IPostSaveListener ; import org . eclipse . jdt . internal . ui . javaeditor . saveparticipant . SaveParticipantRegistry ; public class SaveParticipantRegistryTest extends EclipseTestCase { public void testInstallUninstallPostSaveCleanUp ( ) throws Exception { SaveParticipantRegistry registry = JavaPlugin . getDefault ( ) . getSaveParticipantRegistry ( ) ; IPostSaveListener listener = registry . getSaveParticipantDescriptor ( CleanUpPostSaveListener . POSTSAVELISTENER_ID ) . getPostSaveListener ( ) ; assertTrue ( "<STR_LIT>" + listener . getClass ( ) . getCanonicalName ( ) + "<STR_LIT>" , listener instanceof DelegatingCleanUpPostSaveListener ) ; try { DelegatingCleanUpPostSaveListener . installCleanUp ( ) ; } catch ( ClassCastException e ) { fail ( "<STR_LIT>" ) ; } DelegatingCleanUpPostSaveListener . uninstallCleanUp ( ) ; listener = registry . getSaveParticipantDescriptor ( CleanUpPostSaveListener . POSTSAVELISTENER_ID ) . getPostSaveListener ( ) ; assertTrue ( "<STR_LIT>" + listener . getClass ( ) . getCanonicalName ( ) + "<STR_LIT>" , listener instanceof CleanUpPostSaveListener ) ; DelegatingCleanUpPostSaveListener . installCleanUp ( ) ; listener = registry . getSaveParticipantDescriptor ( CleanUpPostSaveListener . POSTSAVELISTENER_ID ) . getPostSaveListener ( ) ; assertTrue ( "<STR_LIT>" + listener . getClass ( ) . getCanonicalName ( ) + "<STR_LIT>" , listener instanceof DelegatingCleanUpPostSaveListener ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . actions ; import org . codehaus . groovy . eclipse . actions . AddGroovyNatureAction ; import org . codehaus . groovy . eclipse . actions . RemoveGroovyNatureAction ; import org . codehaus . groovy . eclipse . core . builder . ConvertLegacyProject ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . ICommand ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jface . viewers . IStructuredSelection ; import org . eclipse . jface . viewers . StructuredSelection ; public class GroovyNatureActionTestCase extends EclipseTestCase { private AddGroovyNatureAction addGroovyAction ; private RemoveGroovyNatureAction removeGroovyAction ; private ConvertLegacyProject convert ; @ Override public void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; GroovyRuntime . removeGroovyNature ( testProject . getProject ( ) ) ; addGroovyAction = new AddGroovyNatureAction ( ) ; removeGroovyAction = new RemoveGroovyNatureAction ( ) ; removeGroovyAction . doNotAskToRemoveJars ( ) ; convert = new ConvertLegacyProject ( ) ; } public void testAddGroovyNature ( ) throws Exception { assertTrue ( "<STR_LIT>" , testProject . getJavaProject ( ) . getProject ( ) . hasNature ( JavaCore . NATURE_ID ) ) ; IStructuredSelection selection = new StructuredSelection ( new Object [ ] { testProject . getJavaProject ( ) } ) ; addGroovyAction . selectionChanged ( null , selection ) ; assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; addGroovyAction . run ( null ) ; assertTrue ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertTrue ( "<STR_LIT>" , hasGroovyJars ( ) ) ; addGroovyAction . run ( null ) ; assertTrue ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertTrue ( "<STR_LIT>" , hasGroovyJars ( ) ) ; } public void testGroovyNatureNotJavaProject ( ) throws CoreException { testProject . removeNature ( JavaCore . NATURE_ID ) ; assertFalse ( testProject . getJavaProject ( ) . getProject ( ) . hasNature ( JavaCore . NATURE_ID ) ) ; IStructuredSelection selection = new StructuredSelection ( new Object [ ] { testProject . getProject ( ) } ) ; addGroovyAction . selectionChanged ( null , selection ) ; assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; try { addGroovyAction . run ( null ) ; } catch ( Exception ex ) { } assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; } public void testRemoveGroovyNature ( ) throws Exception { assertTrue ( "<STR_LIT>" , testProject . getJavaProject ( ) . getProject ( ) . hasNature ( JavaCore . NATURE_ID ) ) ; IStructuredSelection selection = new StructuredSelection ( new Object [ ] { testProject . getJavaProject ( ) } ) ; addGroovyAction . selectionChanged ( null , selection ) ; removeGroovyAction . selectionChanged ( null , selection ) ; assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertTrue ( "<STR_LIT>" , hasGroovyJars ( ) ) ; removeGroovyAction . run ( null ) ; assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertFalse ( "<STR_LIT>" , hasGroovyJars ( ) ) ; addGroovyAction . run ( null ) ; assertTrue ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertTrue ( "<STR_LIT>" , hasGroovyJars ( ) ) ; removeGroovyAction . run ( null ) ; assertFalse ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertFalse ( "<STR_LIT>" , hasGroovyJars ( ) ) ; } public void testConvertLegacyAction ( ) throws Exception { testProject . addBuilder ( ConvertLegacyProject . OLD_BUILDER ) ; convert . convertProject ( testProject . getProject ( ) ) ; assertTrue ( "<STR_LIT>" , hasGroovyNature ( ) ) ; assertFalse ( "<STR_LIT>" , hasOldGroovyNature ( ) ) ; assertTrue ( "<STR_LIT>" , hasBuilder ( JavaCore . BUILDER_ID ) ) ; assertFalse ( "<STR_LIT>" , hasBuilder ( ConvertLegacyProject . OLD_BUILDER ) ) ; } protected boolean hasOldGroovyNature ( ) throws CoreException { return testProject . getProject ( ) . hasNature ( ConvertLegacyProject . OLD_NATURE ) ; } protected boolean hasBuilder ( String builderId ) throws CoreException { IProjectDescription desc = testProject . getProject ( ) . getDescription ( ) ; ICommand [ ] commands = desc . getBuildSpec ( ) ; for ( ICommand command : commands ) { if ( command . getBuilderName ( ) . equals ( builderId ) ) { return true ; } } return false ; } private boolean hasGroovyJars ( ) throws CoreException { return GroovyRuntime . hasGroovyClasspathContainer ( testProject . getJavaProject ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . core . runtime . jobs . IJobManager ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . jdt . core . IJavaElement ; 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 . core . JavaModelManager ; import org . eclipse . swt . SWTException ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IWorkbenchWindow ; import org . eclipse . ui . PlatformUI ; public class SynchronizationUtils { public static void joinBackgroudActivities ( ) { boolean interrupted = true ; while ( interrupted ) { try { Job . getJobManager ( ) . join ( ResourcesPlugin . FAMILY_AUTO_BUILD , null ) ; interrupted = false ; } catch ( InterruptedException e ) { interrupted = true ; } } boolean wasInterrupted = false ; do { try { Job . getJobManager ( ) . join ( ResourcesPlugin . FAMILY_MANUAL_BUILD , null ) ; wasInterrupted = false ; } catch ( OperationCanceledException e ) { } catch ( InterruptedException e ) { wasInterrupted = true ; } } while ( wasInterrupted ) ; joinJobs ( <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> ) ; } private static boolean joinJobs ( long minTime , long maxTime , long intervalTime ) { long startTime = System . currentTimeMillis ( ) + minTime ; runEventQueue ( ) ; while ( System . currentTimeMillis ( ) < startTime ) runEventQueue ( intervalTime ) ; long endTime = maxTime > <NUM_LIT:0> && maxTime < Long . MAX_VALUE ? System . currentTimeMillis ( ) + maxTime : Long . MAX_VALUE ; boolean calm = allJobsQuiet ( ) ; while ( ! calm && System . currentTimeMillis ( ) < endTime ) { runEventQueue ( intervalTime ) ; calm = allJobsQuiet ( ) ; } return calm ; } private static void sleep ( int intervalTime ) { try { Thread . sleep ( intervalTime ) ; } catch ( InterruptedException e ) { } } private static boolean allJobsQuiet ( ) { IJobManager jobManager = Job . getJobManager ( ) ; Job [ ] jobs = jobManager . find ( null ) ; for ( int i = <NUM_LIT:0> ; i < jobs . length ; i ++ ) { Job job = jobs [ i ] ; int state = job . getState ( ) ; if ( ! job . getName ( ) . equals ( "<STR_LIT>" ) && ! job . getName ( ) . equals ( "<STR_LIT>" ) && ( state == Job . RUNNING || state == Job . WAITING ) ) { return false ; } } return true ; } private static void runEventQueue ( ) { IWorkbenchWindow window = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) ; if ( window != null ) runEventQueue ( window . getShell ( ) ) ; } private static void runEventQueue ( Shell shell ) { try { while ( shell . getDisplay ( ) . readAndDispatch ( ) ) { } } catch ( SWTException e ) { System . err . println ( e ) ; } } private static void runEventQueue ( long minTime ) { long nextCheck = System . currentTimeMillis ( ) + minTime ; while ( System . currentTimeMillis ( ) < nextCheck ) { runEventQueue ( ) ; sleep ( <NUM_LIT:1> ) ; } } public static void printJobs ( ) { IJobManager jobManager = Job . getJobManager ( ) ; Job [ ] jobs = jobManager . find ( null ) ; System . out . println ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < jobs . length ; i ++ ) { Job job = jobs [ i ] ; int state = job . getState ( ) ; if ( ! job . getName ( ) . equals ( "<STR_LIT>" ) && ! job . getName ( ) . equals ( "<STR_LIT>" ) && ( state == Job . RUNNING || state == Job . WAITING ) ) { System . out . println ( job . getName ( ) ) ; } } System . out . println ( "<STR_LIT>" ) ; } public static void waitForIndexingToComplete ( ) { try { performDummySearch ( JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) ) ; } catch ( CoreException e1 ) { e1 . printStackTrace ( ) ; } SynchronizationUtils . joinBackgroudActivities ( ) ; Job [ ] jobs = Job . getJobManager ( ) . find ( null ) ; for ( int i = <NUM_LIT:0> ; i < jobs . length ; i ++ ) { if ( jobs [ i ] . getName ( ) . startsWith ( "<STR_LIT>" ) ) { boolean wasInterrupted = true ; while ( wasInterrupted ) { try { wasInterrupted = false ; jobs [ i ] . join ( ) ; } catch ( InterruptedException e ) { wasInterrupted = true ; } } } } } protected static class Requestor extends TypeNameRequestor { } private static void performDummySearch ( IJavaElement element ) throws CoreException { 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 void waitForRefactoringToComplete ( ) { SynchronizationUtils . joinBackgroudActivities ( ) ; Job [ ] jobs = Job . getJobManager ( ) . find ( null ) ; for ( int i = <NUM_LIT:0> ; i < jobs . length ; i ++ ) { if ( jobs [ i ] . getName ( ) . startsWith ( "<STR_LIT>" ) ) { boolean wasInterrupted = true ; while ( wasInterrupted ) { try { wasInterrupted = false ; jobs [ i ] . join ( ) ; } catch ( InterruptedException e ) { wasInterrupted = true ; } } } } } public static void waitForDSLDProcessingToComplete ( ) { SynchronizationUtils . joinBackgroudActivities ( ) ; Job [ ] jobs = Job . getJobManager ( ) . find ( null ) ; for ( int i = <NUM_LIT:0> ; i < jobs . length ; i ++ ) { if ( jobs [ i ] . getName ( ) . startsWith ( "<STR_LIT>" ) ) { boolean wasInterrupted = true ; while ( wasInterrupted ) { try { wasInterrupted = false ; jobs [ i ] . join ( ) ; } catch ( InterruptedException e ) { wasInterrupted = true ; } } } } } } </s>
|
<s> package org . codehaus . groovy . eclipse . test ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . Bundle ; import org . osgi . framework . BundleContext ; public class Activator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static Activator plugin ; public Activator ( ) { plugin = this ; } @ Override public void start ( final BundleContext context ) throws Exception { plugin = this ; super . start ( context ) ; } @ Override public void stop ( final BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static Activator getDefault ( ) { return plugin ; } public static Bundle bundle ( ) { return getDefault ( ) . getBundle ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . core . GroovyCoreActivator ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IPackageFragment ; public abstract class EclipseTestCase extends TestCase { protected TestProject testProject ; protected IPackageFragment pack ; protected GroovyCoreActivator plugin ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + getName ( ) ) ; testProject = new TestProject ( ) ; } @ Override protected void tearDown ( ) throws Exception { testProject . dispose ( ) ; } public EclipseTestCase ( ) { super ( ) ; } public EclipseTestCase ( String name ) { super ( name ) ; } protected boolean hasGroovyNature ( ) throws CoreException { return testProject . getProject ( ) . hasNature ( GroovyNature . GROOVY_NATURE ) ; } protected void fullProjectBuild ( ) throws Exception { ResourcesPlugin . getWorkspace ( ) . build ( IncrementalProjectBuilder . FULL_BUILD , null ) ; } protected void waitForIndexes ( ) { SynchronizationUtils . waitForIndexingToComplete ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test ; import junit . framework . Test ; import junit . framework . TestSuite ; import org . codehaus . groovy . eclipse . test . actions . AliasingOrganizeImportsTest ; import org . codehaus . groovy . eclipse . test . actions . ConvertToJavaOrGroovyActionTest ; import org . codehaus . groovy . eclipse . test . actions . GroovyNatureActionTestCase ; import org . codehaus . groovy . eclipse . test . actions . OrganizeImportsTest ; import org . codehaus . groovy . eclipse . test . actions . SaveParticipantRegistryTest ; import org . codehaus . groovy . eclipse . test . adapters . GroovyFileAdapterFactoryTestCase ; import org . codehaus . groovy . eclipse . test . adapters . GroovyIFileEditorInputAdapterFactoryTestCase ; import org . codehaus . groovy . eclipse . test . adapters . IsMainTesterTests ; import org . codehaus . groovy . eclipse . test . core . util . ExpressionFinderTestCase ; import org . codehaus . groovy . eclipse . test . debug . BreakpointLocationTests ; import org . codehaus . groovy . eclipse . test . debug . ConsoleLineTrackerTests ; import org . codehaus . groovy . eclipse . test . debug . DebugBreakpointsTests ; import org . codehaus . groovy . eclipse . test . debug . GroovyLauncherShortcutTests ; import org . codehaus . groovy . eclipse . test . ui . BracketInserterTests ; import org . codehaus . groovy . eclipse . test . ui . ErrorLogTest ; import org . codehaus . groovy . eclipse . test . ui . GroovyAutoIndenterTests ; import org . codehaus . groovy . eclipse . test . ui . GroovyAutoIndenterTests2 ; import org . codehaus . groovy . eclipse . test . ui . GroovyTagScannerTests ; import org . codehaus . groovy . eclipse . test . ui . HighlightingExtenderTests ; import org . codehaus . groovy . eclipse . test . wizards . NewGroovyTestCaseWizardTest ; import org . codehaus . groovy . eclipse . test . wizards . NewGroovyTypeWizardTest ; import org . codehaus . groovy . eclipse . ui . search . FindOccurrencesTests ; public class AllUITests { public static Test suite ( ) throws Exception { final TestSuite suite = new TestSuite ( AllUITests . class . getName ( ) ) ; suite . addTestSuite ( GroovyAutoIndenterTests . class ) ; suite . addTestSuite ( GroovyAutoIndenterTests2 . class ) ; suite . addTestSuite ( ErrorLogTest . class ) ; suite . addTestSuite ( GroovyLauncherShortcutTests . class ) ; suite . addTestSuite ( GroovyNatureActionTestCase . class ) ; suite . addTestSuite ( GroovyFileAdapterFactoryTestCase . class ) ; suite . addTestSuite ( GroovyIFileEditorInputAdapterFactoryTestCase . class ) ; suite . addTestSuite ( IsMainTesterTests . class ) ; suite . addTestSuite ( ExpressionFinderTestCase . class ) ; suite . addTestSuite ( GroovyTagScannerTests . class ) ; suite . addTestSuite ( DebugBreakpointsTests . class ) ; suite . addTestSuite ( BreakpointLocationTests . class ) ; suite . addTestSuite ( OrganizeImportsTest . class ) ; suite . addTestSuite ( AliasingOrganizeImportsTest . class ) ; suite . addTestSuite ( SaveParticipantRegistryTest . class ) ; suite . addTestSuite ( ConvertToJavaOrGroovyActionTest . class ) ; suite . addTestSuite ( ConsoleLineTrackerTests . class ) ; suite . addTestSuite ( HighlightingExtenderTests . class ) ; suite . addTestSuite ( BracketInserterTests . class ) ; suite . addTestSuite ( NewGroovyTypeWizardTest . class ) ; suite . addTestSuite ( NewGroovyTestCaseWizardTest . class ) ; suite . addTest ( FindOccurrencesTests . suite ( ) ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test ; import static org . eclipse . jdt . core . search . IJavaSearchConstants . CLASS ; import static org . eclipse . jdt . core . search . IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH ; import static org . eclipse . jdt . core . search . SearchEngine . createJavaSearchScope ; import static org . eclipse . jdt . core . search . SearchPattern . R_CASE_SENSITIVE ; import static org . eclipse . jdt . core . search . SearchPattern . R_EXACT_MATCH ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . UnsupportedEncodingException ; import junit . framework . Assert ; import org . apache . commons . io . IOUtils ; import org . codehaus . groovy . eclipse . core . builder . GroovyClasspathContainer ; import org . codehaus . groovy . eclipse . core . model . GroovyProjectFacade ; import org . eclipse . core . internal . events . BuildCommand ; import org . eclipse . core . resources . ICommand ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IFolder ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . IWorkspaceDescription ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; 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 . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelMarker ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . TypeNameRequestor ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . core . DefaultWorkingCopyOwner ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . JavaProject ; import org . eclipse . jdt . launching . JavaRuntime ; public class TestProject { public static final String TEST_PROJECT_NAME = "<STR_LIT>" ; private final IProject project ; private final IJavaProject javaProject ; private IPackageFragmentRoot sourceFolder ; public TestProject ( String name ) throws CoreException { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; project = root . getProject ( name ) ; if ( ! project . exists ( ) ) { project . create ( null ) ; project . open ( null ) ; } javaProject = JavaCore . create ( project ) ; IFolder binFolder = createBinFolder ( ) ; setJavaNature ( ) ; javaProject . setRawClasspath ( new IClasspathEntry [ <NUM_LIT:0> ] , null ) ; createOutputFolder ( binFolder ) ; sourceFolder = createSourceFolder ( ) ; addSystemLibraries ( ) ; javaProject . setOption ( CompilerOptions . OPTION_Compliance , "<STR_LIT>" ) ; javaProject . setOption ( CompilerOptions . OPTION_Source , "<STR_LIT>" ) ; javaProject . setOption ( CompilerOptions . OPTION_TargetPlatform , "<STR_LIT>" ) ; } public TestProject ( ) throws CoreException { this ( TEST_PROJECT_NAME ) ; } public IProject getProject ( ) { return project ; } public IJavaProject getJavaProject ( ) { return javaProject ; } public GroovyProjectFacade getGroovyProjectFacade ( ) { return new GroovyProjectFacade ( javaProject ) ; } public boolean hasGroovyContainer ( ) throws JavaModelException { IClasspathEntry [ ] entries = javaProject . getRawClasspath ( ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { if ( entries [ i ] . getEntryKind ( ) == IClasspathEntry . CPE_CONTAINER && entries [ i ] . getPath ( ) . equals ( GroovyClasspathContainer . CONTAINER_ID ) ) { return true ; } } return false ; } public IPackageFragment createPackage ( String name ) throws CoreException { if ( sourceFolder == null ) sourceFolder = createSourceFolder ( ) ; return sourceFolder . createPackageFragment ( name , false , null ) ; } public void deletePackage ( String name ) throws CoreException { sourceFolder . getPackageFragment ( name ) . delete ( true , null ) ; } public IType createJavaType ( IPackageFragment pack , String cuName , String source ) throws JavaModelException { StringBuffer buf = new StringBuffer ( ) ; if ( ! pack . isDefaultPackage ( ) ) { buf . append ( "<STR_LIT>" + pack . getElementName ( ) + "<STR_LIT:;>" + System . getProperty ( "<STR_LIT>" ) ) ; } buf . append ( System . getProperty ( "<STR_LIT>" ) ) ; buf . append ( source ) ; ICompilationUnit cu = pack . createCompilationUnit ( cuName , buf . toString ( ) , false , null ) ; return cu . getTypes ( ) [ <NUM_LIT:0> ] ; } public IType createJavaTypeAndPackage ( String packageName , String fileName , String source ) throws CoreException { return createJavaType ( createPackage ( packageName ) , fileName , source ) ; } public IFile createGroovyTypeAndPackage ( String packageName , String fileName , InputStream source ) throws CoreException , IOException { return createGroovyType ( createPackage ( packageName ) , fileName , IOUtils . toString ( source ) ) ; } public IFile createGroovyTypeAndPackage ( String packageName , String fileName , String source ) throws CoreException { return createGroovyType ( createPackage ( packageName ) , fileName , source ) ; } public IFile createGroovyType ( IPackageFragment pack , String cuName , String source ) throws CoreException { StringBuffer buf = new StringBuffer ( ) ; if ( ! pack . getElementName ( ) . equals ( "<STR_LIT>" ) ) { buf . append ( "<STR_LIT>" + pack . getElementName ( ) + "<STR_LIT:;>" + System . getProperty ( "<STR_LIT>" ) ) ; buf . append ( System . getProperty ( "<STR_LIT>" ) ) ; } buf . append ( source ) ; IContainer folder = ( IContainer ) pack . getResource ( ) ; String encoding = javaProject . getOption ( JavaCore . CORE_ENCODING , true ) ; InputStream stream ; try { stream = new ByteArrayInputStream ( encoding == null ? buf . toString ( ) . getBytes ( ) : buf . toString ( ) . getBytes ( encoding ) ) ; } catch ( UnsupportedEncodingException e ) { throw new CoreException ( new Status ( IStatus . ERROR , "<STR_LIT>" , IStatus . ERROR , "<STR_LIT>" , e ) ) ; } return createFile ( folder , cuName , stream ) ; } public void removeNature ( String natureId ) throws CoreException { final IProjectDescription description = project . getDescription ( ) ; final String [ ] ids = description . getNatureIds ( ) ; for ( int i = <NUM_LIT:0> ; i < ids . length ; ++ i ) { if ( ids [ i ] . equals ( natureId ) ) { final String [ ] newIds = remove ( ids , i ) ; description . setNatureIds ( newIds ) ; project . setDescription ( description , null ) ; return ; } } } private String [ ] remove ( String [ ] ids , int index ) { String [ ] newIds = new String [ ids . length - <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:0> , j = <NUM_LIT:0> ; i < ids . length ; i ++ ) { if ( i != index ) { newIds [ j ] = ids [ i ] ; j ++ ; } } return newIds ; } public void addBuilder ( String newBuilder ) throws CoreException { final IProjectDescription description = project . getDescription ( ) ; ICommand [ ] commands = description . getBuildSpec ( ) ; ICommand newCommand = new BuildCommand ( ) ; newCommand . setBuilderName ( newBuilder ) ; ICommand [ ] newCommands = new ICommand [ commands . length + <NUM_LIT:1> ] ; newCommands [ <NUM_LIT:0> ] = newCommand ; System . arraycopy ( commands , <NUM_LIT:0> , newCommands , <NUM_LIT:1> , commands . length ) ; description . setBuildSpec ( newCommands ) ; project . setDescription ( description , null ) ; } public void addNature ( String natureId ) throws CoreException { final IProjectDescription description = project . getDescription ( ) ; final String [ ] ids = description . getNatureIds ( ) ; final String [ ] newIds = new String [ ids . length + <NUM_LIT:1> ] ; newIds [ <NUM_LIT:0> ] = natureId ; System . arraycopy ( ids , <NUM_LIT:0> , newIds , <NUM_LIT:1> , ids . length ) ; description . setNatureIds ( newIds ) ; project . setDescription ( description , null ) ; } private IFile createFile ( IContainer folder , String name , InputStream contents ) throws JavaModelException { IFile file = folder . getFile ( new Path ( name ) ) ; try { if ( file . exists ( ) ) { file . delete ( true , null ) ; } file . create ( contents , IResource . FORCE , null ) ; } catch ( CoreException e ) { throw new JavaModelException ( e ) ; } return file ; } public void dispose ( ) throws CoreException { deleteWorkingCopies ( ) ; project . delete ( true , true , null ) ; } public void deleteContents ( ) throws CoreException { deleteWorkingCopies ( ) ; IPackageFragment [ ] frags = javaProject . getPackageFragments ( ) ; for ( IPackageFragment frag : frags ) { if ( ! frag . isReadOnly ( ) ) { frag . delete ( true , null ) ; } } } private void deleteWorkingCopies ( ) throws JavaModelException { waitForIndexer ( ) ; ICompilationUnit [ ] workingCopies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( DefaultWorkingCopyOwner . PRIMARY , true ) ; if ( workingCopies != null ) { for ( ICompilationUnit workingCopy : workingCopies ) { if ( workingCopy . isWorkingCopy ( ) ) { workingCopy . discardWorkingCopy ( ) ; } } } System . gc ( ) ; } private IFolder createBinFolder ( ) throws CoreException { final IFolder binFolder = project . getFolder ( "<STR_LIT>" ) ; if ( ! binFolder . exists ( ) ) ensureExists ( binFolder ) ; return binFolder ; } private void setJavaNature ( ) throws CoreException { IProjectDescription description = project . getDescription ( ) ; description . setNatureIds ( new String [ ] { JavaCore . NATURE_ID } ) ; project . setDescription ( description , null ) ; } private void createOutputFolder ( IFolder binFolder ) throws JavaModelException { IPath outputLocation = binFolder . getFullPath ( ) ; javaProject . setOutputLocation ( outputLocation , null ) ; } private IPackageFragmentRoot createSourceFolder ( ) throws CoreException { IFolder folder = project . getFolder ( "<STR_LIT:src>" ) ; if ( ! folder . exists ( ) ) ensureExists ( folder ) ; final IClasspathEntry [ ] entries = javaProject . getResolvedClasspath ( false ) ; final IPackageFragmentRoot root = javaProject . getPackageFragmentRoot ( folder ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { final IClasspathEntry entry = entries [ i ] ; if ( entry . getPath ( ) . equals ( folder . getFullPath ( ) ) ) return root ; } IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ oldEntries . length + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , oldEntries . length ) ; newEntries [ oldEntries . length ] = JavaCore . newSourceEntry ( root . getPath ( ) ) ; javaProject . setRawClasspath ( newEntries , null ) ; return root ; } public IPackageFragmentRoot createOtherSourceFolder ( ) throws CoreException { return createOtherSourceFolder ( null ) ; } public IPackageFragmentRoot createOtherSourceFolder ( String outPath ) throws CoreException { return createSourceFolder ( "<STR_LIT>" , outPath ) ; } public IPackageFragmentRoot createSourceFolder ( String path , String outPath ) throws CoreException { return createSourceFolder ( path , outPath , null ) ; } public IPackageFragmentRoot createSourceFolder ( String path , String outPath , IPath [ ] exclusionPattern ) throws CoreException { IFolder folder = project . getFolder ( path ) ; if ( ! folder . exists ( ) ) { ensureExists ( folder ) ; } final IClasspathEntry [ ] entries = javaProject . getResolvedClasspath ( false ) ; final IPackageFragmentRoot root = javaProject . getPackageFragmentRoot ( folder ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { final IClasspathEntry entry = entries [ i ] ; if ( entry . getPath ( ) . equals ( folder . getFullPath ( ) ) ) { return root ; } } IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ oldEntries . length + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , oldEntries . length ) ; IPath outPathPath = outPath == null ? null : getProject ( ) . getFullPath ( ) . append ( outPath ) . makeAbsolute ( ) ; newEntries [ oldEntries . length ] = JavaCore . newSourceEntry ( root . getPath ( ) , exclusionPattern , outPathPath ) ; javaProject . setRawClasspath ( newEntries , null ) ; return root ; } private void ensureExists ( IFolder folder ) throws CoreException { if ( folder . getParent ( ) . getType ( ) == IResource . FOLDER && ! folder . getParent ( ) . exists ( ) ) { ensureExists ( ( IFolder ) folder . getParent ( ) ) ; } folder . create ( false , true , null ) ; } public void addProjectReference ( IJavaProject referent ) throws JavaModelException { IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ oldEntries . length + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , oldEntries . length ) ; newEntries [ oldEntries . length ] = JavaCore . newProjectEntry ( referent . getPath ( ) ) ; javaProject . setRawClasspath ( newEntries , null ) ; } public void addJarFileToClasspath ( IPath path ) throws JavaModelException { IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ oldEntries . length + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , oldEntries . length ) ; newEntries [ oldEntries . length ] = JavaCore . newLibraryEntry ( path , null , null ) ; javaProject . setRawClasspath ( newEntries , null ) ; } private void addSystemLibraries ( ) throws JavaModelException { IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; IClasspathEntry [ ] newEntries = new IClasspathEntry [ oldEntries . length + <NUM_LIT:1> ] ; System . arraycopy ( oldEntries , <NUM_LIT:0> , newEntries , <NUM_LIT:0> , oldEntries . length ) ; newEntries [ oldEntries . length ] = JavaRuntime . getDefaultJREContainerEntry ( ) ; javaProject . setRawClasspath ( newEntries , null ) ; } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) private void waitForIndexer ( ) throws JavaModelException { final TypeNameRequestor requestor = new TypeNameRequestor ( ) { } ; new SearchEngine ( ) . searchAllTypeNames ( null , null , R_EXACT_MATCH | R_CASE_SENSITIVE , CLASS , createJavaSearchScope ( new IJavaElement [ <NUM_LIT:0> ] ) , requestor , WAIT_UNTIL_READY_TO_SEARCH , null ) ; } protected void fullBuild ( ) throws CoreException { this . getProject ( ) . build ( org . eclipse . core . resources . IncrementalProjectBuilder . FULL_BUILD , null ) ; } public String getProblems ( ) throws CoreException { IMarker [ ] markers = getProject ( ) . findMarkers ( IJavaModelMarker . JAVA_MODEL_PROBLEM_MARKER , true , IResource . DEPTH_INFINITE ) ; StringBuilder sb = new StringBuilder ( ) ; if ( markers == null || markers . length == <NUM_LIT:0> ) { return null ; } boolean errorFound = false ; sb . append ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < markers . length ; i ++ ) { if ( ( ( Integer ) markers [ i ] . getAttribute ( IMarker . SEVERITY ) ) . intValue ( ) == IMarker . SEVERITY_ERROR ) { sb . append ( "<STR_LIT:U+0020U+0020>" ) ; sb . append ( markers [ i ] . getResource ( ) . getName ( ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) ; sb . append ( markers [ i ] . getAttribute ( IMarker . LOCATION ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) ; sb . append ( markers [ i ] . getAttribute ( IMarker . MESSAGE ) ) . append ( "<STR_LIT:n>" ) ; errorFound = true ; } } return errorFound ? sb . toString ( ) : null ; } public IFile createFile ( String name , String contents ) throws Exception { String encoding = null ; try { encoding = project . getDefaultCharset ( ) ; } catch ( CoreException ce ) { } InputStream stream = new ByteArrayInputStream ( encoding == null ? contents . getBytes ( ) : contents . getBytes ( encoding ) ) ; IFile file = project . getFile ( new Path ( name ) ) ; if ( ! file . getParent ( ) . exists ( ) ) { createFolder ( file . getParent ( ) ) ; } file . create ( stream , true , null ) ; return file ; } private void createFolder ( IContainer parent ) throws CoreException { if ( ! parent . getParent ( ) . exists ( ) ) { if ( parent . getParent ( ) . getType ( ) != IResource . FOLDER ) { Assert . fail ( "<STR_LIT>" + parent . getParent ( ) ) ; } createFolder ( parent . getParent ( ) ) ; } ( ( IFolder ) parent ) . create ( true , true , null ) ; } public IPackageFragmentRoot getSourceFolder ( ) { return sourceFolder ; } public ICompilationUnit createUnit ( String pkg , String cuName , String cuContents ) throws CoreException { IPackageFragment frag = createPackage ( pkg ) ; ICompilationUnit cu = frag . createCompilationUnit ( cuName , cuContents , false , null ) ; return cu ; } public ICompilationUnit [ ] createUnits ( String [ ] packages , String [ ] cuNames , String [ ] cuContents ) throws CoreException { ICompilationUnit [ ] units = new ICompilationUnit [ packages . length ] ; for ( int i = <NUM_LIT:0> ; i < cuContents . length ; i ++ ) { units [ i ] = createUnit ( packages [ i ] , cuNames [ i ] , cuContents [ i ] ) ; } return units ; } public static void addEntry ( IProject project , IClasspathEntry entryPath ) throws JavaModelException { IClasspathEntry [ ] classpath = getClasspath ( project ) ; IClasspathEntry [ ] newClaspath = new IClasspathEntry [ classpath . length + <NUM_LIT:1> ] ; System . arraycopy ( classpath , <NUM_LIT:0> , newClaspath , <NUM_LIT:0> , classpath . length ) ; newClaspath [ classpath . length ] = entryPath ; setClasspath ( project , newClaspath ) ; } public static IClasspathEntry [ ] getClasspath ( IProject project ) { try { JavaProject javaProject = ( JavaProject ) JavaCore . create ( project ) ; return javaProject . getExpandedClasspath ( ) ; } catch ( JavaModelException e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e ) ; } } public static void addExternalLibrary ( IProject project , String jar ) throws JavaModelException { addExternalLibrary ( project , jar , false ) ; } public static void addExternalLibrary ( IProject project , String jar , boolean isExported ) throws JavaModelException { addEntry ( project , JavaCore . newLibraryEntry ( new Path ( jar ) , null , null , isExported ) ) ; } public static void setClasspath ( IProject project , IClasspathEntry [ ] entries ) throws JavaModelException { IJavaProject javaProject = JavaCore . create ( project ) ; javaProject . setRawClasspath ( entries , null ) ; } public static void setAutoBuilding ( boolean value ) { try { IWorkspace w = ResourcesPlugin . getWorkspace ( ) ; IWorkspaceDescription d = w . getDescription ( ) ; d . setAutoBuilding ( value ) ; w . setDescription ( d ) ; } catch ( CoreException e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e ) ; } } public static boolean isAutoBuilding ( ) { IWorkspace w = ResourcesPlugin . getWorkspace ( ) ; IWorkspaceDescription d = w . getDescription ( ) ; return d . isAutoBuilding ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . wizards ; import java . util . ArrayList ; 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 . wizards . NewClassWizardPage ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . internal . corext . codemanipulation . StubUtility ; import org . eclipse . jdt . internal . corext . template . java . CodeTemplateContextType ; public class NewGroovyTypeWizardTest extends AbstractNewGroovyWizardTest { private static final Class < NewGroovyTypeWizardTest > THIS = NewGroovyTypeWizardTest . class ; public NewGroovyTypeWizardTest ( String name ) { super ( name ) ; } public static Test allTests ( ) { return new TestSuite ( THIS ) ; } public static Test suite ( ) { return allTests ( ) ; } private void assertEqualLines ( String expected , String actual ) { assertEquals ( expected . replace ( "<STR_LIT:n>" , System . getProperty ( "<STR_LIT>" ) ) , actual ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; String newFileTemplate = "<STR_LIT>" ; StubUtility . setCodeTemplate ( CodeTemplateContextType . NEWTYPE_ID , newFileTemplate , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . TYPECOMMENT_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . FILECOMMENT_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . CONSTRUCTORCOMMENT_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . METHODCOMMENT_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . OVERRIDECOMMENT_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . METHODSTUB_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . CONSTRUCTORSTUB_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . CLASSBODY_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . INTERFACEBODY_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . ENUMBODY_ID , "<STR_LIT>" , null ) ; StubUtility . setCodeTemplate ( CodeTemplateContextType . ANNOTATIONBODY_ID , "<STR_LIT>" , null ) ; } public void testNotGroovyProject ( ) throws Exception { GroovyRuntime . removeGroovyNature ( fJProject . getProject ( ) ) ; IPackageFragment frag = fProject . createPackage ( "<STR_LIT:test1>" ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; wizardPage . setPackageFragment ( frag , true ) ; assertStatus ( IStatus . WARNING , "<STR_LIT>" , wizardPage . getStatus ( ) ) ; } public void testExclusionFilters ( ) throws Exception { IPackageFragmentRoot root = fProject . createSourceFolder ( "<STR_LIT>" , null , new IPath [ ] { new Path ( "<STR_LIT>" ) } ) ; IPackageFragment frag = root . createPackageFragment ( "<STR_LIT:p>" , true , null ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( root , true ) ; wizardPage . setPackageFragment ( frag , true ) ; wizardPage . setTypeName ( "<STR_LIT>" , true ) ; assertStatus ( IStatus . ERROR , "<STR_LIT>" , wizardPage . getStatus ( ) ) ; } public void testDiscouraedDefaultPackage ( ) throws Exception { GroovyRuntime . removeGroovyNature ( fJProject . getProject ( ) ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; assertStatus ( IStatus . WARNING , "<STR_LIT>" , wizardPage . getStatus ( ) ) ; } protected void assertStatus ( int severity , String msgFragment , IStatus status ) { assertEquals ( severity , status . getSeverity ( ) ) ; assertTrue ( "<STR_LIT>" + status . getMessage ( ) , status . getMessage ( ) . contains ( msgFragment ) ) ; } public void testCreateGroovyClass1 ( ) throws Exception { IPackageFragment pack1 = fSourceFolder . createPackageFragment ( "<STR_LIT:test1>" , false , null ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; wizardPage . setPackageFragment ( pack1 , true ) ; wizardPage . setEnclosingTypeSelection ( false , true ) ; wizardPage . setTypeName ( "<STR_LIT:E>" , true ) ; wizardPage . setSuperClass ( "<STR_LIT>" , true ) ; List < String > interfaces = new ArrayList < String > ( ) ; wizardPage . setSuperInterfaces ( interfaces , true ) ; wizardPage . setMethodStubSelection ( false , false , false , true ) ; wizardPage . setAddComments ( true , true ) ; wizardPage . enableCommentControl ( true ) ; wizardPage . createType ( new NullProgressMonitor ( ) ) ; String actual = wizardPage . getCreatedType ( ) . getCompilationUnit ( ) . getSource ( ) ; StringBuffer buf = new StringBuffer ( ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT:n>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; String expected = buf . toString ( ) ; assertEqualLines ( expected , actual ) ; } public void _testCreateGroovyClass2GenericSuper ( ) throws Exception { IPackageFragment pack1 = fSourceFolder . createPackageFragment ( "<STR_LIT:test1>" , false , null ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; wizardPage . setPackageFragment ( pack1 , true ) ; wizardPage . setEnclosingTypeSelection ( false , true ) ; wizardPage . setTypeName ( "<STR_LIT:E>" , true ) ; wizardPage . setSuperClass ( "<STR_LIT>" , true ) ; List < String > interfaces = new ArrayList < String > ( ) ; wizardPage . setSuperInterfaces ( interfaces , true ) ; wizardPage . setMethodStubSelection ( false , false , false , true ) ; wizardPage . setAddComments ( true , true ) ; wizardPage . enableCommentControl ( true ) ; wizardPage . createType ( null ) ; String actual = wizardPage . getCreatedType ( ) . getCompilationUnit ( ) . getSource ( ) ; StringBuffer buf = new StringBuffer ( ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT:n>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT:n>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; String expected = buf . toString ( ) ; assertEqualLines ( expected , actual ) ; } public void testCreateGroovyClass2 ( ) throws Exception { IPackageFragment pack1 = fSourceFolder . createPackageFragment ( "<STR_LIT:test1>" , false , null ) ; NewClassWizardPage wizardPage = new NewClassWizardPage ( ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; wizardPage . setPackageFragment ( pack1 , true ) ; wizardPage . setEnclosingTypeSelection ( false , true ) ; wizardPage . setTypeName ( "<STR_LIT:E>" , true ) ; wizardPage . setSuperClass ( "<STR_LIT>" , true ) ; List < String > interfaces = new ArrayList < String > ( ) ; wizardPage . setSuperInterfaces ( interfaces , true ) ; wizardPage . setMethodStubSelection ( false , false , false , true ) ; wizardPage . setAddComments ( true , true ) ; wizardPage . enableCommentControl ( true ) ; wizardPage . createType ( new NullProgressMonitor ( ) ) ; String actual = wizardPage . getCreatedType ( ) . getCompilationUnit ( ) . getSource ( ) ; StringBuffer buf = new StringBuffer ( ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT:n>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT:n>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( "<STR_LIT>" ) ; String expected = buf . toString ( ) ; assertEqualLines ( expected , actual ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . wizards ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . wizards . NewGroovyTestTypeWizardPage ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . junit . wizards . NewTestCaseWizardPageTwo ; public class NewGroovyTestCaseWizardTest extends AbstractNewGroovyWizardTest { private static final String PACKAGE_NAME = "<STR_LIT>" ; protected IPackageFragment frag = null ; public NewGroovyTestCaseWizardTest ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; frag = fSourceFolder . getPackageFragment ( PACKAGE_NAME ) ; if ( frag == null ) { frag = fSourceFolder . createPackageFragment ( PACKAGE_NAME , false , null ) ; } } public void testAddGroovyTestCaseNonGroovyProject ( ) throws Exception { GroovyRuntime . removeGroovyNature ( fJProject . getProject ( ) ) ; NewGroovyTestTypeWizardPage page = createdGroovyTestTypeWizardPage ( ) ; String testCaseName = "<STR_LIT>" ; page . setEnclosingTypeSelection ( false , true ) ; page . setTypeName ( testCaseName , true ) ; page . createType ( new NullProgressMonitor ( ) ) ; IType type = page . getCreatedType ( ) ; assertNull ( type ) ; } public void testAddGroovyTestCaseGroovyProject ( ) throws Exception { GroovyRuntime . addGroovyNature ( fJProject . getProject ( ) ) ; NewGroovyTestTypeWizardPage page = createdGroovyTestTypeWizardPage ( ) ; String testCaseName = "<STR_LIT>" ; page . setEnclosingTypeSelection ( false , true ) ; page . setTypeName ( testCaseName , true ) ; page . createType ( new NullProgressMonitor ( ) ) ; IType type = page . getCreatedType ( ) ; assertEquals ( testCaseName , type . getElementName ( ) ) ; } protected NewGroovyTestTypeWizardPage createdGroovyTestTypeWizardPage ( ) { NewTestCaseWizardPageTwo pageTwo = new NewTestCaseWizardPageTwo ( ) ; NewGroovyTestTypeWizardPage wizardPage = new NewGroovyTestTypeWizardPage ( pageTwo ) ; wizardPage . setPackageFragmentRoot ( fSourceFolder , true ) ; wizardPage . setPackageFragment ( frag , true ) ; return wizardPage ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . wizards ; import java . util . Hashtable ; import junit . framework . TestCase ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . TestProject ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . ui . PreferenceConstants ; import org . eclipse . jface . preference . IPreferenceStore ; public abstract class AbstractNewGroovyWizardTest extends TestCase { protected TestProject fProject ; protected IJavaProject fJProject ; protected IPackageFragmentRoot fSourceFolder ; protected AbstractNewGroovyWizardTest ( String name ) { super ( name ) ; } @ Override protected void setUp ( ) throws Exception { Hashtable < String , String > options = JavaCore . getDefaultOptions ( ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_CHAR , JavaCore . SPACE ) ; options . put ( DefaultCodeFormatterConstants . FORMATTER_TAB_SIZE , "<STR_LIT:4>" ) ; JavaCore . setOptions ( options ) ; IPreferenceStore store = JavaPlugin . getDefault ( ) . getPreferenceStore ( ) ; store . setValue ( PreferenceConstants . CODEGEN_ADD_COMMENTS , false ) ; store . setValue ( PreferenceConstants . CODEGEN_USE_OVERRIDE_ANNOTATION , true ) ; fProject = new TestProject ( "<STR_LIT>" ) ; fJProject = fProject . getJavaProject ( ) ; fSourceFolder = fProject . getSourceFolder ( ) ; GroovyRuntime . addGroovyRuntime ( fJProject . getProject ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { fProject . dispose ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . adapters ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . ui . IFileEditorInput ; import org . eclipse . ui . part . FileEditorInput ; public class GroovyIFileEditorInputAdapterFactoryTestCase extends EclipseTestCase { public void testIFileEditorInputAdapter ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile script = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( script ) ; IFileEditorInput editor = new FileEditorInput ( script ) ; ClassNode node = ( ClassNode ) editor . getAdapter ( ClassNode . class ) ; assertEquals ( "<STR_LIT>" , node . getName ( ) ) ; assertFalse ( node . isInterface ( ) ) ; assertNotNull ( node . getMethods ( "<STR_LIT>" ) ) ; } public void testIFileEditorInputAdapterCompileError ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile script = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( script ) ; IFileEditorInput editor = new FileEditorInput ( script ) ; ClassNode node = ( ClassNode ) editor . getAdapter ( ClassNode . class ) ; assertEquals ( "<STR_LIT>" , node . getName ( ) ) ; assertFalse ( node . isInterface ( ) ) ; assertNotNull ( node . getMethods ( "<STR_LIT>" ) ) ; } public void testIFileEditorInputAdapterHorendousCompileError ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; fullProjectBuild ( ) ; final IFile notScript = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( notScript ) ; IFileEditorInput editor = new FileEditorInput ( notScript ) ; assertNull ( editor . getAdapter ( ClassNode . class ) ) ; } public void testIFileEditorInputAdapterNotGroovyFile ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile notScript = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( notScript ) ; IFileEditorInput editor = new FileEditorInput ( notScript ) ; assertNull ( editor . getAdapter ( ClassNode . class ) ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . adapters ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . eclipse . core . model . GroovyRuntime ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; public class GroovyFileAdapterFactoryTestCase extends EclipseTestCase { public void testFileAdapter ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile script = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( script ) ; ClassNode node = ( ClassNode ) script . getAdapter ( ClassNode . class ) ; assertEquals ( "<STR_LIT>" , node . getName ( ) ) ; assertFalse ( node . isInterface ( ) ) ; assertNotNull ( node . getMethods ( "<STR_LIT>" ) ) ; } public void testFileAdapterCompileError ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL < <NUM_LIT> ) { return ; } testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile script = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; ClassNode node = ( ClassNode ) script . getAdapter ( ClassNode . class ) ; assertEquals ( "<STR_LIT>" , node . getName ( ) ) ; assertFalse ( node . isInterface ( ) ) ; assertNotNull ( node . getMethods ( "<STR_LIT>" ) ) ; } public void testFileAdapterHorendousCompileError ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; fullProjectBuild ( ) ; final IFile script = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; ClassNode node = ( ClassNode ) script . getAdapter ( ClassNode . class ) ; assertNull ( node ) ; } public void testFileAdapterNotGroovyFile ( ) throws Exception { testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; fullProjectBuild ( ) ; final IFile notScript = ( IFile ) testProject . getProject ( ) . findMember ( "<STR_LIT>" ) ; assertNotNull ( notScript ) ; assertNull ( notScript . getAdapter ( ClassNode . class ) ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; GroovyRuntime . addGroovyRuntime ( testProject . getProject ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . test . adapters ; import org . codehaus . groovy . eclipse . test . EclipseTestCase ; import org . codehaus . groovy . eclipse . ui . GroovyResourcePropertyTester ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; public class IsMainTesterTests extends EclipseTestCase { public void testHasMain1 ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain2 ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain2a ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain3 ( ) throws Exception { doTest ( "<STR_LIT>" , false ) ; } public void testHasMain3a ( ) throws Exception { doTest ( "<STR_LIT>" , false ) ; } public void testHasMain4 ( ) throws Exception { doTest ( "<STR_LIT>" , false ) ; } public void testHasMain5 ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain5a ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain6 ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } public void testHasMain7 ( ) throws Exception { doTest ( "<STR_LIT>" , true ) ; } private void doTest ( String text , boolean expected ) throws Exception { testProject . addNature ( GroovyNature . GROOVY_NATURE ) ; IFile file = testProject . createGroovyTypeAndPackage ( "<STR_LIT>" , "<STR_LIT>" , text ) ; GroovyResourcePropertyTester tester = new GroovyResourcePropertyTester ( ) ; boolean result = tester . test ( file , "<STR_LIT>" , null , null ) ; if ( result != expected ) { fail ( "<STR_LIT>" + ( expected ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" + text ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . ui . search ; import java . util . Arrays ; import junit . framework . Test ; import org . codehaus . groovy . eclipse . search . GroovyOccurrencesFinder ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . groovy . tests . search . AbstractGroovySearchTest ; import org . eclipse . jdt . core . tests . util . GroovyUtils ; import org . eclipse . jdt . internal . ui . search . IOccurrencesFinder . OccurrenceLocation ; public class FindOccurrencesTests extends AbstractGroovySearchTest { public FindOccurrencesTests ( String name ) { super ( name ) ; } public static Test suite ( ) { return buildTestSuite ( FindOccurrencesTests . class ) ; } public void testFindLocalOccurrences1 ( ) throws Exception { String contents = "<STR_LIT>" ; doTest ( contents , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; } public void testFindLocalOccurrences2 ( ) throws Exception { String contents = "<STR_LIT>" ; doTest ( contents , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> , <NUM_LIT:1> , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; } public void testFindLocalOccurrences3 ( ) throws Exception { String contents = "<STR_LIT>" ; int afterParen = contents . indexOf ( '<CHAR_LIT:(>' ) ; doTest ( contents , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . indexOf ( "<STR_LIT:x>" , afterParen ) , <NUM_LIT:1> , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; } public void testFindLocalOccurrences4 ( ) throws Exception { String contents = "<STR_LIT>" ; doTest ( contents , contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; } public void testFindForLoopOccurrences ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; doTest ( contents , contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . indexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> , contents . lastIndexOf ( '<CHAR_LIT>' ) , <NUM_LIT:1> ) ; } public void _testFindPrimitive ( ) throws Exception { String contents = "<STR_LIT>" ; int length = "<STR_LIT:int>" . length ( ) ; int first = contents . indexOf ( "<STR_LIT:int>" ) ; int second = contents . indexOf ( "<STR_LIT:int>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT:int>" , second + <NUM_LIT:1> ) ; int fourth = contents . indexOf ( "<STR_LIT:int>" , third + <NUM_LIT:1> ) ; doTest ( contents , second , length , first , length , second , length , third , length , fourth , length ) ; } public void testFindProperty ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int length = "<STR_LIT:foo>" . length ( ) ; int first = contents . indexOf ( "<STR_LIT:foo>" ) ; int second = contents . indexOf ( "<STR_LIT:foo>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT:foo>" , second + <NUM_LIT:1> ) ; doTest ( contents , second , length , first , length , second , length , third , length ) ; } public void testFindField ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int length = "<STR_LIT:foo>" . length ( ) ; int first = contents . indexOf ( "<STR_LIT:foo>" ) ; int second = contents . indexOf ( "<STR_LIT:foo>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT:foo>" , second + <NUM_LIT:1> ) ; doTest ( contents , second , length , first , length , second , length , third , length ) ; } public void testFindGStringOccurrences1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; int length = "<STR_LIT>" . length ( ) ; int def = contents . indexOf ( "<STR_LIT>" ) ; int first = contents . indexOf ( "<STR_LIT>" , def + <NUM_LIT:1> ) ; int second = contents . indexOf ( "<STR_LIT>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT>" , second + <NUM_LIT:1> ) ; int fourth = contents . indexOf ( "<STR_LIT>" , third + <NUM_LIT:1> ) ; doTest ( contents , def , <NUM_LIT:1> , def , length , first , length , second , length , third , length , fourth , length ) ; } public void testFindGStringOccurrences2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" ; int length = "<STR_LIT:i>" . length ( ) ; int def = contents . indexOf ( "<STR_LIT:i>" ) ; int first = contents . indexOf ( "<STR_LIT:i>" , def + <NUM_LIT:1> ) ; int second = contents . indexOf ( "<STR_LIT:i>" , first + <NUM_LIT:1> ) ; int third = contents . indexOf ( "<STR_LIT:i>" , second + <NUM_LIT:1> ) ; int fourth = contents . indexOf ( "<STR_LIT:i>" , third + <NUM_LIT:1> ) ; doTest ( contents , def , <NUM_LIT:1> , def , length , first , length , second , length , third , length , fourth , length ) ; } public void testFindStaticMethods ( ) 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:}>" ; String methName = "<STR_LIT>" ; int len = methName . length ( ) ; int start = contents . indexOf ( methName ) ; int start1 = contents . indexOf ( methName ) ; int start2 = contents . indexOf ( methName , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( methName , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( methName , start3 + <NUM_LIT:1> ) ; int start5 = contents . indexOf ( methName , start4 + <NUM_LIT:1> ) ; int start6 = contents . indexOf ( methName , start5 + <NUM_LIT:1> ) ; int start7 = contents . indexOf ( methName , start6 + <NUM_LIT:1> ) ; int start8 = contents . indexOf ( methName , start7 + <NUM_LIT:1> ) ; int start9 = contents . indexOf ( methName , start8 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len , start5 , len , start6 , len , start7 , len , start8 , len , start9 , len ) ; } public void testFindStaticMethods18 ( ) throws Exception { if ( GroovyUtils . GROOVY_LEVEL > <NUM_LIT> ) { 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:}>" ; String methName = "<STR_LIT>" ; int len = methName . length ( ) ; int start = contents . indexOf ( methName ) ; int start1 = contents . indexOf ( methName ) ; int start2 = contents . indexOf ( methName , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( methName , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( methName , start3 + <NUM_LIT:1> ) ; int start5 = contents . indexOf ( methName , start4 + <NUM_LIT:1> ) ; int start6 = contents . indexOf ( methName , start5 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len , start5 , len , start6 , len ) ; } else { System . out . println ( "<STR_LIT>" ) ; } } public void testInnerClass ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String className = "<STR_LIT>" ; int len = className . length ( ) ; int start = contents . indexOf ( className ) ; int start1 = contents . indexOf ( className ) ; int start2 = contents . indexOf ( className , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( className , start2 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testInnerClass2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String className = "<STR_LIT>" ; int len = className . length ( ) ; int start1 = contents . indexOf ( className ) ; int start2 = contents . indexOf ( className , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( className , start2 + <NUM_LIT:1> ) ; int start = start2 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testInnerClass3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; String className = "<STR_LIT>" ; int len = className . length ( ) ; int start1 = contents . indexOf ( className ) ; int start2 = contents . indexOf ( className , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( className , start2 + <NUM_LIT:1> ) ; int start = start3 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testInnerClass4 ( ) throws Exception { createUnit ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String className = "<STR_LIT>" ; int len = className . length ( ) ; int start1 = contents . indexOf ( className ) ; int start2 = contents . indexOf ( className , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( className , start2 + <NUM_LIT:1> ) ; int start = start1 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testGenerics1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start1 = contents . indexOf ( name ) ; int start2 = contents . indexOf ( name , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( name , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( name , start3 + <NUM_LIT:1> ) ; int start = start1 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len ) ; } public void testGenerics2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start1 = contents . indexOf ( name ) ; int start2 = contents . indexOf ( name , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( name , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( name , start3 + <NUM_LIT:1> ) ; int start = start2 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len ) ; } public void testGenerics3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start1 = contents . indexOf ( name ) ; int start2 = contents . indexOf ( name , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( name , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( name , start3 + <NUM_LIT:1> ) ; int start = start4 ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len ) ; } public void testAnnotationOnImport ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start1 = contents . indexOf ( name ) ; int start2 = contents . indexOf ( name , start1 + <NUM_LIT:1> ) ; int start = start2 ; doTest ( contents , start , len , start1 , len , start2 , len ) ; } public void testLiterals1 ( ) throws Exception { String contents = "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start = contents . indexOf ( name ) ; doTest ( contents , start , len ) ; } public void testLiterals2 ( ) throws Exception { String contents = "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start = contents . indexOf ( name ) ; doTest ( contents , start , len ) ; } public void testLiterals3 ( ) throws Exception { String contents = "<STR_LIT>" ; String name = "<STR_LIT>" ; int len = name . length ( ) ; int start = contents . indexOf ( name ) ; doTest ( contents , start , len ) ; } public void testOverloaded1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . lastIndexOf ( "<STR_LIT>" ) ; doTest ( contents , start , len , start1 , len , start2 , len ) ; } public void testOverloaded2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . lastIndexOf ( "<STR_LIT>" ) ; doTest ( contents , start , len , start1 , len , start2 , len ) ; } public void testOverloaded3 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" , contents . indexOf ( "<STR_LIT>" ) + <NUM_LIT:1> ) + <NUM_LIT:1> ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . lastIndexOf ( "<STR_LIT>" ) ; doTest ( contents , start , len , start1 , len , start2 , len ) ; } public void testDefaultParameters1 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len = "<STR_LIT>" . length ( ) ; int dontCare = contents . indexOf ( "<STR_LIT>" , start ) ; int start1 = dontCare ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( "<STR_LIT>" , start3 + <NUM_LIT:1> ) ; int start5 = contents . indexOf ( "<STR_LIT>" , start4 + <NUM_LIT:1> ) ; int start6 = contents . indexOf ( "<STR_LIT>" , start5 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len , start5 , len , start6 , len ) ; } public void testStaticImports1 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testStaticImports2 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len ) ; } public void testStaticImports3 ( ) throws Exception { createUnit ( "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ) ; String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len1 = "<STR_LIT>" . length ( ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + len1 ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( "<STR_LIT>" , start3 + <NUM_LIT:1> ) ; doTest ( contents , start , len1 , start1 , len1 , start2 , len , start3 , len , start4 , len1 ) ; } public void _testDefaultParameters1a ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; int len = "<STR_LIT>" . length ( ) ; int dontCare = contents . indexOf ( "<STR_LIT>" , start + <NUM_LIT:1> ) ; int start1 = dontCare ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( "<STR_LIT>" , start3 + <NUM_LIT:1> ) ; int start5 = contents . indexOf ( "<STR_LIT>" , start4 + <NUM_LIT:1> ) ; int start6 = contents . indexOf ( "<STR_LIT>" , start5 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start3 , len , start4 , len , start5 , len , start6 , len ) ; } public void _testDefaultParameters2 ( ) throws Exception { String contents = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; int start = contents . indexOf ( "<STR_LIT>" ) ; start = contents . indexOf ( "<STR_LIT>" , start + <NUM_LIT:1> ) ; int len = "<STR_LIT>" . length ( ) ; int start1 = start ; int start2 = contents . indexOf ( "<STR_LIT>" , start1 + <NUM_LIT:1> ) ; int start3 = contents . indexOf ( "<STR_LIT>" , start2 + <NUM_LIT:1> ) ; int start4 = contents . indexOf ( "<STR_LIT>" , start3 + <NUM_LIT:1> ) ; int start5 = contents . indexOf ( "<STR_LIT>" , start4 + <NUM_LIT:1> ) ; int start6 = contents . indexOf ( "<STR_LIT>" , start5 + <NUM_LIT:1> ) ; doTest ( contents , start , len , start1 , len , start2 , len , start5 , len , start6 , len ) ; } private void doTest ( String contents , int start , int length , int ... expected ) throws JavaModelException { GroovyCompilationUnit unit = createUnit ( "<STR_LIT>" , contents ) ; try { unit . becomeWorkingCopy ( null ) ; OccurrenceLocation [ ] actual = find ( unit , start , length ) ; assertOccurrences ( expected , actual ) ; } finally { unit . discardWorkingCopy ( ) ; } } private void assertOccurrences ( int [ ] expected , OccurrenceLocation [ ] actual ) { assertEquals ( "<STR_LIT>" + Arrays . toString ( expected ) + "<STR_LIT>" + printOccurrences ( actual ) , expected . length / <NUM_LIT:2> , actual . length ) ; for ( int i = <NUM_LIT:0> ; i < actual . length ; i ++ ) { assertEquals ( "<STR_LIT>" + i + "<STR_LIT>" + Arrays . toString ( expected ) + "<STR_LIT>" + printOccurrences ( actual ) , expected [ i * <NUM_LIT:2> ] , actual [ i ] . getOffset ( ) ) ; assertEquals ( "<STR_LIT>" + i + "<STR_LIT>" + Arrays . toString ( expected ) + "<STR_LIT>" + printOccurrences ( actual ) , expected [ i * <NUM_LIT:2> + <NUM_LIT:1> ] , actual [ i ] . getLength ( ) ) ; } } private String printOccurrences ( OccurrenceLocation [ ] os ) { StringBuilder sb = new StringBuilder ( ) ; for ( OccurrenceLocation o : os ) { sb . append ( o + "<STR_LIT:n>" ) ; } return sb . toString ( ) ; } private OccurrenceLocation [ ] find ( GroovyCompilationUnit unit , int start , int length ) { GroovyOccurrencesFinder finder = new GroovyOccurrencesFinder ( ) ; finder . setGroovyCompilationUnit ( unit ) ; finder . initialize ( null , start , length ) ; return finder . getOccurrences ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . tests ; import javax . swing . text . html . HTML ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . groovy . search . ITypeLookup ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . groovy . search . TypeLookupResult . TypeConfidence ; public class TestTypeLookup implements ITypeLookup { public TypeLookupResult lookupType ( Expression node , VariableScope scope , ClassNode objectExpressionType ) { return new TypeLookupResult ( ClassHelper . make ( HTML . class ) , VariableScope . VOID_CLASS_NODE , VariableScope . STRING_CLASS_NODE . getMethod ( "<STR_LIT>" , new Parameter [ <NUM_LIT:0> ] ) , TypeConfidence . LOOSELY_INFERRED , scope ) ; } public TypeLookupResult lookupType ( FieldNode node , VariableScope scope ) { return null ; } public TypeLookupResult lookupType ( MethodNode node , VariableScope scope ) { return null ; } public TypeLookupResult lookupType ( AnnotationNode node , VariableScope scope ) { return null ; } public TypeLookupResult lookupType ( ImportNode node , VariableScope scope ) { return null ; } public TypeLookupResult lookupType ( ClassNode node , VariableScope scope ) { return null ; } public TypeLookupResult lookupType ( Parameter node , VariableScope scope ) { return null ; } public void initialize ( GroovyCompilationUnit unit , VariableScope topLevelScope ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . junit . test ; import java . util . HashSet ; import java . util . Set ; import org . eclipse . core . internal . jobs . JobManager ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . jobs . Job ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . junit . launcher . JUnit3TestFinder ; public class JUnit3TestFinderTests extends JUnitTestCase { public JUnit3TestFinderTests ( ) { super ( JUnit3TestFinderTests . class . getName ( ) ) ; } public void testFinderWithSuite ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit3TestFinder ( ) . isTest ( type ) ) ; } public void testFinderOfSubclass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit3TestFinder ( ) . isTest ( type ) ) ; file = getFile ( projectPath , "<STR_LIT>" ) ; unit = JavaCore . createCompilationUnitFrom ( file ) ; type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertFalse ( "<STR_LIT>" , new JUnit3TestFinder ( ) . isTest ( type ) ) ; } public void testFinderOfNonPublicSubclass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit3TestFinder ( ) . isTest ( type ) ) ; file = getFile ( projectPath , "<STR_LIT>" ) ; unit = JavaCore . createCompilationUnitFrom ( file ) ; type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertFalse ( "<STR_LIT>" , new JUnit3TestFinder ( ) . isTest ( type ) ) ; } public void testFindAllTestSuites ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; Set < IType > testTypes = new HashSet < IType > ( ) ; IProject project = getProject ( projectPath ) ; new JUnit3TestFinder ( ) . findTestsInContainer ( JavaCore . create ( project ) , testTypes , new NullProgressMonitor ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , testTypes . size ( ) ) ; boolean testerFound = false ; boolean helloFound = false ; boolean hello2Found = false ; for ( IType type : testTypes ) { if ( type . getElementName ( ) . equals ( "<STR_LIT:Hello>" ) ) helloFound = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) hello2Found = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) testerFound = true ; } assertTrue ( "<STR_LIT>" , helloFound ) ; assertTrue ( "<STR_LIT>" , hello2Found ) ; assertTrue ( "<STR_LIT>" , testerFound ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . junit . test ; import java . util . HashSet ; import java . util . Set ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . internal . junit . JUnitPropertyTester ; import org . eclipse . jdt . internal . junit . launcher . JUnit4TestFinder ; public class JUnit4TestFinderTests extends JUnitTestCase { public JUnit4TestFinderTests ( ) { super ( JUnit4TestFinderTests . class . getName ( ) ) ; } public void testFinderWithSuite ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; } public void testFinderOfSubclass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; file = getFile ( projectPath , "<STR_LIT>" ) ; unit = JavaCore . createCompilationUnitFrom ( file ) ; type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertFalse ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; } public void testFinderOfNonPublicSubclass ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT:Hello>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; file = getFile ( projectPath , "<STR_LIT>" ) ; unit = JavaCore . createCompilationUnitFrom ( file ) ; type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertFalse ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; } public void testUsingTestAnnotation ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; } public void testUsingRunWithAnnotation ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; IFile file = getFile ( projectPath , "<STR_LIT>" ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; IType type = unit . getType ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , type . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new JUnit4TestFinder ( ) . isTest ( type ) ) ; } public void testFindAllTestSuites ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT:Hello>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; Set < IType > testTypes = new HashSet < IType > ( ) ; IProject project = getProject ( projectPath ) ; new JUnit4TestFinder ( ) . findTestsInContainer ( JavaCore . create ( project ) , testTypes , new NullProgressMonitor ( ) ) ; boolean testerFound = false ; boolean helloFound = false ; boolean hello2Found = false ; boolean hello3Found = false ; boolean t2Found = false ; boolean t3Found = false ; for ( IType type : testTypes ) { if ( type . getElementName ( ) . equals ( "<STR_LIT:Hello>" ) ) helloFound = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) hello2Found = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) hello3Found = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) t2Found = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) t3Found = true ; if ( type . getElementName ( ) . equals ( "<STR_LIT>" ) ) testerFound = true ; } assertTrue ( "<STR_LIT>" , helloFound ) ; assertTrue ( "<STR_LIT>" , hello2Found ) ; assertTrue ( "<STR_LIT>" , hello3Found ) ; assertTrue ( "<STR_LIT>" , t2Found ) ; assertTrue ( "<STR_LIT>" , t3Found ) ; assertTrue ( "<STR_LIT>" , testerFound ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:6> , testTypes . size ( ) ) ; } public void testFindTestWithExpectedException ( ) throws Exception { IPath projectPath = createGenericProject ( ) ; IPath root = projectPath . append ( "<STR_LIT:src>" ) ; IPath unitPath = env . addGroovyClass ( root , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; incrementalBuild ( projectPath ) ; expectingNoProblems ( ) ; ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( env . getWorkspace ( ) . getRoot ( ) . getFile ( unitPath ) ) ; boolean found = new JUnitPropertyTester ( ) . test ( unit , "<STR_LIT>" , new Object [ <NUM_LIT:0> ] , null ) ; assertTrue ( "<STR_LIT>" + unit , found ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . junit . test ; import junit . framework . Test ; import junit . framework . TestSuite ; public class AllJUnitTests { public static Test suite ( ) throws Exception { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; suite . addTestSuite ( JUnit3TestFinderTests . class ) ; suite . addTestSuite ( JUnit4TestFinderTests . class ) ; suite . addTestSuite ( MainMethodFinderTests . class ) ; return suite ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . junit . test ; 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 . tests . builder . BuilderTests ; import org . eclipse . jdt . core . tests . util . Util ; public class JUnitTestCase extends BuilderTests { public JUnitTestCase ( String name ) { super ( name ) ; } protected IPath createGenericProject ( ) throws Exception { IPath projectPath = env . addProject ( "<STR_LIT>" , "<STR_LIT>" ) ; env . removePackageFragmentRoot ( projectPath , "<STR_LIT>" ) ; env . addGroovyNature ( "<STR_LIT>" ) ; env . addExternalJars ( projectPath , Util . getJavaClassLibs ( ) ) ; env . addJUnitJar ( projectPath ) ; env . addPackageFragmentRoot ( projectPath , "<STR_LIT:src>" ) ; env . setOutputFolder ( projectPath , "<STR_LIT>" ) ; env . addGroovyJars ( projectPath ) ; fullBuild ( projectPath ) ; return projectPath ; } 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> ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . junit . test ; import org . codehaus . groovy . eclipse . ui . GroovyResourcePropertyTester ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . IPath ; public class GroovyResourcePropertyTests extends JUnitTestCase { public GroovyResourcePropertyTests ( ) { super ( "<STR_LIT>" ) ; } public void testNothing ( ) { System . out . println ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . astviews ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . editor . GroovyEditor ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IFile ; import org . eclipse . jdt . core . ElementChangedEvent ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IElementChangedListener ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaElementDelta ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . groovy . core . util . ContentTypeUtils ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . text . TextSelection ; import org . eclipse . jface . viewers . DoubleClickEvent ; import org . eclipse . jface . viewers . IDoubleClickListener ; import org . eclipse . jface . viewers . ISelection ; import org . eclipse . jface . viewers . IStructuredContentProvider ; import org . eclipse . jface . viewers . IStructuredSelection ; import org . eclipse . jface . viewers . ITreeContentProvider ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . TreeViewer ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . IPartListener ; import org . eclipse . ui . IWorkbenchPart ; import org . eclipse . ui . part . DrillDownAdapter ; import org . eclipse . ui . part . ViewPart ; import org . eclipse . ui . texteditor . ITextEditor ; public class ASTView extends ViewPart { private TreeViewer viewer ; private Action doubleClickAction ; private IEditorPart editor ; private IPartListener partListener ; private IElementChangedListener listener ; class ViewContentProvider implements IStructuredContentProvider , ITreeContentProvider { ITreeNode root ; public void inputChanged ( Viewer v , Object oldInput , Object newInput ) { } public void dispose ( ) { } public Object [ ] getElements ( Object inputElement ) { if ( ! ( inputElement instanceof ModuleNode ) ) { return new Object [ <NUM_LIT:0> ] ; } root = TreeNodeFactory . createTreeNode ( null , inputElement , "<STR_LIT>" ) ; Object [ ] children = root . getChildren ( ) ; return children ; } public Object getParent ( Object child ) { Object parent = ( ( ITreeNode ) child ) . getParent ( ) ; return parent ; } public Object [ ] getChildren ( Object parent ) { ITreeNode [ ] children = ( ( ITreeNode ) parent ) . getChildren ( ) ; return children ; } public boolean hasChildren ( Object parent ) { boolean has = ! ( ( ITreeNode ) parent ) . isLeaf ( ) ; return has ; } } class ViewLabelProvider extends LabelProvider { @ Override public String getText ( Object obj ) { return ( ( ITreeNode ) obj ) . getDisplayName ( ) ; } @ Override public Image getImage ( Object obj ) { return null ; } } public ASTView ( ) { } @ Override public void createPartControl ( Composite parent ) { viewer = new TreeViewer ( parent , SWT . MULTI | SWT . H_SCROLL | SWT . V_SCROLL ) ; new DrillDownAdapter ( viewer ) ; viewer . setContentProvider ( new ViewContentProvider ( ) ) ; viewer . setLabelProvider ( new ViewLabelProvider ( ) ) ; viewer . setSorter ( null ) ; viewer . setInput ( null ) ; makeActions ( ) ; hookDoubleClickAction ( ) ; hookGroovy ( ) ; } @ Override public void dispose ( ) { unhookGroovy ( ) ; super . dispose ( ) ; } private void hookGroovy ( ) { partListener = new IPartListener ( ) { public void partActivated ( IWorkbenchPart part ) { } public void partBroughtToTop ( IWorkbenchPart part ) { try { if ( part instanceof IEditorPart ) { IFile file = ( IFile ) ( ( IEditorPart ) part ) . getEditorInput ( ) . getAdapter ( IFile . class ) ; if ( file != null && ContentTypeUtils . isGroovyLikeFileName ( file . getName ( ) ) ) { ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; if ( unit instanceof GroovyCompilationUnit ) { if ( editor != part ) { editor = ( IEditorPart ) part ; Object [ ] treePaths = viewer . getExpandedElements ( ) ; viewer . setInput ( ( ( GroovyCompilationUnit ) unit ) . getModuleNode ( ) ) ; viewer . setExpandedElements ( treePaths ) ; } else { } return ; } } } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } editor = null ; if ( viewer . getContentProvider ( ) != null ) { viewer . setInput ( null ) ; } } public void partClosed ( IWorkbenchPart part ) { } public void partDeactivated ( IWorkbenchPart part ) { } public void partOpened ( IWorkbenchPart part ) { } } ; getSite ( ) . getPage ( ) . addPartListener ( partListener ) ; if ( getSite ( ) . getPage ( ) . getActiveEditor ( ) instanceof GroovyEditor ) { partListener . partBroughtToTop ( getSite ( ) . getPage ( ) . getActiveEditor ( ) ) ; } listener = new IElementChangedListener ( ) { public void elementChanged ( ElementChangedEvent event ) { if ( editor == null ) { return ; } IJavaElementDelta delta = event . getDelta ( ) ; IFile file = ( IFile ) editor . getEditorInput ( ) . getAdapter ( IFile . class ) ; final GroovyCompilationUnit unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; if ( isUnitInDelta ( delta , unit ) ) { Display . getDefault ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { Object [ ] treePaths = viewer . getExpandedElements ( ) ; viewer . setInput ( unit . getModuleNode ( ) ) ; viewer . setExpandedElements ( treePaths ) ; } } ) ; } } private boolean isUnitInDelta ( IJavaElementDelta delta , GroovyCompilationUnit unit ) { IJavaElement elt = delta . getElement ( ) ; if ( elt . getElementType ( ) == IJavaElement . COMPILATION_UNIT ) { if ( elt . getElementName ( ) . equals ( unit . getElementName ( ) ) ) { return true ; } else { return false ; } } ICompilationUnit candidateUnit = ( ICompilationUnit ) elt . getAncestor ( IJavaElement . COMPILATION_UNIT ) ; if ( candidateUnit != null ) { if ( candidateUnit . getElementName ( ) . equals ( unit . getElementName ( ) ) ) { return true ; } else { return false ; } } IJavaElementDelta [ ] deltas = delta . getAffectedChildren ( ) ; if ( deltas != null ) { for ( IJavaElementDelta delta2 : deltas ) { if ( isUnitInDelta ( delta2 , unit ) ) { return true ; } } } return false ; } } ; JavaCore . addElementChangedListener ( listener , ElementChangedEvent . POST_RECONCILE ) ; } private void unhookGroovy ( ) { JavaCore . removeElementChangedListener ( listener ) ; getSite ( ) . getPage ( ) . removePartListener ( partListener ) ; } private void makeActions ( ) { doubleClickAction = new Action ( ) { @ Override public void run ( ) { ISelection selection = viewer . getSelection ( ) ; Object obj = ( ( IStructuredSelection ) selection ) . getFirstElement ( ) ; if ( obj == null ) { return ; } if ( ( ( ITreeNode ) obj ) . getValue ( ) instanceof ASTNode ) { Object value = ( ( ITreeNode ) obj ) . getValue ( ) ; if ( ! ( value instanceof ASTNode ) ) { return ; } ASTNode node = ( ASTNode ) value ; if ( node . getLineNumber ( ) != - <NUM_LIT:1> ) { int offset0 = node . getStart ( ) ; int offset1 = node . getEnd ( ) ; if ( editor instanceof ITextEditor ) { ( ( ITextEditor ) editor ) . getSelectionProvider ( ) . setSelection ( new TextSelection ( offset0 , offset1 - offset0 ) ) ; } } } } } ; } private void hookDoubleClickAction ( ) { viewer . addDoubleClickListener ( new IDoubleClickListener ( ) { public void doubleClick ( DoubleClickEvent event ) { doubleClickAction . run ( ) ; } } ) ; } @ Override public void setFocus ( ) { viewer . getControl ( ) . setFocus ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . astviews ; import org . eclipse . jface . resource . ImageDescriptor ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class Activator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static Activator plugin ; public Activator ( ) { 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 Activator getDefault ( ) { return plugin ; } public static ImageDescriptor getImageDescriptor ( String path ) { return imageDescriptorFromPlugin ( PLUGIN_ID , path ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . selection ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassCodeVisitorSupport ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . expr . ArgumentListExpression ; import org . codehaus . groovy . ast . expr . ArrayExpression ; import org . codehaus . groovy . ast . expr . AttributeExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . BitwiseNegationExpression ; import org . codehaus . groovy . ast . expr . BooleanExpression ; import org . codehaus . groovy . ast . expr . CastExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . ast . expr . ClosureListExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . ConstructorCallExpression ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . ElvisOperatorExpression ; import org . codehaus . groovy . ast . expr . FieldExpression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . ast . expr . ListExpression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . NotExpression ; import org . codehaus . groovy . ast . expr . PostfixExpression ; import org . codehaus . groovy . ast . expr . PrefixExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . RangeExpression ; import org . codehaus . groovy . ast . expr . SpreadExpression ; import org . codehaus . groovy . ast . expr . SpreadMapExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . TernaryExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . ast . expr . UnaryMinusExpression ; import org . codehaus . groovy . ast . expr . UnaryPlusExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . classgen . BytecodeExpression ; import org . codehaus . groovy . control . SourceUnit ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . ASTFragmentFactory ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . ASTFragmentKind ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . FragmentVisitor ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . MethodCallFragment ; public class FindAllOccurrencesVisitor extends ClassCodeVisitorSupport { class FragmentMatcherVisitor extends FragmentVisitor { private boolean matchWasFound = false ; @ Override public boolean previsit ( IASTFragment fragment ) { IASTFragment matched = fragment . findMatchingSubFragment ( toFind ) ; if ( matched . kind ( ) != ASTFragmentKind . EMPTY ) { occurrences . add ( matched ) ; matchWasFound = true ; } return fragment . kind ( ) == ASTFragmentKind . BINARY ; } boolean matchWasFound ( ) { boolean b = matchWasFound ; matchWasFound = false ; return b ; } } class AssociatedExpressionMatcher extends FragmentVisitor { boolean ignoreNext = false ; @ Override public boolean previsit ( IASTFragment fragment ) { if ( ! ignoreNext ) { fragment . getAssociatedExpression ( ) . visit ( FindAllOccurrencesVisitor . this ) ; } else { ignoreNext = false ; } return true ; } @ Override public boolean visit ( MethodCallFragment fragment ) { fragment . getArguments ( ) . visit ( FindAllOccurrencesVisitor . this ) ; return true ; } } private IASTFragment toFind ; private List < IASTFragment > occurrences ; private ModuleNode module ; private AnnotatedNode limitTo ; private ASTFragmentFactory factory ; private FragmentMatcherVisitor fragmentMatcher ; private AssociatedExpressionMatcher associatedExpressionMatcher ; public FindAllOccurrencesVisitor ( ModuleNode module ) { this ( module , null ) ; } public FindAllOccurrencesVisitor ( ModuleNode module , AnnotatedNode limitTo ) { this . limitTo = limitTo ; this . module = module ; this . factory = new ASTFragmentFactory ( ) ; this . fragmentMatcher = new FragmentMatcherVisitor ( ) ; this . associatedExpressionMatcher = new AssociatedExpressionMatcher ( ) ; } @ Override protected SourceUnit getSourceUnit ( ) { return null ; } public List < IASTFragment > findOccurrences ( IASTFragment fragment ) { this . toFind = fragment ; this . occurrences = new ArrayList < IASTFragment > ( ) ; if ( limitTo == null ) { List < ClassNode > classes = module . getClasses ( ) ; for ( ClassNode classNode : classes ) { visitClass ( classNode ) ; } } else { if ( limitTo instanceof ClassNode ) { visitClass ( ( ClassNode ) limitTo ) ; } else if ( limitTo instanceof MethodNode ) { visitMethod ( ( MethodNode ) limitTo ) ; } else if ( limitTo instanceof FieldNode ) { visitField ( ( FieldNode ) limitTo ) ; } else { limitTo . visit ( this ) ; } } return this . occurrences ; } @ Override protected void visitConstructorOrMethod ( MethodNode node , boolean isConstructor ) { if ( node . getEnd ( ) == <NUM_LIT:0> && ! node . getName ( ) . equals ( "<STR_LIT>" ) ) { return ; } super . visitConstructorOrMethod ( node , isConstructor ) ; } @ Override public void visitField ( FieldNode node ) { if ( node . getEnd ( ) == <NUM_LIT:0> ) { return ; } super . visitField ( node ) ; } @ Override public void visitProperty ( PropertyNode node ) { } @ Override public void visitArgumentlistExpression ( ArgumentListExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitArgumentlistExpression ( expression ) ; } @ Override public void visitArrayExpression ( ArrayExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitArrayExpression ( expression ) ; } @ Override public void visitAttributeExpression ( AttributeExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitAttributeExpression ( expression ) ; } @ Override public void visitBinaryExpression ( BinaryExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; associatedExpressionMatcher . ignoreNext = false ; fragment . accept ( associatedExpressionMatcher ) ; } @ Override public void visitBitwiseNegationExpression ( BitwiseNegationExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitBitwiseNegationExpression ( expression ) ; } @ Override public void visitBooleanExpression ( BooleanExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitBooleanExpression ( expression ) ; } @ Override public void visitBytecodeExpression ( BytecodeExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitBytecodeExpression ( expression ) ; } @ Override public void visitCastExpression ( CastExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitCastExpression ( expression ) ; } @ Override public void visitClassExpression ( ClassExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitClassExpression ( expression ) ; } @ Override public void visitClosureExpression ( ClosureExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitClosureExpression ( expression ) ; } @ Override public void visitClosureListExpression ( ClosureListExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitClosureListExpression ( expression ) ; } @ Override public void visitConstantExpression ( ConstantExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitConstantExpression ( expression ) ; } @ Override public void visitConstructorCallExpression ( ConstructorCallExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitConstructorCallExpression ( expression ) ; } @ Override public void visitDeclarationExpression ( DeclarationExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitDeclarationExpression ( expression ) ; } @ Override public void visitVariableExpression ( VariableExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitVariableExpression ( expression ) ; } @ Override public void visitFieldExpression ( FieldExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitFieldExpression ( expression ) ; } @ Override public void visitGStringExpression ( GStringExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitGStringExpression ( expression ) ; } @ Override public void visitListExpression ( ListExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitListExpression ( expression ) ; } @ Override public void visitMapEntryExpression ( MapEntryExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitMapEntryExpression ( expression ) ; } @ Override public void visitMapExpression ( MapExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitMapExpression ( expression ) ; } @ Override public void visitMethodCallExpression ( MethodCallExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; associatedExpressionMatcher . ignoreNext = true ; fragment . accept ( associatedExpressionMatcher ) ; } @ Override public void visitMethodPointerExpression ( MethodPointerExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; associatedExpressionMatcher . ignoreNext = true ; fragment . accept ( associatedExpressionMatcher ) ; } @ Override public void visitNotExpression ( NotExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitNotExpression ( expression ) ; } @ Override public void visitPostfixExpression ( PostfixExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitPostfixExpression ( expression ) ; } @ Override public void visitPrefixExpression ( PrefixExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitPrefixExpression ( expression ) ; } @ Override public void visitPropertyExpression ( PropertyExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; associatedExpressionMatcher . ignoreNext = true ; fragment . accept ( associatedExpressionMatcher ) ; } @ Override public void visitRangeExpression ( RangeExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitRangeExpression ( expression ) ; } @ Override public void visitShortTernaryExpression ( ElvisOperatorExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitShortTernaryExpression ( expression ) ; } @ Override public void visitSpreadExpression ( SpreadExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitSpreadExpression ( expression ) ; } @ Override public void visitSpreadMapExpression ( SpreadMapExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitSpreadMapExpression ( expression ) ; } @ Override public void visitStaticMethodCallExpression ( StaticMethodCallExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitStaticMethodCallExpression ( expression ) ; } @ Override public void visitTernaryExpression ( TernaryExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitTernaryExpression ( expression ) ; } @ Override public void visitTupleExpression ( TupleExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitTupleExpression ( expression ) ; } @ Override public void visitUnaryMinusExpression ( UnaryMinusExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitUnaryMinusExpression ( expression ) ; } @ Override public void visitUnaryPlusExpression ( UnaryPlusExpression expression ) { IASTFragment fragment = factory . createFragment ( expression ) ; fragment . accept ( fragmentMatcher ) ; if ( ! fragmentMatcher . matchWasFound ( ) ) super . visitUnaryPlusExpression ( expression ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . selection ; import java . util . Stack ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . ImportNodeCompatibilityWrapper ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . PackageNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . expr . ArgumentListExpression ; import org . codehaus . groovy . ast . expr . ArrayExpression ; import org . codehaus . groovy . ast . expr . AttributeExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . BitwiseNegationExpression ; import org . codehaus . groovy . ast . expr . BooleanExpression ; import org . codehaus . groovy . ast . expr . CastExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . ast . expr . ClosureListExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . ConstructorCallExpression ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . ElvisOperatorExpression ; import org . codehaus . groovy . ast . expr . FieldExpression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . ast . expr . ListExpression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . NotExpression ; import org . codehaus . groovy . ast . expr . PostfixExpression ; import org . codehaus . groovy . ast . expr . PrefixExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . RangeExpression ; import org . codehaus . groovy . ast . expr . SpreadExpression ; import org . codehaus . groovy . ast . expr . SpreadMapExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . TernaryExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . ast . expr . UnaryMinusExpression ; import org . codehaus . groovy . ast . expr . UnaryPlusExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . ast . stmt . AssertStatement ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . ast . stmt . BreakStatement ; import org . codehaus . groovy . ast . stmt . CaseStatement ; import org . codehaus . groovy . ast . stmt . CatchStatement ; import org . codehaus . groovy . ast . stmt . ContinueStatement ; import org . codehaus . groovy . ast . stmt . DoWhileStatement ; import org . codehaus . groovy . ast . stmt . EmptyStatement ; import org . codehaus . groovy . ast . stmt . ExpressionStatement ; import org . codehaus . groovy . ast . stmt . ForStatement ; import org . codehaus . groovy . ast . stmt . IfStatement ; import org . codehaus . groovy . ast . stmt . ReturnStatement ; import org . codehaus . groovy . ast . stmt . SwitchStatement ; import org . codehaus . groovy . ast . stmt . SynchronizedStatement ; import org . codehaus . groovy . ast . stmt . ThrowStatement ; import org . codehaus . groovy . ast . stmt . TryCatchStatement ; import org . codehaus . groovy . ast . stmt . WhileStatement ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . ASTFragmentFactory ; import org . codehaus . groovy . eclipse . codebrowsing . fragments . IASTFragment ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . core . util . VisitCompleteException ; import org . eclipse . core . runtime . Assert ; public class FindSurroundingNode extends ASTNodeFinder { public static enum VisitKind { SURROUNDING_NODE , EXTRA_EXPAND , PARENT_STACK } private final VisitKind visitKind ; private Stack < IASTFragment > nodeStack ; private ASTFragmentFactory factory ; private MethodNode runMethod ; public FindSurroundingNode ( Region r ) { this ( r , VisitKind . EXTRA_EXPAND ) ; } public FindSurroundingNode ( Region r , VisitKind visitKind ) { super ( r ) ; nodeStack = new Stack < IASTFragment > ( ) ; this . visitKind = visitKind ; factory = new ASTFragmentFactory ( ) ; } public IASTFragment doVisitSurroundingNode ( ModuleNode module ) { nodeStack . push ( factory . createFragment ( module ) ) ; ASTNode node = super . doVisit ( module ) ; if ( node == null && runMethod != null ) { try { internalVisitConstructorOrMethod ( runMethod , false ) ; } catch ( VisitCompleteException e ) { } } IASTFragment maybeNode = factory . createFragment ( node ) ; if ( visitKind != VisitKind . PARENT_STACK ) { while ( ! nodeStack . isEmpty ( ) ) { maybeNode = nodeStack . peek ( ) ; if ( maybeNode . getEnd ( ) == <NUM_LIT:0> || ( visitKind == VisitKind . EXTRA_EXPAND && super . getRegion ( ) . isSame ( maybeNode ) ) ) { nodeStack . pop ( ) ; } else { break ; } } } return nodeStack . isEmpty ( ) ? maybeNode : nodeStack . peek ( ) ; } @ Override public ASTNode doVisit ( ModuleNode module ) { Assert . isLegal ( false , "<STR_LIT>" ) ; return super . doVisit ( module ) ; } public Stack < IASTFragment > getParentStack ( ) { return nodeStack ; } protected void reset ( ) { nodeStack . clear ( ) ; runMethod = null ; } @ Override public void visitAnnotations ( AnnotatedNode node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitAnnotations ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitAssertStatement ( AssertStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitAssertStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitBlockStatement ( BlockStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitBlockStatement ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitBreakStatement ( BreakStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitBreakStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitCaseStatement ( CaseStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitCaseStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitContinueStatement ( ContinueStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitContinueStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitDoWhileLoop ( DoWhileStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitDoWhileLoop ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitExpressionStatement ( ExpressionStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitExpressionStatement ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitIfElse ( IfStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitIfElse ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitPackage ( PackageNode node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitPackage ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitImports ( ModuleNode module ) { for ( ImportNode importNode : new ImportNodeCompatibilityWrapper ( module ) . getAllImportNodes ( ) ) { if ( importNode . getType ( ) != null ) { nodeStack . push ( factory . createFragment ( importNode ) ) ; check ( importNode . getType ( ) ) ; nodeStack . pop ( ) ; } } } @ Override public void visitSwitch ( SwitchStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitSwitch ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitSynchronizedStatement ( SynchronizedStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitSynchronizedStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitThrowStatement ( ThrowStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitThrowStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitTryCatchFinally ( TryCatchStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitTryCatchFinally ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitWhileLoop ( WhileStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitWhileLoop ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitArgumentlistExpression ( ArgumentListExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitArgumentlistExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitAttributeExpression ( AttributeExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitAttributeExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitBinaryExpression ( BinaryExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; if ( getRegion ( ) . regionIsCoveredByNode ( node ) ) { nodeStack . push ( factory . createFragment ( node , getRegion ( ) . getOffset ( ) , getRegion ( ) . getEnd ( ) ) ) ; } super . visitBinaryExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitBitwiseNegationExpression ( BitwiseNegationExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitBitwiseNegationExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitBooleanExpression ( BooleanExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; if ( ! isColocated ( node . getExpression ( ) , node ) ) { check ( node ) ; } super . visitBooleanExpression ( node ) ; nodeStack . pop ( ) ; } private boolean isColocated ( ASTNode node1 , ASTNode node2 ) { return node1 . getStart ( ) == node2 . getStart ( ) && node1 . getEnd ( ) == node2 . getEnd ( ) ; } @ Override public void visitClosureListExpression ( ClosureListExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitClosureListExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } protected void visitEmptyStatement ( EmptyStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitListExpression ( ListExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitListExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitMapEntryExpression ( MapEntryExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitMapEntryExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitMapExpression ( MapExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitMapExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitMethodCallExpression ( MethodCallExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; if ( getRegion ( ) . regionIsCoveredByNode ( node ) ) { nodeStack . push ( factory . createFragment ( node , getRegion ( ) . getOffset ( ) , getRegion ( ) . getEnd ( ) ) ) ; } super . visitMethodCallExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitMethodPointerExpression ( MethodPointerExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; if ( getRegion ( ) . regionIsCoveredByNode ( node ) ) { nodeStack . push ( factory . createFragment ( node , getRegion ( ) . getOffset ( ) , getRegion ( ) . getEnd ( ) ) ) ; } super . visitMethodPointerExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitNotExpression ( NotExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitNotExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitPostfixExpression ( PostfixExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitPostfixExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitPrefixExpression ( PrefixExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitPrefixExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitPropertyExpression ( PropertyExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitPropertyExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitRangeExpression ( RangeExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitRangeExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitShortTernaryExpression ( ElvisOperatorExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitShortTernaryExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitSpreadExpression ( SpreadExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitSpreadExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitSpreadMapExpression ( SpreadMapExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitSpreadMapExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitTernaryExpression ( TernaryExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitTernaryExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitTupleExpression ( TupleExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitTupleExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitUnaryMinusExpression ( UnaryMinusExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitUnaryMinusExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitUnaryPlusExpression ( UnaryPlusExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitUnaryPlusExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitArrayExpression ( ArrayExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitArrayExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitCastExpression ( CastExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitCastExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitCatchStatement ( CatchStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitCatchStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitClass ( ClassNode node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitClass ( node ) ; if ( ! node . isScript ( ) ) { check ( node ) ; } nodeStack . pop ( ) ; } @ Override public void visitClassExpression ( ClassExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitClassExpression ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitClosureExpression ( ClosureExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitClosureExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitConstantExpression ( ConstantExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitConstantExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitConstructorCallExpression ( ConstructorCallExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitConstructorCallExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override protected void visitConstructorOrMethod ( MethodNode node , boolean isConstructor ) { if ( isRunMethod ( node ) ) { runMethod = node ; return ; } internalVisitConstructorOrMethod ( node , isConstructor ) ; } private void internalVisitConstructorOrMethod ( MethodNode node , boolean isConstructor ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitConstructorOrMethod ( node , isConstructor ) ; check ( node ) ; nodeStack . pop ( ) ; } private boolean isRunMethod ( MethodNode node ) { return node . getDeclaringClass ( ) . isScript ( ) && node . getName ( ) . equals ( "<STR_LIT>" ) && ( node . getParameters ( ) == null || node . getParameters ( ) . length == <NUM_LIT:0> ) ; } @ Override public void visitDeclarationExpression ( DeclarationExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; if ( getRegion ( ) . regionIsCoveredByNode ( node ) ) { nodeStack . push ( factory . createFragment ( node , getRegion ( ) . getOffset ( ) , getRegion ( ) . getEnd ( ) ) ) ; } super . visitDeclarationExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitField ( FieldNode node ) { if ( node . getName ( ) . startsWith ( "<STR_LIT:$>" ) ) { return ; } nodeStack . push ( factory . createFragment ( node ) ) ; super . visitField ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitProperty ( PropertyNode node ) { } @ Override public void visitFieldExpression ( FieldExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitFieldExpression ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitForLoop ( ForStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitForLoop ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitGStringExpression ( GStringExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitGStringExpression ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitReturnStatement ( ReturnStatement node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitReturnStatement ( node ) ; check ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitStaticMethodCallExpression ( StaticMethodCallExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitStaticMethodCallExpression ( node ) ; nodeStack . pop ( ) ; } @ Override public void visitVariableExpression ( VariableExpression node ) { nodeStack . push ( factory . createFragment ( node ) ) ; super . visitVariableExpression ( node ) ; nodeStack . pop ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . selection ; import java . util . Iterator ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . expr . ArgumentListExpression ; import org . codehaus . groovy . ast . expr . ArrayExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . BitwiseNegationExpression ; import org . codehaus . groovy . ast . expr . BooleanExpression ; import org . codehaus . groovy . ast . expr . CastExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . ConstructorCallExpression ; import org . codehaus . groovy . ast . expr . EmptyExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . FieldExpression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . ast . expr . ListExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . PostfixExpression ; import org . codehaus . groovy . ast . expr . PrefixExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . RangeExpression ; import org . codehaus . groovy . ast . expr . SpreadExpression ; import org . codehaus . groovy . ast . expr . SpreadMapExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . TernaryExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . ast . expr . UnaryMinusExpression ; import org . codehaus . groovy . ast . expr . UnaryPlusExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; public class IsSameExpression { public boolean isSame ( Expression left , Expression right ) { if ( left == null && right == null ) { return true ; } if ( left == null || right == null ) { return false ; } if ( handleSpecialCases ( left , right ) ) { return true ; } if ( left . getClass ( ) != right . getClass ( ) ) { return false ; } if ( left instanceof ArgumentListExpression ) { return visit ( ( ArgumentListExpression ) left , ( ArgumentListExpression ) right ) ; } else if ( left instanceof ArrayExpression ) { return visit ( ( ArrayExpression ) left , ( ArrayExpression ) right ) ; } else if ( left instanceof BinaryExpression ) { return visit ( ( BinaryExpression ) left , ( BinaryExpression ) right ) ; } else if ( left instanceof BitwiseNegationExpression ) { return visit ( ( BitwiseNegationExpression ) left , ( BitwiseNegationExpression ) right ) ; } else if ( left instanceof BooleanExpression ) { return visit ( ( BooleanExpression ) left , ( BooleanExpression ) right ) ; } else if ( left instanceof CastExpression ) { return visit ( ( CastExpression ) left , ( CastExpression ) right ) ; } else if ( left instanceof ClassExpression ) { return visit ( ( ClassExpression ) left , ( ClassExpression ) right ) ; } else if ( left instanceof ClosureExpression ) { return visit ( ( ClosureExpression ) left , ( ClosureExpression ) right ) ; } else if ( left instanceof ConstantExpression ) { return visit ( ( ConstantExpression ) left , ( ConstantExpression ) right ) ; } else if ( left instanceof ConstructorCallExpression ) { return visit ( ( ConstructorCallExpression ) left , ( ConstructorCallExpression ) right ) ; } else if ( left instanceof EmptyExpression ) { return visit ( ( EmptyExpression ) left , ( EmptyExpression ) right ) ; } else if ( left instanceof FieldExpression ) { return visit ( ( FieldExpression ) left , ( FieldExpression ) right ) ; } else if ( left instanceof GStringExpression ) { return visit ( ( GStringExpression ) left , ( GStringExpression ) right ) ; } else if ( left instanceof ListExpression ) { return visit ( ( ListExpression ) left , ( ListExpression ) right ) ; } else if ( left instanceof MapExpression ) { return visit ( ( MapExpression ) left , ( MapExpression ) right ) ; } else if ( left instanceof MethodCallExpression ) { return visit ( ( MethodCallExpression ) left , ( MethodCallExpression ) right ) ; } else if ( left instanceof MethodPointerExpression ) { return visit ( ( MethodPointerExpression ) left , ( MethodPointerExpression ) right ) ; } else if ( left instanceof PostfixExpression ) { return visit ( ( PostfixExpression ) left , ( PostfixExpression ) right ) ; } else if ( left instanceof PrefixExpression ) { return visit ( ( PrefixExpression ) left , ( PrefixExpression ) right ) ; } else if ( left instanceof PropertyExpression ) { return visit ( ( PropertyExpression ) left , ( PropertyExpression ) right ) ; } else if ( left instanceof RangeExpression ) { return visit ( ( RangeExpression ) left , ( RangeExpression ) right ) ; } else if ( left instanceof SpreadExpression ) { return visit ( ( SpreadExpression ) left , ( SpreadExpression ) right ) ; } else if ( left instanceof SpreadMapExpression ) { return visit ( ( SpreadMapExpression ) left , ( SpreadMapExpression ) right ) ; } else if ( left instanceof StaticMethodCallExpression ) { return visit ( ( StaticMethodCallExpression ) left , ( StaticMethodCallExpression ) right ) ; } else if ( left instanceof TernaryExpression ) { return visit ( ( TernaryExpression ) left , ( TernaryExpression ) right ) ; } else if ( left instanceof TupleExpression ) { return visit ( ( TupleExpression ) left , ( TupleExpression ) right ) ; } else if ( left instanceof UnaryMinusExpression ) { return visit ( ( UnaryMinusExpression ) left , ( UnaryMinusExpression ) right ) ; } else if ( left instanceof UnaryPlusExpression ) { return visit ( ( UnaryPlusExpression ) left , ( UnaryPlusExpression ) right ) ; } else if ( left instanceof VariableExpression ) { return visit ( ( VariableExpression ) left , ( VariableExpression ) right ) ; } else { return false ; } } private boolean handleSpecialCases ( Expression left , Expression right ) { if ( left instanceof ConstantExpression && right instanceof ClassExpression ) { return right . getType ( ) . getName ( ) . equals ( ( ( ConstantExpression ) left ) . getValue ( ) ) ; } else if ( left instanceof ClassExpression && right instanceof ConstantExpression ) { return left . getType ( ) . getName ( ) . equals ( ( ( ConstantExpression ) right ) . getValue ( ) ) ; } return false ; } private boolean visit ( VariableExpression left , VariableExpression right ) { return left . getName ( ) . equals ( right . getName ( ) ) ; } private boolean visit ( UnaryPlusExpression left , UnaryPlusExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( UnaryMinusExpression left , UnaryMinusExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( TupleExpression left , TupleExpression right ) { return checkExpressionList ( left . getExpressions ( ) , right . getExpressions ( ) ) ; } private boolean visit ( TernaryExpression left , TernaryExpression right ) { return isSame ( left . getBooleanExpression ( ) , right . getBooleanExpression ( ) ) && isSame ( left . getTrueExpression ( ) , right . getTrueExpression ( ) ) && isSame ( left . getFalseExpression ( ) , right . getFalseExpression ( ) ) ; } private boolean visit ( StaticMethodCallExpression left , StaticMethodCallExpression right ) { return visit ( left . getType ( ) , right . getType ( ) ) && left . getMethod ( ) . equals ( right . getMethod ( ) ) && isSame ( left . getArguments ( ) , right . getArguments ( ) ) ; } private boolean visit ( SpreadExpression left , SpreadExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( SpreadMapExpression left , SpreadMapExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( RangeExpression left , RangeExpression right ) { return isSame ( left . getFrom ( ) , right . getFrom ( ) ) && isSame ( left . getTo ( ) , right . getTo ( ) ) ; } private boolean visit ( PropertyExpression left , PropertyExpression right ) { return isSame ( left . getObjectExpression ( ) , right . getObjectExpression ( ) ) && isSame ( left . getProperty ( ) , right . getProperty ( ) ) ; } private boolean visit ( PrefixExpression left , PrefixExpression right ) { return nullEquals ( left . getOperation ( ) , ( right . getOperation ( ) ) ) && isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( PostfixExpression left , PostfixExpression right ) { return nullEquals ( left . getOperation ( ) , ( right . getOperation ( ) ) ) && isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( MethodPointerExpression left , MethodPointerExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) && isSame ( left . getMethodName ( ) , right . getMethodName ( ) ) ; } private boolean visit ( MethodCallExpression left , MethodCallExpression right ) { return isSame ( left . getObjectExpression ( ) , right . getObjectExpression ( ) ) && isSame ( left . getMethod ( ) , right . getMethod ( ) ) && isSame ( left . getArguments ( ) , right . getArguments ( ) ) ; } private boolean visit ( MapExpression left , MapExpression right ) { return checkExpressionList ( left . getMapEntryExpressions ( ) , right . getMapEntryExpressions ( ) ) ; } private boolean visit ( ListExpression left , ListExpression right ) { return checkExpressionList ( left . getExpressions ( ) , right . getExpressions ( ) ) ; } private boolean visit ( GStringExpression left , GStringExpression right ) { return checkExpressionList ( left . getStrings ( ) , right . getStrings ( ) ) && checkExpressionList ( left . getValues ( ) , right . getValues ( ) ) ; } private boolean visit ( FieldExpression left , FieldExpression right ) { return visit ( left . getField ( ) . getDeclaringClass ( ) , right . getField ( ) . getDeclaringClass ( ) ) && nullEquals ( left . getFieldName ( ) , right . getFieldName ( ) ) ; } private boolean visit ( EmptyExpression left , EmptyExpression right ) { return true ; } private boolean visit ( ConstructorCallExpression left , ConstructorCallExpression right ) { return visit ( left . getType ( ) , right . getType ( ) ) && isSame ( left . getArguments ( ) , right . getArguments ( ) ) ; } private boolean visit ( ConstantExpression left , ConstantExpression right ) { return nullEquals ( left . getText ( ) , right . getText ( ) ) ; } private boolean visit ( ClosureExpression left , ClosureExpression right ) { return false ; } private boolean visit ( ClassExpression left , ClassExpression right ) { return visit ( left . getType ( ) , right . getType ( ) ) ; } private boolean visit ( CastExpression left , CastExpression right ) { return visit ( left . getType ( ) , right . getType ( ) ) && isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( BooleanExpression left , BooleanExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( BitwiseNegationExpression left , BitwiseNegationExpression right ) { return isSame ( left . getExpression ( ) , right . getExpression ( ) ) ; } private boolean visit ( BinaryExpression left , BinaryExpression right ) { return left . getOperation ( ) . getType ( ) == right . getOperation ( ) . getType ( ) && isSame ( left . getLeftExpression ( ) , right . getLeftExpression ( ) ) && isSame ( left . getRightExpression ( ) , right . getRightExpression ( ) ) ; } private boolean visit ( ArrayExpression left , ArrayExpression right ) { return checkExpressionList ( left . getExpressions ( ) , right . getExpressions ( ) ) && checkExpressionList ( left . getSizeExpression ( ) , right . getSizeExpression ( ) ) ; } private boolean visit ( ClassNode left , ClassNode right ) { return nullEquals ( left , right ) ; } private boolean nullEquals ( Object left , Object right ) { if ( left == null && right == null ) { return true ; } else if ( left == null || right == null ) { return false ; } else { return left . equals ( right ) ; } } private < T extends Expression > boolean checkExpressionList ( List < T > left , List < T > right ) { if ( right == null && left == null ) { return true ; } else if ( right == null || left == null ) { return false ; } else if ( left . size ( ) != right . size ( ) ) { return false ; } Iterator < T > leftIter = left . iterator ( ) ; Iterator < T > rightIter = right . iterator ( ) ; boolean success = true ; while ( leftIter . hasNext ( ) && rightIter . hasNext ( ) ) { success &= isSame ( leftIter . next ( ) , rightIter . next ( ) ) ; } return success ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing ; import org . eclipse . core . runtime . Plugin ; public class GroovyBrowsingPlugin extends Plugin { private static GroovyBrowsingPlugin plugin ; public GroovyBrowsingPlugin ( ) { plugin = this ; } public static GroovyBrowsingPlugin getDefault ( ) { return plugin ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . selection . IsSameExpression ; import org . codehaus . groovy . syntax . Token ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . Assert ; public class BinaryExpressionFragment implements IASTFragment { private final Token token ; private final Expression expression ; private final IASTFragment next ; private int actualStartPosition ; BinaryExpressionFragment ( Token token , Expression expression , IASTFragment next ) { Assert . isNotNull ( next ) ; this . token = token ; this . expression = expression ; this . next = next ; this . actualStartPosition = expression . getStart ( ) ; } void setActualStartPosition ( int actualStartPosition ) { this . actualStartPosition = actualStartPosition ; } public Expression getAssociatedExpression ( ) { return expression ; } public ASTNode getAssociatedNode ( ) { return expression ; } public int getEnd ( ) { return getNext ( ) . getEnd ( ) ; } public int getStart ( ) { return actualStartPosition ; } public int getLength ( ) { return getEnd ( ) - getStart ( ) ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { return getNext ( ) . getTrimmedEnd ( unit ) ; } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public Token getToken ( ) { return token ; } public IASTFragment getNext ( ) { return next ; } public boolean matches ( IASTFragment other ) { if ( ! ( other instanceof BinaryExpressionFragment ) ) { return false ; } BinaryExpressionFragment otherBinary = ( BinaryExpressionFragment ) other ; return otherBinary . getToken ( ) . getText ( ) . equals ( this . token . getText ( ) ) && new IsSameExpression ( ) . isSame ( expression , otherBinary . getAssociatedExpression ( ) ) && this . next . matches ( otherBinary . getNext ( ) ) ; } @ Override public String toString ( ) { return print ( <NUM_LIT:0> ) ; } public String print ( int indentLvl ) { return ASTFragmentFactory . spaces ( indentLvl ) + "<STR_LIT>" + expression . toString ( ) + "<STR_LIT:n>" + next . print ( indentLvl + <NUM_LIT:1> ) ; } public int fragmentLength ( ) { return <NUM_LIT:1> + next . fragmentLength ( ) ; } public void accept ( FragmentVisitor visitor ) { if ( visitor . previsit ( this ) && visitor . visit ( this ) ) { next . accept ( visitor ) ; } } public ASTFragmentKind kind ( ) { return ASTFragmentKind . BINARY ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { if ( this . fragmentLength ( ) < other . fragmentLength ( ) ) { return new EmptyASTFragment ( ) ; } if ( other . kind ( ) == ASTFragmentKind . SIMPLE_EXPRESSION && new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , other . getAssociatedExpression ( ) ) ) { return new SimpleExpressionASTFragment ( expression ) ; } else if ( other . kind ( ) == ASTFragmentKind . BINARY ) { BinaryExpressionFragment otherBinary = ( BinaryExpressionFragment ) other ; if ( new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , other . getAssociatedExpression ( ) ) && this . getToken ( ) . getText ( ) . equals ( otherBinary . getToken ( ) . getText ( ) ) ) { IASTFragment result = this . next . findMatchingSubFragment ( otherBinary . next ) ; if ( result . kind ( ) == ASTFragmentKind . EMPTY ) { return new EmptyASTFragment ( ) ; } else { BinaryExpressionFragment newResult = new BinaryExpressionFragment ( token , expression , result ) ; newResult . setActualStartPosition ( actualStartPosition ) ; return newResult ; } } } return new EmptyASTFragment ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . selection . IsSameExpression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; public class MethodCallFragment implements IASTFragment { private final Expression arguments ; private final Expression methodExpression ; private final IASTFragment next ; private int actualEndPosition ; MethodCallFragment ( Expression methodExpression , Expression arguments , IASTFragment next , int actualEndPosition ) { this . methodExpression = methodExpression ; this . arguments = arguments ; this . next = next ; this . actualEndPosition = actualEndPosition ; } public MethodCallFragment ( Expression methodExpression , Expression arguments , int actualEndPosition ) { this ( methodExpression , arguments , null , actualEndPosition ) ; } public boolean hasNext ( ) { return next != null ; } public int getEnd ( ) { return hasNext ( ) ? next . getEnd ( ) : actualEndPosition ; } public int getStart ( ) { return methodExpression . getStart ( ) ; } public int getLength ( ) { return getEnd ( ) - getStart ( ) ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { if ( hasNext ( ) ) { return getNext ( ) . getTrimmedEnd ( unit ) ; } else { char [ ] contents = unit . getContents ( ) ; int end = actualEndPosition ; while ( end > methodExpression . getStart ( ) && Character . isWhitespace ( contents [ end ] ) ) { end -- ; } return end ; } } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public Expression getArguments ( ) { return arguments ; } public IASTFragment getNext ( ) { return next ; } public boolean matches ( IASTFragment other ) { if ( ! ( other instanceof MethodCallFragment ) ) { return false ; } MethodCallFragment otherCall = ( MethodCallFragment ) other ; if ( otherCall . hasNext ( ) != hasNext ( ) ) { return false ; } return new IsSameExpression ( ) . isSame ( arguments , otherCall . getArguments ( ) ) && new IsSameExpression ( ) . isSame ( methodExpression , otherCall . getAssociatedExpression ( ) ) ; } public int fragmentLength ( ) { return hasNext ( ) ? <NUM_LIT:1> + next . fragmentLength ( ) : <NUM_LIT:1> ; } public Expression getAssociatedExpression ( ) { return methodExpression ; } public ASTNode getAssociatedNode ( ) { return methodExpression ; } public String print ( int indentLvl ) { return ASTFragmentFactory . spaces ( indentLvl ) + "<STR_LIT>" + methodExpression + "<STR_LIT:.>" + arguments + ( hasNext ( ) ? "<STR_LIT:n>" + next . print ( indentLvl + <NUM_LIT:1> ) : "<STR_LIT>" ) ; } public void accept ( FragmentVisitor visitor ) { if ( visitor . previsit ( this ) && visitor . visit ( this ) && hasNext ( ) ) { next . accept ( visitor ) ; } } public ASTFragmentKind kind ( ) { return ASTFragmentKind . METHOD_CALL ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { if ( other . fragmentLength ( ) > this . fragmentLength ( ) ) { return new EmptyASTFragment ( ) ; } if ( other . kind ( ) == this . kind ( ) ) { MethodCallFragment toMatchCall = ( MethodCallFragment ) other ; if ( new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , toMatchCall . getAssociatedExpression ( ) ) && new IsSameExpression ( ) . isSame ( this . getArguments ( ) , toMatchCall . getArguments ( ) ) ) { if ( ! toMatchCall . hasNext ( ) ) { return new MethodCallFragment ( this . getAssociatedExpression ( ) , this . getArguments ( ) , this . actualEndPosition ) ; } else { IASTFragment result = this . getNext ( ) . findMatchingSubFragment ( toMatchCall . getNext ( ) ) ; if ( result . kind ( ) == ASTFragmentKind . EMPTY ) { return new EmptyASTFragment ( ) ; } else { MethodCallFragment newFragment = new MethodCallFragment ( this . getAssociatedExpression ( ) , this . getArguments ( ) , result , this . actualEndPosition ) ; return newFragment ; } } } } return new EmptyASTFragment ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . Assert ; public class EnclosingASTNodeFragment implements IASTFragment { private final ASTNode node ; EnclosingASTNodeFragment ( ASTNode node ) { this . node = node ; } public void accept ( FragmentVisitor visitor ) { visitor . previsit ( this ) ; visitor . visit ( this ) ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { return null ; } public int fragmentLength ( ) { return <NUM_LIT:1> ; } public Expression getAssociatedExpression ( ) { Assert . isLegal ( false , "<STR_LIT>" ) ; return null ; } public ASTNode getAssociatedNode ( ) { return node ; } public int getEnd ( ) { return node . getEnd ( ) ; } public int getStart ( ) { return node . getStart ( ) ; } public int getLength ( ) { return getEnd ( ) - getStart ( ) ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { char [ ] contents = unit . getContents ( ) ; int end = getEnd ( ) ; int start = node . getStart ( ) ; while ( end > start && Character . isWhitespace ( contents [ end ] ) ) { end -- ; } return end ; } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public ASTFragmentKind kind ( ) { return ASTFragmentKind . ENCLOSING ; } public boolean matches ( IASTFragment other ) { return this . kind ( ) == other . kind ( ) && this . node == ( ( EnclosingASTNodeFragment ) other ) . getAssociatedNode ( ) ; } public String print ( int indentLvl ) { return "<STR_LIT>" + node . toString ( ) ; } @ Override public String toString ( ) { return print ( <NUM_LIT:0> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . selection . IsSameExpression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . Assert ; public class PropertyExpressionFragment implements IASTFragment { private final ASTFragmentKind kind ; private final Expression expression ; private final IASTFragment next ; PropertyExpressionFragment ( ASTFragmentKind token , Expression expression , IASTFragment next ) { Assert . isNotNull ( next ) ; this . kind = token ; this . expression = expression ; this . next = next ; } public Expression getAssociatedExpression ( ) { return expression ; } public ASTNode getAssociatedNode ( ) { return expression ; } public int getEnd ( ) { return getNext ( ) . getEnd ( ) ; } public int getStart ( ) { return expression . getStart ( ) ; } public int getLength ( ) { return getEnd ( ) - getStart ( ) ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { return getNext ( ) . getTrimmedEnd ( unit ) ; } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public IASTFragment getNext ( ) { return next ; } public boolean matches ( IASTFragment other ) { if ( ! ( other instanceof PropertyExpressionFragment ) ) { return false ; } PropertyExpressionFragment otherBinary = ( PropertyExpressionFragment ) other ; return otherBinary . kind ( ) == this . kind && new IsSameExpression ( ) . isSame ( expression , otherBinary . getAssociatedExpression ( ) ) && this . next . matches ( otherBinary . getNext ( ) ) ; } @ Override public String toString ( ) { return print ( <NUM_LIT:0> ) ; } public String print ( int indentLvl ) { return ASTFragmentFactory . spaces ( indentLvl ) + "<STR_LIT>" + expression . toString ( ) + "<STR_LIT:n>" + next . print ( indentLvl + <NUM_LIT:1> ) ; } public int fragmentLength ( ) { return <NUM_LIT:1> + next . fragmentLength ( ) ; } public void accept ( FragmentVisitor visitor ) { if ( visitor . previsit ( this ) && visitor . visit ( this ) ) { next . accept ( visitor ) ; } } public ASTFragmentKind kind ( ) { return kind ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { if ( this . fragmentLength ( ) < other . fragmentLength ( ) ) { return new EmptyASTFragment ( ) ; } if ( other . kind ( ) == ASTFragmentKind . SIMPLE_EXPRESSION && new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , other . getAssociatedExpression ( ) ) ) { return new SimpleExpressionASTFragment ( expression ) ; } else if ( other . kind ( ) == this . kind ( ) ) { PropertyExpressionFragment toMatchBinary = ( PropertyExpressionFragment ) other ; if ( new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , toMatchBinary . getAssociatedExpression ( ) ) ) { IASTFragment result = this . getNext ( ) . findMatchingSubFragment ( toMatchBinary . getNext ( ) ) ; if ( result . kind ( ) == ASTFragmentKind . EMPTY ) { return new EmptyASTFragment ( ) ; } else { return new PropertyExpressionFragment ( this . kind ( ) , this . getAssociatedExpression ( ) , result ) ; } } } return new EmptyASTFragment ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; public interface IASTFragment { public boolean matches ( IASTFragment other ) ; public IASTFragment findMatchingSubFragment ( IASTFragment other ) ; public int getStart ( ) ; public int getEnd ( ) ; public int getTrimmedEnd ( GroovyCompilationUnit unit ) ; public int getLength ( ) ; public int getTrimmedLength ( GroovyCompilationUnit unit ) ; public Expression getAssociatedExpression ( ) ; public ASTNode getAssociatedNode ( ) ; public String print ( int indentLvl ) ; public int fragmentLength ( ) ; public void accept ( FragmentVisitor visitor ) ; public ASTFragmentKind kind ( ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . EmptyExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; public class EmptyASTFragment implements IASTFragment { private static final EmptyExpression emptyExpression = new EmptyExpression ( ) ; public void accept ( FragmentVisitor visitor ) { visitor . previsit ( this ) ; visitor . visit ( this ) ; } public int fragmentLength ( ) { return <NUM_LIT:0> ; } public Expression getAssociatedExpression ( ) { return emptyExpression ; } public ASTNode getAssociatedNode ( ) { return emptyExpression ; } public int getEnd ( ) { return <NUM_LIT:0> ; } public int getStart ( ) { return <NUM_LIT:0> ; } public int getLength ( ) { return <NUM_LIT:0> ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { return <NUM_LIT:0> ; } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public ASTFragmentKind kind ( ) { return ASTFragmentKind . EMPTY ; } public boolean matches ( IASTFragment other ) { return other . kind ( ) == ASTFragmentKind . EMPTY ; } public String print ( int indentLvl ) { return ASTFragmentFactory . spaces ( indentLvl ) + "<STR_LIT>" ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { return this ; } @ Override public String toString ( ) { return print ( <NUM_LIT:0> ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; public abstract class FragmentVisitor { public boolean previsit ( IASTFragment fragment ) { return true ; } public boolean visit ( PropertyExpressionFragment fragment ) { return true ; } public boolean visit ( MethodCallFragment fragment ) { return true ; } public boolean visit ( SimpleExpressionASTFragment fragment ) { return true ; } public boolean visit ( BinaryExpressionFragment fragment ) { return true ; } public boolean visit ( EnclosingASTNodeFragment fragment ) { return true ; } public boolean visit ( EmptyASTFragment fragment ) { return true ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . BooleanExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . syntax . Token ; import org . eclipse . core . runtime . Assert ; public class ASTFragmentFactory { public IASTFragment createFragment ( ASTNode node ) { if ( node instanceof Expression ) { return createFragment ( ( Expression ) node ) ; } else { return new EnclosingASTNodeFragment ( node ) ; } } public IASTFragment createFragment ( Expression expression , int start , int end ) { Assert . isLegal ( expression . getStart ( ) <= start , "<STR_LIT>" + start ) ; Assert . isLegal ( expression . getEnd ( ) >= end , "<STR_LIT>" + end ) ; if ( expression instanceof BooleanExpression ) { Expression inner = ( ( BooleanExpression ) expression ) . getExpression ( ) ; if ( inner . getStart ( ) == expression . getStart ( ) && inner . getEnd ( ) == expression . getEnd ( ) ) { expression = inner ; } } else if ( expression instanceof TupleExpression && ( ( TupleExpression ) expression ) . getExpressions ( ) . size ( ) == <NUM_LIT:1> ) { Expression inner = ( ( TupleExpression ) expression ) . getExpression ( <NUM_LIT:0> ) ; if ( inner . getStart ( ) == expression . getStart ( ) && inner . getEnd ( ) == expression . getEnd ( ) ) { expression = inner ; } } if ( expression instanceof BinaryExpression ) { IASTFragment fragment = createBinaryFragment ( ( BinaryExpression ) expression , start , end ) ; if ( expression instanceof DeclarationExpression ) { if ( fragment . kind ( ) == ASTFragmentKind . BINARY ) { ( ( BinaryExpressionFragment ) fragment ) . setActualStartPosition ( ( ( DeclarationExpression ) expression ) . getStart ( ) ) ; } else if ( fragment . kind ( ) == ASTFragmentKind . SIMPLE_EXPRESSION ) { ( ( SimpleExpressionASTFragment ) fragment ) . setActualStartPosition ( ( ( DeclarationExpression ) expression ) . getStart ( ) ) ; } } return fragment ; } else if ( expression instanceof PropertyExpression ) { return createPropertyBasedFragment ( expression , start , end ) ; } else if ( expression instanceof MethodCallExpression ) { return createPropertyBasedFragment ( expression , start , end ) ; } else if ( expression instanceof MethodPointerExpression ) { return createPropertyBasedFragment ( expression , start , end ) ; } else if ( expression . getStart ( ) == start && expression . getEnd ( ) == end ) { return new SimpleExpressionASTFragment ( expression ) ; } else { return new EmptyASTFragment ( ) ; } } public IASTFragment createFragment ( Expression expression ) { return createFragment ( expression , expression . getStart ( ) , expression . getEnd ( ) ) ; } private IASTFragment createBinaryFragment ( BinaryExpression expression , int start , int end ) { List < Expression > exprs = new ArrayList < Expression > ( ) ; List < Token > tokens = new ArrayList < Token > ( ) ; walkBinaryExpr ( expression , exprs , tokens ) ; Expression firstExpr = exprs . get ( exprs . size ( ) - <NUM_LIT:1> ) ; IASTFragment next = new EmptyASTFragment ( ) ; if ( firstExpr . getStart ( ) >= start && firstExpr . getEnd ( ) <= end ) { next = new SimpleExpressionASTFragment ( firstExpr ) ; } for ( int i = tokens . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { Expression nextExpr = exprs . get ( i ) ; if ( nextExpr . getStart ( ) >= start && nextExpr . getEnd ( ) <= end ) { if ( next . kind ( ) == ASTFragmentKind . EMPTY ) { next = new SimpleExpressionASTFragment ( nextExpr ) ; } else { next = new BinaryExpressionFragment ( tokens . get ( i ) , nextExpr , next ) ; } } } return next ; } private void walkBinaryExpr ( BinaryExpression expression , List < Expression > exprs , List < Token > tokens ) { if ( expression . getLeftExpression ( ) instanceof BinaryExpression ) { walkBinaryExpr ( ( BinaryExpression ) expression . getLeftExpression ( ) , exprs , tokens ) ; } else { exprs . add ( expression . getLeftExpression ( ) ) ; } tokens . add ( expression . getOperation ( ) ) ; if ( expression . getRightExpression ( ) instanceof BinaryExpression ) { walkBinaryExpr ( ( BinaryExpression ) expression . getRightExpression ( ) , exprs , tokens ) ; } else { exprs . add ( expression . getRightExpression ( ) ) ; } } private IASTFragment createPropertyBasedFragment ( Expression expression , int start , int end ) { List < ASTFragmentKind > kinds = new ArrayList < ASTFragmentKind > ( ) ; List < Expression > exprs = new ArrayList < Expression > ( ) ; List < Expression > args = new ArrayList < Expression > ( ) ; List < Integer > ends = new ArrayList < Integer > ( ) ; walkPropertyExpr ( expression , exprs , args , kinds , ends ) ; IASTFragment prev = new EmptyASTFragment ( ) ; boolean wasImplicitCall = false ; Expression firstExpr = exprs . get ( exprs . size ( ) - <NUM_LIT:1> ) ; if ( firstExpr . getStart ( ) >= start && firstExpr . getEnd ( ) <= end ) { if ( kinds . get ( kinds . size ( ) - <NUM_LIT:1> ) == ASTFragmentKind . METHOD_CALL ) { prev = new MethodCallFragment ( firstExpr , args . get ( exprs . size ( ) - <NUM_LIT:1> ) , ends . get ( exprs . size ( ) - <NUM_LIT:1> ) ) ; } else { prev = new SimpleExpressionASTFragment ( firstExpr ) ; } } else if ( checkWasImplicitCall ( firstExpr ) ) { wasImplicitCall = true ; } for ( int i = exprs . size ( ) - <NUM_LIT:2> ; i >= <NUM_LIT:0> ; i -- ) { Expression expr = exprs . get ( i ) ; if ( expr . getStart ( ) >= start && expr . getEnd ( ) <= end ) { if ( kinds . get ( i ) == ASTFragmentKind . METHOD_CALL ) { prev = new MethodCallFragment ( expr , args . get ( i ) , prev . kind ( ) == ASTFragmentKind . EMPTY ? null : prev , ends . get ( i ) ) ; } else { if ( prev . kind ( ) == ASTFragmentKind . EMPTY ) { if ( ! wasImplicitCall ) { prev = new SimpleExpressionASTFragment ( expr ) ; } else { prev = new MethodCallFragment ( expr , args . get ( i + <NUM_LIT:1> ) , null , ends . get ( i ) ) ; } } else { if ( ! wasImplicitCall ) { prev = new PropertyExpressionFragment ( kinds . get ( i ) , expr , prev ) ; } else { prev = new MethodCallFragment ( expr , args . get ( i + <NUM_LIT:1> ) , prev , ends . get ( i ) ) ; } } } wasImplicitCall = false ; } else if ( checkWasImplicitCall ( expr ) ) { wasImplicitCall = true ; } } return prev ; } private boolean checkWasImplicitCall ( Expression firstExpr ) { return firstExpr . getEnd ( ) == <NUM_LIT:0> && firstExpr instanceof ConstantExpression && ( ( ConstantExpression ) firstExpr ) . getText ( ) . equals ( "<STR_LIT>" ) ; } private void walkPropertyExpr ( Expression startExpression , List < Expression > targetExprs , List < Expression > targetArgs , List < ASTFragmentKind > targetKinds , List < Integer > targetEnds ) { if ( startExpression instanceof PropertyExpression ) { PropertyExpression propertyExpression = ( PropertyExpression ) startExpression ; ASTFragmentKind kind = ASTFragmentKind . toPropertyKind ( propertyExpression ) ; walkPropertyExpr ( propertyExpression . getObjectExpression ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; int toRemove = targetKinds . size ( ) - <NUM_LIT:1> ; if ( targetKinds . get ( toRemove ) == ASTFragmentKind . SIMPLE_EXPRESSION ) { targetKinds . set ( toRemove , kind ) ; targetArgs . set ( toRemove , null ) ; } walkPropertyExpr ( propertyExpression . getProperty ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; } else if ( startExpression instanceof MethodCallExpression ) { MethodCallExpression methodCallExpression = ( MethodCallExpression ) startExpression ; walkPropertyExpr ( methodCallExpression . getObjectExpression ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; int toRemove = targetKinds . size ( ) - <NUM_LIT:1> ; if ( targetKinds . get ( toRemove ) == ASTFragmentKind . SIMPLE_EXPRESSION ) { targetKinds . set ( toRemove , ASTFragmentKind . PROPERTY ) ; targetArgs . set ( toRemove , null ) ; } walkPropertyExpr ( methodCallExpression . getMethod ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; toRemove = targetKinds . size ( ) - <NUM_LIT:1> ; targetKinds . set ( toRemove , ASTFragmentKind . METHOD_CALL ) ; targetArgs . set ( toRemove , methodCallExpression . getArguments ( ) ) ; targetEnds . set ( toRemove , methodCallExpression . getEnd ( ) ) ; } else if ( startExpression instanceof MethodPointerExpression ) { MethodPointerExpression methodPointerExpression = ( MethodPointerExpression ) startExpression ; walkPropertyExpr ( methodPointerExpression . getExpression ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; int toRemove = targetKinds . size ( ) - <NUM_LIT:1> ; if ( targetKinds . get ( toRemove ) == ASTFragmentKind . SIMPLE_EXPRESSION ) { targetKinds . set ( toRemove , ASTFragmentKind . METHOD_POINTER ) ; targetArgs . set ( toRemove , null ) ; } walkPropertyExpr ( methodPointerExpression . getMethodName ( ) , targetExprs , targetArgs , targetKinds , targetEnds ) ; } else { targetKinds . add ( ASTFragmentKind . SIMPLE_EXPRESSION ) ; targetArgs . add ( null ) ; targetExprs . add ( startExpression ) ; targetEnds . add ( startExpression . getEnd ( ) ) ; } } public static String spaces ( int num ) { StringBuilder sb = new StringBuilder ( ) ; while ( num -- > <NUM_LIT:0> ) { sb . append ( "<STR_LIT:U+0020U+0020>" ) ; } return sb . toString ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; public enum ASTFragmentKind { PROPERTY , SAFE_PROPERTY , SPREAD_SAFE_PROPERTY , METHOD_POINTER , METHOD_CALL , BINARY , SIMPLE_EXPRESSION , EMPTY , ENCLOSING ; static ASTFragmentKind toPropertyKind ( Expression expr ) { if ( expr instanceof PropertyExpression ) { PropertyExpression prop = ( PropertyExpression ) expr ; if ( prop . isSafe ( ) ) { return SAFE_PROPERTY ; } else if ( prop . isSpreadSafe ( ) ) { return SPREAD_SAFE_PROPERTY ; } else { return PROPERTY ; } } else if ( expr instanceof MethodPointerExpression ) { return METHOD_POINTER ; } else if ( expr instanceof MethodCallExpression ) { return METHOD_CALL ; } else if ( expr instanceof BinaryExpression ) { return BINARY ; } else { return SIMPLE_EXPRESSION ; } } public static boolean isExpressionKind ( IASTFragment fragment ) { if ( fragment == null ) return false ; ASTFragmentKind kind = fragment . kind ( ) ; switch ( kind ) { case PROPERTY : case SAFE_PROPERTY : case SPREAD_SAFE_PROPERTY : case METHOD_POINTER : case METHOD_CALL : case BINARY : case SIMPLE_EXPRESSION : return true ; default : return false ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . fragments ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . selection . IsSameExpression ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; public class SimpleExpressionASTFragment implements IASTFragment { private final Expression expression ; private int actualStartPosition ; SimpleExpressionASTFragment ( Expression expression ) { this . expression = expression ; actualStartPosition = expression . getStart ( ) ; } public Expression getAssociatedExpression ( ) { return expression ; } public ASTNode getAssociatedNode ( ) { return expression ; } void setActualStartPosition ( int actualStartPosition ) { this . actualStartPosition = actualStartPosition ; } public int getEnd ( ) { return expression . getEnd ( ) ; } public int getStart ( ) { return actualStartPosition ; } public int getLength ( ) { return getEnd ( ) - getStart ( ) ; } public int getTrimmedEnd ( GroovyCompilationUnit unit ) { char [ ] contents = unit . getContents ( ) ; int end = getEnd ( ) ; while ( end > actualStartPosition && Character . isWhitespace ( contents [ end ] ) ) { end -- ; } return end ; } public int getTrimmedLength ( GroovyCompilationUnit unit ) { return getTrimmedEnd ( unit ) - getStart ( ) ; } public boolean matches ( IASTFragment other ) { if ( ! ( other instanceof SimpleExpressionASTFragment ) ) { return false ; } return new IsSameExpression ( ) . isSame ( expression , other . getAssociatedExpression ( ) ) ; } @ Override public String toString ( ) { return print ( <NUM_LIT:0> ) ; } public String print ( int indentLvl ) { return ASTFragmentFactory . spaces ( indentLvl ) + "<STR_LIT>" + expression . toString ( ) ; } public int fragmentLength ( ) { return <NUM_LIT:1> ; } public void accept ( FragmentVisitor visitor ) { visitor . previsit ( this ) ; visitor . visit ( this ) ; } public ASTFragmentKind kind ( ) { return ASTFragmentKind . SIMPLE_EXPRESSION ; } public IASTFragment findMatchingSubFragment ( IASTFragment other ) { if ( other . kind ( ) == ASTFragmentKind . SIMPLE_EXPRESSION && new IsSameExpression ( ) . isSame ( this . getAssociatedExpression ( ) , other . getAssociatedExpression ( ) ) ) { return new SimpleExpressionASTFragment ( expression ) ; } else { return new EmptyASTFragment ( ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedBinaryType ; public class GroovyResolvedBinaryType extends ResolvedBinaryType implements IGroovyResolvedElement { private final String extraDoc ; private ASTNode inferredElement ; public GroovyResolvedBinaryType ( JavaElement parent , String name , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedSourceType ; public class GroovyResolvedSourceType extends ResolvedSourceType implements IGroovyResolvedElement { private final String extraDoc ; private final ASTNode inferredElement ; public GroovyResolvedSourceType ( JavaElement parent , String name , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . ISourceReference ; public interface IGroovyResolvedElement extends IJavaElement , ISourceReference { String getExtraDoc ( ) ; String getKey ( ) ; String getInferredElementName ( ) ; ASTNode getInferredElement ( ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedSourceField ; public class GroovyResolvedSourceField extends ResolvedSourceField implements IGroovyResolvedElement { private final String extraDoc ; private ASTNode inferredElement ; public GroovyResolvedSourceField ( JavaElement parent , String name , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedBinaryMethod ; public class GroovyResolvedBinaryMethod extends ResolvedBinaryMethod implements IGroovyResolvedElement { private final String extraDoc ; private ASTNode inferredElement ; public GroovyResolvedBinaryMethod ( JavaElement parent , String name , String [ ] parameterTypes , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , parameterTypes , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedSourceMethod ; public class GroovyResolvedSourceMethod extends ResolvedSourceMethod implements IGroovyResolvedElement { private final String extraDoc ; private ASTNode inferredElement ; public GroovyResolvedSourceMethod ( JavaElement parent , String name , String [ ] parameterTypes , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , parameterTypes , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codebrowsing . elements ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . ResolvedBinaryField ; public class GroovyResolvedBinaryField extends ResolvedBinaryField implements IGroovyResolvedElement { private final String extraDoc ; private final ASTNode inferredElement ; public GroovyResolvedBinaryField ( JavaElement parent , String name , String uniqueKey , String extraDoc , ASTNode inferredElement ) { super ( parent , name , uniqueKey ) ; this . extraDoc = extraDoc ; this . inferredElement = inferredElement ; } public String getExtraDoc ( ) { return extraDoc ; } public String getInferredElementName ( ) { if ( inferredElement instanceof Variable ) { return ( ( Variable ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof MethodNode ) { return ( ( MethodNode ) inferredElement ) . getName ( ) ; } else if ( inferredElement instanceof ClassNode ) { return ( ( ClassNode ) inferredElement ) . getName ( ) ; } else { return inferredElement . getText ( ) ; } } public ASTNode getInferredElement ( ) { return inferredElement ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.