text
stringlengths
30
1.67M
<s> package org . vimplugin . listeners ; import org . vimplugin . VimConnection ; import org . vimplugin . VimEvent ; import org . vimplugin . VimException ; import org . vimplugin . VimPlugin ; import org . vimplugin . VimServer ; import org . vimplugin . editors . VimEditor ; public class FileUnmodified implements IVimListener { public void handleEvent ( VimEvent ve ) throws VimException { String event = ve . getEvent ( ) ; if ( event . equals ( "<STR_LIT>" ) || ( event . equals ( "<STR_LIT>" ) && ve . getArgument ( <NUM_LIT:0> ) . equals ( "<STR_LIT>" ) ) ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; VimConnection vc = ve . getConnection ( ) ; VimServer server = vc != null ? plugin . getVimserver ( vc . getVimID ( ) ) : null ; if ( server != null ) { for ( VimEditor editor : server . getEditors ( ) ) { if ( editor != null && editor . getBufferID ( ) == ve . getBufferID ( ) ) { editor . setDirty ( false ) ; } } } } } } </s>
<s> package org . vimplugin . listeners ; import org . vimplugin . VimEvent ; public class Logger implements IVimListener { private static final org . eclim . logging . Logger logger = org . eclim . logging . Logger . getLogger ( Logger . class ) ; public void handleEvent ( VimEvent ve ) { logger . debug ( ve . getLine ( ) ) ; } } </s>
<s> package org . vimplugin . listeners ; import org . vimplugin . VimEvent ; import org . vimplugin . VimException ; public interface IVimListener { public void handleEvent ( VimEvent ve ) throws VimException ; } </s>
<s> package org . vimplugin . listeners ; import java . util . ArrayList ; import org . eclim . logging . Logger ; import org . eclim . util . StringUtils ; import org . eclipse . jface . bindings . keys . KeyStroke ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . internal . Workbench ; import org . eclipse . ui . internal . keys . BindingService ; import org . eclipse . ui . internal . keys . WorkbenchKeyboard ; import org . eclipse . ui . keys . IBindingService ; import org . vimplugin . DisplayUtils ; import org . vimplugin . VimEvent ; import org . vimplugin . VimException ; public class FeedKeys implements IVimListener { private static final Logger logger = Logger . getLogger ( FeedKeys . class ) ; public void handleEvent ( VimEvent ve ) throws VimException { String argument = null ; if ( ve . getEvent ( ) . equals ( "<STR_LIT>" ) && ( argument = ve . getArgument ( <NUM_LIT:0> ) ) . startsWith ( "<STR_LIT>" ) ) { String keys = argument . substring ( <NUM_LIT:10> , argument . length ( ) - <NUM_LIT:1> ) ; keys = keys . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; keys = keys . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; feedKeys ( keys ) ; } } private void feedKeys ( final String keys ) { try { final Workbench workbench = ( Workbench ) PlatformUI . getWorkbench ( ) ; final Display display = workbench . getDisplay ( ) ; final int [ ] bounds = new int [ <NUM_LIT:2> ] ; display . syncExec ( new Runnable ( ) { public void run ( ) { Shell shell = display . getActiveShell ( ) ; if ( shell == null ) { shell = display . getShells ( ) [ <NUM_LIT:0> ] ; } Point point = shell . toDisplay ( <NUM_LIT:1> , <NUM_LIT:1> ) ; bounds [ <NUM_LIT:0> ] = point . x ; bounds [ <NUM_LIT:1> ] = point . y ; } } ) ; DisplayUtils . doClick ( display , bounds [ <NUM_LIT:0> ] + <NUM_LIT:5> , bounds [ <NUM_LIT:1> ] + <NUM_LIT:5> , false ) ; final String [ ] sequences = StringUtils . split ( keys , '<CHAR_LIT:U+002C>' ) ; display . asyncExec ( new Runnable ( ) { public void run ( ) { BindingService bindingService = ( BindingService ) PlatformUI . getWorkbench ( ) . getAdapter ( IBindingService . class ) ; WorkbenchKeyboard keyboard = bindingService . getKeyboard ( ) ; for ( String sequence : sequences ) { try { if ( sequence . equals ( "<STR_LIT>" ) ) { logger . debug ( "<STR_LIT>" ) ; IWorkbenchPage page = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) ; IEditorPart editor = page . getActiveEditor ( ) ; if ( editor != null ) { editor . setFocus ( ) ; } continue ; } KeyStroke keyStroke = KeyStroke . getInstance ( sequence ) ; Event event = new Event ( ) ; event . widget = display . getActiveShell ( ) ; ArrayList < KeyStroke > keyStrokes = new ArrayList < KeyStroke > ( ) ; keyStrokes . add ( keyStroke ) ; keyboard . press ( keyStrokes , event ) ; logger . debug ( "<STR_LIT>" + sequence ) ; } catch ( Throwable t ) { logger . error ( "<STR_LIT>" , t ) ; } } } } ) ; } catch ( Throwable t ) { logger . error ( "<STR_LIT>" , t ) ; } } } </s>
<s> package org . vimplugin ; import org . vimplugin . editors . VimEditor ; public class VimEvent { private static final org . eclim . logging . Logger logger = org . eclim . logging . Logger . getLogger ( VimEvent . class ) ; private final String line ; private final VimConnection connection ; public VimEvent ( String _line , VimConnection _connection ) { line = _line ; connection = _connection ; } public String getLine ( ) { return line ; } public String getEvent ( ) throws VimException { int beginIndex = line . indexOf ( '<CHAR_LIT::>' ) ; int endIndex = line . indexOf ( '<CHAR_LIT:=>' ) ; try { return line . substring ( beginIndex + <NUM_LIT:1> , endIndex ) ; } catch ( IndexOutOfBoundsException iobe ) { logger . debug ( "<STR_LIT>" + line , iobe ) ; } return "<STR_LIT>" ; } public String getArgument ( int index ) throws VimException { int i = <NUM_LIT:0> ; int beginIndex = - <NUM_LIT:1> ; while ( i <= index ) { beginIndex = line . indexOf ( "<STR_LIT:U+0020>" , beginIndex + <NUM_LIT:1> ) ; i ++ ; } int endIndex = beginIndex ; if ( line . charAt ( beginIndex + <NUM_LIT:1> ) == '<CHAR_LIT:">' ) { while ( true ) { endIndex = line . indexOf ( "<STR_LIT:U+0020>" , endIndex + <NUM_LIT:1> ) ; if ( endIndex == - <NUM_LIT:1> || ( line . charAt ( endIndex - <NUM_LIT:1> ) == '<CHAR_LIT:">' && beginIndex != endIndex - <NUM_LIT:2> ) ) break ; } } else { endIndex = line . indexOf ( "<STR_LIT:U+0020>" , beginIndex + <NUM_LIT:1> ) ; } if ( endIndex == - <NUM_LIT:1> ) { endIndex = line . length ( ) ; } try { return line . substring ( beginIndex + <NUM_LIT:1> , endIndex ) ; } catch ( IndexOutOfBoundsException iobe ) { logger . debug ( "<STR_LIT>" + index + "<STR_LIT>" + line , iobe ) ; } return "<STR_LIT>" ; } public int getBufferID ( ) throws VimException { int beginIndex = line . indexOf ( '<CHAR_LIT::>' ) ; try { return Integer . parseInt ( line . substring ( <NUM_LIT:0> , beginIndex ) ) ; } catch ( NumberFormatException nfe ) { throw new VimException ( "<STR_LIT>" , nfe ) ; } } public VimConnection getConnection ( ) { return connection ; } public VimEditor getEditor ( ) throws VimException { return VimPlugin . getDefault ( ) . getVimserver ( this . getConnection ( ) . getVimID ( ) ) . getEditor ( this . getBufferID ( ) ) ; } } </s>
<s> package org . vimplugin ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . net . ServerSocket ; import java . net . Socket ; import java . net . SocketException ; import java . util . HashSet ; import java . util . regex . Pattern ; import org . vimplugin . editors . VimEditor ; import org . vimplugin . listeners . BufferEnter ; import org . vimplugin . listeners . FeedKeys ; import org . vimplugin . listeners . FileClosed ; import org . vimplugin . listeners . FileModified ; import org . vimplugin . listeners . FileOpened ; import org . vimplugin . listeners . FileUnmodified ; import org . vimplugin . listeners . IVimListener ; import org . vimplugin . listeners . Logger ; import org . vimplugin . listeners . ServerDisconnect ; import org . vimplugin . listeners . ServerStarted ; import org . vimplugin . listeners . TextInsert ; import org . vimplugin . listeners . TextRemoved ; import org . vimplugin . preferences . PreferenceConstants ; public class VimConnection implements Runnable { private static final org . eclim . logging . Logger logger = org . eclim . logging . Logger . getLogger ( VimConnection . class ) ; private static final Pattern EVENT = Pattern . compile ( "<STR_LIT>" ) ; private boolean serverRunning = false ; private boolean startupDone = false ; final HashSet < IVimListener > listeners = new HashSet < IVimListener > ( ) ; final int vimID ; private BufferedReader in ; private PrintWriter out ; private final int port ; private ServerSocket socket ; private Socket vimSocket ; private volatile boolean functionCalled = false ; private Object functionMonitor = new Object ( ) ; private String functionResult ; public VimConnection ( int instanceID ) { port = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getInt ( PreferenceConstants . P_PORT ) ; vimID = instanceID ; } public void run ( ) { try { logger . debug ( "<STR_LIT>" + ( port + vimID ) ) ; socket = new ServerSocket ( port + vimID ) ; logger . debug ( "<STR_LIT>" ) ; vimSocket = socket . accept ( ) ; out = new PrintWriter ( vimSocket . getOutputStream ( ) , true ) ; in = new BufferedReader ( new InputStreamReader ( vimSocket . getInputStream ( ) ) ) ; logger . debug ( "<STR_LIT>" ) ; listeners . add ( new Logger ( ) ) ; listeners . add ( new ServerStarted ( ) ) ; listeners . add ( new ServerDisconnect ( ) ) ; listeners . add ( new TextInsert ( ) ) ; listeners . add ( new TextRemoved ( ) ) ; listeners . add ( new FileOpened ( ) ) ; listeners . add ( new FileClosed ( ) ) ; listeners . add ( new FileModified ( ) ) ; listeners . add ( new FileUnmodified ( ) ) ; listeners . add ( new BufferEnter ( ) ) ; listeners . add ( new FeedKeys ( ) ) ; String line ; try { while ( ! startupDone && ( line = in . readLine ( ) ) != null ) { if ( ! line . startsWith ( "<STR_LIT>" ) ) { VimEvent ve = new VimEvent ( line , this ) ; for ( IVimListener listener : listeners ) { listener . handleEvent ( ve ) ; } } } } catch ( VimException ve ) { logger . error ( "<STR_LIT>" , ve ) ; } try { while ( ( serverRunning && ( line = in . readLine ( ) ) != null ) ) { if ( functionCalled && ! EVENT . matcher ( line ) . matches ( ) ) { synchronized ( functionMonitor ) { functionResult = line ; functionMonitor . notify ( ) ; } } else { VimEvent ve = new VimEvent ( line , this ) ; for ( IVimListener listener : listeners ) { listener . handleEvent ( ve ) ; } } } } catch ( SocketException se ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; VimServer server = plugin . getVimserver ( getVimID ( ) ) ; if ( server != null ) { for ( VimEditor editor : server . getEditors ( ) ) { if ( editor != null ) { editor . forceDispose ( ) ; } } } close ( ) ; } } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; throw new RuntimeException ( e ) ; } } public boolean close ( ) throws IOException { if ( vimSocket != null ) { vimSocket . close ( ) ; } if ( socket != null ) { socket . close ( ) ; } serverRunning = false ; return true ; } public void command ( int bufID , String name , String param ) { int seqno = VimPlugin . getDefault ( ) . nextSeqNo ( ) ; String cmd = bufID + "<STR_LIT::>" + name + "<STR_LIT:!>" + seqno + "<STR_LIT:U+0020>" + param ; logger . debug ( "<STR_LIT>" + cmd ) ; out . println ( cmd ) ; } public String function ( int bufID , String name , String param ) throws IOException { int seqno = VimPlugin . getDefault ( ) . nextSeqNo ( ) ; String tmp = bufID + "<STR_LIT::>" + name + "<STR_LIT:/>" + seqno + "<STR_LIT:U+0020>" + param ; logger . debug ( "<STR_LIT>" + tmp ) ; synchronized ( functionMonitor ) { functionCalled = true ; out . println ( tmp ) ; if ( "<STR_LIT>" . equals ( name ) ) { return null ; } try { functionMonitor . wait ( <NUM_LIT:1000> ) ; } catch ( InterruptedException ie ) { logger . error ( "<STR_LIT>" ) ; return null ; } } String result = functionResult ; functionResult = null ; logger . debug ( "<STR_LIT>" + result ) ; return result ; } public void plain ( String s ) { logger . debug ( "<STR_LIT>" + s ) ; out . println ( s ) ; } public void remotesend ( String s ) { String [ ] args = { "<STR_LIT>" , "<STR_LIT>" , String . valueOf ( vimID ) , "<STR_LIT>" , s } ; try { logger . debug ( "<STR_LIT>" + s ) ; Process process = new ProcessBuilder ( args ) . start ( ) ; InputStream is = process . getInputStream ( ) ; InputStreamReader isr = new InputStreamReader ( is ) ; BufferedReader br = new BufferedReader ( isr ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { logger . debug ( line ) ; } process . waitFor ( ) ; logger . debug ( "<STR_LIT>" + process . exitValue ( ) ) ; } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" , ioe ) ; } catch ( InterruptedException ie ) { logger . error ( "<STR_LIT>" , ie ) ; } } public void addListener ( IVimListener vl ) { listeners . add ( vl ) ; } public int getVimID ( ) { return vimID ; } public void setStartupDone ( boolean startupDone ) { this . startupDone = startupDone ; } public boolean isStartupDone ( ) { return startupDone ; } public void setServerRunning ( boolean serverRunning ) { this . serverRunning = serverRunning ; } public boolean isServerRunning ( ) { return serverRunning ; } } </s>
<s> package org . vimplugin ; import java . io . IOException ; import java . io . PrintWriter ; import java . io . StringWriter ; public class VimExceptionHandler implements Thread . UncaughtExceptionHandler { public void uncaughtException ( Thread t , Throwable e ) { String stacktrace ; StringWriter sw = null ; PrintWriter pw = null ; try { sw = new StringWriter ( ) ; pw = new PrintWriter ( sw ) ; e . printStackTrace ( pw ) ; stacktrace = sw . toString ( ) ; } finally { try { if ( pw != null ) pw . close ( ) ; if ( sw != null ) sw . close ( ) ; } catch ( IOException ignore ) { } } System . err . println ( "<STR_LIT>" + stacktrace ) ; } } </s>
<s> package org . vimplugin ; import java . io . File ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import org . eclim . logging . Logger ; import org . eclim . util . CommandExecutor ; import org . eclipse . core . runtime . Platform ; import org . vimplugin . editors . VimEditor ; import org . vimplugin . preferences . PreferenceConstants ; public class VimServer { private static final Logger logger = Logger . getLogger ( VimServer . class ) ; private boolean embedded ; private boolean tabbed ; private final int ID ; private HashSet < VimEditor > editors = new HashSet < VimEditor > ( ) ; public VimServer ( int instanceID ) { ID = instanceID ; } protected Process p ; protected Thread t ; protected VimConnection vc = null ; public int getID ( ) { return ID ; } public VimConnection getVc ( ) { return vc ; } public boolean isExternalTabbed ( ) { return tabbed ; } public boolean isEmbedded ( ) { return embedded ; } protected String getNetbeansString ( int portID ) { int port = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getInt ( PreferenceConstants . P_PORT ) + portID ; return "<STR_LIT>" + port ; } public void start ( String workingDir , String filePath , boolean tabbed , boolean first ) { String gvim = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_GVIM ) ; String [ ] addopts = getUserArgs ( ) ; String [ ] args = null ; if ( ! tabbed || first ) { int numArgs = tabbed ? <NUM_LIT:8> : <NUM_LIT:6> ; args = new String [ numArgs + addopts . length ] ; args [ <NUM_LIT:0> ] = gvim ; args [ <NUM_LIT:1> ] = "<STR_LIT>" ; args [ <NUM_LIT:2> ] = "<STR_LIT>" ; int offset = <NUM_LIT:0> ; if ( tabbed ) { offset = <NUM_LIT:2> ; args [ <NUM_LIT:3> ] = "<STR_LIT>" ; args [ <NUM_LIT:4> ] = "<STR_LIT>" ; } args [ <NUM_LIT:3> + offset ] = "<STR_LIT>" ; args [ <NUM_LIT:4> + offset ] = String . valueOf ( ID ) ; args [ <NUM_LIT:5> + offset ] = getNetbeansString ( ID ) ; System . arraycopy ( addopts , <NUM_LIT:0> , args , numArgs , addopts . length ) ; this . tabbed = tabbed ; start ( workingDir , false , ( tabbed && ! first ) , args ) ; } else { args = new String [ <NUM_LIT:5> + addopts . length ] ; args [ <NUM_LIT:0> ] = gvim ; args [ <NUM_LIT:1> ] = "<STR_LIT>" ; args [ <NUM_LIT:2> ] = String . valueOf ( ID ) ; args [ <NUM_LIT:3> ] = "<STR_LIT>" ; args [ <NUM_LIT:4> ] = "<STR_LIT>" + workingDir . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) + "<STR_LIT>" ; System . arraycopy ( addopts , <NUM_LIT:0> , args , <NUM_LIT:5> , addopts . length ) ; start ( workingDir , false , ( tabbed && ! first ) , args ) ; String vim = gvim ; if ( Platform . getOS ( ) . equals ( Platform . OS_WIN32 ) ) { vim = gvim . replace ( "<STR_LIT>" , "<STR_LIT>" ) ; } args = new String [ <NUM_LIT:5> ] ; args [ <NUM_LIT:0> ] = vim ; args [ <NUM_LIT:1> ] = "<STR_LIT>" ; args [ <NUM_LIT:2> ] = String . valueOf ( ID ) ; args [ <NUM_LIT:3> ] = "<STR_LIT>" ; args [ <NUM_LIT:4> ] = "<STR_LIT>" ; int tries = <NUM_LIT:0> ; while ( tries < <NUM_LIT:5> ) { try { String result = CommandExecutor . execute ( args , <NUM_LIT:1000> ) . getResult ( ) . trim ( ) ; if ( filePath . equals ( result ) ) { break ; } Thread . sleep ( <NUM_LIT> ) ; tries ++ ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } } } public void start ( String workingDir , long wid ) { String gvim = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_GVIM ) ; String netbeans = getNetbeansString ( ID ) ; String dontfork = "<STR_LIT>" ; String socketid = "<STR_LIT>" ; if ( Platform . getOS ( ) . equals ( Platform . OS_WIN32 ) ) { socketid = "<STR_LIT>" ; } String stringwid = String . valueOf ( wid ) ; String [ ] addopts = getUserArgs ( ) ; String [ ] args = new String [ <NUM_LIT:9> + addopts . length ] ; args [ <NUM_LIT:0> ] = gvim ; args [ <NUM_LIT:1> ] = "<STR_LIT>" ; args [ <NUM_LIT:2> ] = String . valueOf ( ID ) ; args [ <NUM_LIT:3> ] = netbeans ; args [ <NUM_LIT:4> ] = dontfork ; args [ <NUM_LIT:5> ] = socketid ; args [ <NUM_LIT:6> ] = stringwid ; args [ <NUM_LIT:7> ] = "<STR_LIT>" ; args [ <NUM_LIT:8> ] = "<STR_LIT>" ; System . arraycopy ( addopts , <NUM_LIT:0> , args , <NUM_LIT:9> , addopts . length ) ; start ( workingDir , true , false , args ) ; } private void start ( String workingDir , boolean embedded , boolean tabbed , String ... args ) { if ( ! tabbed && vc != null && vc . isServerRunning ( ) ) { return ; } VimPlugin plugin = VimPlugin . getDefault ( ) ; if ( vc == null || ! vc . isServerRunning ( ) ) { vc = new VimConnection ( ID ) ; t = new Thread ( vc ) ; t . setUncaughtExceptionHandler ( new VimExceptionHandler ( ) ) ; t . setDaemon ( true ) ; t . start ( ) ; } try { logger . debug ( "<STR_LIT>" ) ; logger . debug ( Arrays . toString ( args ) ) ; ProcessBuilder builder = new ProcessBuilder ( args ) ; if ( workingDir != null ) { builder . directory ( new File ( workingDir ) ) ; } p = builder . start ( ) ; logger . debug ( "<STR_LIT>" ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } long maxTime = System . currentTimeMillis ( ) + <NUM_LIT> ; while ( ! vc . isServerRunning ( ) ) { if ( System . currentTimeMillis ( ) >= maxTime ) { try { vc . close ( ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } String message = plugin . getMessage ( "<STR_LIT>" , plugin . getMessage ( "<STR_LIT>" ) ) ; throw new RuntimeException ( message ) ; } long stoptime = <NUM_LIT> ; logger . debug ( "<STR_LIT>" ) ; try { Thread . sleep ( stoptime ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } this . embedded = embedded ; } public synchronized boolean stop ( ) throws IOException { boolean result = false ; if ( p != null ) { Thread waiter = new Thread ( ) { public void run ( ) { try { logger . debug ( "<STR_LIT>" ) ; p . waitFor ( ) ; } catch ( InterruptedException ie ) { } } } ; waiter . start ( ) ; try { waiter . join ( <NUM_LIT> ) ; } catch ( InterruptedException ie ) { } p . destroy ( ) ; p = null ; logger . debug ( "<STR_LIT>" ) ; } if ( vc != null ) { result = vc . close ( ) ; vc = null ; } if ( t != null ) { t . interrupt ( ) ; } return result ; } public void setEditors ( HashSet < VimEditor > editors ) { this . editors = editors ; } public HashSet < VimEditor > getEditors ( ) { return editors ; } public VimEditor getEditor ( int bufid ) { for ( VimEditor veditor : getEditors ( ) ) { if ( veditor . getBufferID ( ) == bufid ) { return veditor ; } } return null ; } protected String [ ] getUserArgs ( ) { String opts = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_OPTS ) ; char [ ] chars = opts . toCharArray ( ) ; char quote = '<CHAR_LIT:U+0020>' ; StringBuffer arg = new StringBuffer ( ) ; ArrayList < String > args = new ArrayList < String > ( ) ; for ( char c : chars ) { if ( c == '<CHAR_LIT:U+0020>' && quote == '<CHAR_LIT:U+0020>' ) { if ( arg . length ( ) > <NUM_LIT:0> ) { args . add ( arg . toString ( ) ) ; arg = new StringBuffer ( ) ; } } else if ( c == '<CHAR_LIT:">' || c == '<STR_LIT>' ) { if ( quote != '<CHAR_LIT:U+0020>' && c == quote ) { quote = '<CHAR_LIT:U+0020>' ; } else if ( quote == '<CHAR_LIT:U+0020>' ) { quote = c ; } else { arg . append ( c ) ; } } else { arg . append ( c ) ; } } if ( arg . length ( ) > <NUM_LIT:0> ) { args . add ( arg . toString ( ) ) ; } return args . toArray ( new String [ args . size ( ) ] ) ; } } </s>
<s> package org . vimplugin . editors ; import java . util . Arrays ; import org . eclim . logging . Logger ; import org . eclipse . core . commands . CommandManager ; import org . eclipse . core . commands . common . NotDefinedException ; import org . eclipse . core . commands . contexts . ContextManager ; import org . eclipse . jface . bindings . Binding ; import org . eclipse . jface . bindings . BindingManager ; import org . eclipse . jface . bindings . Scheme ; import org . eclipse . jface . bindings . keys . KeyBinding ; import org . eclipse . jface . bindings . keys . KeySequence ; import org . eclipse . jface . bindings . keys . ParseException ; import org . eclipse . jface . contexts . IContextIds ; import org . eclipse . ui . IPartListener ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . IWorkbenchPart ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . keys . IBindingService ; public class VimEditorPartListener implements IPartListener { private static final Logger logger = Logger . getLogger ( VimEditorPartListener . class ) ; private static final String [ ] CONTEXT_IDS = new String [ ] { IContextIds . CONTEXT_ID_WINDOW , IContextIds . CONTEXT_ID_DIALOG_AND_WINDOW , } ; private boolean keysDisabled = false ; private IBindingService bindingService ; private String [ ] keys = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private KeySequence [ ] keySequences ; public VimEditorPartListener ( ) { IWorkbench workbench = PlatformUI . getWorkbench ( ) ; bindingService = ( IBindingService ) workbench . getService ( IBindingService . class ) ; keySequences = new KeySequence [ keys . length ] ; for ( int ii = <NUM_LIT:0> ; ii < keys . length ; ii ++ ) { try { keySequences [ ii ] = KeySequence . getInstance ( keys [ ii ] ) ; } catch ( ParseException pe ) { logger . error ( "<STR_LIT>" + keys [ ii ] , pe ) ; } } } public void partActivated ( IWorkbenchPart part ) { if ( part instanceof VimEditor ) { VimEditor editor = ( VimEditor ) part ; if ( editor . isEmbedded ( ) ) { disableKeys ( ) ; } } else { enableKeys ( ) ; } } public void partBroughtToTop ( IWorkbenchPart part ) { } public void partClosed ( IWorkbenchPart part ) { } public void partDeactivated ( IWorkbenchPart part ) { } public void partOpened ( IWorkbenchPart part ) { } private BindingManager getLocalChangeManager ( ) { BindingManager manager = new BindingManager ( new ContextManager ( ) , new CommandManager ( ) ) ; Scheme scheme = bindingService . getActiveScheme ( ) ; try { try { manager . setActiveScheme ( scheme ) ; } catch ( NotDefinedException nde ) { } manager . setLocale ( bindingService . getLocale ( ) ) ; manager . setPlatform ( bindingService . getPlatform ( ) ) ; manager . setBindings ( bindingService . getBindings ( ) ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return manager ; } private void disableKeys ( ) { if ( ! keysDisabled ) { logger . debug ( "<STR_LIT>" + Arrays . toString ( keys ) ) ; BindingManager localChangeManager = getLocalChangeManager ( ) ; String schemeId = localChangeManager . getActiveScheme ( ) . getId ( ) ; for ( KeySequence keySequence : keySequences ) { for ( String contextId : CONTEXT_IDS ) { localChangeManager . removeBindings ( keySequence , schemeId , contextId , null , null , null , Binding . USER ) ; localChangeManager . addBinding ( new KeyBinding ( keySequence , null , schemeId , contextId , null , null , null , Binding . USER ) ) ; } } keysDisabled = true ; saveKeyChanges ( localChangeManager ) ; } } private void enableKeys ( ) { if ( keysDisabled ) { logger . debug ( "<STR_LIT>" ) ; BindingManager localChangeManager = getLocalChangeManager ( ) ; String schemeId = localChangeManager . getActiveScheme ( ) . getId ( ) ; for ( KeySequence keySequence : keySequences ) { for ( String contextId : CONTEXT_IDS ) { localChangeManager . removeBindings ( keySequence , schemeId , contextId , null , null , null , Binding . USER ) ; } } keysDisabled = false ; saveKeyChanges ( localChangeManager ) ; } } private void saveKeyChanges ( BindingManager localChangeManager ) { try { bindingService . savePreferences ( localChangeManager . getActiveScheme ( ) , localChangeManager . getBindings ( ) ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } } </s>
<s> package org . vimplugin . editors ; import org . eclipse . swt . custom . StyledText ; import org . eclipse . swt . widgets . Composite ; public class VimText extends StyledText { public VimText ( Composite parent , int style ) { super ( parent , style ) ; } } </s>
<s> package org . vimplugin . editors ; import java . io . ByteArrayInputStream ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . lang . reflect . Field ; import java . net . URI ; import org . eclim . logging . Logger ; import org . eclim . util . CommandExecutor ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IFile ; 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 . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Status ; import org . eclipse . jface . dialogs . IDialogConstants ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . preference . PreferenceDialog ; import org . eclipse . jface . text . IDocument ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . graphics . Rectangle ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Canvas ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorInput ; import org . eclipse . ui . IEditorSite ; import org . eclipse . ui . IFileEditorInput ; import org . eclipse . ui . IMemento ; import org . eclipse . ui . IURIEditorInput ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . PartInitException ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . dialogs . PreferencesUtil ; import org . eclipse . ui . editors . text . TextEditor ; import org . eclipse . ui . internal . part . StatusPart ; import org . eclipse . ui . texteditor . AbstractTextEditor ; import org . eclipse . ui . texteditor . IDocumentProvider ; import org . vimplugin . DisplayUtils ; import org . vimplugin . VimConnection ; import org . vimplugin . VimPlugin ; import org . vimplugin . VimServer ; import org . vimplugin . preferences . PreferenceConstants ; public class VimEditor extends TextEditor { private static final Logger logger = Logger . getLogger ( VimEditor . class ) ; private static final String ECLIMD_VIEW_ID = "<STR_LIT>" ; private int serverID ; private int bufferID ; private Canvas editorGUI ; private IFile selectedFile ; private IDocument document ; private VimViewer viewer ; private VimDocumentProvider documentProvider ; private boolean dirty ; private boolean alreadyClosed = false ; private Composite parent ; public static final String win32WID = "<STR_LIT>" ; public static final String gtkWID = "<STR_LIT>" ; private Shell shell ; private boolean embedded ; private boolean tabbed ; private boolean documentListen ; public VimEditor ( ) { super ( ) ; bufferID = - <NUM_LIT:1> ; setDocumentProvider ( documentProvider = new VimDocumentProvider ( ) ) ; } @ Override public void createPartControl ( Composite parent ) { this . parent = parent ; this . shell = parent . getShell ( ) ; VimPlugin plugin = VimPlugin . getDefault ( ) ; if ( ! plugin . gvimAvailable ( ) ) { MessageDialog dialog = new MessageDialog ( shell , "<STR_LIT>" , null , plugin . getMessage ( "<STR_LIT>" ) , MessageDialog . ERROR , new String [ ] { IDialogConstants . OK_LABEL , IDialogConstants . CANCEL_LABEL } , <NUM_LIT:0> ) { protected void buttonPressed ( int buttonId ) { super . buttonPressed ( buttonId ) ; if ( buttonId == IDialogConstants . OK_ID ) { PreferenceDialog prefs = PreferencesUtil . createPreferenceDialogOn ( shell , "<STR_LIT>" , null , null ) ; if ( prefs != null ) { prefs . open ( ) ; } } } } ; dialog . open ( ) ; if ( ! plugin . gvimAvailable ( ) ) { throw new RuntimeException ( plugin . getMessage ( "<STR_LIT>" ) ) ; } } IPreferenceStore prefs = plugin . getPreferenceStore ( ) ; tabbed = prefs . getBoolean ( PreferenceConstants . P_TABBED ) ; embedded = prefs . getBoolean ( PreferenceConstants . P_EMBED ) ; documentListen = false ; if ( embedded ) { if ( ! plugin . gvimEmbedSupported ( ) ) { String message = plugin . getMessage ( "<STR_LIT>" , plugin . getMessage ( "<STR_LIT>" ) ) ; throw new RuntimeException ( message ) ; } } if ( ! plugin . gvimNbSupported ( ) ) { String message = plugin . getMessage ( "<STR_LIT>" , plugin . getMessage ( "<STR_LIT>" ) ) ; throw new RuntimeException ( message ) ; } alreadyClosed = false ; dirty = false ; String projectPath = null ; String filePath = null ; IEditorInput input = getEditorInput ( ) ; if ( input instanceof IFileEditorInput ) { selectedFile = ( ( IFileEditorInput ) input ) . getFile ( ) ; IProject project = selectedFile . getProject ( ) ; IPath path = project . getRawLocation ( ) ; if ( path == null ) { String name = project . getName ( ) ; path = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) ; path = path . append ( name ) ; } projectPath = path . toPortableString ( ) ; filePath = selectedFile . getRawLocation ( ) . toPortableString ( ) ; if ( filePath . toLowerCase ( ) . indexOf ( projectPath . toLowerCase ( ) ) != - <NUM_LIT:1> ) { filePath = filePath . substring ( projectPath . length ( ) + <NUM_LIT:1> ) ; } } else { URI uri = ( ( IURIEditorInput ) input ) . getURI ( ) ; filePath = uri . toString ( ) . substring ( "<STR_LIT>" . length ( ) ) ; filePath = filePath . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; } if ( filePath != null ) { editorGUI = new Canvas ( parent , SWT . EMBEDDED ) ; VimConnection vc = createVim ( projectPath , filePath , parent ) ; viewer = new VimViewer ( bufferID , vc , editorGUI != null ? editorGUI : parent , SWT . EMBEDDED ) ; viewer . getTextWidget ( ) . setVisible ( false ) ; viewer . setDocument ( document ) ; viewer . setEditable ( isEditable ( ) ) ; try { Field fSourceViewer = AbstractTextEditor . class . getDeclaredField ( "<STR_LIT>" ) ; fSourceViewer . setAccessible ( true ) ; fSourceViewer . set ( this , viewer ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } boolean startEclimd = plugin . getPreferenceStore ( ) . getBoolean ( PreferenceConstants . P_START_ECLIMD ) ; if ( startEclimd ) { IWorkbenchPage page = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) ; try { if ( page != null && page . findView ( ECLIMD_VIEW_ID ) == null ) { page . showView ( ECLIMD_VIEW_ID ) ; } } catch ( PartInitException pie ) { logger . error ( "<STR_LIT>" , pie ) ; } } if ( embedded ) { plugin . getPartListener ( ) . partOpened ( this ) ; plugin . getPartListener ( ) . partBroughtToTop ( this ) ; plugin . getPartListener ( ) . partActivated ( this ) ; } } } private VimConnection createVim ( String workingDir , String filePath , Composite parent ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; bufferID = plugin . getNumberOfBuffers ( ) ; plugin . setNumberOfBuffers ( bufferID + <NUM_LIT:1> ) ; IStatus status = null ; VimConnection vc = null ; if ( embedded ) { try { vc = createEmbeddedVim ( workingDir , filePath , editorGUI ) ; } catch ( Exception e ) { embedded = false ; vc = createExternalVim ( workingDir , filePath , parent ) ; String message = plugin . getMessage ( e instanceof NoSuchFieldException ? "<STR_LIT>" : "<STR_LIT>" ) ; status = new Status ( IStatus . ERROR , PlatformUI . PLUGIN_ID , <NUM_LIT:0> , message , e ) ; } } else { vc = createExternalVim ( workingDir , filePath , parent ) ; String message = plugin . getMessage ( "<STR_LIT>" ) ; status = new Status ( IStatus . OK , PlatformUI . PLUGIN_ID , message ) ; } if ( status != null ) { editorGUI . dispose ( ) ; editorGUI = null ; new StatusPart ( parent , status ) ; if ( status . getSeverity ( ) == IStatus . OK ) { for ( Control c : parent . getChildren ( ) ) { if ( c instanceof Composite ) { for ( Control ch : ( ( Composite ) c ) . getChildren ( ) ) { if ( ch instanceof Button ) { ch . setVisible ( false ) ; } } } } } } plugin . getVimserver ( serverID ) . getEditors ( ) . add ( this ) ; return vc ; } private VimConnection createExternalVim ( String workingDir , String filePath , Composite parent ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; boolean first = plugin . getVimserver ( VimPlugin . DEFAULT_VIMSERVER_ID ) == null ; serverID = tabbed ? plugin . getDefaultVimServer ( ) : plugin . createVimServer ( ) ; plugin . getVimserver ( serverID ) . start ( workingDir , filePath , tabbed , first ) ; VimConnection vc = plugin . getVimserver ( serverID ) . getVc ( ) ; vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT:\">" + filePath + "<STR_LIT:\">" ) ; if ( documentListen ) { vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; } else { vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; } return vc ; } private VimConnection createEmbeddedVim ( String workingDir , String filePath , Composite parent ) throws Exception { long wid = <NUM_LIT:0> ; Field f = null ; try { f = Composite . class . getField ( VimEditor . gtkWID ) ; } catch ( NoSuchFieldException nsfe ) { f = Control . class . getField ( VimEditor . win32WID ) ; } wid = f . getLong ( parent ) ; VimPlugin plugin = VimPlugin . getDefault ( ) ; serverID = plugin . createVimServer ( ) ; plugin . getVimserver ( serverID ) . start ( workingDir , wid ) ; VimConnection vc = plugin . getVimserver ( serverID ) . getVc ( ) ; vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT:\">" + filePath + "<STR_LIT:\">" ) ; if ( documentListen ) { vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; } else { vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; } return vc ; } public void forceDispose ( ) { final VimEditor editor = this ; Display display = getSite ( ) . getShell ( ) . getDisplay ( ) ; display . asyncExec ( new Runnable ( ) { public void run ( ) { if ( editor != null && ! editor . alreadyClosed ) { editor . setDirty ( false ) ; editor . showBusy ( true ) ; editor . close ( false ) ; getSite ( ) . getPage ( ) . closeEditor ( editor , false ) ; } } } ) ; } @ Override public void dispose ( ) { close ( true ) ; if ( viewer != null ) { viewer . getTextWidget ( ) . dispose ( ) ; viewer = null ; } if ( editorGUI != null ) { editorGUI . dispose ( ) ; editorGUI = null ; } document = null ; super . dispose ( ) ; } @ Override public void close ( boolean save ) { if ( this . alreadyClosed ) { super . close ( false ) ; return ; } VimPlugin plugin = VimPlugin . getDefault ( ) ; alreadyClosed = true ; VimServer server = plugin . getVimserver ( serverID ) ; if ( server != null ) { server . getEditors ( ) . remove ( this ) ; if ( save && dirty ) { server . getVc ( ) . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; dirty = false ; firePropertyChange ( PROP_DIRTY ) ; } if ( server . getEditors ( ) . size ( ) > <NUM_LIT:0> ) { server . getVc ( ) . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; String gvim = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_GVIM ) ; String [ ] args = new String [ <NUM_LIT:5> ] ; args [ <NUM_LIT:0> ] = gvim ; args [ <NUM_LIT:1> ] = "<STR_LIT>" ; args [ <NUM_LIT:2> ] = String . valueOf ( server . getID ( ) ) ; args [ <NUM_LIT:3> ] = "<STR_LIT>" ; args [ <NUM_LIT:4> ] = "<STR_LIT>" ; try { CommandExecutor . execute ( args , <NUM_LIT:1000> ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } else { try { VimConnection vc = server . getVc ( ) ; if ( vc != null ) { server . getVc ( ) . function ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; } plugin . stopVimServer ( serverID ) ; } catch ( IOException e ) { message ( plugin . getMessage ( "<STR_LIT>" ) , e ) ; } } } super . close ( false ) ; } @ Override public boolean isEditable ( ) { return false ; } @ Override public void doSave ( IProgressMonitor monitor ) { VimPlugin . getDefault ( ) . getVimserver ( serverID ) . getVc ( ) . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; dirty = false ; firePropertyChange ( PROP_DIRTY ) ; } @ Override public void doSaveAs ( ) { performSaveAs ( null ) ; } @ Override public void init ( IEditorSite site , IEditorInput input ) throws PartInitException { setSite ( site ) ; setInput ( input ) ; try { document = documentProvider . createDocument ( input ) ; } catch ( Exception e ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; message ( plugin . getMessage ( "<STR_LIT>" ) , e ) ; } } @ Override public boolean isDirty ( ) { return dirty ; } @ Override public boolean isSaveAsAllowed ( ) { return true ; } private String getFilePath ( IEditorInput input ) { String filePath = null ; if ( input instanceof IFileEditorInput ) { selectedFile = ( ( IFileEditorInput ) input ) . getFile ( ) ; filePath = selectedFile . getRawLocation ( ) . toPortableString ( ) ; } else { URI uri = ( ( IURIEditorInput ) input ) . getURI ( ) ; filePath = uri . toString ( ) . substring ( "<STR_LIT>" . length ( ) ) ; filePath = filePath . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; } return filePath ; } public void setDirty ( boolean result ) { dirty = result ; final VimEditor vime = this ; Display display = getSite ( ) . getShell ( ) . getDisplay ( ) ; display . asyncExec ( new Runnable ( ) { public void run ( ) { vime . firePropertyChangeAsync ( PROP_DIRTY ) ; } } ) ; } public void firePropertyChangeAsync ( int prop ) { super . firePropertyChange ( prop ) ; } @ Override public void setFocus ( ) { if ( alreadyClosed ) { getSite ( ) . getPage ( ) . closeEditor ( this , false ) ; return ; } if ( embedded ) { parent . setFocus ( ) ; } VimPlugin plugin = VimPlugin . getDefault ( ) ; VimConnection conn = plugin . getVimserver ( serverID ) . getVc ( ) ; try { String cursor = conn . function ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; if ( cursor == null ) { return ; } } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" , ioe ) ; } conn . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" ) ; if ( embedded && parent . getDisplay ( ) . getActiveShell ( ) != null ) { boolean autoClickFocus = plugin . getPreferenceStore ( ) . getBoolean ( PreferenceConstants . P_FOCUS_AUTO_CLICK ) ; if ( autoClickFocus ) { Rectangle bounds = parent . getBounds ( ) ; final Point point = parent . toDisplay ( bounds . x + <NUM_LIT:5> , bounds . y + bounds . height - <NUM_LIT> ) ; new Thread ( ) { public void run ( ) { DisplayUtils . doClick ( parent . getDisplay ( ) , point . x , point . y , true ) ; } } . start ( ) ; } } } public void setTitleTo ( final String path ) { Display . getDefault ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { String filename = path . substring ( path . lastIndexOf ( File . separator ) + <NUM_LIT:1> ) ; setPartName ( filename ) ; } } ) ; } @ Override public IDocumentProvider getDocumentProvider ( ) { return documentProvider ; } public void setDocumentText ( String text ) { document . set ( text ) ; setDirty ( true ) ; } private String removeBackSlashes ( String text ) { if ( text . length ( ) <= <NUM_LIT:2> ) return text ; int offset = <NUM_LIT:0> , length = text . length ( ) , offset1 = <NUM_LIT:0> ; String newText = "<STR_LIT>" ; while ( offset < length ) { offset1 = text . indexOf ( '<STR_LIT:\\>' , offset ) ; if ( offset1 < <NUM_LIT:0> ) { newText = newText + text . substring ( offset ) ; break ; } newText = newText + text . substring ( offset , offset1 ) + ( text . length ( ) > offset1 + <NUM_LIT:1> ? text . substring ( offset1 + <NUM_LIT:1> , offset1 + <NUM_LIT:2> ) : "<STR_LIT>" ) ; offset = offset1 + <NUM_LIT:2> ; } return newText ; } public void insertDocumentText ( String text , int offset ) { text = removeBackSlashes ( text ) ; try { String contents = document . get ( ) ; offset = FileUtils . byteOffsetToCharOffset ( new ByteArrayInputStream ( contents . getBytes ( ) ) , offset , null ) ; String first = contents . substring ( <NUM_LIT:0> , offset ) ; String last = contents . substring ( offset ) ; if ( text . equals ( new String ( "<STR_LIT>" ) ) ) { first = first + System . getProperty ( "<STR_LIT>" ) + last ; } else { first = first + text + last ; } document . set ( first ) ; setDirty ( true ) ; } catch ( Exception e ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; logger . error ( plugin . getMessage ( "<STR_LIT>" ) , e ) ; } } public void removeDocumentText ( int offset , int length ) { try { String contents = document . get ( ) ; int loffset = FileUtils . byteOffsetToCharOffset ( new ByteArrayInputStream ( contents . getBytes ( ) ) , offset + length , null ) ; offset = FileUtils . byteOffsetToCharOffset ( new ByteArrayInputStream ( contents . getBytes ( ) ) , offset , null ) ; length = loffset - offset ; String first = contents . substring ( <NUM_LIT:0> , offset ) ; String last = contents . substring ( offset + length ) ; first = first + last ; document . set ( first ) ; setDirty ( true ) ; } catch ( Exception e ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; logger . error ( plugin . getMessage ( "<STR_LIT>" ) , e ) ; } } @ Override protected void createActions ( ) { super . createActions ( ) ; } @ Override protected void doSetInput ( IEditorInput input ) throws CoreException { if ( getEditorInput ( ) != null ) { String oldFilePath = getFilePath ( getEditorInput ( ) ) ; String newFilePath = getFilePath ( input ) ; if ( ! oldFilePath . equals ( newFilePath ) ) { VimConnection vc = VimPlugin . getDefault ( ) . getVimserver ( serverID ) . getVc ( ) ; if ( input instanceof IFileEditorInput ) { IProject project = selectedFile . getProject ( ) ; IPath path = project . getRawLocation ( ) ; if ( path == null ) { String name = project . getName ( ) ; path = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) ; path = path . append ( name ) ; } String projectPath = path . toPortableString ( ) ; if ( newFilePath . toLowerCase ( ) . indexOf ( projectPath . toLowerCase ( ) ) != - <NUM_LIT:1> ) { newFilePath = newFilePath . substring ( projectPath . length ( ) + <NUM_LIT:1> ) ; } } if ( isDirty ( ) ) { vc . remotesend ( "<STR_LIT>" + newFilePath . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) + "<STR_LIT>" ) ; } else { vc . command ( bufferID , "<STR_LIT>" , "<STR_LIT:\">" + newFilePath + "<STR_LIT:\">" ) ; } } } super . doSetInput ( input ) ; } @ Override public void saveState ( IMemento arg0 ) { } public IFile getSelectedFile ( ) { return selectedFile ; } public int getServerID ( ) { return serverID ; } public int getBufferID ( ) { return bufferID ; } public boolean isEmbedded ( ) { return embedded ; } private void message ( String message , Throwable e ) { String stacktrace ; StringWriter sw = null ; PrintWriter pw = null ; try { sw = new StringWriter ( ) ; pw = new PrintWriter ( sw ) ; e . printStackTrace ( pw ) ; stacktrace = sw . toString ( ) ; } finally { try { if ( pw != null ) pw . close ( ) ; if ( sw != null ) sw . close ( ) ; } catch ( IOException ignore ) { } } MessageDialog . openError ( shell , "<STR_LIT>" , message + stacktrace ) ; } } </s>
<s> package org . vimplugin . editors ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . ui . editors . text . FileDocumentProvider ; public class VimDocumentProvider extends FileDocumentProvider { private IDocument document ; protected IDocument createDocument ( Object element ) throws CoreException { document = super . createDocument ( element ) ; return document ; } } </s>
<s> package org . vimplugin . editors ; import java . io . ByteArrayInputStream ; import org . eclim . logging . Logger ; import org . eclim . util . file . FileUtils ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IEventConsumer ; import org . eclipse . jface . text . IFindReplaceTarget ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . IRewriteTarget ; import org . eclipse . jface . text . ITextDoubleClickStrategy ; import org . eclipse . jface . text . ITextHover ; import org . eclipse . jface . text . ITextInputListener ; import org . eclipse . jface . text . ITextListener ; import org . eclipse . jface . text . ITextOperationTarget ; import org . eclipse . jface . text . ITextViewerExtension ; import org . eclipse . jface . text . IUndoManager ; import org . eclipse . jface . text . IViewportListener ; import org . eclipse . jface . text . TextPresentation ; import org . eclipse . jface . text . source . Annotation ; import org . eclipse . jface . text . source . IAnnotationHover ; import org . eclipse . jface . text . source . IAnnotationModel ; import org . eclipse . jface . text . source . ISourceViewer ; import org . eclipse . jface . text . source . SourceViewerConfiguration ; import org . eclipse . jface . viewers . ISelectionProvider ; import org . eclipse . swt . custom . StyledText ; import org . eclipse . swt . custom . VerifyKeyListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . vimplugin . VimConnection ; public class VimViewer implements ISourceViewer , ITextViewerExtension { private static final Logger logger = Logger . getLogger ( VimViewer . class ) ; private int bufferID ; private IDocument document ; private VimText textWidget ; private VimConnection vimConnection ; public VimViewer ( int bufferID , VimConnection vimConnection , Composite parent , int styles ) { this . textWidget = new VimText ( parent , styles ) ; this . bufferID = bufferID ; this . vimConnection = vimConnection ; } public void configure ( SourceViewerConfiguration configuration ) { } public void setAnnotationHover ( IAnnotationHover annotationHover ) { } public void setDocument ( IDocument document , IAnnotationModel annotationModel ) { setDocument ( document ) ; } public void setDocument ( IDocument document , IAnnotationModel annotationModel , int modelRangeOffset , int modelRangeLength ) { setDocument ( document , modelRangeOffset , modelRangeLength ) ; } public IAnnotationModel getAnnotationModel ( ) { return null ; } public void setRangeIndicator ( Annotation rangeIndicator ) { } public void setRangeIndication ( int offset , int length , boolean moveCursor ) { } public IRegion getRangeIndication ( ) { return null ; } public void removeRangeIndication ( ) { } public void showAnnotations ( boolean show ) { } public StyledText getTextWidget ( ) { return textWidget ; } public void setUndoManager ( IUndoManager manager ) { } public void setTextDoubleClickStrategy ( ITextDoubleClickStrategy strategy , String contentType ) { } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public void setAutoIndentStrategy ( org . eclipse . jface . text . IAutoIndentStrategy strategy , String contentType ) { } public void setTextHover ( ITextHover textViewerHover , String contentType ) { } public void activatePlugins ( ) { } public void resetPlugins ( ) { } public void addViewportListener ( IViewportListener listener ) { } public void removeViewportListener ( IViewportListener listener ) { } public void addTextListener ( ITextListener listener ) { } public void removeTextListener ( ITextListener listener ) { } public void addTextInputListener ( ITextInputListener listener ) { } public void removeTextInputListener ( ITextInputListener listener ) { } public void setDocument ( IDocument document ) { this . document = document ; } public IDocument getDocument ( ) { return document ; } public void setEventConsumer ( IEventConsumer consumer ) { } public void setEditable ( boolean editable ) { } public boolean isEditable ( ) { return true ; } public void setDocument ( IDocument document , int modelRangeOffset , int modelRangeLength ) { setDocument ( document ) ; } public void setVisibleRegion ( int offset , int length ) { } public void resetVisibleRegion ( ) { } public IRegion getVisibleRegion ( ) { return null ; } public boolean overlapsWithVisibleRegion ( int offset , int length ) { return false ; } public void changeTextPresentation ( TextPresentation presentation , boolean controlRedraw ) { } public void invalidateTextPresentation ( ) { } public void setTextColor ( Color color ) { } public void setTextColor ( Color color , int offset , int length , boolean controlRedraw ) { } public ITextOperationTarget getTextOperationTarget ( ) { return null ; } public IFindReplaceTarget getFindReplaceTarget ( ) { return null ; } public void setDefaultPrefixes ( String [ ] defaultPrefixes , String contentType ) { } public void setIndentPrefixes ( String [ ] indentPrefixes , String contentType ) { } public void setSelectedRange ( int offset , int length ) { try { int [ ] pos = FileUtils . offsetToLineColumn ( new ByteArrayInputStream ( document . get ( ) . getBytes ( ) ) , offset ) ; vimConnection . command ( bufferID , "<STR_LIT>" , "<STR_LIT>" + pos [ <NUM_LIT:0> ] + '<CHAR_LIT:/>' + pos [ <NUM_LIT:1> ] ) ; vimConnection . remotesend ( "<STR_LIT>" ) ; vimConnection . remotesend ( "<STR_LIT>" ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } public Point getSelectedRange ( ) { return null ; } public ISelectionProvider getSelectionProvider ( ) { return null ; } public void revealRange ( int offset , int length ) { } public void setTopIndex ( int index ) { } public int getTopIndex ( ) { return <NUM_LIT:0> ; } public int getTopIndexStartOffset ( ) { return <NUM_LIT:0> ; } public int getBottomIndex ( ) { return <NUM_LIT:0> ; } public int getBottomIndexEndOffset ( ) { return <NUM_LIT:0> ; } public int getTopInset ( ) { return <NUM_LIT:0> ; } public void prependVerifyKeyListener ( VerifyKeyListener listener ) { } public void appendVerifyKeyListener ( VerifyKeyListener listener ) { } public void removeVerifyKeyListener ( VerifyKeyListener listener ) { } public Control getControl ( ) { return getTextWidget ( ) ; } public void setMark ( int arg0 ) { } public int getMark ( ) { return - <NUM_LIT:1> ; } public void setRedraw ( boolean redraw ) { } public IRewriteTarget getRewriteTarget ( ) { return null ; } } </s>
<s> package org . vimplugin ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . text . MessageFormat ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Locale ; import java . util . Properties ; import java . util . ResourceBundle ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . logging . Logger ; import org . eclim . util . CommandExecutor ; import org . eclim . util . IOUtils ; import org . eclim . util . StringUtils ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . resource . ImageDescriptor ; import org . eclipse . swt . widgets . Display ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; import org . vimplugin . editors . VimEditorPartListener ; import org . vimplugin . preferences . PreferenceConstants ; public class VimPlugin extends AbstractUIPlugin { private static final Logger logger = Logger . getLogger ( VimPlugin . class ) ; private static final String GVIM_FEATURE_TEST = "<STR_LIT>" ; private static final String FEATURES_COMMAND_UNIX = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static final String FEATURES_COMMAND_WINDOWS = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static VimPlugin plugin ; public static final int DEFAULT_VIMSERVER_ID = <NUM_LIT:0> ; private HashMap < String , Boolean > features ; private VimEditorPartListener partListener ; public static VimPlugin getDefault ( ) { return plugin ; } public static ImageDescriptor getImageDescriptor ( String path ) { return AbstractUIPlugin . imageDescriptorFromPlugin ( "<STR_LIT>" , path ) ; } private int nextServerID ; private int numberOfBuffers ; private int seqNo ; private final HashMap < Integer , VimServer > vimServers = new HashMap < Integer , VimServer > ( ) ; private Properties properties ; private ResourceBundle messages ; public VimPlugin ( ) { plugin = this ; properties = new Properties ( ) ; try { properties . load ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; } catch ( IOException ioe ) { MessageDialog . openError ( getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getShell ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ioe . printStackTrace ( ) ; } messages = ResourceBundle . getBundle ( "<STR_LIT>" , Locale . getDefault ( ) , getClass ( ) . getClassLoader ( ) ) ; } public int getDefaultVimServer ( ) { return createVimServer ( DEFAULT_VIMSERVER_ID ) ; } public int createVimServer ( ) { return createVimServer ( nextServerID ++ ) ; } private int createVimServer ( int id ) { if ( ! vimServers . containsKey ( id ) ) { VimServer vimserver = new VimServer ( id ) ; vimServers . put ( id , vimserver ) ; } return id ; } public boolean stopVimServer ( int id ) { boolean b = false ; try { b = getVimserver ( id ) . stop ( ) ; vimServers . remove ( id ) ; } catch ( IOException ioe ) { MessageDialog . openError ( getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getShell ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ioe . printStackTrace ( ) ; } return b ; } public VimServer getVimserver ( int id ) { return vimServers . get ( id ) ; } @ Override public void start ( BundleContext context ) throws Exception { super . start ( context ) ; nextServerID = <NUM_LIT:1> ; numberOfBuffers = <NUM_LIT:1> ; seqNo = <NUM_LIT:0> ; partListener = new VimEditorPartListener ( ) ; Display . getDefault ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { IWorkbench workbench = PlatformUI . getWorkbench ( ) ; workbench . getActiveWorkbenchWindow ( ) . getActivePage ( ) . addPartListener ( partListener ) ; } } ) ; } @ Override public void stop ( BundleContext context ) throws Exception { super . stop ( context ) ; plugin = null ; if ( PlatformUI . isWorkbenchRunning ( ) ) { IWorkbench workbench = PlatformUI . getWorkbench ( ) ; if ( workbench != null ) { workbench . getActiveWorkbenchWindow ( ) . getActivePage ( ) . removePartListener ( partListener ) ; } } } public int nextSeqNo ( ) { return seqNo ++ ; } public void setNumberOfBuffers ( int numberOfBuffers ) { this . numberOfBuffers = numberOfBuffers ; } public int getNumberOfBuffers ( ) { return numberOfBuffers ; } public boolean gvimAvailable ( ) { String gvim = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_GVIM ) ; File file = new File ( gvim ) ; if ( file . exists ( ) ) { return true ; } return false ; } public boolean gvimEmbedSupported ( ) { return hasFeature ( "<STR_LIT>" ) ; } public boolean gvimNbSupported ( ) { return hasFeature ( "<STR_LIT>" ) ; } public boolean gvimNbDocumentListenSupported ( ) { return hasFeature ( "<STR_LIT>" ) ; } public void resetGvimState ( ) { features = null ; } public VimEditorPartListener getPartListener ( ) { return this . partListener ; } private boolean hasFeature ( String name ) { if ( features == null ) { String gvim = VimPlugin . getDefault ( ) . getPreferenceStore ( ) . getString ( PreferenceConstants . P_GVIM ) ; try { File tempFile = File . createTempFile ( "<STR_LIT>" , null ) ; tempFile . deleteOnExit ( ) ; String command = FEATURES_COMMAND_UNIX ; if ( Platform . getOS ( ) . equals ( Platform . OS_WIN32 ) ) { command = FEATURES_COMMAND_WINDOWS ; } command = GVIM_FEATURE_TEST . replaceFirst ( "<STR_LIT>" , command ) ; command = command . replaceFirst ( "<STR_LIT>" , tempFile . getAbsolutePath ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) . replaceAll ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; String [ ] cmd = { gvim , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , command } ; logger . debug ( Arrays . toString ( cmd ) ) ; CommandExecutor process = CommandExecutor . execute ( cmd , <NUM_LIT> ) ; if ( process . getReturnCode ( ) != <NUM_LIT:0> ) { logger . error ( "<STR_LIT>" + process . getErrorMessage ( ) ) ; return false ; } FileInputStream in = null ; try { String result = IOUtils . toString ( in = new FileInputStream ( tempFile ) ) ; result = result . trim ( ) ; logger . debug ( "<STR_LIT>" + result ) ; features = new HashMap < String , Boolean > ( ) ; for ( String f : StringUtils . split ( result ) ) { String [ ] keyVal = StringUtils . split ( f , "<STR_LIT::>" ) ; if ( keyVal . length != <NUM_LIT:2> ) { logger . error ( "<STR_LIT>" + result ) ; return false ; } features . put ( keyVal [ <NUM_LIT:0> ] , Boolean . valueOf ( keyVal [ <NUM_LIT:1> ] . equals ( "<STR_LIT:1>" ) ) ) ; } } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" , ioe ) ; IOUtils . closeQuietly ( in ) ; return false ; } finally { IOUtils . closeQuietly ( in ) ; try { tempFile . delete ( ) ; } catch ( Exception ignore ) { } } } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; return false ; } } return features . containsKey ( name ) && features . get ( name ) . booleanValue ( ) ; } public String getProperty ( String name ) { return properties . getProperty ( name ) ; } public String getProperty ( String name , String def ) { return properties . getProperty ( name , def ) ; } public String getMessage ( String key , Object ... args ) { String message = messages . getString ( key ) ; if ( Os . isFamily ( Os . FAMILY_MAC ) ) { message = message . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; } if ( args != null && args . length > <NUM_LIT:0> ) { return MessageFormat . format ( message , args ) ; } return message ; } } </s>
<s> package org . vimplugin ; public class VimException extends Exception { private static final long serialVersionUID = <NUM_LIT:1L> ; public VimException ( String message ) { super ( message ) ; } public VimException ( String message , Exception cause ) { super ( message , cause ) ; } } </s>
<s> package org . vimplugin . preferences ; import org . eclipse . core . runtime . preferences . AbstractPreferenceInitializer ; import org . eclipse . jface . preference . IPreferenceStore ; import org . vimplugin . VimPlugin ; public class PreferenceInitializer extends AbstractPreferenceInitializer { @ Override public void initializeDefaultPreferences ( ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; IPreferenceStore store = plugin . getPreferenceStore ( ) ; store . setDefault ( PreferenceConstants . P_PORT , <NUM_LIT> ) ; store . setDefault ( PreferenceConstants . P_EMBED , "<STR_LIT:true>" . equals ( plugin . getProperty ( "<STR_LIT>" ) ) ) ; store . setDefault ( PreferenceConstants . P_TABBED , true ) ; store . setDefault ( PreferenceConstants . P_FOCUS_AUTO_CLICK , true ) ; store . setDefault ( PreferenceConstants . P_START_ECLIMD , true ) ; store . setDefault ( PreferenceConstants . P_GVIM , plugin . getProperty ( "<STR_LIT>" ) ) ; } } </s>
<s> package org . vimplugin . preferences ; public class PreferenceConstants { public static final String P_PORT = "<STR_LIT>" ; public static final String P_GVIM = "<STR_LIT>" ; public static final String P_OPTS = "<STR_LIT>" ; public static final String P_EMBED = "<STR_LIT>" ; public static final String P_TABBED = "<STR_LIT>" ; public static final String P_FOCUS_AUTO_CLICK = "<STR_LIT>" ; public static final String P_START_ECLIMD = "<STR_LIT>" ; } </s>
<s> package org . vimplugin . preferences ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclipse . jface . preference . BooleanFieldEditor ; import org . eclipse . jface . preference . FieldEditorPreferencePage ; import org . eclipse . jface . preference . FileFieldEditor ; import org . eclipse . jface . preference . StringFieldEditor ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . IWorkbenchPreferencePage ; import org . vimplugin . VimPlugin ; public class VimPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public VimPreferences ( ) { super ( FieldEditorPreferencePage . GRID ) ; VimPlugin plugin = VimPlugin . getDefault ( ) ; setPreferenceStore ( plugin . getPreferenceStore ( ) ) ; setDescription ( plugin . getMessage ( "<STR_LIT>" ) ) ; } @ Override public void createFieldEditors ( ) { VimPlugin plugin = VimPlugin . getDefault ( ) ; if ( ! Os . isFamily ( Os . FAMILY_MAC ) ) { addField ( new BooleanFieldEditor ( PreferenceConstants . P_EMBED , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; } addField ( new BooleanFieldEditor ( PreferenceConstants . P_TABBED , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; addField ( new BooleanFieldEditor ( PreferenceConstants . P_START_ECLIMD , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; addField ( new BooleanFieldEditor ( PreferenceConstants . P_FOCUS_AUTO_CLICK , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; addField ( new StringFieldEditor ( PreferenceConstants . P_PORT , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; addField ( new FileFieldEditor ( PreferenceConstants . P_GVIM , plugin . getMessage ( "<STR_LIT>" ) , true , getFieldEditorParent ( ) ) ) ; addField ( new StringFieldEditor ( PreferenceConstants . P_OPTS , plugin . getMessage ( "<STR_LIT>" ) , getFieldEditorParent ( ) ) ) ; } public void init ( IWorkbench workbench ) { } public boolean performOk ( ) { boolean result = super . performOk ( ) ; VimPlugin . getDefault ( ) . resetGvimState ( ) ; return result ; } } </s>
<s> package org . vimplugin . views ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . Arrays ; import org . eclim . logging . Logger ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Listener ; import org . eclipse . swt . widgets . Text ; import org . eclipse . ui . part . ViewPart ; import org . vimplugin . VimPlugin ; public class CommandView extends ViewPart { private static final Logger logger = Logger . getLogger ( CommandView . class ) ; private Text input ; @ Override public void createPartControl ( Composite parent ) { input = new Text ( parent , SWT . MULTI ) ; input . addListener ( SWT . KeyDown , new Listener ( ) { public void handleEvent ( Event e ) { if ( e . character == <NUM_LIT> ) { String line1 = input . getText ( ) . substring ( <NUM_LIT:3> ) ; if ( input . getText ( ) . startsWith ( "<STR_LIT>" ) ) { String [ ] args = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , line1 } ; try { logger . debug ( "<STR_LIT>" + Arrays . toString ( args ) ) ; Process process = new ProcessBuilder ( args ) . start ( ) ; InputStream is = process . getInputStream ( ) ; InputStreamReader isr = new InputStreamReader ( is ) ; BufferedReader br = new BufferedReader ( isr ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { logger . debug ( line ) ; } process . waitFor ( ) ; logger . debug ( "<STR_LIT>" + process . exitValue ( ) ) ; } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" , ioe ) ; } catch ( InterruptedException ie ) { logger . error ( "<STR_LIT>" , ie ) ; } } else if ( input . getText ( ) . startsWith ( "<STR_LIT>" ) ) { VimPlugin . getDefault ( ) . getVimserver ( <NUM_LIT:0> ) . getVc ( ) . plain ( line1 ) ; } input . setText ( "<STR_LIT>" ) ; } } } ) ; } @ Override public void setFocus ( ) { input . setFocus ( ) ; } } </s>
<s> package org . vimplugin ; import org . eclim . logging . Logger ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; public class DisplayUtils { private static final Logger logger = Logger . getLogger ( DisplayUtils . class ) ; public static void doClick ( final Display display , final int x , final int y , boolean restore ) { final int [ ] orig = { <NUM_LIT:0> , <NUM_LIT:0> } ; if ( restore ) { display . syncExec ( new Runnable ( ) { public void run ( ) { Point point = display . getCursorLocation ( ) ; orig [ <NUM_LIT:0> ] = point . x ; orig [ <NUM_LIT:1> ] = point . y ; } } ) ; } Event event = new Event ( ) ; event . x = x ; event . y = y ; event . type = SWT . MouseMove ; post ( display , event ) ; final boolean [ ] moved = { false } ; Thread check = new Thread ( ) { public void run ( ) { final int [ ] cursor = { <NUM_LIT:0> , <NUM_LIT:0> } ; while ( ! isInterrupted ( ) && cursor [ <NUM_LIT:0> ] != x || cursor [ <NUM_LIT:1> ] != y ) { display . syncExec ( new Runnable ( ) { public void run ( ) { Point point = display . getCursorLocation ( ) ; cursor [ <NUM_LIT:0> ] = point . x ; cursor [ <NUM_LIT:1> ] = point . y ; if ( point . x == x && point . y == y ) { moved [ <NUM_LIT:0> ] = true ; } } } ) ; try { Thread . sleep ( <NUM_LIT> ) ; } catch ( InterruptedException ie ) { break ; } } } } ; check . start ( ) ; try { check . join ( <NUM_LIT> ) ; check . interrupt ( ) ; } catch ( InterruptedException ie ) { logger . debug ( "<STR_LIT>" , ie ) ; } if ( moved [ <NUM_LIT:0> ] ) { event = new Event ( ) ; event . button = <NUM_LIT:1> ; event . type = SWT . MouseDown ; post ( display , event ) ; event . type = SWT . MouseUp ; post ( display , event ) ; } if ( restore ) { event = new Event ( ) ; event . x = orig [ <NUM_LIT:0> ] ; event . y = orig [ <NUM_LIT:1> ] ; event . type = SWT . MouseMove ; post ( display , event ) ; } } public static void doKeypress ( Display display , int key , int ... modifiers ) { for ( int modifier : modifiers ) { Event event = new Event ( ) ; event . type = SWT . KeyDown ; event . keyCode = modifier ; post ( display , event ) ; } Event event = new Event ( ) ; event . keyCode = key ; event . type = SWT . KeyDown ; post ( display , event ) ; event . type = SWT . KeyUp ; post ( display , event ) ; for ( int modifier : modifiers ) { event = new Event ( ) ; event . type = SWT . KeyUp ; event . keyCode = modifier ; post ( display , event ) ; } } public static void doKeypress ( Display display , char key , int ... modifiers ) { for ( int modifier : modifiers ) { Event event = new Event ( ) ; event . type = SWT . KeyDown ; event . keyCode = modifier ; post ( display , event ) ; } Event event = new Event ( ) ; event . character = key ; event . type = SWT . KeyDown ; post ( display , event ) ; event . type = SWT . KeyUp ; post ( display , event ) ; for ( int modifier : modifiers ) { event = new Event ( ) ; event . type = SWT . KeyUp ; event . keyCode = modifier ; post ( display , event ) ; } } private static void post ( Display display , Event event ) { if ( ! display . post ( event ) ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } } </s>
<s> package org . vimplugin . actions ; import org . eclipse . jface . action . Action ; public class UndoAction extends Action { public UndoAction ( ) { super ( ) ; update ( ) ; } public void run ( ) { } public void update ( ) { setEnabled ( true ) ; } } </s>
<s> package org . vimplugin . actions ; import org . eclipse . jface . action . Action ; public class PasteAction extends Action { public PasteAction ( ) { super ( ) ; update ( ) ; } public void run ( ) { } public void update ( ) { setEnabled ( true ) ; } } </s>
<s> package org . vimplugin . actions ; import org . eclipse . jface . action . Action ; public class CopyAction extends Action { public CopyAction ( ) { super ( ) ; update ( ) ; } public void run ( ) { } public void update ( ) { setEnabled ( true ) ; } } </s>
<s> package org . vimplugin . actions ; import org . eclipse . jface . action . Action ; public class RedoAction extends Action { public RedoAction ( ) { super ( ) ; update ( ) ; } public void run ( ) { } public void update ( ) { setEnabled ( true ) ; } } </s>
<s> package org . vimplugin ; import org . eclipse . jface . action . * ; import org . eclipse . ui . * ; import org . eclipse . ui . part . EditorActionBarContributor ; import org . eclipse . ui . actions . ActionFactory ; import org . eclipse . ui . texteditor . * ; import org . vimplugin . actions . * ; public class VimActionContributor extends EditorActionBarContributor { protected RetargetTextEditorAction fContentAssistProposal ; protected RetargetTextEditorAction fContentAssistTip ; public VimActionContributor ( ) { super ( ) ; } public void init ( IActionBars bars ) { super . init ( bars ) ; IMenuManager menuManager = bars . getMenuManager ( ) ; IMenuManager editMenu = menuManager . findMenuUsingPath ( IWorkbenchActionConstants . M_EDIT ) ; if ( editMenu != null ) { editMenu . add ( new Separator ( ) ) ; } IActionBars actionBars = getActionBars ( ) ; actionBars . setGlobalActionHandler ( ActionFactory . DELETE . getId ( ) , new UndoAction ( ) ) ; actionBars . setGlobalActionHandler ( ActionFactory . UNDO . getId ( ) , new UndoAction ( ) ) ; actionBars . setGlobalActionHandler ( ActionFactory . REDO . getId ( ) , new RedoAction ( ) ) ; actionBars . setGlobalActionHandler ( ActionFactory . COPY . getId ( ) , new CopyAction ( ) ) ; actionBars . setGlobalActionHandler ( ActionFactory . PASTE . getId ( ) , new PasteAction ( ) ) ; actionBars . setGlobalActionHandler ( ActionFactory . SELECT_ALL . getId ( ) , new UndoAction ( ) ) ; } private void doSetActiveEditor ( IEditorPart part ) { super . setActiveEditor ( part ) ; } public void setActiveEditor ( IEditorPart part ) { doSetActiveEditor ( part ) ; } public void dispose ( ) { doSetActiveEditor ( null ) ; super . dispose ( ) ; } } </s>
<s> package com . martiansoftware . nailgun ; import java . util . Properties ; public class NGConstants { public static final int DEFAULT_PORT = <NUM_LIT> ; public static final int EXIT_EXCEPTION = <NUM_LIT> ; public static final int EXIT_NOSUCHCOMMAND = <NUM_LIT> ; public static final char CHUNKTYPE_ARGUMENT = '<CHAR_LIT:A>' ; public static final char CHUNKTYPE_ENVIRONMENT = '<CHAR_LIT>' ; public static final char CHUNKTYPE_COMMAND = '<CHAR_LIT>' ; public static final char CHUNKTYPE_WORKINGDIRECTORY = '<CHAR_LIT>' ; public static final char CHUNKTYPE_KEEP_ALIVE = '<CHAR_LIT>' ; public static final char CHUNKTYPE_BYE = '<CHAR_LIT>' ; public static final char CHUNKTYPE_STDIN = '<CHAR_LIT:0>' ; public static final char CHUNKTYPE_STDIN_EOF = '<CHAR_LIT:.>' ; public static final char CHUNKTYPE_STDOUT = '<CHAR_LIT:1>' ; public static final char CHUNKTYPE_STDERR = '<CHAR_LIT>' ; public static final char CHUNKTYPE_EXIT = '<CHAR_LIT>' ; public static final String VERSION ; static { Properties props = new Properties ( ) ; try { props . load ( NGConstants . class . getClassLoader ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; } catch ( java . io . IOException e ) { System . err . println ( "<STR_LIT>" ) ; } VERSION = props . getProperty ( "<STR_LIT:version>" , "<STR_LIT>" ) ; } } </s>
<s> package com . martiansoftware . nailgun ; import java . io . InputStream ; import java . io . PrintStream ; import java . lang . reflect . Method ; import java . net . InetAddress ; import java . net . ServerSocket ; import java . net . Socket ; import java . net . UnknownHostException ; import java . util . Iterator ; import java . util . Map ; import com . martiansoftware . nailgun . builtins . DefaultNail ; @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) public class NGServer implements Runnable { private InetAddress addr = null ; private int port = <NUM_LIT:0> ; private ClassLoader classLoader ; private boolean captureSystemStreams = true ; private boolean capturedSystemStreams = false ; private ServerSocket serversocket ; private boolean shutdown = false ; private boolean running = false ; private AliasManager aliasManager ; private boolean allowNailsByClassName = true ; private Class defaultNailClass = null ; private NGSessionPool sessionPool = null ; public final PrintStream out = System . out ; public final PrintStream err = System . err ; public final InputStream in = System . in ; private Map allNailStats = null ; private SecurityManager originalSecurityManager = null ; public NGServer ( InetAddress addr , int port , ClassLoader classloader ) { init ( addr , port , classloader ) ; } public NGServer ( ) { init ( null , NGConstants . DEFAULT_PORT , null ) ; } private void init ( InetAddress addr , int port , ClassLoader classLoader ) { this . addr = addr ; this . port = port ; this . classLoader = classLoader ; this . aliasManager = new AliasManager ( ) ; allNailStats = new java . util . HashMap ( ) ; sessionPool = new NGSessionPool ( this , <NUM_LIT:10> ) ; } public ClassLoader getClassLoader ( ) { return this . classLoader != null ? this . classLoader : this . getClass ( ) . getClassLoader ( ) ; } public void setAllowNailsByClassName ( boolean allowNailsByClassName ) { this . allowNailsByClassName = allowNailsByClassName ; } public boolean allowsNailsByClassName ( ) { return ( allowNailsByClassName ) ; } public void setDefaultNailClass ( Class defaultNailClass ) { this . defaultNailClass = defaultNailClass ; } public Class getDefaultNailClass ( ) { return ( ( defaultNailClass == null ) ? DefaultNail . class : defaultNailClass ) ; } public void setCaptureSystemStreams ( boolean captureSystemStreams ) { this . captureSystemStreams = captureSystemStreams ; } public boolean hasCapturedSystemStreams ( ) { return capturedSystemStreams ; } private NailStats getOrCreateStatsFor ( Class nailClass ) { NailStats result = null ; synchronized ( allNailStats ) { result = ( NailStats ) allNailStats . get ( nailClass ) ; if ( result == null ) { result = new NailStats ( nailClass ) ; allNailStats . put ( nailClass , result ) ; } } return ( result ) ; } void nailStarted ( Class nailClass ) { NailStats stats = getOrCreateStatsFor ( nailClass ) ; stats . nailStarted ( ) ; } void nailFinished ( Class nailClass ) { NailStats stats = ( NailStats ) allNailStats . get ( nailClass ) ; stats . nailFinished ( ) ; } public Map getNailStats ( ) { Map result = new java . util . TreeMap ( ) ; synchronized ( allNailStats ) { for ( Iterator i = allNailStats . keySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Class nailclass = ( Class ) i . next ( ) ; result . put ( nailclass . getName ( ) , ( ( NailStats ) allNailStats . get ( nailclass ) ) . clone ( ) ) ; } } return ( result ) ; } public AliasManager getAliasManager ( ) { return ( aliasManager ) ; } public void shutdown ( boolean exitVM ) { synchronized ( this ) { if ( shutdown ) return ; shutdown = true ; } try { serversocket . close ( ) ; } catch ( Throwable toDiscard ) { } sessionPool . shutdown ( ) ; Class [ ] argTypes = new Class [ <NUM_LIT:1> ] ; argTypes [ <NUM_LIT:0> ] = NGServer . class ; Object [ ] argValues = new Object [ <NUM_LIT:1> ] ; argValues [ <NUM_LIT:0> ] = this ; for ( Iterator i = getAliasManager ( ) . getAliases ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Alias alias = ( Alias ) i . next ( ) ; getOrCreateStatsFor ( alias . getAliasedClass ( ) ) ; } synchronized ( allNailStats ) { for ( Iterator i = allNailStats . values ( ) . iterator ( ) ; i . hasNext ( ) ; ) { NailStats ns = ( NailStats ) i . next ( ) ; Class nailClass = ns . getNailClass ( ) ; try { Method nailShutdown = nailClass . getMethod ( "<STR_LIT>" , argTypes ) ; nailShutdown . invoke ( null , argValues ) ; } catch ( Throwable toDiscard ) { } } } if ( hasCapturedSystemStreams ( ) ) { System . setIn ( in ) ; System . setOut ( out ) ; System . setErr ( err ) ; } System . setSecurityManager ( originalSecurityManager ) ; if ( exitVM ) { System . exit ( <NUM_LIT:0> ) ; } } public boolean isRunning ( ) { return ( running ) ; } public int getPort ( ) { return ( ( serversocket == null ) ? port : serversocket . getLocalPort ( ) ) ; } public void run ( ) { running = true ; NGSession sessionOnDeck = null ; originalSecurityManager = System . getSecurityManager ( ) ; System . setSecurityManager ( new NGSecurityManager ( originalSecurityManager ) ) ; if ( captureSystemStreams ) { synchronized ( System . in ) { if ( ! ( System . in instanceof ThreadLocalInputStream ) ) { System . setIn ( new ThreadLocalInputStream ( in ) ) ; System . setOut ( new ThreadLocalPrintStream ( out ) ) ; System . setErr ( new ThreadLocalPrintStream ( err ) ) ; capturedSystemStreams = true ; } } } try { if ( addr == null ) { serversocket = new ServerSocket ( port ) ; } else { serversocket = new ServerSocket ( port , <NUM_LIT:0> , addr ) ; } while ( ! shutdown ) { sessionOnDeck = sessionPool . take ( ) ; Socket socket = serversocket . accept ( ) ; sessionOnDeck . run ( socket ) ; } } catch ( Throwable t ) { if ( ! shutdown ) { throw new RuntimeException ( t ) ; } } if ( sessionOnDeck != null ) { sessionOnDeck . shutdown ( ) ; } running = false ; } private static void usage ( ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; } public static void main ( String [ ] args ) throws NumberFormatException , UnknownHostException { if ( args . length > <NUM_LIT:1> ) { usage ( ) ; return ; } InetAddress serverAddress = null ; int port = NGConstants . DEFAULT_PORT ; if ( args . length != <NUM_LIT:0> ) { String [ ] argParts = args [ <NUM_LIT:0> ] . split ( "<STR_LIT::>" ) ; String addrPart = null ; String portPart = null ; if ( argParts . length == <NUM_LIT:2> ) { addrPart = argParts [ <NUM_LIT:0> ] ; portPart = argParts [ <NUM_LIT:1> ] ; } else if ( argParts [ <NUM_LIT:0> ] . indexOf ( '<CHAR_LIT:.>' ) >= <NUM_LIT:0> ) { addrPart = argParts [ <NUM_LIT:0> ] ; } else { portPart = argParts [ <NUM_LIT:0> ] ; } if ( addrPart != null ) { serverAddress = InetAddress . getByName ( addrPart ) ; } if ( portPart != null ) { port = Integer . parseInt ( portPart ) ; } } NGServer server = new NGServer ( serverAddress , port , null ) ; Thread t = new Thread ( server ) ; t . setName ( "<STR_LIT>" + serverAddress + "<STR_LIT:U+002CU+0020>" + port + "<STR_LIT:)>" ) ; t . start ( ) ; Runtime . getRuntime ( ) . addShutdownHook ( new NGServerShutdowner ( server ) ) ; int runningPort = server . getPort ( ) ; while ( runningPort == <NUM_LIT:0> ) { try { Thread . sleep ( <NUM_LIT> ) ; } catch ( Throwable toIgnore ) { } runningPort = server . getPort ( ) ; } System . out . println ( "<STR_LIT>" + ( ( serverAddress == null ) ? "<STR_LIT>" : serverAddress . getHostAddress ( ) ) + "<STR_LIT>" + runningPort + "<STR_LIT:.>" ) ; } private static class NGServerShutdowner extends Thread { private NGServer server = null ; NGServerShutdowner ( NGServer server ) { this . server = server ; } public void run ( ) { int count = <NUM_LIT:0> ; server . shutdown ( false ) ; while ( server . isRunning ( ) && ( count < <NUM_LIT> ) ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } ++ count ; } if ( server . isRunning ( ) ) { System . err . println ( "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" ) ; } } } } </s>
<s> package com . martiansoftware . nailgun ; import java . io . InputStream ; import java . io . PrintStream ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . net . Socket ; import java . util . List ; import java . util . Properties ; import org . apache . tools . ant . ExitException ; @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) class NGSession extends Thread { private NGServer server = null ; private NGSessionPool sessionPool = null ; private Object lock = new Object ( ) ; private Socket nextSocket = null ; private boolean done = false ; private long instanceNumber = <NUM_LIT:0> ; private static Object sharedLock = new Object ( ) ; private static long instanceCounter = <NUM_LIT:0> ; private static Class [ ] mainSignature ; private static Class [ ] nailMainSignature ; static { mainSignature = new Class [ <NUM_LIT:1> ] ; mainSignature [ <NUM_LIT:0> ] = String [ ] . class ; nailMainSignature = new Class [ <NUM_LIT:1> ] ; nailMainSignature [ <NUM_LIT:0> ] = NGContext . class ; } NGSession ( NGSessionPool sessionPool , NGServer server ) { super ( ) ; this . sessionPool = sessionPool ; this . server = server ; synchronized ( sharedLock ) { this . instanceNumber = ++ instanceCounter ; } } void shutdown ( ) { done = true ; synchronized ( lock ) { nextSocket = null ; lock . notifyAll ( ) ; } } public void run ( Socket socket ) { synchronized ( lock ) { nextSocket = socket ; lock . notify ( ) ; } Thread . yield ( ) ; } private Socket nextSocket ( ) { Socket result = null ; synchronized ( lock ) { result = nextSocket ; while ( ! done && result == null ) { try { lock . wait ( ) ; } catch ( InterruptedException e ) { done = true ; } result = nextSocket ; } nextSocket = null ; } return ( result ) ; } public void run ( ) { updateThreadName ( null ) ; Socket socket = nextSocket ( ) ; while ( socket != null ) { boolean keepAlive = false ; boolean byeChunk = false ; java . io . DataInputStream sockin = null ; java . io . OutputStream sockout = null ; try { byte [ ] lbuf = new byte [ <NUM_LIT:5> ] ; sockin = new java . io . DataInputStream ( socket . getInputStream ( ) ) ; sockout = socket . getOutputStream ( ) ; List remoteArgs = new java . util . ArrayList ( ) ; Properties remoteEnv = new Properties ( ) ; String cwd = null ; String command = null ; while ( command == null && ! byeChunk ) { sockin . readFully ( lbuf ) ; long bytesToRead = LongUtils . fromArray ( lbuf , <NUM_LIT:0> ) ; char chunkType = ( char ) lbuf [ <NUM_LIT:4> ] ; byte [ ] b = new byte [ ( int ) bytesToRead ] ; sockin . readFully ( b ) ; String line = new String ( b , "<STR_LIT:UTF-8>" ) ; switch ( chunkType ) { case NGConstants . CHUNKTYPE_ARGUMENT : remoteArgs . add ( line ) ; break ; case NGConstants . CHUNKTYPE_ENVIRONMENT : int equalsIndex = line . indexOf ( '<CHAR_LIT:=>' ) ; if ( equalsIndex > <NUM_LIT:0> ) { remoteEnv . setProperty ( line . substring ( <NUM_LIT:0> , equalsIndex ) , line . substring ( equalsIndex + <NUM_LIT:1> ) ) ; } break ; case NGConstants . CHUNKTYPE_COMMAND : command = line ; break ; case NGConstants . CHUNKTYPE_WORKINGDIRECTORY : cwd = line ; break ; case NGConstants . CHUNKTYPE_KEEP_ALIVE : keepAlive = true ; break ; case NGConstants . CHUNKTYPE_BYE : byeChunk = true ; keepAlive = false ; break ; default : } } updateThreadName ( socket . getInetAddress ( ) . getHostAddress ( ) + "<STR_LIT::U+0020>" + command ) ; InputStream in = new NGInputStream ( sockin ) ; PrintStream out = new PrintStream ( new NGOutputStream ( sockout , NGConstants . CHUNKTYPE_STDOUT ) ) ; PrintStream err = new PrintStream ( new NGOutputStream ( sockout , NGConstants . CHUNKTYPE_STDERR ) ) ; PrintStream exit = new PrintStream ( new NGOutputStream ( sockout , NGConstants . CHUNKTYPE_EXIT ) ) ; if ( server . hasCapturedSystemStreams ( ) ) { ( ( ThreadLocalInputStream ) System . in ) . init ( in ) ; ( ( ThreadLocalPrintStream ) System . out ) . init ( out ) ; ( ( ThreadLocalPrintStream ) System . err ) . init ( err ) ; } if ( ! byeChunk ) { try { Alias alias = server . getAliasManager ( ) . getAlias ( command ) ; Class cmdclass = null ; if ( alias != null ) { cmdclass = alias . getAliasedClass ( ) ; } else if ( server . allowsNailsByClassName ( ) ) { cmdclass = Class . forName ( command , true , server . getClassLoader ( ) ) ; } else { cmdclass = server . getDefaultNailClass ( ) ; } Object [ ] methodArgs = new Object [ <NUM_LIT:1> ] ; Method mainMethod = null ; String [ ] cmdlineArgs = ( String [ ] ) remoteArgs . toArray ( new String [ remoteArgs . size ( ) ] ) ; try { mainMethod = cmdclass . getMethod ( "<STR_LIT>" , nailMainSignature ) ; NGContext context = new NGContext ( ) ; context . setArgs ( cmdlineArgs ) ; context . in = in ; context . out = out ; context . err = err ; context . setCommand ( command ) ; context . setExitStream ( exit ) ; context . setNGServer ( server ) ; context . setEnv ( remoteEnv ) ; context . setInetAddress ( socket . getInetAddress ( ) ) ; context . setPort ( socket . getPort ( ) ) ; context . setWorkingDirectory ( cwd ) ; methodArgs [ <NUM_LIT:0> ] = context ; } catch ( NoSuchMethodException toDiscard ) { } if ( mainMethod == null ) { mainMethod = cmdclass . getMethod ( "<STR_LIT>" , mainSignature ) ; methodArgs [ <NUM_LIT:0> ] = cmdlineArgs ; } if ( mainMethod != null ) { server . nailStarted ( cmdclass ) ; NGSecurityManager . setExit ( exit ) ; try { mainMethod . invoke ( null , methodArgs ) ; } catch ( InvocationTargetException ite ) { throw ( ite . getCause ( ) ) ; } catch ( Throwable t ) { throw ( t ) ; } finally { server . nailFinished ( cmdclass ) ; } exit . print ( <NUM_LIT:0> ) ; } } catch ( ExitException exitEx ) { exit . print ( exitEx . getStatus ( ) ) ; server . out . println ( Thread . currentThread ( ) . getName ( ) + "<STR_LIT>" + exitEx . getStatus ( ) ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; exit . print ( NGConstants . EXIT_EXCEPTION ) ; } } } catch ( Throwable t ) { t . printStackTrace ( ) ; break ; } finally { if ( ! keepAlive ) { try { byte [ ] leftovers = new byte [ <NUM_LIT:8> ] ; while ( sockin . read ( leftovers ) > <NUM_LIT:0> ) { } } catch ( Exception ignore ) { } try { sockout . close ( ) ; } catch ( Exception ignore ) { } try { sockin . close ( ) ; } catch ( Exception ignore ) { } try { socket . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } } if ( ! keepAlive ) { if ( server . hasCapturedSystemStreams ( ) ) { if ( System . in instanceof ThreadLocalInputStream ) { ( ( ThreadLocalInputStream ) System . in ) . init ( null ) ; } if ( System . out instanceof ThreadLocalPrintStream ) { ( ( ThreadLocalPrintStream ) System . out ) . init ( null ) ; } if ( System . out instanceof ThreadLocalPrintStream ) { ( ( ThreadLocalPrintStream ) System . err ) . init ( null ) ; } } updateThreadName ( null ) ; sessionPool . give ( this ) ; socket = nextSocket ( ) ; } } } private void updateThreadName ( String detail ) { setName ( "<STR_LIT>" + instanceNumber + "<STR_LIT::U+0020>" + ( ( detail == null ) ? "<STR_LIT>" : detail ) ) ; } } </s>
<s> package org . eclim . logging . log4j ; import java . io . IOException ; import java . io . OutputStream ; import java . io . Writer ; public class ConsoleAppender extends org . apache . log4j . ConsoleAppender { private boolean writerSet ; public void activateOptions ( ) { if ( getTarget ( ) . equals ( SYSTEM_ERR ) ) { setWriter ( createWriter ( new SystemStream ( System . err ) ) ) ; } else { setWriter ( createWriter ( new SystemStream ( System . out ) ) ) ; } super . activateOptions ( ) ; } public synchronized void setWriter ( Writer writer ) { if ( ! writerSet ) { super . setWriter ( writer ) ; writerSet = true ; } } private static class SystemStream extends OutputStream { private OutputStream out ; public SystemStream ( OutputStream out ) { this . out = out ; } public void close ( ) { } public void flush ( ) throws IOException { out . flush ( ) ; } public void write ( final byte [ ] bytes ) throws IOException { out . write ( bytes ) ; } public void write ( final byte [ ] bytes , final int offset , final int length ) throws IOException { out . write ( bytes , offset , length ) ; } public void write ( final int bytes ) throws IOException { out . write ( bytes ) ; } } } </s>
<s> package org . eclim . logging . log4j ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import org . apache . log4j . AppenderSkeleton ; import org . apache . log4j . Layout ; import org . apache . log4j . spi . LoggingEvent ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Text ; public class ViewAppender extends AppenderSkeleton { private Method logAccessor ; @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) public void setView ( String view ) throws ClassNotFoundException , NoSuchMethodException { Class viewClass = Class . forName ( view ) ; logAccessor = viewClass . getMethod ( "<STR_LIT>" ) ; } @ Override protected void append ( final LoggingEvent event ) { try { final Text log = ( Text ) logAccessor . invoke ( null ) ; if ( log != null && ! log . isDisposed ( ) ) { Display . getDefault ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { write ( log , event ) ; } } ) ; } } catch ( IllegalAccessException iae ) { throw new RuntimeException ( iae ) ; } catch ( InvocationTargetException ite ) { throw new RuntimeException ( ite ) ; } } private void write ( Text log , LoggingEvent event ) { if ( ! log . isDisposed ( ) ) { log . append ( layout . format ( event ) ) ; if ( layout . ignoresThrowable ( ) ) { String [ ] s = event . getThrowableStrRep ( ) ; if ( s != null ) { int len = s . length ; for ( int i = <NUM_LIT:0> ; i < len ; i ++ ) { log . append ( s [ i ] ) ; log . append ( Layout . LINE_SEP ) ; } } } } } public boolean requiresLayout ( ) { return true ; } public void close ( ) { } } </s>
<s> package org . eclim . logging ; import org . eclipse . core . resources . ResourcesPlugin ; public class Logger { private static String workspace = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; static { System . setProperty ( "<STR_LIT>" , workspace ) ; } private org . slf4j . Logger logger ; private Logger ( org . slf4j . Logger logger ) { this . logger = logger ; } public static Logger getLogger ( Class < ? > theClass ) { return getLogger ( theClass . getName ( ) ) ; } public static Logger getLogger ( String name ) { return new Logger ( org . slf4j . LoggerFactory . getLogger ( name ) ) ; } public void debug ( String message , Throwable t ) { logger . debug ( message , t ) ; } public void debug ( String message , Object ... args ) { logger . debug ( message , args ) ; } public void info ( String message , Throwable t ) { logger . info ( message , t ) ; } public void info ( String message , Object ... args ) { logger . info ( message , args ) ; } public void warn ( String message , Throwable t ) { logger . warn ( message , t ) ; } public void warn ( String message , Object ... args ) { logger . warn ( message , args ) ; } public void error ( String message , Throwable t ) { logger . error ( message , t ) ; } public void error ( String message , Object ... args ) { logger . error ( message , args ) ; } public boolean isDebugEnabled ( ) { return logger . isDebugEnabled ( ) ; } public boolean isInfoEnabled ( ) { return logger . isInfoEnabled ( ) ; } public boolean isWarnEnabled ( ) { return logger . isWarnEnabled ( ) ; } public boolean isErrorEnabled ( ) { return logger . isErrorEnabled ( ) ; } } </s>
<s> package org . eclim . annotation ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Target ( ElementType . TYPE ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Command { String name ( ) ; String options ( ) default "<STR_LIT>" ; String description ( ) default "<STR_LIT>" ; } </s>
<s> package org . eclim . util ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; public class CommandExecutor implements Runnable { private int returnCode = - <NUM_LIT:1> ; private String [ ] cmd ; private String result ; private String error ; private Process process ; private CommandExecutor ( String [ ] cmd ) { this . cmd = cmd ; } public static CommandExecutor execute ( String [ ] cmd ) throws Exception { return execute ( cmd , - <NUM_LIT:1> ) ; } public static CommandExecutor execute ( String [ ] cmd , long timeout ) throws Exception { CommandExecutor executor = new CommandExecutor ( cmd ) ; Thread thread = new Thread ( executor ) ; thread . start ( ) ; if ( timeout > <NUM_LIT:0> ) { thread . join ( timeout ) ; } else { thread . join ( ) ; } return executor ; } public void run ( ) { try { Runtime runtime = Runtime . getRuntime ( ) ; process = runtime . exec ( cmd ) ; final ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; final ByteArrayOutputStream err = new ByteArrayOutputStream ( ) ; Thread outThread = new Thread ( ) { public void run ( ) { try { IOUtils . copy ( process . getInputStream ( ) , out ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } } ; outThread . start ( ) ; Thread errThread = new Thread ( ) { public void run ( ) { try { IOUtils . copy ( process . getErrorStream ( ) , err ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } } ; errThread . start ( ) ; returnCode = process . waitFor ( ) ; outThread . join ( <NUM_LIT:1000> ) ; errThread . join ( <NUM_LIT:1000> ) ; result = out . toString ( ) ; error = err . toString ( ) ; } catch ( Exception e ) { returnCode = <NUM_LIT:12> ; error = e . getMessage ( ) ; e . printStackTrace ( ) ; } } public void destroy ( ) { if ( process != null ) { process . destroy ( ) ; } } public String getResult ( ) { return result ; } public int getReturnCode ( ) { return returnCode ; } public String getErrorMessage ( ) { return error ; } } </s>
<s> package org . eclim . util . file ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . lang . builder . EqualsBuilder ; public class Position { private String filename ; private int offset = <NUM_LIT:0> ; private int length = <NUM_LIT:0> ; private int line = <NUM_LIT:1> ; private int column = <NUM_LIT:1> ; private String message ; public static Position fromOffset ( String filename , String message , int offset , int length ) { int line = <NUM_LIT:1> ; int column = <NUM_LIT:1> ; try { int [ ] pos = FileUtils . offsetToLineColumn ( filename , offset ) ; if ( pos != null ) { line = pos [ <NUM_LIT:0> ] ; column = pos [ <NUM_LIT:1> ] ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return new Position ( filename , message , offset , length , line , column ) ; } public static Position fromLineColumn ( String filename , String message , int line , int column ) { return new Position ( filename , message , <NUM_LIT:0> , <NUM_LIT:0> , line , column ) ; } private Position ( String filename , String message , int offset , int length , int line , int column ) { this . filename = filename ; this . message = message != null ? message : StringUtils . EMPTY ; this . offset = offset ; this . length = length ; this . line = line ; this . column = column ; } public String getFilename ( ) { return this . filename ; } public int getOffset ( ) { return this . offset ; } public int getLength ( ) { return this . length ; } public int getLine ( ) { return this . line ; } public int getColumn ( ) { return this . column ; } public void setMessage ( String message ) { this . message = message ; } public String getMessage ( ) { return this . message ; } @ Override public boolean equals ( Object obj ) { if ( ! ( obj instanceof Position ) ) { return false ; } if ( this == obj ) { return true ; } Position rhs = ( Position ) obj ; return new EqualsBuilder ( ) . append ( filename , rhs . getFilename ( ) ) . append ( offset , rhs . getOffset ( ) ) . append ( length , rhs . getLength ( ) ) . append ( line , rhs . getLine ( ) ) . append ( column , rhs . getColumn ( ) ) . isEquals ( ) ; } } </s>
<s> package org . eclim . util . file ; import java . io . IOException ; import java . io . Reader ; import java . lang . reflect . Field ; import org . eclim . logging . Logger ; public class BufferedReader extends Reader { private static final Logger logger = Logger . getLogger ( BufferedReader . class ) ; Reader in ; char [ ] buffer ; int pos ; int limit ; int markPos = - <NUM_LIT:1> ; static final int DEFAULT_BUFFER_SIZE = <NUM_LIT> ; private StringBuffer sbuf = null ; public BufferedReader ( Reader in ) { this ( in , DEFAULT_BUFFER_SIZE ) ; } public BufferedReader ( Reader in , int size ) { super ( getDeclaredField ( Reader . class , in , "<STR_LIT>" ) ) ; if ( size <= <NUM_LIT:0> ) throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; this . in = in ; buffer = new char [ size ] ; } private static Object getDeclaredField ( Class < ? > clazz , Object instance , String fieldName ) { try { Field field = clazz . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; return field . get ( instance ) ; } catch ( IllegalAccessException iae ) { logger . error ( "<STR_LIT>" , iae ) ; } catch ( NoSuchFieldException nsfe ) { logger . error ( "<STR_LIT>" , nsfe ) ; } throw new RuntimeException ( "<STR_LIT>" ) ; } public void close ( ) throws IOException { synchronized ( lock ) { if ( in != null ) in . close ( ) ; in = null ; buffer = null ; } } public boolean markSupported ( ) { return true ; } public void mark ( int readLimit ) throws IOException { if ( readLimit < <NUM_LIT:0> ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; synchronized ( lock ) { checkStatus ( ) ; if ( pos + readLimit > limit ) { char [ ] old_buffer = buffer ; int extraBuffSpace = <NUM_LIT:0> ; if ( pos > limit ) extraBuffSpace = <NUM_LIT:1> ; if ( readLimit + extraBuffSpace > limit ) buffer = new char [ readLimit + extraBuffSpace ] ; limit -= pos ; if ( limit >= <NUM_LIT:0> ) { System . arraycopy ( old_buffer , pos , buffer , <NUM_LIT:0> , limit ) ; pos = <NUM_LIT:0> ; } } if ( limit < <NUM_LIT:0> ) { pos = <NUM_LIT:1> ; limit = markPos = <NUM_LIT:0> ; } else markPos = pos ; } } public void reset ( ) throws IOException { synchronized ( lock ) { checkStatus ( ) ; if ( markPos < <NUM_LIT:0> ) throw new IOException ( "<STR_LIT>" ) ; if ( limit > <NUM_LIT:0> ) pos = markPos ; } } public boolean ready ( ) throws IOException { synchronized ( lock ) { checkStatus ( ) ; return pos < limit || in . ready ( ) ; } } public int read ( char [ ] buf , int offset , int count ) throws IOException { if ( offset < <NUM_LIT:0> || offset + count > buf . length || count < <NUM_LIT:0> ) throw new IndexOutOfBoundsException ( ) ; synchronized ( lock ) { checkStatus ( ) ; boolean retAtEndOfBuffer = false ; int avail = limit - pos ; if ( count > avail ) { if ( avail > <NUM_LIT:0> ) count = avail ; else { if ( limit == buffer . length ) markPos = - <NUM_LIT:1> ; if ( pos > limit ) { retAtEndOfBuffer = true ; -- pos ; } if ( markPos < <NUM_LIT:0> ) { if ( count >= buffer . length && ! retAtEndOfBuffer ) return in . read ( buf , offset , count ) ; pos = limit = <NUM_LIT:0> ; } avail = in . read ( buffer , limit , buffer . length - limit ) ; if ( retAtEndOfBuffer && avail > <NUM_LIT:0> && buffer [ limit ] == '<STR_LIT:\n>' ) { -- avail ; limit ++ ; } if ( avail < count ) { if ( avail <= <NUM_LIT:0> ) return avail ; count = avail ; } limit += avail ; } } System . arraycopy ( buffer , pos , buf , offset , count ) ; pos += count ; return count ; } } private int fill ( ) throws IOException { checkStatus ( ) ; boolean retAtEndOfBuffer = false ; if ( pos > limit ) { retAtEndOfBuffer = true ; -- pos ; } if ( markPos >= <NUM_LIT:0> && limit == buffer . length ) markPos = - <NUM_LIT:1> ; if ( markPos < <NUM_LIT:0> ) pos = limit = <NUM_LIT:0> ; int count = in . read ( buffer , limit , buffer . length - limit ) ; if ( count > <NUM_LIT:0> ) limit += count ; if ( retAtEndOfBuffer && buffer [ pos ] == '<STR_LIT:\n>' ) { -- count ; if ( markPos == pos ) ++ markPos ; ++ pos ; } return count ; } public int read ( ) throws IOException { synchronized ( lock ) { checkStatus ( ) ; if ( pos >= limit && fill ( ) <= <NUM_LIT:0> ) return - <NUM_LIT:1> ; return buffer [ pos ++ ] ; } } private int lineEnd ( int limit ) { int i = pos ; for ( ; i < limit ; i ++ ) { char ch = buffer [ i ] ; if ( ch == '<STR_LIT:\n>' ) break ; } return i ; } public String readLine ( ) throws IOException { checkStatus ( ) ; if ( pos > limit ) { int ch = read ( ) ; if ( ch < <NUM_LIT:0> ) return null ; if ( ch != '<STR_LIT:\n>' ) -- pos ; } int i = lineEnd ( limit ) ; if ( i < limit ) { String str = String . valueOf ( buffer , pos , i - ( pos - <NUM_LIT:1> ) ) ; pos = i + <NUM_LIT:1> ; return str ; } if ( sbuf == null ) sbuf = new StringBuffer ( <NUM_LIT> ) ; else sbuf . setLength ( <NUM_LIT:0> ) ; sbuf . append ( buffer , pos , i - pos ) ; pos = i ; boolean eof = false ; for ( ; ; ) { if ( pos >= limit ) { int count = fill ( ) ; if ( count < <NUM_LIT:0> ) { eof = true ; break ; } continue ; } int ch = buffer [ pos ++ ] ; if ( ch == '<STR_LIT:\n>' ) { break ; } i = lineEnd ( limit ) ; int end = i - ( pos - <NUM_LIT:2> ) ; if ( end > buffer . length ) end = i - ( pos - <NUM_LIT:1> ) ; sbuf . append ( buffer , pos - <NUM_LIT:1> , end ) ; pos = i ; } return ( sbuf . length ( ) == <NUM_LIT:0> && eof ) ? null : sbuf . toString ( ) ; } public long skip ( long count ) throws IOException { synchronized ( lock ) { checkStatus ( ) ; if ( count < <NUM_LIT:0> ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; if ( count == <NUM_LIT:0> ) return <NUM_LIT:0> ; if ( pos > limit ) { if ( read ( ) < <NUM_LIT:0> ) return <NUM_LIT:0> ; else -- pos ; } int avail = limit - pos ; if ( count < avail ) { pos += count ; return count ; } pos = limit ; long todo = count - avail ; if ( todo > buffer . length ) { markPos = - <NUM_LIT:1> ; todo -= in . skip ( todo ) ; } else { while ( todo > <NUM_LIT:0> ) { avail = fill ( ) ; if ( avail <= <NUM_LIT:0> ) break ; if ( avail > todo ) avail = ( int ) todo ; pos += avail ; todo -= avail ; } } return count - todo ; } } private void checkStatus ( ) throws IOException { if ( in == null ) throw new IOException ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . util . file ; import java . io . BufferedInputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . InputStream ; import java . util . Enumeration ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import javax . naming . CompositeName ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . eclim . util . IOUtils ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; public class FileUtils { public static final String JAR_PREFIX = "<STR_LIT>" ; public static final String ZIP_PREFIX = "<STR_LIT>" ; public static final String JAR_EXT = "<STR_LIT>" ; public static final String ZIP_EXT = "<STR_LIT>" ; public static final char UNIX_SEPARATOR = '<CHAR_LIT:/>' ; public static final char WINDOWS_SEPARATOR = '<STR_LIT:\\>' ; public static final String UTF8 = "<STR_LIT:utf-8>" ; public static int byteOffsetToCharOffset ( String filename , int byteOffset , String encoding ) throws Exception { FileSystemManager fsManager = VFS . getManager ( ) ; FileObject file = fsManager . resolveFile ( filename ) ; return byteOffsetToCharOffset ( file . getContent ( ) . getInputStream ( ) , byteOffset , encoding ) ; } public static int byteOffsetToCharOffset ( InputStream in , int byteOffset , String encoding ) throws Exception { if ( encoding == null ) { encoding = UTF8 ; } BufferedInputStream bin = null ; try { byte [ ] bytes = new byte [ byteOffset ] ; bin = new BufferedInputStream ( in ) ; bin . read ( bytes , <NUM_LIT:0> , bytes . length ) ; String value = new String ( bytes , encoding ) ; return value . length ( ) ; } finally { IOUtils . closeQuietly ( bin ) ; } } public static int [ ] offsetToLineColumn ( String filename , int offset ) throws Exception { FileOffsets offsets = FileOffsets . compile ( filename ) ; return offsets . offsetToLineColumn ( offset ) ; } public static int [ ] offsetToLineColumn ( InputStream in , int offset ) throws Exception { FileOffsets offsets = FileOffsets . compile ( in ) ; return offsets . offsetToLineColumn ( offset ) ; } public static Matcher matcher ( Pattern pattern , String file ) throws Exception { FileInputStream is = null ; try { is = new FileInputStream ( file ) ; String contents = IOUtils . toString ( is ) ; return pattern . matcher ( contents ) ; } finally { IOUtils . closeQuietly ( is ) ; } } public static String toUrl ( String file ) { file = file . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( new File ( file ) . exists ( ) ) { return file ; } if ( file . startsWith ( JAR_PREFIX ) || file . startsWith ( ZIP_PREFIX ) ) { return file ; } StringBuffer buffer = new StringBuffer ( ) ; try { CompositeName fileName = new CompositeName ( file ) ; Enumeration < String > names = fileName . getAll ( ) ; while ( names . hasMoreElements ( ) ) { String name = names . nextElement ( ) ; if ( name . indexOf ( "<STR_LIT:$>" ) != - <NUM_LIT:1> ) { name = name . substring ( <NUM_LIT:0> , name . indexOf ( "<STR_LIT:$>" ) ) + '<CHAR_LIT:.>' + getExtension ( name ) ; } if ( name . length ( ) != <NUM_LIT:0> ) { buffer . append ( '<CHAR_LIT:/>' ) . append ( name ) ; if ( ! new File ( buffer . toString ( ) ) . exists ( ) ) { String path = getFullPath ( buffer . toString ( ) ) ; if ( path . endsWith ( "<STR_LIT:/>" ) || path . endsWith ( "<STR_LIT:\\>" ) ) { path = path . substring ( <NUM_LIT:0> , path . length ( ) - <NUM_LIT:1> ) ; } if ( path . endsWith ( JAR_EXT ) ) { buffer = new StringBuffer ( JAR_PREFIX ) . append ( path ) . append ( '<CHAR_LIT>' ) . append ( '<CHAR_LIT:/>' ) . append ( name ) ; } else if ( path . endsWith ( ZIP_EXT ) ) { buffer = new StringBuffer ( ZIP_PREFIX ) . append ( path ) . append ( '<CHAR_LIT>' ) . append ( '<CHAR_LIT:/>' ) . append ( name ) ; } } } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return buffer . toString ( ) ; } public static String concat ( String head , String ... parts ) { IPath path = Path . fromOSString ( head ) ; for ( String part : parts ) { path = path . append ( part ) ; } return path . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } public static String getBaseName ( String path ) { IPath p = Path . fromOSString ( path ) ; return p . segment ( p . segmentCount ( ) - <NUM_LIT:1> ) ; } public static String getExtension ( String path ) { String ext = Path . fromOSString ( path ) . getFileExtension ( ) ; if ( ext == null ) { return StringUtils . EMPTY ; } return ext ; } public static String getPath ( String path ) { IPath p = null ; int index = path . indexOf ( '<CHAR_LIT::>' ) ; if ( index != - <NUM_LIT:1> ) { p = new Path ( path . substring ( index + <NUM_LIT:1> ) ) ; } else { p = new Path ( path ) ; } if ( ! p . hasTrailingSeparator ( ) ) { p = p . uptoSegment ( p . segmentCount ( ) - <NUM_LIT:1> ) ; } return p . makeRelative ( ) . addTrailingSeparator ( ) . toOSString ( ) ; } public static String getFullPath ( String path ) { IPath p = Path . fromOSString ( path ) ; if ( ! p . hasTrailingSeparator ( ) ) { p = p . uptoSegment ( p . segmentCount ( ) - <NUM_LIT:1> ) ; } return p . addTrailingSeparator ( ) . toOSString ( ) ; } public static String getFileName ( String path ) { IPath p = Path . fromOSString ( path ) ; if ( p . hasTrailingSeparator ( ) ) { return StringUtils . EMPTY ; } return p . removeFileExtension ( ) . segment ( p . segmentCount ( ) - <NUM_LIT:1> ) ; } public static String removeExtension ( String path ) { return Path . fromOSString ( path ) . removeFileExtension ( ) . toOSString ( ) ; } public static String addTrailingSlash ( String path ) { if ( ! path . endsWith ( "<STR_LIT:/>" ) ) { return path += '<CHAR_LIT:/>' ; } return path ; } public static String removeTrailingSlash ( String path ) { if ( path . endsWith ( "<STR_LIT:/>" ) ) { return path . substring ( <NUM_LIT:0> , path . length ( ) - <NUM_LIT:1> ) ; } return path ; } public static String separatorsToUnix ( String path ) { if ( path == null || path . indexOf ( WINDOWS_SEPARATOR ) == - <NUM_LIT:1> ) { return path ; } return path . replace ( WINDOWS_SEPARATOR , UNIX_SEPARATOR ) ; } public static void deleteDirectory ( File dir ) { if ( ! dir . exists ( ) ) { return ; } for ( File f : dir . listFiles ( ) ) { if ( f . isDirectory ( ) ) { deleteDirectory ( f ) ; } else { f . delete ( ) ; } } dir . delete ( ) ; } } </s>
<s> package org . eclim . util . file ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . ArrayList ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . eclim . Services ; import org . eclim . util . IOUtils ; public class FileOffsets { private Integer [ ] offsets ; private String [ ] multiByteLines ; private FileOffsets ( ) { } public static FileOffsets compile ( String filename ) { try { FileSystemManager fsManager = VFS . getManager ( ) ; FileObject file = fsManager . resolveFile ( filename ) ; if ( ! file . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , filename ) ) ; } return compile ( file . getContent ( ) . getInputStream ( ) ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public static FileOffsets compile ( InputStream in ) { FileOffsets offsets = new FileOffsets ( ) ; offsets . compileOffsets ( in ) ; return offsets ; } private void compileOffsets ( InputStream in ) { BufferedReader reader = null ; try { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; ArrayList < Integer > lines = new ArrayList < Integer > ( ) ; lines . add ( new Integer ( <NUM_LIT:0> ) ) ; ArrayList < String > byteLines = new ArrayList < String > ( ) ; byteLines . add ( null ) ; int offset = <NUM_LIT:0> ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { offset += line . length ( ) ; lines . add ( new Integer ( offset ) ) ; if ( line . length ( ) != line . getBytes ( ) . length ) { byteLines . add ( line ) ; } else { byteLines . add ( null ) ; } } offsets = ( Integer [ ] ) lines . toArray ( new Integer [ lines . size ( ) ] ) ; multiByteLines = ( String [ ] ) byteLines . toArray ( new String [ byteLines . size ( ) ] ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { IOUtils . closeQuietly ( reader ) ; } } public int [ ] offsetToLineColumn ( int offset ) { if ( offset <= <NUM_LIT:0> ) { return new int [ ] { <NUM_LIT:1> , <NUM_LIT:1> } ; } int bot = - <NUM_LIT:1> ; int top = offsets . length - <NUM_LIT:1> ; while ( top - bot > <NUM_LIT:1> ) { int mid = ( top + bot ) / <NUM_LIT:2> ; if ( offsets [ mid ] . intValue ( ) < offset ) { bot = mid ; } else { top = mid ; } } if ( offsets [ top ] . intValue ( ) > offset ) { top -- ; } int line = top + <NUM_LIT:1> ; int column = <NUM_LIT:1> + offset - offsets [ top ] . intValue ( ) ; String value = multiByteLines . length > line ? multiByteLines [ line ] : null ; if ( value != null ) { column = value . substring ( <NUM_LIT:0> , column ) . getBytes ( ) . length ; } return new int [ ] { line , column } ; } public int getLineStart ( int line ) { return offsets [ line - <NUM_LIT:1> ] . intValue ( ) ; } public int getLineEnd ( int line ) { if ( offsets . length == line ) { return offsets [ offsets . length - <NUM_LIT:1> ] . intValue ( ) ; } return offsets [ line ] . intValue ( ) - <NUM_LIT:1> ; } } </s>
<s> package org . eclim . util ; import java . util . Collection ; public class CollectionUtils { private CollectionUtils ( ) { } @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) public static void addAll ( Collection collection , Object [ ] array ) { for ( Object obj : array ) { collection . add ( obj ) ; } } } </s>
<s> package org . eclim . util ; import java . util . Map ; public class StringUtils extends org . apache . commons . lang . StringUtils { private static final String PLACEHOLDER_PREFIX = "<STR_LIT>" ; private static final String PLACEHOLDER_SUFFIX = "<STR_LIT:}>" ; @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) public static String replacePlaceholders ( String string , Map values ) { if ( string == null || values == null ) { return string ; } StringBuffer buffer = new StringBuffer ( string ) ; int start = buffer . indexOf ( PLACEHOLDER_PREFIX ) ; int end = buffer . indexOf ( PLACEHOLDER_SUFFIX ) ; while ( start != - <NUM_LIT:1> && end != - <NUM_LIT:1> ) { String placeholder = buffer . substring ( start + PLACEHOLDER_PREFIX . length ( ) , end ) ; Object value = values . get ( placeholder ) ; if ( value != null ) { buffer . replace ( start , end + <NUM_LIT:1> , value . toString ( ) ) ; } start = buffer . indexOf ( PLACEHOLDER_PREFIX , start + <NUM_LIT:1> ) ; end = buffer . indexOf ( PLACEHOLDER_SUFFIX , start + <NUM_LIT:1> ) ; } return buffer . toString ( ) ; } } </s>
<s> package org . eclim . util ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . io . Reader ; import java . io . StringWriter ; import java . io . Writer ; import java . util . ArrayList ; import java . util . List ; public class IOUtils { private static final int DEFAULT_BUFFER_SIZE = <NUM_LIT> * <NUM_LIT:4> ; private IOUtils ( ) { } public static void closeQuietly ( InputStream stream ) { try { if ( stream != null ) { stream . close ( ) ; } } catch ( Exception e ) { } } public static void closeQuietly ( OutputStream stream ) { try { if ( stream != null ) { stream . close ( ) ; } } catch ( Exception e ) { } } public static void closeQuietly ( Reader stream ) { try { if ( stream != null ) { stream . close ( ) ; } } catch ( Exception e ) { } } public static void closeQuietly ( Writer stream ) { try { if ( stream != null ) { stream . close ( ) ; } } catch ( Exception e ) { } } public static void copy ( InputStream in , OutputStream out ) throws IOException { byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int n = <NUM_LIT:0> ; while ( - <NUM_LIT:1> != ( n = in . read ( buffer ) ) ) { out . write ( buffer , <NUM_LIT:0> , n ) ; } } public static void copy ( Reader in , Writer out ) throws IOException { char [ ] buffer = new char [ DEFAULT_BUFFER_SIZE ] ; int n = <NUM_LIT:0> ; while ( - <NUM_LIT:1> != ( n = in . read ( buffer ) ) ) { out . write ( buffer , <NUM_LIT:0> , n ) ; } } public static List < String > readLines ( InputStream in ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( in ) ) ; ArrayList < String > lines = new ArrayList < String > ( ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { lines . add ( line ) ; } return lines ; } public static void writeLines ( List < String > lines , OutputStream out ) throws IOException { PrintWriter writer = new PrintWriter ( new OutputStreamWriter ( out ) ) ; for ( String line : lines ) { writer . println ( line ) ; } writer . flush ( ) ; } public static String toString ( InputStream in ) throws IOException { return toString ( new InputStreamReader ( in ) ) ; } public static String toString ( Reader in ) throws IOException { StringWriter out = new StringWriter ( ) ; copy ( in , out ) ; return out . toString ( ) ; } } </s>
<s> package org . eclim . command ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . eclim . util . StringUtils ; public class Error { private String message ; private String filename ; private int line ; private int column ; private int endLine ; private int endColumn ; private boolean warning ; public Error ( String message , String filename , int line , int column , boolean warning ) { this ( message , filename , line , column , - <NUM_LIT:1> , - <NUM_LIT:1> , warning ) ; } public Error ( String message , String filename , int line , int column , int endLine , int endColumn , boolean warning ) { this . message = message != null ? message : StringUtils . EMPTY ; this . filename = filename ; this . line = line > <NUM_LIT:0> ? line : <NUM_LIT:1> ; this . column = column > <NUM_LIT:0> ? column : <NUM_LIT:1> ; this . endLine = endLine ; this . endColumn = endColumn ; this . warning = warning ; } public String getMessage ( ) { return message != null ? message : StringUtils . EMPTY ; } public String getFilename ( ) { return filename ; } public int getLine ( ) { return line ; } public int getColumn ( ) { return this . column ; } public int getEndLine ( ) { return this . endLine ; } public int getEndColumn ( ) { return this . endColumn ; } public boolean isWarning ( ) { return warning ; } public boolean equals ( Object other ) { if ( ! ( other instanceof Error ) ) { return false ; } if ( this == other ) { return true ; } Error error = ( Error ) other ; boolean equal = new EqualsBuilder ( ) . append ( getFilename ( ) , error . getFilename ( ) ) . append ( getLine ( ) , error . getLine ( ) ) . append ( getColumn ( ) , error . getColumn ( ) ) . append ( getEndLine ( ) , error . getEndLine ( ) ) . append ( getEndColumn ( ) , error . getEndColumn ( ) ) . append ( getMessage ( ) , error . getMessage ( ) ) . isEquals ( ) ; return equal ; } public int hashCode ( ) { return new HashCodeBuilder ( <NUM_LIT> , <NUM_LIT> ) . append ( filename ) . append ( line ) . append ( column ) . append ( endLine ) . append ( endColumn ) . append ( message ) . toHashCode ( ) ; } } </s>
<s> package org . eclim . command ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import org . apache . commons . cli . Option ; import org . apache . commons . lang . StringUtils ; public class CommandLine { private HashMap < String , Object > options = new HashMap < String , Object > ( ) ; private Command command ; private String [ ] args ; private String [ ] unrecognized ; public CommandLine ( Command command , org . apache . commons . cli . CommandLine commandLine , String [ ] args ) { this . command = command ; this . args = args ; Option [ ] options = commandLine . getOptions ( ) ; for ( Option option : options ) { if ( option . hasArgs ( ) ) { this . options . put ( option . getOpt ( ) , commandLine . getOptionValues ( option . getOpt ( ) ) ) ; } else { this . options . put ( option . getOpt ( ) , commandLine . getOptionValue ( option . getOpt ( ) ) ) ; } } unrecognized = commandLine . getArgs ( ) ; } public Command getCommand ( ) { return this . command ; } public boolean hasOption ( String name ) { return options . containsKey ( name ) ; } public String getValue ( String name ) throws Exception { String value = null ; Object val = options . get ( name ) ; if ( val != null ) { if ( val . getClass ( ) . isArray ( ) ) { value = ( ( String [ ] ) val ) [ <NUM_LIT:0> ] ; } else { value = ( String ) val ; } value = StringUtils . replace ( value , "<STR_LIT>" , "<STR_LIT:*>" ) ; value = StringUtils . replace ( value , "<STR_LIT>" , "<STR_LIT:$>" ) ; value = StringUtils . replace ( value , "<STR_LIT>" , "<STR_LIT:<>" ) ; value = StringUtils . replace ( value , "<STR_LIT>" , "<STR_LIT:>>" ) ; return value ; } return null ; } public Object getRawValue ( String name ) throws Exception { return options . get ( name ) ; } public String getValue ( String name , String dflt ) throws Exception { String value = getValue ( name ) ; return value != null ? value : dflt ; } public String [ ] getValues ( String name ) throws Exception { String [ ] values = null ; Object val = options . get ( name ) ; if ( val != null ) { if ( ! val . getClass ( ) . isArray ( ) ) { values = new String [ ] { ( String ) val } ; } else { values = ( String [ ] ) val ; } for ( int ii = <NUM_LIT:0> ; ii < values . length ; ii ++ ) { values [ ii ] = StringUtils . replace ( values [ ii ] , "<STR_LIT>" , "<STR_LIT:*>" ) ; values [ ii ] = StringUtils . replace ( values [ ii ] , "<STR_LIT>" , "<STR_LIT:$>" ) ; values [ ii ] = StringUtils . replace ( values [ ii ] , "<STR_LIT>" , "<STR_LIT:<>" ) ; values [ ii ] = StringUtils . replace ( values [ ii ] , "<STR_LIT>" , "<STR_LIT:>>" ) ; if ( values [ ii ] . startsWith ( "<STR_LIT>" ) ) { values [ ii ] = values [ ii ] . substring ( <NUM_LIT:1> ) ; } } return values ; } return null ; } public int getIntValue ( String name ) throws Exception { String arg = getValue ( name ) ; return arg != null ? Integer . parseInt ( arg ) : - <NUM_LIT:1> ; } public long getLongValue ( String name ) throws Exception { String arg = getValue ( name ) ; return arg != null ? Long . parseLong ( arg ) : - <NUM_LIT:1> ; } public String [ ] getUnrecognizedArgs ( ) { return unrecognized ; } public String [ ] getArgs ( ) { return args ; } public void addOption ( String option , String value ) { options . put ( option , value ) ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; for ( Map . Entry < String , Object > entry : this . options . entrySet ( ) ) { buffer . append ( "<STR_LIT>" ) . append ( entry . getKey ( ) ) ; buffer . append ( "<STR_LIT>" ) ; Object value = entry . getValue ( ) ; if ( value instanceof Object [ ] ) { buffer . append ( Arrays . toString ( ( Object [ ] ) value ) ) ; } else { buffer . append ( value ) ; } buffer . append ( '<STR_LIT:\n>' ) ; } if ( unrecognized != null && unrecognized . length > <NUM_LIT:0> ) { buffer . append ( "<STR_LIT>" + Arrays . toString ( unrecognized ) ) ; } return buffer . toString ( ) ; } } </s>
<s> package org . eclim . command ; import java . util . ArrayList ; import java . util . Collection ; import org . apache . commons . cli . CommandLineParser ; import org . apache . commons . cli . GnuParser ; import org . apache . commons . cli . Option ; import org . apache . commons . cli . OptionBuilder ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; @ SuppressWarnings ( "<STR_LIT>" ) public class Options { public static final String COMMAND_OPTION = "<STR_LIT>" ; public static final String PRETTY_OPTION = "<STR_LIT>" ; public static final String EDITOR_OPTION = "<STR_LIT>" ; public static final String ACTION_OPTION = "<STR_LIT:a>" ; public static final String APPLY_OPTION = "<STR_LIT:a>" ; public static final String ARGS_OPTION = "<STR_LIT:a>" ; public static final String BASEDIR_OPTION = "<STR_LIT:b>" ; public static final String BUILD_OPTION = "<STR_LIT:b>" ; public static final String BUILD_FILE_OPTION = "<STR_LIT:b>" ; public static final String CASE_INSENSITIVE_OPTION = "<STR_LIT:i>" ; public static final String CLASSNAME_OPTION = "<STR_LIT:c>" ; public static final String CONTEXT_OPTION = "<STR_LIT:x>" ; public static final String DEBUG_OPTION = "<STR_LIT:d>" ; public static final String DELIMETER_OPTION = "<STR_LIT:d>" ; public static final String DEPENDS_OPTION = "<STR_LIT:d>" ; public static final String DEST_OPTION = "<STR_LIT:d>" ; public static final String DIR_OPTION = "<STR_LIT:d>" ; public static final String ENCODING_OPTION = "<STR_LIT:e>" ; public static final String EXCLUDES_OPTION = "<STR_LIT:e>" ; public static final String ERRORS_OPTION = "<STR_LIT:e>" ; public static final String FAMILY_OPTION = "<STR_LIT:f>" ; public static final String FILE_OPTION = "<STR_LIT:f>" ; public static final String FOLDER_OPTION = "<STR_LIT:f>" ; public static final String HELP = "<STR_LIT>" ; public static final String HALT_OPTION = "<STR_LIT>" ; public static final String INDENT_OPTION = "<STR_LIT:i>" ; public static final String INDEXED_OPTION = "<STR_LIT:i>" ; public static final String JARS_OPTION = "<STR_LIT>" ; public static final String LANG_OPTION = "<STR_LIT>" ; public static final String LAYOUT_OPTION = "<STR_LIT>" ; public static final String LENGTH_OPTION = "<STR_LIT>" ; public static final String LINE_OPTION = "<STR_LIT>" ; public static final String LINE_WIDTH_OPTION = "<STR_LIT>" ; public static final String METHOD_OPTION = "<STR_LIT:m>" ; public static final String NAME_OPTION = "<STR_LIT:n>" ; public static final String NATURE_OPTION = "<STR_LIT:n>" ; public static final String OFFSET_OPTION = "<STR_LIT>" ; public static final String PATH_OPTION = "<STR_LIT:p>" ; public static final String PATTERN_OPTION = "<STR_LIT:p>" ; public static final String PEEK_OPTION = "<STR_LIT:p>" ; public static final String PROJECT_OPTION = "<STR_LIT:p>" ; public static final String PROPERTIES_OPTION = "<STR_LIT:r>" ; public static final String REVISION_OPTION = "<STR_LIT:r>" ; public static final String SCHEMA_OPTION = "<STR_LIT:s>" ; public static final String SCOPE_OPTION = "<STR_LIT:s>" ; public static final String SEARCH_OPTION = "<STR_LIT:s>" ; public static final String SETTINGS_OPTION = "<STR_LIT:s>" ; public static final String SETTING_OPTION = "<STR_LIT:s>" ; public static final String SOURCE_OPTION = "<STR_LIT:s>" ; public static final String SUPERTYPE_OPTION = "<STR_LIT:s>" ; public static final String TEMPLATE_OPTION = "<STR_LIT:t>" ; public static final String TEST_OPTION = "<STR_LIT:t>" ; public static final String TYPE_OPTION = "<STR_LIT:t>" ; public static final String URL_OPTION = "<STR_LIT>" ; public static final String VALIDATE_OPTION = "<STR_LIT>" ; public static final String VALUE_OPTION = "<STR_LIT>" ; public static final String VALUES_OPTION = "<STR_LIT>" ; public static final String VARIABLE_OPTION = "<STR_LIT>" ; private static final String ANY = "<STR_LIT>" ; private static final String ARG = "<STR_LIT>" ; private static final String REQUIRED = "<STR_LIT>" ; private static org . apache . commons . cli . Options coreOptions = new org . apache . commons . cli . Options ( ) ; static { coreOptions . addOption ( OptionBuilder . withArgName ( COMMAND_OPTION ) . isRequired ( true ) . hasArg ( ) . withDescription ( Services . getMessage ( "<STR_LIT>" ) ) . create ( COMMAND_OPTION ) ) ; coreOptions . addOption ( OptionBuilder . withArgName ( PRETTY_OPTION ) . withDescription ( Services . getMessage ( "<STR_LIT>" ) ) . create ( PRETTY_OPTION ) ) ; coreOptions . addOption ( OptionBuilder . withArgName ( EDITOR_OPTION ) . hasArg ( ) . withDescription ( Services . getMessage ( "<STR_LIT>" ) ) . create ( EDITOR_OPTION ) ) ; } protected org . apache . commons . cli . Options options = new org . apache . commons . cli . Options ( ) ; protected CommandLine commandLine ; public Options ( ) { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Collection < Option > opts = coreOptions . getOptions ( ) ; for ( Option option : opts ) { options . addOption ( option ) ; } } public CommandLine parse ( String [ ] args ) throws Exception { String commandName = null ; for ( int ii = <NUM_LIT:0> ; ii < args . length ; ii ++ ) { if ( args [ ii ] . equals ( '<CHAR_LIT:->' + COMMAND_OPTION ) ) { if ( args . length > ii + <NUM_LIT:1> ) { commandName = args [ ii + <NUM_LIT:1> ] . trim ( ) ; } break ; } } Command command = null ; if ( commandName != null ) { command = Services . getCommand ( commandName ) ; if ( command == null ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , commandName ) ) ; } org . eclim . annotation . Command info = ( org . eclim . annotation . Command ) command . getClass ( ) . getAnnotation ( org . eclim . annotation . Command . class ) ; Collection < Option > commandOptions = parseOptions ( info . options ( ) ) ; for ( Option option : commandOptions ) { options . addOption ( option ) ; } } CommandLineParser parser = new GnuParser ( ) ; return new CommandLine ( command , parser . parse ( options , args ) , args ) ; } public Collection < Option > parseOptions ( String optionsString ) { ArrayList < Option > options = new ArrayList < Option > ( ) ; if ( optionsString != null && optionsString . trim ( ) . length ( ) > <NUM_LIT:0> ) { String [ ] lines = StringUtils . split ( optionsString , '<CHAR_LIT:U+002C>' ) ; for ( int ii = <NUM_LIT:0> ; ii < lines . length ; ii ++ ) { if ( lines [ ii ] . trim ( ) . length ( ) > <NUM_LIT:0> ) { options . add ( parseOption ( lines [ ii ] . trim ( ) ) ) ; } } } return options ; } public Option parseOption ( String option ) { String [ ] parts = StringUtils . split ( option ) ; if ( REQUIRED . equals ( parts [ <NUM_LIT:0> ] ) ) { OptionBuilder . isRequired ( ) ; } if ( ARG . equals ( parts [ <NUM_LIT:3> ] ) ) { OptionBuilder . hasArg ( ) ; } else if ( ANY . equals ( parts [ <NUM_LIT:3> ] ) ) { OptionBuilder . hasOptionalArgs ( ) ; } OptionBuilder . withLongOpt ( parts [ <NUM_LIT:2> ] ) ; return OptionBuilder . create ( parts [ <NUM_LIT:1> ] ) ; } } </s>
<s> package org . eclim . command ; public interface OutputFilter < T > { public String filter ( CommandLine commandLine , T result ) ; } </s>
<s> package org . eclim . command ; import java . io . PrintStream ; import java . lang . reflect . Type ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collection ; import java . util . Collections ; import java . util . Comparator ; import java . util . Iterator ; import org . apache . commons . cli . Option ; import org . apache . commons . cli . ParseException ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . lang . SystemUtils ; import org . eclim . Services ; import org . eclim . logging . Logger ; import org . eclipse . swt . widgets . Display ; import com . google . gson . GsonBuilder ; import com . google . gson . JsonElement ; import com . google . gson . JsonPrimitive ; import com . google . gson . JsonSerializationContext ; import com . google . gson . JsonSerializer ; import com . martiansoftware . nailgun . NGContext ; public class Main { private static final Logger logger = Logger . getLogger ( Main . class ) ; public static final void nailMain ( final NGContext context ) { try { logger . debug ( "<STR_LIT>" + Arrays . toString ( context . getArgs ( ) ) ) ; ArrayList < String > arguments = new ArrayList < String > ( ) ; for ( String arg : context . getArgs ( ) ) { if ( arg . startsWith ( "<STR_LIT>" ) ) { String [ ] prop = StringUtils . split ( arg . substring ( <NUM_LIT:2> ) , '<CHAR_LIT:=>' ) ; System . setProperty ( prop [ <NUM_LIT:0> ] , prop [ <NUM_LIT:1> ] ) ; } else { arguments . add ( arg ) ; } } if ( arguments . isEmpty ( ) || arguments . contains ( "<STR_LIT>" ) ) { usage ( context . out ) ; System . exit ( arguments . isEmpty ( ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } Options options = new Options ( ) ; final CommandLine commandLine = options . parse ( ( String [ ] ) arguments . toArray ( new String [ arguments . size ( ) ] ) ) ; String commandName = commandLine . getValue ( Options . COMMAND_OPTION ) ; logger . debug ( "<STR_LIT>" , commandName ) ; final Command command = commandLine . getCommand ( ) ; command . setContext ( context ) ; final Object [ ] results = new Object [ <NUM_LIT:1> ] ; Display . getDefault ( ) . syncExec ( new Runnable ( ) { public void run ( ) { try { results [ <NUM_LIT:0> ] = command . execute ( commandLine ) ; } catch ( Exception e ) { results [ <NUM_LIT:0> ] = e ; } finally { command . cleanup ( commandLine ) ; } } } ) ; Object result = results [ <NUM_LIT:0> ] ; if ( result != null ) { if ( result instanceof Throwable ) { throw ( Throwable ) result ; } GsonBuilder builder = new GsonBuilder ( ) ; if ( commandLine . hasOption ( Options . PRETTY_OPTION ) ) { builder = builder . setPrettyPrinting ( ) ; } if ( commandLine . hasOption ( Options . EDITOR_OPTION ) && commandLine . getValue ( Options . EDITOR_OPTION ) . equals ( "<STR_LIT>" ) ) { builder = builder . registerTypeAdapter ( Boolean . TYPE , new BooleanSerializer ( ) ) . registerTypeAdapter ( Boolean . class , new BooleanSerializer ( ) ) ; } context . out . println ( builder . create ( ) . toJson ( result ) ) ; } } catch ( ParseException e ) { context . out . println ( Services . getMessage ( e . getClass ( ) . getName ( ) , e . getMessage ( ) ) ) ; logger . debug ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } catch ( Throwable e ) { logger . debug ( "<STR_LIT>" + Arrays . toString ( context . getArgs ( ) ) , e ) ; e . printStackTrace ( context . err ) ; logger . debug ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } } public static void usage ( PrintStream out ) { ArrayList < org . eclim . annotation . Command > commands = new ArrayList < org . eclim . annotation . Command > ( ) ; for ( Class < ? extends Command > command : Services . getCommandClasses ( ) ) { commands . add ( command . getAnnotation ( org . eclim . annotation . Command . class ) ) ; } Collections . sort ( commands , new Comparator < org . eclim . annotation . Command > ( ) { public int compare ( org . eclim . annotation . Command o1 , org . eclim . annotation . Command o2 ) { return o1 . name ( ) . compareTo ( o2 . name ( ) ) ; } } ) ; String osOpts = StringUtils . EMPTY ; if ( SystemUtils . IS_OS_UNIX ) { osOpts = "<STR_LIT>" ; } out . println ( "<STR_LIT>" + osOpts + "<STR_LIT>" ) ; out . println ( "<STR_LIT>" ) ; for ( org . eclim . annotation . Command command : commands ) { Collection < Option > options = new Options ( ) . parseOptions ( command . options ( ) ) ; StringBuffer opts = new StringBuffer ( ) ; Iterator < Option > iterator = options . iterator ( ) ; for ( int ii = <NUM_LIT:0> ; iterator . hasNext ( ) ; ii ++ ) { Option option = iterator . next ( ) ; opts . append ( option . isRequired ( ) ? "<STR_LIT:U+0020>" : "<STR_LIT>" ) ; opts . append ( '<CHAR_LIT:->' ) . append ( option . getOpt ( ) ) ; if ( option . hasArg ( ) ) { opts . append ( '<CHAR_LIT:U+0020>' ) . append ( option . getLongOpt ( ) ) ; } if ( ! option . isRequired ( ) ) { opts . append ( '<CHAR_LIT:]>' ) ; } if ( ( ii + <NUM_LIT:1> ) % <NUM_LIT:4> == <NUM_LIT:0> && ii != options . size ( ) - <NUM_LIT:1> ) { opts . append ( StringUtils . rightPad ( "<STR_LIT:n>" , command . name ( ) . length ( ) + <NUM_LIT:5> ) ) ; } } StringBuffer info = new StringBuffer ( ) . append ( "<STR_LIT:U+0020U+0020U+0020U+0020>" ) . append ( command . name ( ) ) . append ( opts ) ; out . println ( info ) ; if ( ! command . description ( ) . equals ( StringUtils . EMPTY ) ) { out . println ( "<STR_LIT>" + command . description ( ) ) ; } } } private static class BooleanSerializer implements JsonSerializer < Boolean > { public JsonElement serialize ( Boolean bool , Type typeOfSrc , JsonSerializationContext context ) { return new JsonPrimitive ( bool . booleanValue ( ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } } } </s>
<s> package org . eclim . command ; import java . util . ArrayList ; import org . eclim . Services ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; import org . osgi . framework . FrameworkListener ; import org . osgi . framework . wiring . FrameworkWiring ; import com . martiansoftware . nailgun . NGContext ; @ org . eclim . annotation . Command ( name = "<STR_LIT>" ) public class ReloadCommand implements Command { private NGContext context ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { Bundle system = Platform . getBundle ( "<STR_LIT>" ) ; FrameworkWiring framework = ( FrameworkWiring ) system . adapt ( FrameworkWiring . class ) ; ArrayList < Bundle > bundles = new ArrayList < Bundle > ( ) ; bundles . add ( Platform . getBundle ( "<STR_LIT>" ) ) ; framework . refreshBundles ( bundles , new FrameworkListener [ <NUM_LIT:0> ] ) ; return Services . getMessage ( "<STR_LIT>" ) ; } @ Override public NGContext getContext ( ) { return context ; } @ Override public void setContext ( NGContext context ) { this . context = context ; } @ Override public void cleanup ( CommandLine commandLine ) { } } </s>
<s> package org . eclim . command ; import org . eclim . command . CommandLine ; import com . martiansoftware . nailgun . NGContext ; public interface Command { public Object execute ( CommandLine commandLine ) throws Exception ; public void cleanup ( CommandLine commandLine ) ; public NGContext getContext ( ) ; public void setContext ( NGContext context ) ; } </s>
<s> package org . eclim . eclipse ; import java . util . Map ; import org . eclim . logging . Logger ; import org . eclipse . e4 . ui . internal . workbench . E4Workbench ; import org . eclipse . equinox . app . IApplicationContext ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . internal . ide . application . IDEApplication ; public class EclimApplication extends IDEApplication { private static final Logger logger = Logger . getLogger ( EclimApplication . class ) ; private static EclimApplication instance ; private static boolean stopping ; @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) @ Override public Object start ( IApplicationContext context ) throws Exception { Map args = context . getArguments ( ) ; String [ ] appArgs = ( String [ ] ) args . get ( IApplicationContext . APPLICATION_ARGS ) ; String [ ] presentationArgs = new String [ ] { "<STR_LIT:->" + E4Workbench . PERSIST_STATE , "<STR_LIT:false>" , "<STR_LIT:->" + E4Workbench . PRESENTATION_URI_ARG , "<STR_LIT>" , } ; String [ ] newArgs = new String [ appArgs . length + presentationArgs . length ] ; System . arraycopy ( appArgs , <NUM_LIT:0> , newArgs , <NUM_LIT:0> , appArgs . length ) ; System . arraycopy ( presentationArgs , <NUM_LIT:0> , newArgs , appArgs . length , presentationArgs . length ) ; args . put ( IApplicationContext . APPLICATION_ARGS , newArgs ) ; instance = this ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { public void run ( ) { try { EclimApplication . shutdown ( ) ; } catch ( Exception ex ) { logger . error ( "<STR_LIT>" , ex ) ; } } } ) ; return super . start ( context ) ; } public static boolean isEnabled ( ) { return instance != null ; } public synchronized static void shutdown ( ) throws Exception { if ( instance != null && ! stopping ) { stopping = true ; EclimDaemon . getInstance ( ) . stop ( ) ; final IWorkbench workbench = PlatformUI . getWorkbench ( ) ; workbench . getDisplay ( ) . syncExec ( new Runnable ( ) { public void run ( ) { workbench . getActiveWorkbenchWindow ( ) . close ( ) ; } } ) ; } } } </s>
<s> package org . eclim . eclipse ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . net . URL ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . Plugin ; import org . eclipse . core . runtime . internal . adaptor . EclipseAdaptorMsg ; import org . eclipse . core . runtime . internal . adaptor . MessageHelper ; import org . eclipse . osgi . service . resolver . BundleDescription ; import org . eclipse . osgi . service . resolver . PlatformAdmin ; import org . eclipse . osgi . service . resolver . ResolverError ; import org . eclipse . osgi . service . resolver . State ; import org . eclipse . osgi . service . resolver . VersionConstraint ; import org . eclipse . osgi . util . NLS ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . osgi . framework . BundleContext ; import org . osgi . framework . ServiceReference ; public class EclimPlugin extends Plugin { private static EclimPlugin plugin ; private static final String FILE_PREFIX = "<STR_LIT>" ; private static final String PLUGIN_XML = "<STR_LIT>" ; public EclimPlugin ( ) { plugin = this ; } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; URL url = FileLocator . toFileURL ( getBundle ( ) . getResource ( PLUGIN_XML ) ) ; String home = url . toString ( ) ; home = home . substring ( FILE_PREFIX . length ( ) , home . length ( ) - PLUGIN_XML . length ( ) ) ; home = home . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; System . setProperty ( "<STR_LIT>" , home ) ; } public void stop ( BundleContext context ) throws Exception { super . stop ( context ) ; plugin = null ; } public static EclimPlugin getDefault ( ) { return plugin ; } public static Shell getShell ( ) { Display display = Display . getDefault ( ) ; Shell shell = display . getActiveShell ( ) ; if ( shell != null ) { return shell ; } Shell [ ] shells = display . getShells ( ) ; if ( shells . length > <NUM_LIT:0> ) { return shells [ <NUM_LIT:0> ] ; } return null ; } @ SuppressWarnings ( { "<STR_LIT:unchecked>" , "<STR_LIT:rawtypes>" } ) public String diagnose ( String bundleName ) { StringWriter out = new StringWriter ( ) ; PrintWriter writer = new PrintWriter ( out ) ; BundleContext context = getDefault ( ) . getBundle ( ) . getBundleContext ( ) ; ServiceReference platformAdminRef = context . getServiceReference ( PlatformAdmin . class . getName ( ) ) ; PlatformAdmin platformAdmin = ( PlatformAdmin ) context . getService ( platformAdminRef ) ; State state = platformAdmin . getState ( false ) ; BundleDescription bundle = null ; BundleDescription [ ] allBundles = state . getBundles ( bundleName ) ; if ( allBundles . length == <NUM_LIT:0> ) { writer . println ( NLS . bind ( EclipseAdaptorMsg . ECLIPSE_CONSOLE_CANNOT_FIND_BUNDLE_ERROR , bundleName ) ) ; } else { bundle = allBundles [ <NUM_LIT:0> ] ; VersionConstraint [ ] unsatisfied = platformAdmin . getStateHelper ( ) . getUnsatisfiedConstraints ( bundle ) ; ResolverError [ ] resolverErrors = platformAdmin . getState ( false ) . getResolverErrors ( bundle ) ; for ( int i = <NUM_LIT:0> ; i < resolverErrors . length ; i ++ ) { if ( ( resolverErrors [ i ] . getType ( ) & ( ResolverError . MISSING_FRAGMENT_HOST | ResolverError . MISSING_GENERIC_CAPABILITY | ResolverError . MISSING_IMPORT_PACKAGE | ResolverError . MISSING_REQUIRE_BUNDLE ) ) != <NUM_LIT:0> ) { continue ; } writer . print ( "<STR_LIT:U+0020U+0020>" ) ; writer . println ( resolverErrors [ i ] . toString ( ) ) ; } if ( unsatisfied . length == <NUM_LIT:0> && resolverErrors . length == <NUM_LIT:0> ) { writer . print ( "<STR_LIT:U+0020U+0020>" ) ; writer . println ( EclipseAdaptorMsg . ECLIPSE_CONSOLE_NO_CONSTRAINTS ) ; } if ( unsatisfied . length > <NUM_LIT:0> ) { writer . print ( "<STR_LIT:U+0020U+0020>" ) ; writer . println ( EclipseAdaptorMsg . ECLIPSE_CONSOLE_DIRECT_CONSTRAINTS ) ; } for ( int i = <NUM_LIT:0> ; i < unsatisfied . length ; i ++ ) { writer . print ( "<STR_LIT:U+0020U+0020U+0020U+0020>" ) ; writer . println ( MessageHelper . getResolutionFailureMessage ( unsatisfied [ i ] ) ) ; } VersionConstraint [ ] unsatisfiedLeaves = platformAdmin . getStateHelper ( ) . getUnsatisfiedLeaves ( new BundleDescription [ ] { bundle } ) ; boolean foundLeaf = false ; for ( int i = <NUM_LIT:0> ; i < unsatisfiedLeaves . length ; i ++ ) { if ( unsatisfiedLeaves [ i ] . getBundle ( ) == bundle ) { continue ; } if ( ! foundLeaf ) { foundLeaf = true ; writer . print ( "<STR_LIT:U+0020U+0020>" ) ; writer . println ( EclipseAdaptorMsg . ECLIPSE_CONSOLE_LEAF_CONSTRAINTS ) ; } writer . print ( "<STR_LIT:U+0020U+0020U+0020U+0020>" ) ; writer . println ( unsatisfiedLeaves [ i ] . getBundle ( ) . getLocation ( ) + "<STR_LIT>" + unsatisfiedLeaves [ i ] . getBundle ( ) . getBundleId ( ) + "<STR_LIT:]>" ) ; writer . print ( "<STR_LIT>" ) ; writer . println ( MessageHelper . getResolutionFailureMessage ( unsatisfiedLeaves [ i ] ) ) ; } } return out . toString ( ) ; } } </s>
<s> package org . eclim . eclipse ; import java . io . File ; import java . io . FileFilter ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . net . BindException ; import java . net . InetAddress ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; import java . util . List ; import org . eclim . Services ; import org . eclim . command . ReloadCommand ; import org . eclim . logging . Logger ; import org . eclim . plugin . PluginResources ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; import org . osgi . framework . FrameworkEvent ; import org . osgi . framework . FrameworkListener ; import com . martiansoftware . nailgun . NGServer ; public class EclimDaemon implements FrameworkListener { private static final Logger logger = Logger . getLogger ( EclimDaemon . class ) ; private static String CORE = "<STR_LIT>" ; private static EclimDaemon instance = new EclimDaemon ( ) ; private boolean started ; private boolean starting ; private boolean stopping ; private NGServer server ; private EclimDaemon ( ) { } public static EclimDaemon getInstance ( ) { return instance ; } public void start ( ) { if ( started || starting ) { return ; } String workspace = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; logger . info ( "<STR_LIT>" + workspace ) ; starting = true ; logger . info ( "<STR_LIT>" ) ; final String host = Services . getPluginResources ( "<STR_LIT>" ) . getProperty ( "<STR_LIT>" ) ; final String portString = Services . getPluginResources ( "<STR_LIT>" ) . getProperty ( "<STR_LIT>" ) ; try { final int port = Integer . parseInt ( portString ) ; registerInstance ( workspace , port ) ; InetAddress address = InetAddress . getByName ( host ) ; server = new NGServer ( address , port , getExtensionClassLoader ( ) ) ; server . setCaptureSystemStreams ( false ) ; logger . info ( "<STR_LIT>" ) ; PluginResources defaultResources = Services . getPluginResources ( "<STR_LIT>" ) ; defaultResources . registerCommand ( ReloadCommand . class ) ; logger . info ( "<STR_LIT>" ) ; Bundle bundle = Platform . getBundle ( CORE ) ; if ( bundle == null ) { String diagnosis = EclimPlugin . getDefault ( ) . diagnose ( CORE ) ; logger . error ( Services . getMessage ( "<STR_LIT>" , CORE , diagnosis ) ) ; return ; } bundle . start ( Bundle . START_TRANSIENT ) ; bundle . getBundleContext ( ) . addFrameworkListener ( this ) ; synchronized ( this ) { wait ( <NUM_LIT> ) ; } starting = false ; started = true ; logger . info ( "<STR_LIT>" , host , port ) ; server . run ( ) ; } catch ( NumberFormatException nfe ) { logger . error ( "<STR_LIT>" , new RuntimeException ( "<STR_LIT>" + portString + "<STR_LIT:'>" ) ) ; } catch ( BindException be ) { logger . error ( "<STR_LIT>" , host , portString , be ) ; } catch ( Throwable t ) { logger . error ( "<STR_LIT>" , t ) ; } finally { starting = false ; started = false ; } } public void stop ( ) throws Exception { if ( started && ! stopping ) { try { stopping = true ; logger . info ( "<STR_LIT>" ) ; if ( server != null && server . isRunning ( ) ) { server . shutdown ( false ) ; } unregisterInstance ( ) ; logger . info ( "<STR_LIT>" + CORE ) ; Bundle bundle = Platform . getBundle ( CORE ) ; if ( bundle != null ) { try { bundle . stop ( ) ; } catch ( IllegalStateException ise ) { } } logger . info ( "<STR_LIT>" ) ; } finally { stopping = false ; } } } private void registerInstance ( String workspace , int port ) throws Exception { File instances = new File ( FileUtils . concat ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ) ; FileOutputStream out = null ; try { List < String > entries = readInstances ( ) ; if ( entries != null ) { String instance = workspace + '<CHAR_LIT::>' + port ; if ( ! entries . contains ( instance ) ) { entries . add ( <NUM_LIT:0> , instance ) ; out = new FileOutputStream ( instances ) ; IOUtils . writeLines ( entries , out ) ; } } } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" + ioe . getMessage ( ) + "<STR_LIT:n>" + instances ) ; } finally { IOUtils . closeQuietly ( out ) ; } } private void unregisterInstance ( ) throws Exception { File instances = new File ( FileUtils . concat ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ) ; FileOutputStream out = null ; try { List < String > entries = readInstances ( ) ; if ( entries == null ) { return ; } String workspace = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; String port = Services . getPluginResources ( "<STR_LIT>" ) . getProperty ( "<STR_LIT>" ) ; String instance = workspace + '<CHAR_LIT::>' + port ; entries . remove ( instance ) ; if ( entries . size ( ) == <NUM_LIT:0> ) { if ( ! instances . delete ( ) ) { logger . error ( "<STR_LIT>" + instances ) ; } } else { out = new FileOutputStream ( instances ) ; IOUtils . writeLines ( entries , out ) ; } } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" + ioe . getMessage ( ) + "<STR_LIT:n>" + instances ) ; return ; } finally { IOUtils . closeQuietly ( out ) ; } } private List < String > readInstances ( ) throws Exception { File doteclim = new File ( FileUtils . concat ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ) ; if ( ! doteclim . exists ( ) ) { if ( ! doteclim . mkdirs ( ) ) { logger . error ( "<STR_LIT>" + doteclim ) ; return null ; } } File instances = new File ( FileUtils . concat ( doteclim . getAbsolutePath ( ) , "<STR_LIT>" ) ) ; if ( ! instances . exists ( ) ) { try { instances . createNewFile ( ) ; } catch ( IOException ioe ) { logger . error ( "<STR_LIT>" + ioe . getMessage ( ) + "<STR_LIT:n>" + instances ) ; return null ; } } FileInputStream in = null ; try { in = new FileInputStream ( instances ) ; List < String > entries = IOUtils . readLines ( in ) ; return entries ; } finally { IOUtils . closeQuietly ( in ) ; } } private ClassLoader getExtensionClassLoader ( ) throws Exception { File extdir = new File ( FileUtils . concat ( Services . DOT_ECLIM , "<STR_LIT>" ) ) ; if ( extdir . exists ( ) ) { FileFilter filter = new FileFilter ( ) { public boolean accept ( File file ) { return file . isDirectory ( ) || file . getName ( ) . endsWith ( "<STR_LIT>" ) ; } } ; ArrayList < URL > urls = new ArrayList < URL > ( ) ; listFileUrls ( extdir , filter , urls ) ; return new URLClassLoader ( urls . toArray ( new URL [ urls . size ( ) ] ) , this . getClass ( ) . getClassLoader ( ) ) ; } return null ; } private void listFileUrls ( File dir , FileFilter filter , ArrayList < URL > results ) throws Exception { File [ ] files = dir . listFiles ( filter ) ; for ( File file : files ) { if ( file . isFile ( ) ) { results . add ( file . toURI ( ) . toURL ( ) ) ; } else { listFileUrls ( file , filter , results ) ; } } } @ Override public synchronized void frameworkEvent ( FrameworkEvent event ) { Bundle bundle = event . getBundle ( ) ; if ( event . getType ( ) == FrameworkEvent . INFO && CORE . equals ( bundle . getSymbolicName ( ) ) ) { logger . info ( "<STR_LIT>" ) ; notify ( ) ; } } } </s>
<s> package org . eclim . eclipse . jface . text ; import org . eclipse . jface . viewers . ISelection ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . ISelectionProvider ; public class DummySelectionProvider implements ISelectionProvider { private ISelection selection ; public DummySelectionProvider ( ISelection selection ) { this . selection = selection ; } public void addSelectionChangedListener ( ISelectionChangedListener listener ) { } public ISelection getSelection ( ) { return selection ; } public void removeSelectionChangedListener ( ISelectionChangedListener listener ) { } public void setSelection ( ISelection selection ) { this . selection = selection ; } } </s>
<s> package org . eclim . eclipse . jface . text . contentassist ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . contentassist . ICompletionListener ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; import org . eclipse . jface . text . contentassist . IContentAssistant ; import org . eclipse . jface . text . contentassist . IContentAssistantExtension2 ; public class DummyContentAssistantExtension2 implements IContentAssistant , IContentAssistantExtension2 { public void install ( ITextViewer textViewer ) { } public void uninstall ( ) { } public String showPossibleCompletions ( ) { return null ; } public String showContextInformation ( ) { return null ; } public IContentAssistProcessor getContentAssistProcessor ( String contentType ) { return null ; } public void addCompletionListener ( ICompletionListener listener ) { } public void removeCompletionListener ( ICompletionListener listener ) { } public void setRepeatedInvocationMode ( boolean cycling ) { } public void setShowEmptyList ( boolean showEmpty ) { } public void setStatusLineVisible ( boolean show ) { } public void setStatusMessage ( String message ) { } public void setEmptyMessage ( String message ) { } } </s>
<s> package org . eclim . eclipse . jface . text ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IEventConsumer ; import org . eclipse . jface . text . IFindReplaceTarget ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . ITextDoubleClickStrategy ; import org . eclipse . jface . text . ITextHover ; import org . eclipse . jface . text . ITextInputListener ; import org . eclipse . jface . text . ITextListener ; import org . eclipse . jface . text . ITextOperationTarget ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . IUndoManager ; import org . eclipse . jface . text . IViewportListener ; import org . eclipse . jface . text . TextPresentation ; import org . eclipse . jface . text . TextSelection ; import org . eclipse . jface . viewers . ISelectionProvider ; import org . eclipse . swt . custom . StyledText ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Point ; public class DummyTextViewer implements ITextViewer { public IDocument document ; public ISelectionProvider selectionProvider ; public DummyTextViewer ( IDocument document , int offset , int length ) { this . document = document ; selectionProvider = new DummySelectionProvider ( new TextSelection ( document , offset , length ) ) ; } public StyledText getTextWidget ( ) { return null ; } public void setUndoManager ( IUndoManager undoManager ) { } public void setTextDoubleClickStrategy ( ITextDoubleClickStrategy strategy , String contentType ) { } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public void setAutoIndentStrategy ( org . eclipse . jface . text . IAutoIndentStrategy strategy , String contentType ) { } public void setTextHover ( ITextHover textViewerHover , String contentType ) { } public void activatePlugins ( ) { } public void resetPlugins ( ) { } public void addViewportListener ( IViewportListener listener ) { } public void removeViewportListener ( IViewportListener listener ) { } public void addTextListener ( ITextListener listener ) { } public void removeTextListener ( ITextListener listener ) { } public void addTextInputListener ( ITextInputListener listener ) { } public void removeTextInputListener ( ITextInputListener listener ) { } public void setDocument ( IDocument document ) { } public IDocument getDocument ( ) { return document ; } public void setEventConsumer ( IEventConsumer consumer ) { } public void setEditable ( boolean editable ) { } public boolean isEditable ( ) { return true ; } public void setDocument ( IDocument document , int modelRangeOffset , int modelRangeLength ) { } public void setVisibleRegion ( int offset , int length ) { } public void resetVisibleRegion ( ) { } public IRegion getVisibleRegion ( ) { return null ; } public boolean overlapsWithVisibleRegion ( int offset , int length ) { return false ; } public void changeTextPresentation ( TextPresentation presentation , boolean controlRedraw ) { } public void invalidateTextPresentation ( ) { } public void setTextColor ( Color color ) { } public void setTextColor ( Color color , int offset , int length , boolean controlRedraw ) { } public ITextOperationTarget getTextOperationTarget ( ) { return null ; } public IFindReplaceTarget getFindReplaceTarget ( ) { return null ; } public void setDefaultPrefixes ( String [ ] defaultPrefixes , String contentType ) { } public void setIndentPrefixes ( String [ ] indentPrefixes , String contentType ) { } public void setSelectedRange ( int offset , int length ) { } public Point getSelectedRange ( ) { return new Point ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; } public ISelectionProvider getSelectionProvider ( ) { return selectionProvider ; } public void revealRange ( int offset , int length ) { } public void setTopIndex ( int index ) { } public int getTopIndex ( ) { return - <NUM_LIT:1> ; } public int getTopIndexStartOffset ( ) { return - <NUM_LIT:1> ; } public int getBottomIndex ( ) { return - <NUM_LIT:1> ; } public int getBottomIndexEndOffset ( ) { return - <NUM_LIT:1> ; } public int getTopInset ( ) { return - <NUM_LIT:1> ; } } </s>
<s> package org . eclim . eclipse ; import org . eclim . logging . Logger ; import org . eclipse . ui . IStartup ; import org . eclipse . ui . IWorkbench ; import org . eclipse . ui . PlatformUI ; public class EclimStartup implements IStartup { private static final Logger logger = Logger . getLogger ( EclimStartup . class ) ; @ Override public void earlyStartup ( ) { if ( EclimApplication . isEnabled ( ) ) { final IWorkbench workbench = PlatformUI . getWorkbench ( ) ; workbench . getDisplay ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { try { new Thread ( ) { public void run ( ) { EclimDaemon . getInstance ( ) . start ( ) ; } } . start ( ) ; } catch ( Exception ex ) { logger . error ( "<STR_LIT>" , ex ) ; } } } ) ; } } } </s>
<s> package org . eclim . eclipse . ui ; import org . eclim . eclipse . EclimDaemon ; import org . eclim . logging . Logger ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Text ; import org . eclipse . ui . part . ViewPart ; public class EclimdView extends ViewPart { private static final Logger logger = Logger . getLogger ( EclimdView . class ) ; private static Text log ; @ Override public void createPartControl ( Composite parent ) { log = new Text ( parent , SWT . LEFT | SWT . MULTI | SWT . READ_ONLY | SWT . H_SCROLL | SWT . V_SCROLL ) ; try { new Thread ( ) { public void run ( ) { EclimDaemon . getInstance ( ) . start ( ) ; } } . start ( ) ; } catch ( Exception ex ) { logger . error ( "<STR_LIT>" , ex ) ; } } @ Override public void dispose ( ) { try { EclimDaemon . getInstance ( ) . stop ( ) ; } catch ( Exception ex ) { logger . error ( "<STR_LIT>" , ex ) ; } } @ Override public void setFocus ( ) { log . setFocus ( ) ; } public static Text getLog ( ) { return log ; } } </s>
<s> package org . eclim . eclipse . ui ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Text ; import org . eclipse . ui . part . ViewPart ; public class VimpluginDebugView extends ViewPart { private static Text log ; @ Override public void createPartControl ( Composite parent ) { log = new Text ( parent , SWT . LEFT | SWT . MULTI | SWT . READ_ONLY | SWT . H_SCROLL | SWT . V_SCROLL ) ; } @ Override public void dispose ( ) { log . dispose ( ) ; log = null ; } @ Override public void setFocus ( ) { log . setFocus ( ) ; } public static Text getLog ( ) { return log ; } } </s>
<s> package org . eclim . eclipse . ui . internal ; import java . lang . reflect . InvocationTargetException ; import org . eclim . eclipse . EclimPlugin ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . jface . operation . IRunnableWithProgress ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . internal . WorkbenchWindow ; public class EclimWorkbenchWindow extends WorkbenchWindow { private IWorkbenchPage page ; public EclimWorkbenchWindow ( ) { super ( null , null ) ; } public IWorkbenchPage getActivePage ( ) { try { if ( page == null ) { page = new EclimWorkbenchPage ( this , ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ) ; } return page ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public Shell getShell ( ) { return EclimPlugin . getShell ( ) ; } public void run ( boolean fork , boolean cancelable , IRunnableWithProgress runnable ) throws InvocationTargetException , InterruptedException { } @ Override public void fillActionBars ( int flags ) { } } </s>
<s> package org . eclim . eclipse . ui . internal ; import org . eclipse . core . runtime . IAdaptable ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . WorkbenchException ; import org . eclipse . ui . internal . WorkbenchPage ; import org . eclipse . ui . internal . WorkbenchWindow ; public class EclimWorkbenchPage extends WorkbenchPage { private IEditorPart editor ; public EclimWorkbenchPage ( WorkbenchWindow window , IAdaptable input ) throws WorkbenchException { super ( window , input ) ; } public IEditorPart getActiveEditor ( ) { return editor ; } public void setActiveEditor ( IEditorPart editor ) { this . editor = editor ; } } </s>
<s> package org . eclim . eclipse . ui ; import org . apache . commons . lang . StringUtils ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . eclipse . ui . internal . EclimWorkbenchWindow ; import org . eclipse . jface . action . MenuManager ; import org . eclipse . jface . viewers . ISelectionProvider ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IActionBars ; import org . eclipse . ui . IEditorActionBarContributor ; import org . eclipse . ui . IEditorSite ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . IWorkbenchPart ; import org . eclipse . ui . IWorkbenchWindow ; @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) public class EclimEditorSite implements IEditorSite { private IWorkbenchWindow window ; private ISelectionProvider selectionProvider ; public EclimEditorSite ( ) { window = new EclimWorkbenchWindow ( ) ; } public String getId ( ) { return StringUtils . EMPTY ; } public String getPluginId ( ) { return "<STR_LIT>" ; } public String getRegisteredName ( ) { return StringUtils . EMPTY ; } public void registerContextMenu ( String arg0 , MenuManager arg1 , ISelectionProvider arg2 ) { } public void registerContextMenu ( MenuManager arg0 , ISelectionProvider arg1 ) { } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public org . eclipse . ui . IKeyBindingService getKeyBindingService ( ) { return null ; } public IWorkbenchPart getPart ( ) { return null ; } public IWorkbenchPage getPage ( ) { return window . getActivePage ( ) ; } public ISelectionProvider getSelectionProvider ( ) { return selectionProvider ; } public Shell getShell ( ) { return EclimPlugin . getShell ( ) ; } public IWorkbenchWindow getWorkbenchWindow ( ) { return window ; } public void setSelectionProvider ( ISelectionProvider provider ) { this . selectionProvider = provider ; } public Object getAdapter ( Class arg0 ) { return null ; } public Object getService ( Class arg0 ) { return null ; } public boolean hasService ( Class arg0 ) { return false ; } public IEditorActionBarContributor getActionBarContributor ( ) { return null ; } public IActionBars getActionBars ( ) { return null ; } public void registerContextMenu ( MenuManager arg0 , ISelectionProvider arg1 , boolean arg2 ) { } public void registerContextMenu ( String arg0 , MenuManager arg1 , ISelectionProvider arg2 , boolean arg3 ) { } } </s>
<s> package org . eclim . eclipse . e4 ; import java . util . List ; import javax . inject . Inject ; import javax . inject . Named ; import org . eclipse . e4 . core . di . annotations . Optional ; import org . eclipse . e4 . ui . internal . workbench . E4Workbench ; import org . eclipse . e4 . ui . internal . workbench . swt . PartRenderingEngine ; import org . eclipse . e4 . ui . model . application . ui . MUIElement ; import org . eclipse . e4 . ui . model . application . ui . basic . MWindow ; public class HeadlessPresentationEngine extends PartRenderingEngine { @ Inject public HeadlessPresentationEngine ( @ Named ( E4Workbench . RENDERER_FACTORY_URI ) @ Optional String factoryUrl ) { super ( factoryUrl ) ; } @ Override protected Object createWidget ( MUIElement element , Object parent ) { if ( parent == null && element instanceof MWindow ) { element . setVisible ( false ) ; } return super . createWidget ( element , parent ) ; } @ Override protected boolean someAreVisible ( List < MWindow > windows ) { for ( MWindow win : windows ) { if ( win . isToBeRendered ( ) && win . getWidget ( ) != null ) { return true ; } } return false ; } } </s>
<s> package org . eclim . plugin ; import java . io . File ; import java . io . InputStream ; import java . net . URL ; import java . text . MessageFormat ; import java . util . ArrayList ; import java . util . Collection ; import java . util . HashMap ; import java . util . List ; import java . util . Locale ; import java . util . Properties ; import java . util . ResourceBundle ; import org . eclim . Services ; import org . eclim . command . Command ; import org . eclim . logging . Logger ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . runtime . FileLocator ; public abstract class AbstractPluginResources implements PluginResources { private static final Logger logger = Logger . getLogger ( AbstractPluginResources . class ) ; private static final String PLUGIN_PROPERTIES = "<STR_LIT>" ; private String name ; private String pluginName ; private Properties properties ; private ResourceBundle bundle ; private List < String > missingResources = new ArrayList < String > ( ) ; private HashMap < String , Class < ? extends Command > > commands = new HashMap < String , Class < ? extends Command > > ( ) ; public void initialize ( String name ) { this . name = name ; int index = name . lastIndexOf ( '<CHAR_LIT:.>' ) ; pluginName = index != - <NUM_LIT:1> ? name . substring ( index + <NUM_LIT:1> ) : name ; } public String getName ( ) { return name ; } public Collection < ? extends Class < ? extends Command > > getCommandClasses ( ) { return commands . values ( ) ; } public Command getCommand ( String name ) throws Exception { if ( ! containsCommand ( name ) ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , name ) ) ; } Class < ? extends Command > cc = commands . get ( name ) ; return cc . newInstance ( ) ; } public boolean containsCommand ( String name ) { return commands . containsKey ( name ) ; } public String getMessage ( String key , Object ... args ) { ResourceBundle bundle = getResourceBundle ( ) ; String message = bundle . getString ( key ) ; return MessageFormat . format ( message , args ) ; } public ResourceBundle getResourceBundle ( ) { if ( bundle == null ) { bundle = ResourceBundle . getBundle ( getBundleBaseName ( ) , Locale . getDefault ( ) , getClass ( ) . getClassLoader ( ) ) ; } return bundle ; } public String getProperty ( String name ) { return getProperty ( name , null ) ; } public String getProperty ( String name , String defaultValue ) { if ( properties == null ) { properties = new Properties ( ) ; try { properties . load ( getClass ( ) . getResourceAsStream ( PLUGIN_PROPERTIES ) ) ; } catch ( Exception e ) { logger . warn ( "<STR_LIT>" + getName ( ) + "<STR_LIT:'>" , e ) ; } } return System . getProperty ( name , properties . getProperty ( name , defaultValue ) ) ; } public URL getResource ( String resource ) { if ( missingResources . contains ( resource ) ) { return null ; } try { String localResource = resource ; int index = localResource . indexOf ( "<STR_LIT>" ) ; if ( index != - <NUM_LIT:1> ) { localResource = FileUtils . concat ( localResource . substring ( <NUM_LIT:0> , index + <NUM_LIT:9> ) , pluginName , localResource . substring ( index + <NUM_LIT:9> ) ) ; } String file = FileUtils . concat ( Services . DOT_ECLIM , localResource ) ; if ( new File ( file ) . exists ( ) ) { return new URL ( "<STR_LIT>" + FileUtils . separatorsToUnix ( file ) ) ; } URL url = getClass ( ) . getResource ( resource ) ; if ( url != null ) { return FileLocator . resolve ( url ) ; } missingResources . add ( resource ) ; logger . debug ( "<STR_LIT>" + getName ( ) + "<STR_LIT>" + resource ) ; return null ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public InputStream getResourceAsStream ( String resource ) { try { URL url = getResource ( resource ) ; if ( url != null ) { return url . openStream ( ) ; } return null ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public void close ( ) throws Exception { } public void registerCommand ( Class < ? extends Command > command ) { org . eclim . annotation . Command info = ( org . eclim . annotation . Command ) command . getAnnotation ( org . eclim . annotation . Command . class ) ; if ( info != null ) { commands . put ( info . name ( ) , command ) ; } else { logger . error ( Services . getMessage ( "<STR_LIT>" , command ) ) ; } } protected abstract String getBundleBaseName ( ) ; @ Override public boolean equals ( Object other ) { return ( ( PluginResources ) other ) . getName ( ) . equals ( getName ( ) ) ; } @ Override public int hashCode ( ) { return getName ( ) . hashCode ( ) ; } } </s>
<s> package org . eclim . plugin ; import java . io . InputStream ; import java . net . URL ; import java . util . Properties ; import java . util . Set ; import org . eclim . Services ; import org . eclim . command . Command ; import org . eclim . logging . Logger ; import org . eclim . util . IOUtils ; import org . eclipse . core . runtime . FileLocator ; import org . eclipse . core . runtime . Path ; import org . osgi . framework . Bundle ; import org . osgi . framework . BundleContext ; import org . osgi . framework . BundleEvent ; import org . osgi . framework . BundleListener ; import org . scannotation . AnnotationDB ; public class Plugin extends org . eclipse . core . runtime . Plugin implements BundleListener { private static final Logger logger = Logger . getLogger ( Plugin . class ) ; private static Plugin plugin ; public Plugin ( ) { plugin = this ; } public static Plugin getDefault ( ) { return plugin ; } public void start ( BundleContext context ) throws Exception { logger . debug ( "<STR_LIT>" , context . getBundle ( ) . getSymbolicName ( ) ) ; super . start ( context ) ; context . addBundleListener ( this ) ; } public void activate ( BundleContext context ) { String name = context . getBundle ( ) . getSymbolicName ( ) ; logger . debug ( "<STR_LIT>" , name ) ; logger . debug ( "<STR_LIT>" , name ) ; Properties properties = new Properties ( ) ; InputStream in = null ; try { in = context . getBundle ( ) . getResource ( "<STR_LIT>" ) . openStream ( ) ; properties . load ( in ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } finally { IOUtils . closeQuietly ( in ) ; } String resourceClass = properties . getProperty ( "<STR_LIT>" ) ; logger . debug ( "<STR_LIT>" , name , resourceClass ) ; Bundle bundle = this . getBundle ( ) ; try { PluginResources resources = ( PluginResources ) bundle . loadClass ( resourceClass ) . newInstance ( ) ; logger . debug ( "<STR_LIT>" , name ) ; resources . initialize ( name ) ; Services . addPluginResources ( resources ) ; loadCommands ( bundle , resources ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" + name , e ) ; } } public void stop ( BundleContext context ) throws Exception { super . stop ( context ) ; PluginResources resources = Services . removePluginResources ( Services . getPluginResources ( context . getBundle ( ) . getSymbolicName ( ) ) ) ; resources . close ( ) ; } private void loadCommands ( Bundle bundle , PluginResources resources ) { String name = this . getBundle ( ) . getSymbolicName ( ) ; try { Class < ? > rclass = resources . getClass ( ) ; ClassLoader classloader = rclass . getClassLoader ( ) ; String resourceName = rclass . getName ( ) . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) + "<STR_LIT:.class>" ; URL resource = classloader . getResource ( resourceName ) ; String url = resource . toString ( ) ; url = url . substring ( <NUM_LIT:0> , url . indexOf ( resourceName ) ) ; String jarName = resources . getName ( ) . substring ( "<STR_LIT>" . length ( ) ) + "<STR_LIT>" ; URL jarUrl = FileLocator . toFileURL ( FileLocator . find ( bundle , new Path ( jarName ) , null ) ) ; logger . debug ( "<STR_LIT>" , name ) ; AnnotationDB db = new AnnotationDB ( ) ; db . setScanClassAnnotations ( true ) ; db . setScanFieldAnnotations ( false ) ; db . setScanMethodAnnotations ( false ) ; db . setScanParameterAnnotations ( false ) ; db . scanArchives ( jarUrl ) ; Set < String > commandClasses = db . getAnnotationIndex ( ) . get ( org . eclim . annotation . Command . class . getName ( ) ) ; if ( commandClasses != null ) { for ( String commandClass : commandClasses ) { logger . debug ( "<STR_LIT>" , name , commandClass ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Class < ? extends Command > cclass = ( Class < ? extends Command > ) classloader . loadClass ( commandClass ) ; resources . registerCommand ( cclass ) ; } } else { logger . debug ( "<STR_LIT>" , name ) ; } } catch ( Throwable t ) { logger . error ( "<STR_LIT>" , t ) ; } } public void bundleChanged ( BundleEvent event ) { Bundle bundle = event . getBundle ( ) ; if ( this . getBundle ( ) . getSymbolicName ( ) . equals ( bundle . getSymbolicName ( ) ) ) { if ( logger . isDebugEnabled ( ) ) { String state = "<STR_LIT:unknown>" ; switch ( bundle . getState ( ) ) { case Bundle . ACTIVE : state = "<STR_LIT>" ; break ; case Bundle . INSTALLED : state = "<STR_LIT>" ; break ; case Bundle . RESOLVED : state = "<STR_LIT>" ; break ; case Bundle . STARTING : state = "<STR_LIT>" ; break ; case Bundle . STOPPING : state = "<STR_LIT>" ; break ; case Bundle . UNINSTALLED : state = "<STR_LIT>" ; break ; } logger . debug ( "<STR_LIT>" , bundle . getSymbolicName ( ) , state ) ; } if ( bundle . getState ( ) == Bundle . ACTIVE ) { this . activate ( bundle . getBundleContext ( ) ) ; } } } } </s>
<s> package org . eclim . plugin ; import java . io . InputStream ; import java . net . URL ; import java . util . Collection ; import java . util . ResourceBundle ; import org . eclim . command . Command ; public interface PluginResources { public void initialize ( String name ) ; public void registerCommand ( Class < ? extends Command > command ) ; public Command getCommand ( String name ) throws Exception ; public boolean containsCommand ( String name ) ; public String getMessage ( String key , Object ... args ) ; public ResourceBundle getResourceBundle ( ) ; public String getProperty ( String name ) ; public String getProperty ( String name , String defaultValue ) ; public URL getResource ( String resource ) ; public InputStream getResourceAsStream ( String resource ) ; public void close ( ) throws Exception ; public String getName ( ) ; public Collection < ? extends Class < ? extends Command > > getCommandClasses ( ) ; } </s>
<s> package org . eclim ; import java . io . InputStream ; import java . net . URL ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . MissingResourceException ; import java . util . ResourceBundle ; import org . eclim . command . Command ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . PluginResources ; public class Services { public static final String DOT_ECLIM = System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ; private static HashMap < String , PluginResources > pluginResources = new HashMap < String , PluginResources > ( ) ; static { PluginResources defaultResources = new DefaultPluginResources ( ) ; defaultResources . initialize ( "<STR_LIT>" ) ; addPluginResources ( defaultResources ) ; } public static List < Class < ? extends Command > > getCommandClasses ( ) { ArrayList < Class < ? extends Command > > commands = new ArrayList < Class < ? extends Command > > ( ) ; for ( PluginResources resources : pluginResources . values ( ) ) { commands . addAll ( resources . getCommandClasses ( ) ) ; } return commands ; } public static Command getCommand ( String name ) throws Exception { for ( PluginResources resources : pluginResources . values ( ) ) { if ( resources . containsCommand ( name ) ) { return resources . getCommand ( name ) ; } } return null ; } public static String getMessage ( String key , Object ... args ) { for ( PluginResources resources : pluginResources . values ( ) ) { try { String message = resources . getMessage ( key , args ) ; return message ; } catch ( MissingResourceException nsme ) { } } return key ; } public static ResourceBundle getResourceBundle ( String plugin ) { if ( plugin != null ) { PluginResources resources = ( PluginResources ) pluginResources . get ( plugin ) ; if ( resources != null ) { return resources . getResourceBundle ( ) ; } } return null ; } public static URL getResource ( String resource ) { for ( PluginResources resources : pluginResources . values ( ) ) { URL url = resources . getResource ( resource ) ; if ( url != null ) { return url ; } } return null ; } public static InputStream getResourceAsStream ( String resource ) { for ( PluginResources resources : pluginResources . values ( ) ) { InputStream stream = resources . getResourceAsStream ( resource ) ; if ( stream != null ) { return stream ; } } return null ; } public static PluginResources getPluginResources ( String plugin ) { PluginResources resources = ( PluginResources ) pluginResources . get ( plugin ) ; if ( resources == null ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , plugin ) ) ; } return resources ; } public static void addPluginResources ( PluginResources resources ) { pluginResources . put ( resources . getName ( ) , resources ) ; } public static PluginResources removePluginResources ( PluginResources resources ) { return pluginResources . remove ( resources . getName ( ) ) ; } public static class DefaultPluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } public String getName ( ) { return NAME ; } } } </s>
<s> package org . eclim . plugin . cdt ; import org . eclim . Services ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . cdt . project . CProjectManager ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclipse . cdt . core . CCProjectNature ; import org . eclipse . cdt . core . CProjectNature ; public class PluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; public static final String NATURE_C = CProjectNature . C_NATURE_ID ; public static final String NATURE_CPP = CCProjectNature . CC_NATURE_ID ; @ Override public void initialize ( String name ) { super . initialize ( name ) ; ProjectNatureFactory . addNature ( "<STR_LIT:c>" , CProjectNature . C_NATURE_ID ) ; ProjectNatureFactory . addNature ( "<STR_LIT>" , new String [ ] { CProjectNature . C_NATURE_ID , CCProjectNature . CC_NATURE_ID , } ) ; ProjectNatureFactory . addNature ( "<STR_LIT>" , new String [ ] { CProjectNature . C_NATURE_ID , CCProjectNature . CC_NATURE_ID , } ) ; ProjectManagement . addProjectManager ( CProjectNature . C_NATURE_ID , new CProjectManager ( ) ) ; ProjectManagement . addProjectManager ( CCProjectNature . CC_NATURE_ID , new CProjectManager ( ) ) ; } @ Override protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . cdt . util ; import org . eclim . Services ; import org . eclim . plugin . cdt . PluginResources ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . CoreModelUtil ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . ITranslationUnit ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . Path ; public class CUtils { public static ICProject getCProject ( String project ) throws Exception { return getCProject ( ProjectUtils . getProject ( project , true ) ) ; } public static ICProject getCProject ( IProject project ) throws Exception { if ( ProjectUtils . getPath ( project ) == null ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) ) ) ; } if ( ! project . hasNature ( PluginResources . NATURE_C ) && ! project . hasNature ( PluginResources . NATURE_CPP ) ) { String name = ProjectNatureFactory . getAliasForNature ( PluginResources . NATURE_C ) + "<STR_LIT>" + ProjectNatureFactory . getAliasForNature ( PluginResources . NATURE_CPP ) ; throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) , name ) ) ; } ICProject cproject = CoreModel . getDefault ( ) . create ( project ) ; if ( cproject == null || ! cproject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project ) ) ; } return cproject ; } public static ITranslationUnit getTranslationUnit ( String project , String file ) throws Exception { return getTranslationUnit ( getCProject ( project ) , file ) ; } public static ITranslationUnit getTranslationUnit ( ICProject project , String file ) throws Exception { Path path = new Path ( ProjectUtils . getFilePath ( project . getProject ( ) , file ) ) ; ITranslationUnit src = CoreModelUtil . findTranslationUnitForLocation ( path , project ) ; if ( src == null || ! src . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , file ) ) ; } src . close ( ) ; src . open ( null ) ; return src ; } } </s>
<s> package org . eclim . plugin . cdt . project ; import java . io . FileInputStream ; import java . util . Arrays ; import java . util . List ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . eclim . Services ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . plugin . cdt . PluginResources ; import org . eclim . plugin . cdt . util . CUtils ; import org . eclim . plugin . core . project . ProjectManager ; import org . eclim . plugin . core . util . XmlUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileOffsets ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . index . IIndexManager ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . ICModelStatus ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . IPathEntry ; import org . eclipse . cdt . core . settings . model . ICConfigurationDescription ; import org . eclipse . cdt . core . settings . model . ICProjectDescription ; import org . eclipse . cdt . core . settings . model . ICProjectDescriptionManager ; import org . eclipse . cdt . core . settings . model . extension . CConfigurationData ; import org . eclipse . cdt . core . settings . model . util . PathEntryTranslator ; import org . eclipse . cdt . managedbuilder . buildproperties . IBuildPropertyManager ; import org . eclipse . cdt . managedbuilder . buildproperties . IBuildPropertyValue ; import org . eclipse . cdt . managedbuilder . core . BuildListComparator ; import org . eclipse . cdt . managedbuilder . core . IBuilder ; import org . eclipse . cdt . managedbuilder . core . IConfiguration ; import org . eclipse . cdt . managedbuilder . core . IToolChain ; import org . eclipse . cdt . managedbuilder . core . ManagedBuildManager ; import org . eclipse . cdt . managedbuilder . internal . core . Configuration ; import org . eclipse . cdt . managedbuilder . internal . core . ManagedBuildInfo ; import org . eclipse . cdt . managedbuilder . internal . core . ManagedProject ; import org . eclipse . cdt . managedbuilder . internal . core . ToolChain ; import org . eclipse . cdt . managedbuilder . internal . dataprovider . ConfigurationDataProvider ; import org . eclipse . cdt . managedbuilder . ui . wizards . CfgHolder ; import org . eclipse . cdt . managedbuilder . ui . wizards . MBSWizardHandler ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jface . wizard . IWizard ; import org . eclipse . swt . widgets . Composite ; public class CProjectManager implements ProjectManager { private static final String CPROJECT_XSD = "<STR_LIT>" ; private static final Pattern ENTRY_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern INCLUDE_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; @ Override public void create ( final IProject project , CommandLine commandLine ) throws Exception { final IBuildPropertyManager buildManager = ManagedBuildManager . getBuildPropertyManager ( ) ; final IBuildPropertyValue [ ] vs = buildManager . getPropertyType ( MBSWizardHandler . ARTIFACT ) . getSupportedValues ( ) ; Arrays . sort ( vs , BuildListComparator . getInstance ( ) ) ; MBSWizardHandler handler = null ; toolchainLoop : for ( IBuildPropertyValue value : vs ) { final IToolChain [ ] toolChains = ManagedBuildManager . getExtensionsToolChains ( MBSWizardHandler . ARTIFACT , value . getId ( ) , false ) ; if ( toolChains != null && toolChains . length > <NUM_LIT:0> ) { for ( IToolChain tc : toolChains ) { if ( ! tc . isAbstract ( ) && ! tc . isSystemObject ( ) && tc . isSupported ( ) && ManagedBuildManager . isPlatformOk ( tc ) ) { handler = new LocalMBSWizardHandler ( value , EclimPlugin . getShell ( ) , null , tc ) ; CfgHolder [ ] cfgs = handler . getCfgItems ( false ) ; if ( cfgs != null && cfgs . length > <NUM_LIT:0> && cfgs [ <NUM_LIT:0> ] . getConfiguration ( ) != null ) { break toolchainLoop ; } } } IToolChain ntc = ManagedBuildManager . getExtensionToolChain ( ConfigurationDataProvider . PREF_TC_ID ) ; handler = new LocalSTDWizardHandler ( value , EclimPlugin . getShell ( ) , null , ntc ) ; } } try { handler . createProject ( project , true , true , new NullProgressMonitor ( ) ) ; ICProject cproject = CUtils . getCProject ( project ) ; CCorePlugin . getIndexManager ( ) . reindex ( cproject ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } @ Override public List < Error > update ( IProject project , CommandLine commandLine ) throws Exception { PluginResources resources = ( PluginResources ) Services . getPluginResources ( PluginResources . NAME ) ; List < Error > errors = XmlUtils . validateXml ( project . getName ( ) , "<STR_LIT>" , resources . getResource ( CPROJECT_XSD ) . toString ( ) ) ; if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } ICProjectDescriptionManager manager = CoreModel . getDefault ( ) . getProjectDescriptionManager ( ) ; ICProjectDescription desc = manager . getProjectDescription ( project , false ) ; ICConfigurationDescription config = desc . getDefaultSettingConfiguration ( ) ; PathEntryTranslator . PathEntryCollector cr = PathEntryTranslator . collectEntries ( project , config ) ; IPathEntry [ ] entries = cr . getEntries ( PathEntryTranslator . INCLUDE_USER , config ) ; ICProject cproject = CoreModel . getDefault ( ) . create ( project ) ; String dotcproject = project . getFile ( "<STR_LIT>" ) . getRawLocation ( ) . toOSString ( ) ; FileOffsets offsets = FileOffsets . compile ( dotcproject ) ; String cprojectValue = IOUtils . toString ( new FileInputStream ( dotcproject ) ) ; for ( IPathEntry entry : entries ) { ICModelStatus status = CoreModel . validatePathEntry ( cproject , entry , true , true ) ; if ( ! status . isOK ( ) ) { errors . add ( createErrorFromStatus ( offsets , dotcproject , cprojectValue , entry , status ) ) ; } } return errors ; } @ Override public void delete ( IProject project , CommandLine commandLine ) throws Exception { } @ Override public void refresh ( IProject project , CommandLine commandLine ) throws Exception { ICProject cproject = CUtils . getCProject ( project ) ; CCorePlugin . getIndexManager ( ) . reindex ( cproject ) ; CCorePlugin . getIndexManager ( ) . joinIndexer ( IIndexManager . FOREVER , new NullProgressMonitor ( ) ) ; } @ Override public void refresh ( IProject project , IFile file ) throws Exception { } private Error createErrorFromStatus ( FileOffsets offsets , String filename , String contents , IPathEntry entry , ICModelStatus status ) throws Exception { int line = <NUM_LIT:0> ; int col = <NUM_LIT:0> ; Matcher matcher = null ; String pattern = null ; switch ( entry . getEntryKind ( ) ) { case IPathEntry . CDT_OUTPUT : case IPathEntry . CDT_SOURCE : matcher = ENTRY_PATTERN . matcher ( status . getString ( ) ) ; pattern = "<STR_LIT>" + matcher . replaceFirst ( "<STR_LIT>" ) + "<STR_LIT:\">" ; break ; case IPathEntry . CDT_INCLUDE : case IPathEntry . CDT_INCLUDE_FILE : matcher = INCLUDE_PATTERN . matcher ( status . getString ( ) ) ; pattern = "<STR_LIT>" + matcher . replaceFirst ( "<STR_LIT>" ) + "<STR_LIT:\">" ; break ; } if ( matcher != null ) { matcher = Pattern . compile ( "<STR_LIT>" + pattern + "<STR_LIT>" ) . matcher ( contents ) ; if ( matcher . find ( ) ) { int [ ] position = offsets . offsetToLineColumn ( matcher . start ( ) ) ; line = position [ <NUM_LIT:0> ] ; col = position [ <NUM_LIT:1> ] ; } } return new Error ( status . getMessage ( ) , filename , line , col , false ) ; } private class LocalMBSWizardHandler extends MBSWizardHandler { private IToolChain toolchain ; public LocalMBSWizardHandler ( IBuildPropertyValue val , Composite p , IWizard w , IToolChain tc ) { super ( val , p , w ) ; this . toolchain = tc ; } public IToolChain [ ] getSelectedToolChains ( ) { return new IToolChain [ ] { toolchain } ; } protected void doCustom ( IProject project ) { } public CfgHolder [ ] getCfgItems ( boolean defaults ) { CfgHolder [ ] cfgs = super . getCfgItems ( defaults ) ; if ( cfgs == null || cfgs . length == <NUM_LIT:0> ) { IToolChain tc = ManagedBuildManager . getExtensionToolChain ( ConfigurationDataProvider . PREF_TC_ID ) ; cfgs = new CfgHolder [ <NUM_LIT:1> ] ; cfgs [ <NUM_LIT:0> ] = new CfgHolder ( tc , null ) ; } return cfgs ; } } private class LocalSTDWizardHandler extends LocalMBSWizardHandler { public LocalSTDWizardHandler ( IBuildPropertyValue val , Composite p , IWizard w , IToolChain tc ) { super ( val , p , w , tc ) ; } public void createProject ( IProject project , boolean defaults , boolean onFinish , IProgressMonitor monitor ) throws CoreException { try { monitor . beginTask ( "<STR_LIT>" , <NUM_LIT:100> ) ; setProjectDescription ( project , defaults , onFinish , monitor ) ; doTemplatesPostProcess ( project ) ; doCustom ( project ) ; monitor . worked ( <NUM_LIT:30> ) ; } finally { monitor . done ( ) ; } } private void setProjectDescription ( IProject project , boolean defaults , boolean onFinish , IProgressMonitor monitor ) throws CoreException { ICProjectDescriptionManager mngr = CoreModel . getDefault ( ) . getProjectDescriptionManager ( ) ; ICProjectDescription des = mngr . createProjectDescription ( project , false , ! onFinish ) ; ManagedBuildInfo info = ManagedBuildManager . createBuildInfo ( project ) ; ManagedProject mProj = new ManagedProject ( des ) ; info . setManagedProject ( mProj ) ; monitor . worked ( <NUM_LIT:20> ) ; cfgs = CfgHolder . unique ( getCfgItems ( false ) ) ; cfgs = CfgHolder . reorder ( cfgs ) ; int work = <NUM_LIT> / cfgs . length ; for ( int i = <NUM_LIT:0> ; i < cfgs . length ; i ++ ) { String s = ( cfgs [ i ] . getToolChain ( ) == null ) ? "<STR_LIT:0>" : ( ( ToolChain ) ( cfgs [ i ] . getToolChain ( ) ) ) . getId ( ) ; Configuration cfg = new Configuration ( mProj , ( ToolChain ) cfgs [ i ] . getToolChain ( ) , ManagedBuildManager . calculateChildId ( s , null ) , cfgs [ i ] . getName ( ) ) ; cfgs [ i ] . setConfiguration ( cfg ) ; IBuilder bld = cfg . getEditableBuilder ( ) ; if ( bld != null ) { if ( bld . isInternalBuilder ( ) ) { IConfiguration prefCfg = ManagedBuildManager . getPreferenceConfiguration ( false ) ; IBuilder prefBuilder = prefCfg . getBuilder ( ) ; cfg . changeBuilder ( prefBuilder , ManagedBuildManager . calculateChildId ( cfg . getId ( ) , null ) , prefBuilder . getName ( ) ) ; bld = cfg . getEditableBuilder ( ) ; bld . setBuildPath ( null ) ; } bld . setManagedBuildOn ( false ) ; } cfg . setArtifactName ( mProj . getDefaultArtifactName ( ) ) ; CConfigurationData data = cfg . getConfigurationData ( ) ; des . createConfiguration ( ManagedBuildManager . CFG_DATA_PROVIDER_ID , data ) ; monitor . worked ( work ) ; } mngr . setProjectDescription ( project , des ) ; } } } </s>
<s> package org . eclim . plugin . cdt . command . hierarchy ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . text . Collator ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Set ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . cdt . command . search . SearchCommand ; import org . eclim . plugin . cdt . util . CUtils ; import org . eclim . util . StringUtils ; import org . eclim . util . file . Position ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . dom . ast . IASTNode ; import org . eclipse . cdt . core . dom . ast . IBinding ; import org . eclipse . cdt . core . dom . ast . cpp . ICPPMethod ; import org . eclipse . cdt . core . index . IIndex ; import org . eclipse . cdt . core . index . IIndexBinding ; import org . eclipse . cdt . core . index . IIndexManager ; import org . eclipse . cdt . core . index . IIndexName ; import org . eclipse . cdt . core . model . ICElement ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . IFunction ; import org . eclipse . cdt . core . model . IFunctionDeclaration ; import org . eclipse . cdt . core . model . ITranslationUnit ; import org . eclipse . cdt . core . model . IWorkingCopy ; import org . eclipse . cdt . internal . core . dom . parser . cpp . ClassTypeHelper ; import org . eclipse . cdt . internal . core . model . ASTCache ; import org . eclipse . cdt . internal . ui . callhierarchy . CallHierarchyUI ; import org . eclipse . cdt . internal . ui . editor . ASTProvider ; import org . eclipse . cdt . internal . ui . editor . WorkingCopyManager ; import org . eclipse . cdt . internal . ui . viewsupport . IndexUI ; import org . eclipse . cdt . ui . CUIPlugin ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jface . text . ITextSelection ; import org . eclipse . jface . text . TextSelection ; import org . eclipse . ui . IEditorInput ; import org . eclipse . ui . part . FileEditorInput ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CallHierarchyCommand extends SearchCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; int length = commandLine . getIntValue ( Options . LENGTH_OPTION ) ; ICProject cproject = CUtils . getCProject ( projectName ) ; CUIPlugin cuiPlugin = CUIPlugin . getDefault ( ) ; ITranslationUnit src = CUtils . getTranslationUnit ( cproject , file ) ; CCorePlugin . getIndexManager ( ) . update ( new ICElement [ ] { src } , IIndexManager . UPDATE_ALL ) ; CCorePlugin . getIndexManager ( ) . joinIndexer ( <NUM_LIT> , new NullProgressMonitor ( ) ) ; src = src . getWorkingCopy ( ) ; IEditorInput input = new FileEditorInput ( ( IFile ) src . getResource ( ) ) ; WorkingCopyManager manager = ( WorkingCopyManager ) cuiPlugin . getWorkingCopyManager ( ) ; manager . connect ( input ) ; manager . setWorkingCopy ( input , ( IWorkingCopy ) src ) ; HashMap < String , Object > result = new HashMap < String , Object > ( ) ; try { ASTProvider provider = ASTProvider . getASTProvider ( ) ; Field astCache = ASTProvider . class . getDeclaredField ( "<STR_LIT>" ) ; astCache . setAccessible ( true ) ; ( ( ASTCache ) astCache . get ( provider ) ) . setActiveElement ( src ) ; TextSelection selection = new TextSelection ( offset , length ) ; Method findDefinitions = CallHierarchyUI . class . getDeclaredMethod ( "<STR_LIT>" , ICProject . class , IEditorInput . class , ITextSelection . class ) ; findDefinitions . setAccessible ( true ) ; ICElement [ ] elements = ( ICElement [ ] ) findDefinitions . invoke ( null , cproject , input , selection ) ; if ( elements != null && elements . length > <NUM_LIT:0> ) { ICElement callee = elements [ <NUM_LIT:0> ] ; Set < ICElement > seen = new HashSet < ICElement > ( ) ; ICProject project = callee . getCProject ( ) ; ICProject [ ] scope = getScope ( SCOPE_PROJECT , project ) ; IIndex index = CCorePlugin . getIndexManager ( ) . getIndex ( scope , IIndexManager . ADD_DEPENDENCIES | IIndexManager . ADD_DEPENDENT ) ; index . acquireReadLock ( ) ; try { IIndexName name = IndexUI . elementToName ( index , callee ) ; result = formatElement ( index , callee , name , seen ) ; } finally { index . releaseReadLock ( ) ; } } } finally { manager . removeWorkingCopy ( input ) ; manager . disconnect ( input ) ; } return result ; } private ArrayList < HashMap < String , Object > > findCalledBy ( IIndex index , ICElement callee , Set < ICElement > seen ) throws Exception { ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; ICProject project = callee . getCProject ( ) ; IIndexBinding calleeBinding = IndexUI . elementToBinding ( index , callee ) ; if ( calleeBinding != null ) { results . addAll ( findCalledBy ( index , calleeBinding , true , project , seen ) ) ; if ( calleeBinding instanceof ICPPMethod ) { IBinding [ ] overriddenBindings = null ; try { Method findOverridden = ClassTypeHelper . class . getMethod ( "<STR_LIT>" , ICPPMethod . class , IASTNode . class ) ; overriddenBindings = ( IBinding [ ] ) findOverridden . invoke ( null , ( ICPPMethod ) calleeBinding , null ) ; } catch ( NoSuchMethodException nsme ) { Method findOverridden = ClassTypeHelper . class . getMethod ( "<STR_LIT>" , ICPPMethod . class ) ; overriddenBindings = ( IBinding [ ] ) findOverridden . invoke ( null , ( ICPPMethod ) calleeBinding ) ; } for ( IBinding overriddenBinding : overriddenBindings ) { results . addAll ( findCalledBy ( index , overriddenBinding , false , project , seen ) ) ; } } } return results ; } private ArrayList < HashMap < String , Object > > findCalledBy ( IIndex index , IBinding callee , boolean includeOrdinaryCalls , ICProject project , Set < ICElement > seen ) throws Exception { IIndexName [ ] names = index . findNames ( callee , IIndex . FIND_REFERENCES | IIndex . SEARCH_ACROSS_LANGUAGE_BOUNDARIES ) ; ArrayList < Call > calls = new ArrayList < Call > ( names . length ) ; for ( IIndexName name : names ) { if ( includeOrdinaryCalls || name . couldBePolymorphicMethodCall ( ) ) { IIndexName caller = name . getEnclosingDefinition ( ) ; if ( caller == null ) { continue ; } ICElement element = IndexUI . getCElementForName ( project , index , caller ) ; if ( element == null ) { continue ; } calls . add ( new Call ( name , element ) ) ; } } Collections . sort ( calls ) ; ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; for ( Call call : calls ) { results . add ( formatElement ( index , call . element , call . name , seen ) ) ; } return results ; } private HashMap < String , Object > formatElement ( IIndex index , ICElement element , IIndexName name , Set < ICElement > seen ) throws Exception { HashMap < String , Object > result = new HashMap < String , Object > ( ) ; String [ ] types = null ; if ( element instanceof IFunction ) { types = ( ( IFunction ) element ) . getParameterTypes ( ) ; } else if ( element instanceof IFunctionDeclaration ) { types = ( ( IFunctionDeclaration ) element ) . getParameterTypes ( ) ; } String message = element . getElementName ( ) + '<CHAR_LIT:(>' + StringUtils . join ( types , "<STR_LIT:U+002CU+0020>" ) + '<CHAR_LIT:)>' ; result . put ( "<STR_LIT:name>" , message ) ; if ( name != null ) { IResource resource = element . getResource ( ) ; if ( resource != null ) { String file = element . getResource ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; result . put ( "<STR_LIT>" , Position . fromOffset ( file , null , name . getNodeOffset ( ) , <NUM_LIT:0> ) ) ; } } if ( ! seen . contains ( element ) ) { seen . add ( element ) ; result . put ( "<STR_LIT>" , findCalledBy ( index , element , seen ) ) ; } return result ; } private static class Call implements Comparable < Call > { private static final Collator COLLATOR = Collator . getInstance ( ) ; public IIndexName name ; public ICElement element ; public String location ; public Call ( IIndexName name , ICElement element ) { this . name = name ; this . element = element ; this . location = element . getResource ( ) . getLocation ( ) . toOSString ( ) + element . getElementName ( ) ; } @ Override public int compareTo ( Call o ) { int result = COLLATOR . compare ( location , o . location ) ; if ( result == <NUM_LIT:0> ) { return name . getNodeOffset ( ) - o . name . getNodeOffset ( ) ; } return result ; } } } </s>
<s> package org . eclim . plugin . cdt . command . complete ; import java . lang . reflect . Method ; import org . apache . commons . lang . StringUtils ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . eclipse . ui . EclimEditorSite ; import org . eclim . plugin . core . command . complete . AbstractCodeCompleteCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . cdt . internal . ui . editor . CEditor ; import org . eclipse . cdt . internal . ui . editor . CSourceViewer ; import org . eclipse . cdt . internal . ui . text . CTextTools ; import org . eclipse . cdt . internal . ui . text . contentassist . CCompletionProposal ; import org . eclipse . cdt . ui . CUIPlugin ; import org . eclipse . cdt . ui . text . CSourceViewerConfiguration ; import org . eclipse . core . resources . IProject ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . contentassist . ContentAssistant ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . swt . SWT ; import org . eclipse . ui . IEditorInput ; import org . eclipse . ui . part . FileEditorInput ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CodeCompleteCommand extends AbstractCodeCompleteCommand { @ Override protected ICompletionProposal [ ] getCompletionProposals ( CommandLine commandLine , String projectName , String file , int offset ) throws Exception { IProject project = ProjectUtils . getProject ( projectName ) ; CEditor editor = new CEditor ( ) ; IEditorInput input = new FileEditorInput ( ProjectUtils . getFile ( project , file ) ) ; editor . init ( new EclimEditorSite ( ) , input ) ; editor . setInput ( input ) ; CTextTools textTools = CUIPlugin . getDefault ( ) . getTextTools ( ) ; IPreferenceStore store = CUIPlugin . getDefault ( ) . getCombinedPreferenceStore ( ) ; CSourceViewerConfiguration config = new CSourceViewerConfiguration ( textTools . getColorManager ( ) , store , editor , textTools . getDocumentPartitioning ( ) ) ; CSourceViewer viewer = new CSourceViewer ( EclimPlugin . getShell ( ) , null , null , false , SWT . V_SCROLL | SWT . H_SCROLL | SWT . MULTI | SWT . FULL_SELECTION , CUIPlugin . getDefault ( ) . getPreferenceStore ( ) ) ; viewer . setDocument ( ProjectUtils . getDocument ( project , file ) ) ; ContentAssistant ca = ( ContentAssistant ) config . getContentAssistant ( viewer ) ; Method computeCompletionProposals = ContentAssistant . class . getDeclaredMethod ( "<STR_LIT>" , ITextViewer . class , Integer . TYPE ) ; computeCompletionProposals . setAccessible ( true ) ; return ( ICompletionProposal [ ] ) computeCompletionProposals . invoke ( ca , viewer , offset ) ; } @ Override protected String getCompletion ( ICompletionProposal proposal ) { if ( proposal instanceof CCompletionProposal ) { String displayString = proposal . getDisplayString ( ) ; String completion = ( ( CCompletionProposal ) proposal ) . getReplacementString ( ) ; if ( displayString . lastIndexOf ( '<CHAR_LIT:)>' ) > displayString . lastIndexOf ( '<CHAR_LIT:(>' ) + <NUM_LIT:1> && ( completion . length ( ) > <NUM_LIT:0> && completion . charAt ( completion . length ( ) - <NUM_LIT:1> ) == '<CHAR_LIT:)>' ) ) { completion = completion . substring ( <NUM_LIT:0> , completion . length ( ) - <NUM_LIT:1> ) ; } else if ( completion . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT>' ) { completion = completion . substring ( <NUM_LIT:1> , completion . length ( ) ) ; } return completion ; } return super . getCompletion ( proposal ) ; } @ Override protected String getMenu ( ICompletionProposal proposal ) { String menu = proposal . getDisplayString ( ) ; return menu != null ? menu : StringUtils . EMPTY ; } @ Override protected String getInfo ( ICompletionProposal proposal ) { String info = proposal . getAdditionalProposalInfo ( ) ; if ( info == null ) { String display = proposal . getDisplayString ( ) ; if ( display != null && display . matches ( "<STR_LIT>" ) ) { info = display ; } } if ( info == null ) { info = StringUtils . EMPTY ; } return info ; } } </s>
<s> package org . eclim . plugin . cdt . command . src ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . cdt . util . CUtils ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . CollectionUtils ; import org . eclim . util . file . FileOffsets ; import org . eclipse . cdt . codan . core . model . CheckerLaunchMode ; import org . eclipse . cdt . codan . internal . core . CodanRunner ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . dom . ast . IASTTranslationUnit ; import org . eclipse . cdt . core . index . IIndex ; import org . eclipse . cdt . core . index . IIndexManager ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . ICElement ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . ITranslationUnit ; import org . eclipse . cdt . core . parser . IProblem ; import org . eclipse . cdt . internal . core . dom . parser . cpp . semantics . CPPVisitor ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . core . runtime . NullProgressMonitor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SrcUpdateCommand extends AbstractCommand { private static final int AST_STYLE = ITranslationUnit . AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit . AST_SKIP_INDEXED_HEADERS ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProject cproject = CUtils . getCProject ( project ) ; if ( cproject . exists ( ) ) { ITranslationUnit src = CUtils . getTranslationUnit ( cproject , file ) ; CCorePlugin . getIndexManager ( ) . update ( new ICElement [ ] { src } , IIndexManager . UPDATE_ALL ) ; if ( commandLine . hasOption ( Options . VALIDATE_OPTION ) ) { List < IProblem > problems = getProblems ( src ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; String filename = src . getResource ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; FileOffsets offsets = FileOffsets . compile ( filename ) ; for ( IProblem problem : problems ) { int [ ] lineColumn = offsets . offsetToLineColumn ( problem . getSourceStart ( ) ) ; errors . add ( new Error ( problem . getMessage ( ) , filename , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , problem . isWarning ( ) ) ) ; } IMarker [ ] markers = getMarkers ( src ) ; for ( IMarker marker : markers ) { int [ ] lineColumn = offsets . offsetToLineColumn ( ( ( Integer ) marker . getAttribute ( IMarker . CHAR_START ) ) . intValue ( ) ) ; int severity = ( ( Integer ) marker . getAttribute ( IMarker . SEVERITY ) ) . intValue ( ) ; errors . add ( new Error ( ( String ) marker . getAttribute ( IMarker . MESSAGE ) , filename , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , severity != IMarker . SEVERITY_ERROR ) ) ; } Collections . sort ( errors , new Comparator < Error > ( ) { public int compare ( Error e1 , Error e2 ) { if ( e1 . getLine ( ) != e2 . getLine ( ) ) { return e1 . getLine ( ) - e2 . getLine ( ) ; } if ( e1 . getColumn ( ) != e2 . getColumn ( ) ) { return e1 . getColumn ( ) - e2 . getColumn ( ) ; } return <NUM_LIT:0> ; } public boolean equals ( Object obj ) { return false ; } } ) ; if ( commandLine . hasOption ( Options . BUILD_OPTION ) ) { project . build ( IncrementalProjectBuilder . INCREMENTAL_BUILD , new NullProgressMonitor ( ) ) ; } return errors ; } } return null ; } private List < IProblem > getProblems ( ITranslationUnit src ) throws Exception { IIndex index = null ; try { ICProject [ ] projects = CoreModel . getDefault ( ) . getCModel ( ) . getCProjects ( ) ; index = CCorePlugin . getIndexManager ( ) . getIndex ( projects ) ; index . acquireReadLock ( ) ; IASTTranslationUnit ast = src . getAST ( index , AST_STYLE ) ; ArrayList < IProblem > problems = new ArrayList < IProblem > ( ) ; CollectionUtils . addAll ( problems , ast . getPreprocessorProblems ( ) ) ; CollectionUtils . addAll ( problems , CPPVisitor . getProblems ( ast ) ) ; return problems ; } finally { if ( index != null ) { index . releaseReadLock ( ) ; } } } private IMarker [ ] getMarkers ( ITranslationUnit src ) throws Exception { IResource resource = src . getResource ( ) ; CodanRunner . processResource ( resource , CheckerLaunchMode . RUN_ON_DEMAND , new NullProgressMonitor ( ) ) ; return resource . findMarkers ( null , true , IResource . DEPTH_ZERO ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . cdt . core . CCProjectNature ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . CProjectNature ; import org . eclipse . cdt . core . settings . model . ICConfigurationDescription ; import org . eclipse . cdt . core . settings . model . ICProjectDescription ; import org . eclipse . cdt . core . settings . model . ICSourceEntry ; import org . eclipse . cdt . managedbuilder . core . IConfiguration ; import org . eclipse . cdt . managedbuilder . core . IOption ; import org . eclipse . cdt . managedbuilder . core . ITool ; import org . eclipse . cdt . managedbuilder . core . ManagedBuildManager ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ConfigurationsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProjectDescription desc = CCorePlugin . getDefault ( ) . getProjectDescription ( project , false ) ; ICConfigurationDescription [ ] cconfigs = desc . getConfigurations ( ) ; ArrayList < HashMap < String , Object > > configs = new ArrayList < HashMap < String , Object > > ( ) ; for ( ICConfigurationDescription cconfig : cconfigs ) { HashMap < String , Object > cfg = new HashMap < String , Object > ( ) ; configs . add ( cfg ) ; cfg . put ( "<STR_LIT:name>" , cconfig . getName ( ) ) ; ICSourceEntry [ ] sources = cconfig . getSourceEntries ( ) ; if ( sources . length > <NUM_LIT:0> ) { ArrayList < HashMap < String , Object > > srcs = new ArrayList < HashMap < String , Object > > ( ) ; cfg . put ( "<STR_LIT>" , srcs ) ; for ( ICSourceEntry entry : sources ) { HashMap < String , Object > src = new HashMap < String , Object > ( ) ; srcs . add ( src ) ; String dirname = entry . getFullPath ( ) . removeFirstSegments ( <NUM_LIT:1> ) . toString ( ) ; if ( dirname . length ( ) == <NUM_LIT:0> ) { dirname = "<STR_LIT:/>" ; } src . put ( "<STR_LIT>" , dirname ) ; IPath [ ] excludes = entry . getExclusionPatterns ( ) ; if ( excludes . length > <NUM_LIT:0> ) { ArrayList < String > ex = new ArrayList < String > ( ) ; src . put ( "<STR_LIT>" , ex ) ; for ( int ii = <NUM_LIT:0> ; ii < excludes . length ; ii ++ ) { ex . add ( excludes [ ii ] . toString ( ) ) ; } } } } IConfiguration config = ManagedBuildManager . getConfigurationForDescription ( cconfig ) ; ITool [ ] tools = config . getTools ( ) ; if ( tools . length > <NUM_LIT:0> ) { ArrayList < HashMap < String , Object > > tls = new ArrayList < HashMap < String , Object > > ( ) ; cfg . put ( "<STR_LIT>" , tls ) ; for ( ITool tool : tools ) { if ( ! tool . isEnabled ( ) || ! acceptTool ( project , tool ) ) { continue ; } IOption ioption = getOptionByType ( tool , IOption . INCLUDE_PATH ) ; IOption soption = getOptionByType ( tool , IOption . PREPROCESSOR_SYMBOLS ) ; if ( ioption == null && soption == null ) { continue ; } HashMap < String , Object > tl = new HashMap < String , Object > ( ) ; tls . add ( tl ) ; tl . put ( "<STR_LIT:name>" , tool . getName ( ) ) ; if ( ioption != null ) { String [ ] includes = ioption . getIncludePaths ( ) ; if ( includes . length > <NUM_LIT:0> ) { ArrayList < String > ins = new ArrayList < String > ( ) ; tl . put ( "<STR_LIT>" , ins ) ; for ( String include : includes ) { ins . add ( include ) ; } } } if ( soption != null ) { String [ ] symbols = soption . getDefinedSymbols ( ) ; if ( symbols . length > <NUM_LIT:0> ) { ArrayList < String > syms = new ArrayList < String > ( ) ; tl . put ( "<STR_LIT>" , syms ) ; for ( String symbol : symbols ) { syms . add ( symbol ) ; } } } } } } return configs ; } private boolean acceptTool ( IProject project , ITool tool ) throws Exception { switch ( tool . getNatureFilter ( ) ) { case ITool . FILTER_C : if ( project . hasNature ( CProjectNature . C_NATURE_ID ) && ! project . hasNature ( CCProjectNature . CC_NATURE_ID ) ) { return true ; } break ; case ITool . FILTER_CC : if ( project . hasNature ( CCProjectNature . CC_NATURE_ID ) ) { return true ; } break ; case ITool . FILTER_BOTH : return true ; } return false ; } private IOption getOptionByType ( ITool tool , int type ) throws Exception { IOption [ ] options = tool . getOptions ( ) ; for ( IOption option : options ) { if ( option . getValueType ( ) == type ) { return option ; } } return null ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclipse . cdt . core . settings . model . CMacroEntry ; import org . eclipse . cdt . core . settings . model . ICLanguageSettingEntry ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SymbolEntryCommand extends AbstractSettingEntryCommand { @ Override protected ICLanguageSettingEntry createEntry ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . NAME_OPTION ) ; String value = commandLine . getValue ( Options . VALUE_OPTION ) ; return new CMacroEntry ( name , value , <NUM_LIT:0> ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import java . util . ArrayList ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . IIncludeReference ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class IncludePathsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProject cproject = CoreModel . getDefault ( ) . create ( project ) ; ArrayList < String > results = new ArrayList < String > ( ) ; for ( IIncludeReference ref : cproject . getIncludeReferences ( ) ) { results . add ( ref . getPath ( ) . toOSString ( ) ) ; } return results ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . util . file . FileUtils ; import org . eclipse . cdt . core . settings . model . CIncludePathEntry ; import org . eclipse . cdt . core . settings . model . ICLanguageSettingEntry ; import org . eclipse . cdt . core . settings . model . ICSettingEntry ; import org . eclipse . core . runtime . Path ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class IncludeEntryCommand extends AbstractSettingEntryCommand { @ Override protected ICLanguageSettingEntry createEntry ( CommandLine commandLine ) throws Exception { String dir = commandLine . getValue ( Options . DIR_OPTION ) ; dir = FileUtils . removeTrailingSlash ( dir ) ; Path path = new Path ( dir ) ; if ( path . isAbsolute ( ) ) { return new CIncludePathEntry ( path , ICSettingEntry . LOCAL ) ; } return new CIncludePathEntry ( path , ICSettingEntry . VALUE_WORKSPACE_PATH ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import java . util . Iterator ; import java . util . List ; import org . eclim . Services ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . StringUtils ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . settings . model . ICConfigurationDescription ; import org . eclipse . cdt . core . settings . model . ICFolderDescription ; import org . eclipse . cdt . core . settings . model . ICLanguageSetting ; import org . eclipse . cdt . core . settings . model . ICLanguageSettingEntry ; import org . eclipse . cdt . core . settings . model . ICProjectDescription ; import org . eclipse . core . resources . IProject ; public abstract class AbstractSettingEntryCommand extends AbstractCommand { private static final String ADD = "<STR_LIT>" ; private static final String DELETE = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String action = commandLine . getValue ( Options . ACTION_OPTION ) ; if ( ADD . equals ( action ) ) { return add ( commandLine ) ; } if ( DELETE . equals ( action ) ) { return delete ( commandLine ) ; } throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , action ) ) ; } protected String add ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String lang = commandLine . getValue ( Options . LANG_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProjectDescription desc = CCorePlugin . getDefault ( ) . getProjectDescription ( project , true ) ; ICConfigurationDescription [ ] configs = desc . getConfigurations ( ) ; ICLanguageSettingEntry entry = createEntry ( commandLine ) ; for ( ICConfigurationDescription config : configs ) { ICFolderDescription fdesc = config . getRootFolderDescription ( ) ; ICLanguageSetting [ ] ls = fdesc . getLanguageSettings ( ) ; for ( ICLanguageSetting l : ls ) { String name = StringUtils . split ( l . getName ( ) ) [ <NUM_LIT:0> ] . toLowerCase ( ) ; if ( name . equals ( lang ) ) { List < ICLanguageSettingEntry > lst = l . getSettingEntriesList ( entry . getKind ( ) ) ; lst . add ( entry ) ; l . setSettingEntries ( entry . getKind ( ) , lst ) ; } } } CCorePlugin . getDefault ( ) . setProjectDescription ( project , desc ) ; return Services . getMessage ( "<STR_LIT>" ) ; } protected String delete ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String lang = commandLine . getValue ( Options . LANG_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProjectDescription desc = CCorePlugin . getDefault ( ) . getProjectDescription ( project , true ) ; ICConfigurationDescription [ ] configs = desc . getConfigurations ( ) ; ICLanguageSettingEntry entry = createEntry ( commandLine ) ; boolean deleted = false ; for ( ICConfigurationDescription config : configs ) { ICFolderDescription fdesc = config . getRootFolderDescription ( ) ; ICLanguageSetting [ ] ls = fdesc . getLanguageSettings ( ) ; for ( ICLanguageSetting l : ls ) { String name = StringUtils . split ( l . getName ( ) ) [ <NUM_LIT:0> ] . toLowerCase ( ) ; if ( name . equals ( lang ) ) { List < ICLanguageSettingEntry > lst = l . getSettingEntriesList ( entry . getKind ( ) ) ; Iterator < ICLanguageSettingEntry > iterator = lst . iterator ( ) ; while ( iterator . hasNext ( ) ) { if ( iterator . next ( ) . getName ( ) . equals ( entry . getName ( ) ) ) { iterator . remove ( ) ; } } l . setSettingEntries ( entry . getKind ( ) , lst ) ; deleted = true ; } } } if ( deleted ) { CCorePlugin . getDefault ( ) . setProjectDescription ( project , desc ) ; return Services . getMessage ( "<STR_LIT>" ) ; } return Services . getMessage ( "<STR_LIT>" , entry . getName ( ) ) ; } protected abstract ICLanguageSettingEntry createEntry ( CommandLine commandLine ) throws Exception ; } </s>
<s> package org . eclim . plugin . cdt . command . project ; import java . util . ArrayList ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . ISourceRoot ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class SourcePathsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProject cproject = CoreModel . getDefault ( ) . create ( project ) ; ArrayList < String > results = new ArrayList < String > ( ) ; for ( ISourceRoot root : cproject . getSourceRoots ( ) ) { results . add ( ProjectUtils . getFilePath ( project , root . getPath ( ) . toOSString ( ) ) ) ; } return results ; } } </s>
<s> package org . eclim . plugin . cdt . command . project ; import java . util . ArrayList ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . StringUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . settings . model . CSourceEntry ; import org . eclipse . cdt . core . settings . model . ICConfigurationDescription ; import org . eclipse . cdt . core . settings . model . ICProjectDescription ; import org . eclipse . cdt . core . settings . model . ICSourceEntry ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SourceEntryCommand extends AbstractCommand { private static final String ADD = "<STR_LIT>" ; private static final String DELETE = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String action = commandLine . getValue ( Options . ACTION_OPTION ) ; if ( ADD . equals ( action ) ) { return add ( commandLine ) ; } if ( DELETE . equals ( action ) ) { return delete ( commandLine ) ; } throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , action ) ) ; } private String add ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String dir = commandLine . getValue ( Options . DIR_OPTION ) ; String excludes = commandLine . getValue ( Options . EXCLUDES_OPTION ) ; dir = FileUtils . removeTrailingSlash ( dir ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProjectDescription desc = CCorePlugin . getDefault ( ) . getProjectDescription ( project , true ) ; ICConfigurationDescription [ ] configs = desc . getConfigurations ( ) ; ArrayList < IPath > excludePaths = new ArrayList < IPath > ( ) ; if ( excludes != null ) { for ( String exclude : StringUtils . split ( excludes , '<CHAR_LIT:U+002C>' ) ) { excludePaths . add ( new Path ( exclude ) ) ; } } ICSourceEntry source = new CSourceEntry ( new Path ( dir ) , excludePaths . toArray ( new IPath [ excludePaths . size ( ) ] ) , CSourceEntry . VALUE_WORKSPACE_PATH ) ; for ( ICConfigurationDescription config : configs ) { ICSourceEntry [ ] sources = config . getSourceEntries ( ) ; ArrayList < ICSourceEntry > keep = new ArrayList < ICSourceEntry > ( ) ; for ( ICSourceEntry entry : sources ) { String name = entry . getFullPath ( ) . removeFirstSegments ( <NUM_LIT:1> ) . toString ( ) ; if ( ! name . equals ( dir ) ) { keep . add ( entry ) ; } } keep . add ( source ) ; config . setSourceEntries ( keep . toArray ( new ICSourceEntry [ keep . size ( ) ] ) ) ; } CCorePlugin . getDefault ( ) . setProjectDescription ( project , desc ) ; return Services . getMessage ( "<STR_LIT>" ) ; } private String delete ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String dir = commandLine . getValue ( Options . DIR_OPTION ) ; dir = FileUtils . removeTrailingSlash ( dir ) ; IProject project = ProjectUtils . getProject ( projectName ) ; ICProjectDescription desc = CCorePlugin . getDefault ( ) . getProjectDescription ( project , true ) ; ICConfigurationDescription [ ] configs = desc . getConfigurations ( ) ; boolean deleted = false ; for ( ICConfigurationDescription config : configs ) { ICSourceEntry [ ] sources = config . getSourceEntries ( ) ; ArrayList < ICSourceEntry > keep = new ArrayList < ICSourceEntry > ( ) ; for ( ICSourceEntry entry : sources ) { String name = entry . getFullPath ( ) . removeFirstSegments ( <NUM_LIT:1> ) . toString ( ) ; if ( ! name . equals ( dir ) ) { keep . add ( entry ) ; } } if ( sources . length != keep . size ( ) ) { deleted = true ; config . setSourceEntries ( keep . toArray ( new ICSourceEntry [ keep . size ( ) ] ) ) ; } } if ( deleted ) { CCorePlugin . getDefault ( ) . setProjectDescription ( project , desc ) ; return Services . getMessage ( "<STR_LIT>" ) ; } return Services . getMessage ( "<STR_LIT>" , dir ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . search ; import java . lang . reflect . Method ; import java . util . ArrayList ; import java . util . LinkedHashSet ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . cdt . PluginResources ; import org . eclim . plugin . cdt . util . CUtils ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . CollectionUtils ; import org . eclim . util . file . Position ; import org . eclipse . cdt . core . CCProjectNature ; import org . eclipse . cdt . core . CCorePlugin ; import org . eclipse . cdt . core . CProjectNature ; import org . eclipse . cdt . core . dom . IName ; import org . eclipse . cdt . core . dom . ast . IASTFileLocation ; import org . eclipse . cdt . core . dom . ast . IASTName ; import org . eclipse . cdt . core . dom . ast . IASTNodeSelector ; import org . eclipse . cdt . core . dom . ast . IASTTranslationUnit ; import org . eclipse . cdt . core . dom . ast . IBinding ; import org . eclipse . cdt . core . index . IIndex ; import org . eclipse . cdt . core . index . IIndexFileLocation ; import org . eclipse . cdt . core . index . IIndexManager ; import org . eclipse . cdt . core . model . CoreModel ; import org . eclipse . cdt . core . model . ICProject ; import org . eclipse . cdt . core . model . ITranslationUnit ; import org . eclipse . cdt . internal . ui . search . CSearchMessages ; import org . eclipse . cdt . internal . ui . search . CSearchElement ; import org . eclipse . cdt . internal . ui . search . CSearchMatch ; import org . eclipse . cdt . internal . ui . search . CSearchPatternQuery ; import org . eclipse . cdt . internal . ui . search . CSearchQuery ; import org . eclipse . cdt . internal . ui . search . CSearchResult ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . search . ui . text . Match ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SearchCommand extends AbstractCommand { public static final String CONTEXT_ALL = "<STR_LIT:all>" ; public static final String CONTEXT_CONTEXT = "<STR_LIT>" ; public static final String CONTEXT_DECLARATIONS = "<STR_LIT>" ; public static final String CONTEXT_DEFINITIONS = "<STR_LIT>" ; public static final String CONTEXT_REFERENCES = "<STR_LIT>" ; private static final int FIND_CONTEXT = - <NUM_LIT:1> ; public static final String SCOPE_ALL = "<STR_LIT:all>" ; public static final String SCOPE_PROJECT = "<STR_LIT>" ; public static final String TYPE_ALL = "<STR_LIT:all>" ; public static final String TYPE_CLASS_STRUCT = "<STR_LIT>" ; public static final String TYPE_FUNCTION = "<STR_LIT>" ; public static final String TYPE_VARIABLE = "<STR_LIT>" ; public static final String TYPE_UNION = "<STR_LIT>" ; public static final String TYPE_METHOD = "<STR_LIT>" ; public static final String TYPE_FIELD = "<STR_LIT:field>" ; public static final String TYPE_ENUM = "<STR_LIT>" ; public static final String TYPE_ENUMERATOR = "<STR_LIT>" ; public static final String TYPE_NAMESPACE = "<STR_LIT>" ; public static final String TYPE_TYPEDEF = "<STR_LIT>" ; public static final String TYPE_MACRO = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . NAME_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; String offset = commandLine . getValue ( Options . OFFSET_OPTION ) ; String length = commandLine . getValue ( Options . LENGTH_OPTION ) ; IProject project = projectName != null ? ProjectUtils . getProject ( projectName ) : null ; ICProject cproject = null ; if ( project != null ) { cproject = CUtils . getCProject ( project ) ; } if ( file != null && offset != null && length != null ) { return executeElementSearch ( commandLine , cproject ) ; } return executePatternSearch ( commandLine , cproject ) ; } private Object executeElementSearch ( CommandLine commandLine , ICProject cproject ) throws Exception { ArrayList < Position > results = new ArrayList < Position > ( ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ITranslationUnit src = CUtils . getTranslationUnit ( cproject , file ) ; if ( src != null ) { int context = getContext ( commandLine . getValue ( Options . CONTEXT_OPTION ) , FIND_CONTEXT ) ; ICProject [ ] scope = new ICProject [ ] { cproject } ; if ( SCOPE_ALL . equals ( commandLine . getValue ( Options . SCOPE_OPTION ) ) ) { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; ArrayList < ICProject > cprojects = new ArrayList < ICProject > ( ) ; for ( IProject project : projects ) { if ( project . isOpen ( ) && ( project . hasNature ( PluginResources . NATURE_C ) || project . hasNature ( PluginResources . NATURE_CPP ) ) ) { cprojects . add ( CUtils . getCProject ( project ) ) ; } } scope = cprojects . toArray ( new ICProject [ cprojects . size ( ) ] ) ; } IIndex index = CCorePlugin . getIndexManager ( ) . getIndex ( scope , IIndexManager . ADD_DEPENDENCIES | IIndexManager . ADD_DEPENDENT ) ; index . acquireReadLock ( ) ; try { int offset = getOffset ( commandLine ) ; int length = commandLine . getIntValue ( Options . LENGTH_OPTION ) ; IName [ ] names = findElement ( src , scope , context , offset , length ) ; for ( IName iname : names ) { IASTFileLocation loc = iname . getFileLocation ( ) ; String filename = loc . getFileName ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; results . add ( Position . fromOffset ( filename , null , loc . getNodeOffset ( ) , <NUM_LIT:0> ) ) ; } } finally { index . releaseReadLock ( ) ; } } return results ; } private Object executePatternSearch ( CommandLine commandLine , ICProject cproject ) throws Exception { String scopeName = commandLine . getValue ( Options . SCOPE_OPTION ) ; ICProject [ ] scope = getScope ( scopeName , cproject ) ; String scopeDesc = null ; if ( cproject == null || SCOPE_ALL . equals ( scopeName ) ) { scopeDesc = CSearchMessages . WorkspaceScope ; } else if ( SCOPE_PROJECT . equals ( scopeName ) ) { scopeDesc = CSearchMessages . ProjectScope ; } int context = getContext ( commandLine . getValue ( Options . CONTEXT_OPTION ) ) ; int type = getType ( commandLine . getValue ( Options . TYPE_OPTION ) ) ; String pattern = commandLine . getValue ( Options . PATTERN_OPTION ) ; boolean caseSensitive = ! commandLine . hasOption ( Options . CASE_INSENSITIVE_OPTION ) ; CSearchQuery query = new CSearchPatternQuery ( scope , scopeDesc , pattern , caseSensitive , type | context ) ; ArrayList < Position > results = new ArrayList < Position > ( ) ; if ( query != null ) { query . run ( new NullProgressMonitor ( ) ) ; CSearchResult result = ( CSearchResult ) query . getSearchResult ( ) ; for ( Object e : result . getElements ( ) ) { Method method = CSearchElement . class . getDeclaredMethod ( "<STR_LIT>" ) ; method . setAccessible ( true ) ; IIndexFileLocation location = ( IIndexFileLocation ) method . invoke ( e ) ; String filename = location . getURI ( ) . getPath ( ) ; if ( Os . isFamily ( "<STR_LIT>" ) && filename . startsWith ( "<STR_LIT:/>" ) ) { filename = filename . substring ( <NUM_LIT:1> ) ; } for ( Match m : result . getMatches ( e ) ) { CSearchMatch match = ( CSearchMatch ) m ; results . add ( Position . fromOffset ( filename , null , match . getOffset ( ) , <NUM_LIT:0> ) ) ; } } } return results ; } protected IName [ ] findElement ( ITranslationUnit src , ICProject [ ] scope , int context , int offset , int length ) throws Exception { LinkedHashSet < IName > names = new LinkedHashSet < IName > ( ) ; IIndex index = CCorePlugin . getIndexManager ( ) . getIndex ( scope , IIndexManager . ADD_DEPENDENCIES | IIndexManager . ADD_DEPENDENT ) ; index . acquireReadLock ( ) ; try { IASTTranslationUnit ast = src . getAST ( index , ITranslationUnit . AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit . AST_SKIP_INDEXED_HEADERS ) ; IASTNodeSelector selector = ast . getNodeSelector ( null ) ; IASTName name = selector . findEnclosingName ( offset , length ) ; if ( name != null ) { IBinding binding = name . resolveBinding ( ) ; int flags = IIndex . SEARCH_ACROSS_LANGUAGE_BOUNDARIES ; if ( context == FIND_CONTEXT ) { if ( ! name . isDeclaration ( ) && ! name . isDefinition ( ) ) { flags |= IIndex . FIND_DEFINITIONS ; } else { flags |= ( name . isDefinition ( ) ? IIndex . FIND_DECLARATIONS : IIndex . FIND_DEFINITIONS ) ; } } else if ( context == CSearchQuery . FIND_ALL_OCCURRENCES ) { flags |= IIndex . FIND_ALL_OCCURRENCES ; } else if ( context == CSearchQuery . FIND_REFERENCES ) { flags |= IIndex . FIND_REFERENCES ; } else if ( context == CSearchQuery . FIND_DECLARATIONS_DEFINITIONS ) { flags |= IIndex . FIND_DECLARATIONS_DEFINITIONS ; } else if ( context == CSearchQuery . FIND_DECLARATIONS ) { flags |= IIndex . FIND_DECLARATIONS ; } else if ( context == CSearchQuery . FIND_DEFINITIONS ) { flags |= IIndex . FIND_DEFINITIONS ; } CollectionUtils . addAll ( names , index . findNames ( binding , flags ) ) ; if ( names . size ( ) == <NUM_LIT:0> && context == FIND_CONTEXT && ( flags & IIndex . FIND_DEFINITIONS ) != <NUM_LIT:0> ) { CollectionUtils . addAll ( names , index . findNames ( binding , IIndex . SEARCH_ACROSS_LANGUAGE_BOUNDARIES | IIndex . FIND_DECLARATIONS ) ) ; } if ( names . size ( ) == <NUM_LIT:0> ) { if ( ( flags & IIndex . FIND_DECLARATIONS ) != <NUM_LIT:0> ) { CollectionUtils . addAll ( names , ast . getDeclarations ( binding ) ) ; } if ( ( flags & IIndex . FIND_DEFINITIONS ) != <NUM_LIT:0> ) { CollectionUtils . addAll ( names , ast . getDefinitions ( binding ) ) ; } if ( ( flags & IIndex . FIND_REFERENCES ) != <NUM_LIT:0> ) { CollectionUtils . addAll ( names , ast . getReferences ( binding ) ) ; } } } } finally { index . releaseReadLock ( ) ; } return names . toArray ( new IName [ names . size ( ) ] ) ; } protected ICProject [ ] getScope ( String scope , ICProject project ) throws Exception { if ( project == null || SCOPE_ALL . equals ( scope ) ) { ArrayList < ICProject > elements = new ArrayList < ICProject > ( ) ; IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( IProject p : projects ) { if ( p . isOpen ( ) && ( p . hasNature ( CProjectNature . C_NATURE_ID ) || p . hasNature ( CCProjectNature . CC_NATURE_ID ) ) ) { elements . add ( CoreModel . getDefault ( ) . create ( p ) ) ; } } return elements . toArray ( new ICProject [ elements . size ( ) ] ) ; } ArrayList < ICProject > elements = new ArrayList < ICProject > ( ) ; elements . add ( project ) ; IProject [ ] depends = project . getProject ( ) . getReferencedProjects ( ) ; for ( IProject p : depends ) { if ( ! p . isOpen ( ) ) { p . open ( null ) ; } elements . add ( CoreModel . getDefault ( ) . create ( p ) ) ; } return elements . toArray ( new ICProject [ elements . size ( ) ] ) ; } protected int getContext ( String context ) { return getContext ( context , CSearchQuery . FIND_DECLARATIONS_DEFINITIONS ) ; } protected int getContext ( String context , int dflt ) { if ( context == null ) { return dflt ; } if ( CONTEXT_ALL . equals ( context ) ) { return CSearchQuery . FIND_ALL_OCCURRENCES ; } else if ( CONTEXT_CONTEXT . equals ( context ) ) { return FIND_CONTEXT ; } else if ( CONTEXT_REFERENCES . equals ( context ) ) { return CSearchQuery . FIND_REFERENCES ; } else if ( CONTEXT_DECLARATIONS . equals ( context ) ) { return CSearchQuery . FIND_DECLARATIONS ; } else if ( CONTEXT_DEFINITIONS . equals ( context ) ) { return CSearchQuery . FIND_DEFINITIONS ; } return CSearchQuery . FIND_DECLARATIONS_DEFINITIONS ; } protected int getType ( String type ) { if ( TYPE_CLASS_STRUCT . equals ( type ) ) { return CSearchPatternQuery . FIND_CLASS_STRUCT ; } else if ( TYPE_FUNCTION . equals ( type ) ) { return CSearchPatternQuery . FIND_FUNCTION ; } else if ( TYPE_VARIABLE . equals ( type ) ) { return CSearchPatternQuery . FIND_VARIABLE ; } else if ( TYPE_UNION . equals ( type ) ) { return CSearchPatternQuery . FIND_UNION ; } else if ( TYPE_METHOD . equals ( type ) ) { return CSearchPatternQuery . FIND_METHOD ; } else if ( TYPE_FIELD . equals ( type ) ) { return CSearchPatternQuery . FIND_FIELD ; } else if ( TYPE_ENUM . equals ( type ) ) { return CSearchPatternQuery . FIND_ENUM ; } else if ( TYPE_ENUMERATOR . equals ( type ) ) { return CSearchPatternQuery . FIND_ENUMERATOR ; } else if ( TYPE_NAMESPACE . equals ( type ) ) { return CSearchPatternQuery . FIND_NAMESPACE ; } else if ( TYPE_TYPEDEF . equals ( type ) ) { return CSearchPatternQuery . FIND_TYPEDEF ; } else if ( TYPE_MACRO . equals ( type ) ) { return CSearchPatternQuery . FIND_MACRO ; } return CSearchPatternQuery . FIND_ALL_TYPES ; } } </s>
<s> package org . eclim . plugin . cdt ; public class Cdt { public static final String TEST_PROJECT = "<STR_LIT>" ; } </s>
<s> package org . eclim . plugin . cdt . command . hierarchy ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . cdt . Cdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CallHierarchyCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_FILE_LINK = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String path = Eclim . getProjectPath ( Cdt . TEST_PROJECT ) + "<STR_LIT>" ; Map < String , Object > position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; List < Map < String , Object > > calls = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , calls . size ( ) ) ; result = calls . get ( <NUM_LIT:0> ) ; position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; List < Map < String , Object > > nestedCalls = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:10> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , nestedCalls . size ( ) ) ; result = nestedCalls . get ( <NUM_LIT:0> ) ; position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:6> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , position . get ( "<STR_LIT>" ) ) ; result = nestedCalls . get ( <NUM_LIT:1> ) ; position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:7> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:10> , position . get ( "<STR_LIT>" ) ) ; result = calls . get ( <NUM_LIT:1> ) ; position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:6> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:3> , position . get ( "<STR_LIT>" ) ) ; result = calls . get ( <NUM_LIT:2> ) ; position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:7> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:20> , position . get ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void executeLinked ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; Map < String , Object > result = ( Map < String , Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_LINK , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String path = Eclim . getProjectPath ( Cdt . TEST_PROJECT ) + "<STR_LIT>" ; Map < String , Object > position = ( Map < String , Object > ) result . get ( "<STR_LIT>" ) ; List < Map < String , Object > > calls = ( List < Map < String , Object > > ) result . get ( "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:name>" ) , "<STR_LIT>" ) ; assertEquals ( path + "<STR_LIT>" , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , position . get ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , calls . size ( ) ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . complete ; import java . util . List ; import java . util . Map ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . Eclim ; import org . eclim . plugin . cdt . Cdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CodeCompleteCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeAll ( ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { return ; } assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completePrefix ( ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { return ; } assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . search ; import java . util . List ; import java . util . Map ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . Eclim ; import org . eclim . plugin . cdt . Cdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SearchCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_FILE_C = "<STR_LIT>" ; private static final String TEST_FILE_H = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElement ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE_C ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE_H ) ; result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:4> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; file = Eclim . resolveFile ( Cdt . TEST_PROJECT , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT:all>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , results . size ( ) ) ; file = Eclim . resolveFile ( Cdt . TEST_PROJECT , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:2> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE ) ; result = results . get ( <NUM_LIT:3> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" , "<STR_LIT>" , "<STR_LIT>" } ) ; result = results . get ( <NUM_LIT:0> ) ; if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; } else { assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; int line = ( ( Integer ) result . get ( "<STR_LIT>" ) ) . intValue ( ) ; assertTrue ( line > <NUM_LIT> && line < <NUM_LIT> ) ; } } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchFunction ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:16> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchConstant ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { assertTrue ( ( ( String ) result . get ( "<STR_LIT>" ) ) . endsWith ( "<STR_LIT>" ) ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; } else { assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; int line = ( ( Integer ) result . get ( "<STR_LIT>" ) ) . intValue ( ) ; assertTrue ( line > <NUM_LIT> && line < <NUM_LIT> ) ; } } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchStruct ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:8> ) ; } } </s>
<s> package org . eclim . plugin . cdt . command . src ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . cdt . Cdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SrcUpdateCommandTest { private static final String TEST_C_FILE = "<STR_LIT>" ; private static final String TEST_CPP_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validateC ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_C_FILE , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_C_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validateCPP ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Cdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Cdt . TEST_PROJECT , "<STR_LIT>" , TEST_CPP_FILE , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Cdt . TEST_PROJECT , TEST_CPP_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:7> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:4> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . pdt . command . complete ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . eclim . annotation . Command ; import org . eclim . plugin . dltk . command . complete . AbstractCodeCompleteCommand ; import org . eclipse . dltk . core . ISourceModule ; import org . eclipse . dltk . ui . text . completion . IScriptCompletionProposal ; import org . eclipse . dltk . ui . text . completion . ScriptCompletionProposalCollector ; import org . eclipse . php . internal . ui . editor . contentassist . PHPCompletionProposalCollector ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CodeCompleteCommand extends AbstractCodeCompleteCommand { private static final Pattern DISPALY_TO_COMPLETION = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern METHOD_WITH_ARGS = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern REMOVE_HEAD = Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE | Pattern . DOTALL ) ; @ Override protected ScriptCompletionProposalCollector getCompletionCollector ( ISourceModule module ) throws Exception { return new PHPCompletionProposalCollector ( null , module , true ) ; } @ Override protected String getCompletion ( IScriptCompletionProposal proposal ) { String completion = proposal . getDisplayString ( ) . trim ( ) ; completion = DISPALY_TO_COMPLETION . matcher ( completion ) . replaceFirst ( "<STR_LIT>" ) ; Matcher matcher = METHOD_WITH_ARGS . matcher ( completion ) ; if ( matcher . find ( ) ) { completion = matcher . group ( <NUM_LIT:1> ) ; } else if ( completion . startsWith ( "<STR_LIT:$>" ) ) { completion = completion . substring ( <NUM_LIT:1> ) ; } return completion ; } @ Override protected String getInfo ( IScriptCompletionProposal proposal ) { String info = super . getInfo ( proposal ) ; if ( info != null ) { info = REMOVE_HEAD . matcher ( info ) . replaceFirst ( "<STR_LIT>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT::U+0020>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ; info = info . replaceAll ( "<STR_LIT:n>" , "<STR_LIT>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT:n>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; info = info . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ; info = info . trim ( ) ; } return info ; } } </s>
<s> package org . eclim . plugin . pdt . command . src ; import org . eclim . annotation . Command ; import org . eclim . plugin . dltk . command . src . AbstractSrcUpdateCommand ; import org . eclipse . php . internal . core . project . PHPNature ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SrcUpdateCommand extends AbstractSrcUpdateCommand { @ Override protected String getNature ( ) { return PHPNature . ID ; } } </s>
<s> package org . eclim . plugin . pdt . command . search ; import org . eclim . annotation . Command ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclipse . dltk . core . IModelElement ; import org . eclipse . dltk . core . ISourceModule ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class SearchCommand extends org . eclim . plugin . dltk . command . search . SearchCommand { @ Override protected String getNature ( ) { return ProjectNatureFactory . getNatureForAlias ( "<STR_LIT>" ) ; } @ Override protected String getElementSeparator ( ) { return "<STR_LIT>" ; } @ Override protected String getElementTypeName ( ) { return "<STR_LIT:class>" ; } @ Override protected IModelElement [ ] getElements ( ISourceModule src , int offset , int length ) throws Exception { IModelElement [ ] elements = super . getElements ( src , offset , length ) ; return elements ; } } </s>
<s> package org . eclim . plugin . pdt . project ; import org . eclim . plugin . dltk . project . DltkProjectManager ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . dltk . core . DLTKLanguageManager ; import org . eclipse . dltk . core . IDLTKLanguageToolkit ; import org . eclipse . dltk . core . ISourceModule ; import org . eclipse . php . internal . core . project . PHPNature ; import org . eclipse . php . internal . ui . PHPUiPlugin ; import org . eclipse . ui . IEditorInput ; import org . eclipse . ui . part . FileEditorInput ; public class PhpProjectManager extends DltkProjectManager { @ Override public IDLTKLanguageToolkit getLanguageToolkit ( ) { return DLTKLanguageManager . getLanguageToolkit ( PHPNature . ID ) ; } @ Override public void refresh ( IProject project , IFile file ) throws Exception { IEditorInput input = new FileEditorInput ( file ) ; ISourceModule module = PHPUiPlugin . getEditorInputTypeRoot ( input ) ; if ( module != null ) { module . makeConsistent ( new NullProgressMonitor ( ) ) ; } } } </s>
<s> package org . eclim . plugin . pdt . preference ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . jface . preference . IPersistentPreferenceStore ; import org . eclipse . php . internal . core . PHPCoreConstants ; import org . eclipse . php . internal . ui . PHPUiPlugin ; public class OptionHandler implements org . eclim . plugin . core . preference . OptionHandler { private static final String NATURE = "<STR_LIT>" ; private static final String PREFIX = "<STR_LIT>" ; private static final String VERSION = PREFIX + PHPCoreConstants . PHP_OPTIONS_PHP_VERSION ; private IPersistentPreferenceStore store ; private Map < String , String > options ; public String getNature ( ) { return NATURE ; } public Map < String , String > getValues ( ) throws Exception { if ( options == null ) { options = new HashMap < String , String > ( ) ; options . put ( VERSION , getPreferences ( ) . getString ( PHPCoreConstants . PHP_OPTIONS_PHP_VERSION ) ) ; } return options ; } public Map < String , String > getValues ( IProject project ) throws Exception { IEclipsePreferences preferences = getPreferences ( project ) ; Map < String , String > map = getValues ( ) ; for ( String key : preferences . keys ( ) ) { map . put ( PREFIX + key , preferences . get ( key , null ) ) ; } return map ; } public void setOption ( String name , String value ) throws Exception { if ( VERSION . equals ( name ) ) { getValues ( ) . put ( VERSION , value ) ; IPersistentPreferenceStore store = getPreferences ( ) ; store . setValue ( name . substring ( PREFIX . length ( ) ) , value ) ; store . save ( ) ; } } public void setOption ( IProject project , String name , String value ) throws Exception { IEclipsePreferences preferences = getPreferences ( project ) ; if ( name . startsWith ( PREFIX ) ) { name = name . substring ( PREFIX . length ( ) ) ; } preferences . put ( name , value ) ; preferences . flush ( ) ; } private IPersistentPreferenceStore getPreferences ( ) { if ( store == null ) { store = ( IPersistentPreferenceStore ) PHPUiPlugin . getDefault ( ) . getPreferenceStore ( ) ; } return store ; } private IEclipsePreferences getPreferences ( IProject project ) { IScopeContext context = new ProjectScope ( project ) ; IEclipsePreferences preferences = context . getNode ( "<STR_LIT>" ) ; return preferences ; } } </s>
<s> package org . eclim . plugin . pdt . util ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . jobs . IJobManager ; import org . eclipse . core . runtime . jobs . Job ; public class PhpUtils { public static void waitOnBuild ( ) { IJobManager manager = Job . getJobManager ( ) ; Job [ ] jobs = manager . find ( ResourcesPlugin . FAMILY_AUTO_BUILD ) ; if ( jobs != null && jobs . length > <NUM_LIT:0> ) { for ( Job job : jobs ) { job . wakeUp ( ) ; } int tries = <NUM_LIT:0> ; while ( tries < <NUM_LIT:10> && jobs != null && jobs . length > <NUM_LIT:0> ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( Exception ignore ) { } jobs = manager . find ( ResourcesPlugin . FAMILY_AUTO_BUILD ) ; tries ++ ; } } } } </s>
<s> package org . eclim . plugin . pdt ; import org . eclim . Services ; import org . eclim . logging . Logger ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . core . preference . PreferenceFactory ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . pdt . preference . OptionHandler ; import org . eclim . plugin . pdt . project . PhpProjectManager ; import org . eclipse . php . internal . core . PHPCorePlugin ; import org . eclipse . php . internal . core . project . PHPNature ; public class PluginResources extends AbstractPluginResources { private static final Logger logger = Logger . getLogger ( PluginResources . class ) ; public static final String NAME = "<STR_LIT>" ; @ Override public void initialize ( String name ) { super . initialize ( name ) ; ProjectNatureFactory . addNature ( "<STR_LIT>" , PHPNature . ID ) ; ProjectManagement . addProjectManager ( PHPNature . ID , new PhpProjectManager ( ) ) ; Preferences . addOptionHandler ( "<STR_LIT>" , new OptionHandler ( ) ) ; PreferenceFactory . addOptions ( "<STR_LIT>" , "<STR_LIT>" ) ; try { PHPCorePlugin . initializeAfterLoad ( null ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } } protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . pdt ; public class Pdt { public static final String TEST_PROJECT = "<STR_LIT>" ; } </s>
<s> package org . eclim . plugin . pdt . command . complete ; import java . io . FileWriter ; import java . util . List ; import java . util . Map ; import org . apache . commons . lang . StringUtils ; import org . eclim . Eclim ; import org . eclim . plugin . pdt . Pdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class CodeCompleteCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final String TEST_FILE_ERRATIC = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeAll ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:2> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completePrefix ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeMagic ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeErratic ( ) throws Exception { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; String [ ] contents = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020U+0020}>" , "<STR_LIT>" , "<STR_LIT:U+0020U+0020}>" , "<STR_LIT:}>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; int index = <NUM_LIT> ; for ( int ii = <NUM_LIT:0> ; ii < <NUM_LIT:10> ; ii ++ ) { FileWriter out = new FileWriter ( Eclim . resolveFile ( Pdt . TEST_PROJECT , TEST_FILE_ERRATIC ) ) ; out . write ( StringUtils . join ( contents , "<STR_LIT:n>" ) ) ; out . close ( ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_ERRATIC , "<STR_LIT>" , String . valueOf ( index ) , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; String [ ] newContents = new String [ contents . length + <NUM_LIT:1> ] ; System . arraycopy ( contents , <NUM_LIT:0> , newContents , <NUM_LIT:0> , contents . length - <NUM_LIT:1> ) ; newContents [ contents . length - <NUM_LIT:1> ] = "<STR_LIT>" ; newContents [ contents . length ] = "<STR_LIT>" ; contents = newContents ; index += <NUM_LIT> ; Thread . sleep ( <NUM_LIT:1000> ) ; } } } </s>
<s> package org . eclim . plugin . pdt . command . src ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . pdt . Pdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SrcUpdateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validate ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . pdt . command . search ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . pdt . Pdt ; import org . junit . Test ; import static org . junit . Assert . * ; public class SearchCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElementClass ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:7> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElementMethod ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElementVariable ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:8> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:7> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchElementFunction ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:10> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchClass ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:class>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:7> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchMethod ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void searchFunction ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Pdt . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Pdt . TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String file = Eclim . resolveFile ( Pdt . TEST_PROJECT , "<STR_LIT>" ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , file ) ; assertEquals ( result . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , <NUM_LIT:10> ) ; } } </s>
<s> package org . eclim . plugin . core . util ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . net . URL ; import java . net . URLConnection ; import java . net . URLDecoder ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . regex . Pattern ; import javax . xml . parsers . SAXParser ; import javax . xml . parsers . SAXParserFactory ; import javax . xml . xpath . XPath ; import javax . xml . xpath . XPathExpression ; import javax . xml . xpath . XPathFactory ; import org . apache . commons . lang . SystemUtils ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . eclim . Services ; import org . eclim . command . Error ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileUtils ; import org . w3c . dom . Element ; import org . xml . sax . Attributes ; import org . xml . sax . InputSource ; import org . xml . sax . Locator ; import org . xml . sax . SAXException ; import org . xml . sax . SAXParseException ; import org . xml . sax . helpers . DefaultHandler ; public class XmlUtils { private static final Pattern WIN_BUG = Pattern . compile ( "<STR_LIT>" ) ; private static XPath XPATH ; public static XPathExpression createXPathExpression ( String xpath ) throws Exception { if ( XPATH == null ) { XPATH = XPathFactory . newInstance ( ) . newXPath ( ) ; } return XPATH . compile ( xpath ) ; } public static List < Error > validateXml ( String project , String filename ) throws Exception { return validateXml ( project , filename , false , null ) ; } public static List < Error > validateXml ( String project , String filename , boolean schema ) throws Exception { return validateXml ( project , filename , schema , null ) ; } public static List < Error > validateXml ( String project , String filename , boolean schema , DefaultHandler handler ) throws Exception { SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; factory . setValidating ( true ) ; if ( schema ) { factory . setFeature ( "<STR_LIT>" , true ) ; factory . setFeature ( "<STR_LIT>" , true ) ; } SAXParser parser = factory . newSAXParser ( ) ; filename = ProjectUtils . getFilePath ( project , filename ) ; filename = filename . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; ErrorAggregator errorHandler = new ErrorAggregator ( filename ) ; EntityResolver entityResolver = new EntityResolver ( FileUtils . getFullPath ( filename ) ) ; try { parser . parse ( new File ( filename ) , getHandler ( handler , errorHandler , entityResolver ) ) ; } catch ( SAXParseException spe ) { ArrayList < Error > errors = new ArrayList < Error > ( ) ; errors . add ( new Error ( spe . getMessage ( ) , filename , spe . getLineNumber ( ) , spe . getColumnNumber ( ) , false ) ) ; return errors ; } return errorHandler . getErrors ( ) ; } public static List < Error > validateXml ( String project , String filename , String schema ) throws Exception { SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; factory . setValidating ( true ) ; factory . setFeature ( "<STR_LIT>" , true ) ; factory . setFeature ( "<STR_LIT>" , true ) ; SAXParser parser = factory . newSAXParser ( ) ; parser . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( ! schema . startsWith ( "<STR_LIT>" ) ) { schema = "<STR_LIT>" + schema ; } parser . setProperty ( "<STR_LIT>" , schema ) ; parser . setProperty ( "<STR_LIT>" , schema . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ) ; filename = ProjectUtils . getFilePath ( project , filename ) ; filename = filename . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; ErrorAggregator errorHandler = new ErrorAggregator ( filename ) ; EntityResolver entityResolver = new EntityResolver ( FileUtils . getFullPath ( filename ) ) ; try { parser . parse ( new File ( filename ) , getHandler ( null , errorHandler , entityResolver ) ) ; } catch ( SAXParseException spe ) { ArrayList < Error > errors = new ArrayList < Error > ( ) ; errors . add ( new Error ( spe . getMessage ( ) , filename , spe . getLineNumber ( ) , spe . getColumnNumber ( ) , false ) ) ; return errors ; } return errorHandler . getErrors ( ) ; } public static String getElementValue ( Element element , String name ) { return ( ( Element ) element . getElementsByTagName ( name ) . item ( <NUM_LIT:0> ) ) . getFirstChild ( ) . getNodeValue ( ) ; } private static DefaultHandler getHandler ( DefaultHandler handler , DefaultHandler errorHandler , EntityResolver entityResolver ) { DefaultHandler hdlr = handler != null ? handler : new DefaultHandler ( ) ; return new AggregateHandler ( hdlr , errorHandler , entityResolver ) ; } private static class AggregateHandler extends DefaultHandler { private DefaultHandler handler ; private DefaultHandler errorHandler ; private org . xml . sax . EntityResolver entityResolver ; public AggregateHandler ( DefaultHandler handler , DefaultHandler errorHandler , EntityResolver entityResolver ) { this . handler = handler ; this . errorHandler = errorHandler != null ? errorHandler : handler ; this . entityResolver = entityResolver != null ? entityResolver : handler ; } public InputSource resolveEntity ( String publicId , String systemId ) throws IOException , SAXException { return entityResolver . resolveEntity ( publicId , systemId ) ; } public void notationDecl ( String name , String publicId , String systemId ) throws SAXException { handler . notationDecl ( name , publicId , systemId ) ; } public void unparsedEntityDecl ( String name , String publicId , String systemId , String notationName ) throws SAXException { handler . unparsedEntityDecl ( name , publicId , systemId , notationName ) ; } public void setDocumentLocator ( Locator locator ) { handler . setDocumentLocator ( locator ) ; } public void startDocument ( ) throws SAXException { handler . startDocument ( ) ; } public void endDocument ( ) throws SAXException { handler . endDocument ( ) ; } public void startPrefixMapping ( String prefix , String uri ) throws SAXException { handler . startPrefixMapping ( prefix , uri ) ; } public void endPrefixMapping ( String prefix ) throws SAXException { handler . endPrefixMapping ( prefix ) ; } public void startElement ( String uri , String localName , String qName , Attributes attributes ) throws SAXException { handler . startElement ( uri , localName , qName , attributes ) ; } public void endElement ( String uri , String localName , String qName ) throws SAXException { handler . endElement ( uri , localName , qName ) ; } public void characters ( char [ ] ch , int start , int length ) throws SAXException { handler . characters ( ch , start , length ) ; } public void ignorableWhitespace ( char [ ] ch , int start , int length ) throws SAXException { handler . ignorableWhitespace ( ch , start , length ) ; } public void processingInstruction ( String target , String data ) throws SAXException { handler . processingInstruction ( target , data ) ; } public void skippedEntity ( String name ) throws SAXException { handler . skippedEntity ( name ) ; } public void warning ( SAXParseException e ) throws SAXException { errorHandler . warning ( e ) ; } public void error ( SAXParseException e ) throws SAXException { errorHandler . error ( e ) ; } public void fatalError ( SAXParseException e ) throws SAXException { errorHandler . fatalError ( e ) ; } } private static class ErrorAggregator extends DefaultHandler { private ArrayList < Error > errors = new ArrayList < Error > ( ) ; private String filename ; public ErrorAggregator ( String filename ) { this . filename = filename ; } public void warning ( SAXParseException ex ) throws SAXException { addError ( ex , true ) ; } public void error ( SAXParseException ex ) throws SAXException { addError ( ex , false ) ; } public void fatalError ( SAXParseException ex ) throws SAXException { addError ( ex , false ) ; } private void addError ( SAXParseException ex , boolean warning ) { String location = ex . getSystemId ( ) ; if ( location != null ) { if ( location . startsWith ( "<STR_LIT>" ) ) { location = location . substring ( "<STR_LIT>" . length ( ) ) ; } else if ( location . startsWith ( "<STR_LIT>" ) ) { location = location . substring ( "<STR_LIT>" . length ( ) ) ; } } if ( location != null && WIN_BUG . matcher ( location ) . matches ( ) ) { location = location . substring ( <NUM_LIT:1> ) ; } if ( location == null ) { location = filename ; } try { errors . add ( new Error ( ex . getMessage ( ) , URLDecoder . decode ( location , "<STR_LIT:utf-8>" ) , ex . getLineNumber ( ) , ex . getColumnNumber ( ) , warning ) ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public List < Error > getErrors ( ) { return errors ; } } private static class EntityResolver implements org . xml . sax . EntityResolver { private static String TEMP_PREFIX = "<STR_LIT>" + SystemUtils . JAVA_IO_TMPDIR . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; static { if ( TEMP_PREFIX . endsWith ( "<STR_LIT:\\>" ) || TEMP_PREFIX . endsWith ( "<STR_LIT:/>" ) ) { TEMP_PREFIX = TEMP_PREFIX . substring ( <NUM_LIT:0> , TEMP_PREFIX . length ( ) - <NUM_LIT:1> ) ; } } private String path ; private String lastPath ; private HashMap < String , IOException > missingSources = new HashMap < String , IOException > ( ) ; public EntityResolver ( String path ) { this . path = path ; } public InputSource resolveEntity ( String publicId , String systemId ) throws SAXException , IOException { String location = systemId ; location = location . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( location . startsWith ( TEMP_PREFIX ) ) { location = location . substring ( TEMP_PREFIX . length ( ) ) ; return resolveEntity ( publicId , lastPath + location ) ; } else if ( location . startsWith ( "<STR_LIT:http://>" ) ) { if ( missingSources . containsKey ( systemId ) ) { throw missingSources . get ( systemId ) ; } int index = location . indexOf ( '<CHAR_LIT:/>' , <NUM_LIT:8> ) ; lastPath = location . substring ( <NUM_LIT:0> , index + <NUM_LIT:1> ) ; location = location . substring ( index ) ; location = TEMP_PREFIX + location ; FileSystemManager fsManager = VFS . getManager ( ) ; FileObject tempFile = fsManager . resolveFile ( location ) ; if ( ! tempFile . exists ( ) || tempFile . getContent ( ) . getSize ( ) == <NUM_LIT:0> ) { InputStream in = null ; OutputStream out = null ; try { if ( ! tempFile . exists ( ) ) { tempFile . createFile ( ) ; } URL remote = new URL ( systemId ) ; URLConnection conn = remote . openConnection ( ) ; conn . setConnectTimeout ( <NUM_LIT> ) ; conn . setReadTimeout ( <NUM_LIT> ) ; conn . connect ( ) ; in = conn . getInputStream ( ) ; out = tempFile . getContent ( ) . getOutputStream ( ) ; IOUtils . copy ( in , out ) ; } catch ( Exception e ) { IOUtils . closeQuietly ( out ) ; try { tempFile . delete ( ) ; } catch ( Exception ignore ) { } IOException ex = new IOException ( e . getMessage ( ) ) ; ex . initCause ( e ) ; missingSources . put ( systemId , ex ) ; throw ex ; } finally { IOUtils . closeQuietly ( in ) ; IOUtils . closeQuietly ( out ) ; } } InputSource source = new InputSource ( tempFile . getContent ( ) . getInputStream ( ) ) ; source . setSystemId ( location ) ; return source ; } else if ( location . startsWith ( "<STR_LIT>" ) ) { location = location . substring ( "<STR_LIT>" . length ( ) ) ; if ( location . startsWith ( "<STR_LIT>" ) ) { location = location . substring ( <NUM_LIT:2> ) ; } if ( FileUtils . getFullPath ( location ) . equals ( FileUtils . getPath ( location ) ) ) { location = FileUtils . concat ( path , location ) ; } if ( ! new File ( location ) . exists ( ) ) { StringBuffer resource = new StringBuffer ( ) . append ( "<STR_LIT>" ) . append ( FileUtils . getExtension ( location ) ) . append ( '<CHAR_LIT:/>' ) . append ( FileUtils . getFileName ( location ) ) . append ( '<CHAR_LIT:.>' ) . append ( FileUtils . getExtension ( location ) ) ; URL url = Services . getResource ( resource . toString ( ) ) ; if ( url != null ) { return new InputSource ( url . toString ( ) ) ; } } return new InputSource ( location ) ; } return new InputSource ( systemId ) ; } } } </s>
<s> package org . eclim . plugin . core . util ; import org . eclim . util . file . FileUtils ; import org . eclim . util . file . Position ; public class VimUtils { public static final String DEFAULT_LINE_COL = "<STR_LIT>" ; public static String translateLineColumn ( String filename , int offset ) throws Exception { if ( offset >= <NUM_LIT:0> ) { int [ ] pos = FileUtils . offsetToLineColumn ( filename , offset ) ; if ( pos != null ) { return pos [ <NUM_LIT:0> ] + "<STR_LIT>" + pos [ <NUM_LIT:1> ] ; } } return "<STR_LIT>" ; } public static String translateLineColumn ( Position position ) throws Exception { if ( position . getOffset ( ) != - <NUM_LIT:1> ) { int [ ] pos = FileUtils . offsetToLineColumn ( position . getFilename ( ) , position . getOffset ( ) ) ; if ( pos != null ) { return pos [ <NUM_LIT:0> ] + "<STR_LIT>" + pos [ <NUM_LIT:1> ] ; } } return "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . core . util ; import java . io . File ; import org . eclim . Services ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectManager ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclipse . core . filebuffers . FileBuffers ; import org . eclipse . core . filebuffers . ITextFileBuffer ; import org . eclipse . core . filebuffers . ITextFileBufferManager ; import org . eclipse . core . filebuffers . LocationKind ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . jface . text . IDocument ; public class ProjectUtils { public static String getPath ( String project ) throws Exception { return getPath ( getProject ( project ) ) ; } public static String getPath ( IProject project ) throws Exception { IPath path = getIPath ( project ) ; return path != null ? path . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) : null ; } public static IPath getIPath ( IProject project ) throws Exception { IPath path = project . getRawLocation ( ) ; if ( path == null ) { String name = project . getName ( ) ; path = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) ; path = path . append ( name ) ; } return path ; } public static IProject getProject ( String name ) throws Exception { return getProject ( name , false ) ; } public static IProject getProject ( String name , boolean open ) throws Exception { IProject project = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProject ( name ) ; if ( open && project . exists ( ) && ! project . isOpen ( ) ) { project . open ( null ) ; } return project ; } public static String getFilePath ( String project , String file ) throws Exception { return getFilePath ( getProject ( project ) , file ) ; } public static String getFilePath ( IProject project , String file ) throws Exception { file = file . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( file . startsWith ( "<STR_LIT:/>" + project . getName ( ) ) ) { if ( file . startsWith ( "<STR_LIT:/>" + project . getName ( ) + "<STR_LIT:/>" ) ) { file = file . substring ( <NUM_LIT:2> + project . getName ( ) . length ( ) ) ; } else if ( file . endsWith ( "<STR_LIT:/>" + project . getName ( ) ) ) { file = file . substring ( <NUM_LIT:1> + project . getName ( ) . length ( ) ) ; } if ( file . length ( ) == <NUM_LIT:0> ) { return getPath ( project ) ; } } else if ( file . startsWith ( "<STR_LIT:/>" ) || file . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) || file . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) ) { return file ; } String projectPath = getPath ( project ) ; if ( file . toLowerCase ( ) . startsWith ( projectPath . toLowerCase ( ) ) ) { return file ; } IFile ifile = project . getFile ( file ) ; return ifile . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } public static IFile getFile ( String project , String file ) throws Exception { return getFile ( getProject ( project ) , file ) ; } public static IFile getFile ( IProject project , String file ) throws Exception { if ( ! project . isOpen ( ) ) { project . open ( null ) ; } String path = getPath ( project ) ; path = path . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; IFile ifile = project . getFile ( file ) ; ifile . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; String [ ] natures = ProjectNatureFactory . getProjectNatures ( project ) ; for ( String nature : natures ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; if ( manager != null ) { manager . refresh ( project , ifile ) ; } } return ifile ; } public static IDocument getDocument ( String project , String file ) throws Exception { return getDocument ( getProject ( project ) , file ) ; } public static IDocument getDocument ( IProject project , String file ) throws Exception { File thefile = new File ( getFilePath ( project , file ) ) ; if ( ! thefile . exists ( ) ) { return null ; } ITextFileBufferManager manager = FileBuffers . getTextFileBufferManager ( ) ; IPath location = new Path ( thefile . getAbsolutePath ( ) ) ; boolean connected = false ; try { ITextFileBuffer buffer = manager . getTextFileBuffer ( location , LocationKind . LOCATION ) ; if ( buffer == null ) { manager . connect ( location , LocationKind . LOCATION , new NullProgressMonitor ( ) ) ; connected = true ; buffer = manager . getTextFileBuffer ( location , LocationKind . LOCATION ) ; if ( buffer == null ) { return null ; } } return buffer . getDocument ( ) ; } finally { if ( connected ) { try { manager . disconnect ( location , LocationKind . LOCATION , new NullProgressMonitor ( ) ) ; } catch ( Exception e ) { } } } } public static void closeQuietly ( IProject project ) { try { if ( project != null ) { project . close ( null ) ; } } catch ( Exception ignore ) { } } public static void assertExists ( IProject project ) throws Exception { if ( project == null || ! project . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project != null ? project . getName ( ) : null ) ) ; } } } </s>
<s> package org . eclim . plugin . core ; import java . io . File ; import java . io . FilenameFilter ; import org . eclim . Services ; import org . eclim . eclipse . EclimDaemon ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . logging . Logger ; import org . eclim . plugin . Plugin ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . IResourceChangeListener ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; import org . osgi . framework . BundleContext ; import org . osgi . framework . BundleException ; import org . osgi . framework . FrameworkEvent ; public class CorePlugin extends Plugin implements IResourceChangeListener { private static final Logger logger = Logger . getLogger ( CorePlugin . class ) ; private String [ ] plugins ; private boolean building ; private static CorePlugin plugin ; public CorePlugin ( ) { plugin = this ; } public static CorePlugin getDefault ( ) { return plugin ; } public void activate ( BundleContext context ) { super . activate ( context ) ; logger . info ( "<STR_LIT>" ) ; String pluginsDir = System . getProperty ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" + File . separator ; String [ ] pluginDirs = new File ( pluginsDir ) . list ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { if ( name . startsWith ( "<STR_LIT>" ) && name . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> && name . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> && name . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> ) { return true ; } return false ; } } ) ; plugins = new String [ pluginDirs . length ] ; for ( int ii = <NUM_LIT:0> ; ii < pluginDirs . length ; ii ++ ) { plugins [ ii ] = pluginDirs [ ii ] . substring ( <NUM_LIT:0> , pluginDirs [ ii ] . lastIndexOf ( '<CHAR_LIT:_>' ) ) ; } for ( String plugin : plugins ) { logger . info ( "<STR_LIT>" + plugin ) ; Bundle bundle = Platform . getBundle ( plugin ) ; if ( bundle == null ) { String diagnosis = EclimPlugin . getDefault ( ) . diagnose ( plugin ) ; String message = Services . getMessage ( "<STR_LIT>" , plugin , diagnosis ) ; logger . error ( message ) ; } else { try { bundle . start ( Bundle . START_TRANSIENT ) ; } catch ( BundleException be ) { logger . error ( "<STR_LIT>" + bundle . getSymbolicName ( ) , be ) ; } } } ResourcesPlugin . getWorkspace ( ) . addResourceChangeListener ( this , IResourceChangeEvent . PRE_BUILD | IResourceChangeEvent . POST_BUILD ) ; logger . info ( "<STR_LIT>" ) ; EclimDaemon . getInstance ( ) . frameworkEvent ( new FrameworkEvent ( FrameworkEvent . INFO , getBundle ( ) , null ) ) ; } public void stop ( BundleContext context ) throws Exception { super . stop ( context ) ; for ( String plugin : plugins ) { logger . info ( "<STR_LIT>" + plugin ) ; Bundle bundle = Platform . getBundle ( plugin ) ; if ( bundle != null ) { bundle . stop ( ) ; } } ResourcesPlugin . getWorkspace ( ) . removeResourceChangeListener ( this ) ; } public void resourceChanged ( IResourceChangeEvent event ) { int type = event . getType ( ) ; if ( type == IResourceChangeEvent . PRE_BUILD ) { logger . debug ( "<STR_LIT>" ) ; building = true ; } else if ( type == IResourceChangeEvent . POST_BUILD ) { logger . debug ( "<STR_LIT>" ) ; building = false ; } } public boolean isBuildRunning ( ) { return building ; } } </s>
<s> package org . eclim . plugin . core ; import org . eclim . Services ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . core . preference . PreferenceFactory ; public class PluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; @ Override public void initialize ( String name ) { super . initialize ( name ) ; PreferenceFactory . addPreferences ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . core . preference ; public class Preference extends Option { private String defaultValue ; public String getDefaultValue ( ) { return this . defaultValue != null ? this . defaultValue : "<STR_LIT>" ; } public void setDefaultValue ( String defaultValue ) { this . defaultValue = defaultValue ; } } </s>