text
stringlengths 30
1.67M
|
|---|
<s> package org . codehaus . groovy . eclipse . quickfix . proposals ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; public class QuickFixProblemContext { private final ProblemDescriptor problemDescriptor ; private final IInvocationContext context ; private final IProblemLocation location ; public QuickFixProblemContext ( ProblemDescriptor problemDescriptor , IInvocationContext context , IProblemLocation location ) { this . problemDescriptor = problemDescriptor ; this . context = context ; this . location = location ; } public ICompilationUnit getCompilationUnit ( ) { return context . getCompilationUnit ( ) ; } public ProblemDescriptor getProblemDescriptor ( ) { return problemDescriptor ; } public boolean isError ( ) { return location != null ? location . isError ( ) : true ; } public int getOffset ( ) { return location != null ? location . getOffset ( ) : context . getSelectionOffset ( ) ; } public int getLength ( ) { return location != null ? location . getLength ( ) : context . getSelectionLength ( ) ; } public ASTNode getCoveringNode ( CompilationUnit astRoot ) { return context . getCoveringNode ( ) ; } public ASTNode getCoveredNode ( CompilationUnit astRoot ) { return context . getCoveredNode ( ) ; } public CompilationUnit getASTRoot ( ) { return context . getASTRoot ( ) ; } public IResource getResource ( ) { return getCompilationUnit ( ) != null ? getCompilationUnit ( ) . getResource ( ) : null ; } public IInvocationContext getContext ( ) { return context ; } public IProblemLocation getLocation ( ) { return location ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . proposals ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public class GroovyQuickFixResolverRegistry { private QuickFixProblemContext problem ; private Map < ProblemType , List < IQuickFixResolver > > registry ; public GroovyQuickFixResolverRegistry ( QuickFixProblemContext problem ) { this . problem = problem ; } protected QuickFixProblemContext getQuickFixProblem ( ) { return problem ; } public List < IQuickFixResolver > getQuickFixResolvers ( ) { ProblemDescriptor descriptor = getQuickFixProblem ( ) . getProblemDescriptor ( ) ; return descriptor != null ? getRegistry ( ) . get ( descriptor . getType ( ) ) : null ; } protected Map < ProblemType , List < IQuickFixResolver > > getRegistry ( ) { if ( registry == null ) { registry = new HashMap < ProblemType , List < IQuickFixResolver > > ( ) ; IQuickFixResolver [ ] registeredResolvers = getRegisteredResolvers ( getQuickFixProblem ( ) ) ; for ( IQuickFixResolver resolver : registeredResolvers ) { List < ProblemType > types = resolver . getProblemTypes ( ) ; for ( ProblemType type : types ) { List < IQuickFixResolver > resolvers = registry . get ( type ) ; if ( resolvers == null ) { resolvers = new ArrayList < IQuickFixResolver > ( ) ; registry . put ( type , resolvers ) ; } resolvers . add ( resolver ) ; } } } return registry ; } protected static IQuickFixResolver [ ] getRegisteredResolvers ( QuickFixProblemContext problem ) { return new IQuickFixResolver [ ] { new ConvertToGroovyFileResolver ( problem ) , new AddMissingGroovyImportsResolver ( problem ) , new AddGroovyRuntimeResolver ( problem ) , new AddUnimplementedResolver ( problem ) , } ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . proposals ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Hashtable ; import java . util . List ; import java . util . Map ; import org . eclipse . jdt . internal . corext . fix . CleanUpConstants ; import org . eclipse . jdt . internal . corext . fix . IProposableFix ; import org . eclipse . jdt . internal . corext . fix . UnimplementedCodeFix ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . internal . ui . fix . UnimplementedCodeCleanUp ; import org . eclipse . jdt . internal . ui . text . correction . proposals . FixCorrectionProposal ; import org . eclipse . jdt . ui . cleanup . CleanUpOptions ; import org . eclipse . jdt . ui . cleanup . ICleanUp ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; import org . eclipse . swt . graphics . Image ; public class AddUnimplementedResolver extends AbstractQuickFixResolver { protected AddUnimplementedResolver ( QuickFixProblemContext problem ) { super ( problem ) ; } public List < IJavaCompletionProposal > getQuickFixProposals ( ) { Collection < IJavaCompletionProposal > proposals = new ArrayList < IJavaCompletionProposal > ( <NUM_LIT:2> ) ; addUnimplementedMethodsProposals ( getQuickFixProblem ( ) . getContext ( ) , getQuickFixProblem ( ) . getLocation ( ) , proposals ) ; List < IJavaCompletionProposal > newProposals = new ArrayList < IJavaCompletionProposal > ( ) ; for ( Object command : proposals ) { if ( command instanceof IJavaCompletionProposal ) { newProposals . add ( ( IJavaCompletionProposal ) command ) ; } } return newProposals ; } public static void addUnimplementedMethodsProposals ( IInvocationContext context , IProblemLocation problem , Collection < IJavaCompletionProposal > proposals ) { IProposableFix addMethodFix = UnimplementedCodeFix . createAddUnimplementedMethodsFix ( context . getASTRoot ( ) , problem ) ; if ( addMethodFix != null ) { Image image = JavaPluginImages . get ( JavaPluginImages . IMG_CORRECTION_CHANGE ) ; Map < String , String > settings = new Hashtable < String , String > ( ) ; settings . put ( CleanUpConstants . ADD_MISSING_METHODES , CleanUpOptions . TRUE ) ; ICleanUp cleanUp = new UnimplementedCodeCleanUp ( settings ) ; proposals . add ( new FixCorrectionProposal ( addMethodFix , cleanUp , <NUM_LIT:10> , image , context ) ) ; } IProposableFix makeAbstractFix = UnimplementedCodeFix . createMakeTypeAbstractFix ( context . getASTRoot ( ) , problem ) ; if ( makeAbstractFix != null ) { Image image = JavaPluginImages . get ( JavaPluginImages . IMG_CORRECTION_CHANGE ) ; Map < String , String > settings = new Hashtable < String , String > ( ) ; settings . put ( UnimplementedCodeCleanUp . MAKE_TYPE_ABSTRACT , CleanUpOptions . TRUE ) ; ICleanUp cleanUp = new UnimplementedCodeCleanUp ( settings ) ; proposals . add ( new FixCorrectionProposal ( makeAbstractFix , cleanUp , <NUM_LIT:5> , image , context ) ) ; } } @ Override protected ProblemType [ ] getTypes ( ) { return new ProblemType [ ] { ProblemType . UNIMPLEMENTED_METHODS_TYPE } ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Status ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class GroovyQuickFixPlugin extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static GroovyQuickFixPlugin plugin ; public GroovyQuickFixPlugin ( ) { } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; plugin = this ; } public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static GroovyQuickFixPlugin getDefault ( ) { return plugin ; } public static void log ( String message , Throwable exception ) { IStatus status = createErrorStatus ( message , exception ) ; log ( status ) ; } public static void logWarning ( String message , Throwable exception ) { log ( createWarningStatus ( message , exception ) ) ; } public static void log ( Throwable exception ) { log ( createErrorStatus ( "<STR_LIT>" , exception ) ) ; } public static void log ( IStatus status ) { getDefault ( ) . getLog ( ) . log ( status ) ; } public static IStatus createErrorStatus ( String message , Throwable exception ) { if ( message == null ) { message = "<STR_LIT>" ; } return new Status ( IStatus . ERROR , PLUGIN_ID , <NUM_LIT:0> , message , exception ) ; } public static IStatus createWarningStatus ( String message , Throwable exception ) { if ( message == null ) { message = "<STR_LIT>" ; } return new Status ( IStatus . WARNING , PLUGIN_ID , <NUM_LIT:0> , message , exception ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickfix . processors ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . quickfix . proposals . GroovyQuickFixResolverRegistry ; import org . codehaus . groovy . eclipse . quickfix . proposals . IQuickFixResolver ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemDescriptor ; import org . codehaus . groovy . eclipse . quickfix . proposals . ProblemType ; import org . codehaus . groovy . eclipse . quickfix . proposals . QuickFixProblemContext ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; import org . eclipse . jdt . ui . text . java . IQuickFixProcessor ; public class GroovyQuickFixProcessor implements IQuickFixProcessor { public boolean hasCorrections ( ICompilationUnit unit , int problemId ) { return isProblemInGroovyProject ( unit ) && ProblemType . isRecognizedProblemId ( problemId ) ; } public IJavaCompletionProposal [ ] getCorrections ( IInvocationContext context , IProblemLocation [ ] locations ) throws CoreException { if ( isProblemInGroovyProject ( context , locations ) ) { QuickFixProblemContext problemContext = getQuickFixProblemContext ( context , locations ) ; if ( problemContext != null ) { List < IQuickFixResolver > resolvers = new GroovyQuickFixResolverRegistry ( problemContext ) . getQuickFixResolvers ( ) ; if ( resolvers != null ) { List < IJavaCompletionProposal > proposals = new ArrayList < IJavaCompletionProposal > ( ) ; for ( IQuickFixResolver resolver : resolvers ) { List < IJavaCompletionProposal > foundProposals = resolver . getQuickFixProposals ( ) ; if ( foundProposals != null ) { proposals . addAll ( foundProposals ) ; } } return proposals . toArray ( new IJavaCompletionProposal [ proposals . size ( ) ] ) ; } } } return new IJavaCompletionProposal [ ] { } ; } protected QuickFixProblemContext getQuickFixProblemContext ( IInvocationContext context , IProblemLocation [ ] locations ) { if ( context == null || locations == null || locations . length == <NUM_LIT:0> ) { return null ; } IProblemLocation location = locations [ <NUM_LIT:0> ] ; ProblemDescriptor descriptor = getProblemDescriptor ( location . getProblemId ( ) , location . getMarkerType ( ) , location . getProblemArguments ( ) ) ; if ( descriptor != null ) { return new QuickFixProblemContext ( descriptor , context , location ) ; } return null ; } public ProblemDescriptor getProblemDescriptor ( int problemID , String markerDescription , String [ ] messages ) { ProblemType type = ProblemType . getProblemType ( problemID , markerDescription , messages ) ; if ( type != null ) { return new ProblemDescriptor ( type , messages ) ; } return null ; } protected boolean isProblemInGroovyProject ( IInvocationContext context , IProblemLocation [ ] locations ) { if ( context != null && locations != null && locations . length > <NUM_LIT:0> ) { return isProblemInGroovyProject ( context . getCompilationUnit ( ) ) ; } return false ; } protected boolean isProblemInGroovyProject ( ICompilationUnit unit ) { if ( unit != null ) { IResource resource = unit . getResource ( ) ; if ( resource != null ) { IProject project = resource . getProject ( ) ; if ( project != null && project . isAccessible ( ) && GroovyNature . hasGroovyNature ( project ) ) { return true ; } } } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . eclipse . refactoring . core . convert . ConvertToMethodRefactoring ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; public class ConvertToMethodCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private ConvertToMethodRefactoring convertToMethodRefactoring ; public ConvertToMethodCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { convertToMethodRefactoring . applyRefactoring ( document ) ; } public Point getSelection ( IDocument document ) { return new Point ( offset , length + offset ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } convertToMethodRefactoring = new ConvertToMethodRefactoring ( unit , offset ) ; return convertToMethodRefactoring . isApplicable ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; import org . eclipse . text . edits . MultiTextEdit ; import org . eclipse . text . edits . ReplaceEdit ; import org . eclipse . text . edits . TextEdit ; public class ConvertToMultiLineStringCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private Expression literal ; public ConvertToMultiLineStringCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { TextEdit thisEdit = findReplacement ( document ) ; try { if ( thisEdit != null ) { thisEdit . apply ( document ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public Point getSelection ( IDocument document ) { return new Point ( offset , length + offset ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } boolean result = false ; Region region = new Region ( offset , length ) ; ASTNodeFinder finder = new StringConstantFinder ( region ) ; ModuleNode moduleNode = unit . getModuleNode ( ) ; ASTNode node = finder . doVisit ( moduleNode ) ; if ( ( node instanceof ConstantExpression && ( ( ConstantExpression ) node ) . getValue ( ) instanceof String ) || node instanceof GStringExpression ) { Expression expr = ( Expression ) node ; char [ ] contents = unit . getContents ( ) ; int start = expr . getStart ( ) ; int end = expr . getEnd ( ) ; char [ ] nodeText = new char [ end - start ] ; System . arraycopy ( contents , start , nodeText , <NUM_LIT:0> , end - start ) ; if ( isStringLiteral ( nodeText ) && ! isMultiLineString ( String . valueOf ( nodeText ) ) ) { literal = expr ; result = true ; } } return result ; } private boolean isStringLiteral ( char [ ] nodeText ) { return nodeText . length > <NUM_LIT:1> && ( nodeText [ <NUM_LIT:0> ] == '<STR_LIT>' || nodeText [ <NUM_LIT:0> ] == '<CHAR_LIT:">' ) && ( nodeText [ nodeText . length - <NUM_LIT:1> ] == '<STR_LIT>' || nodeText [ nodeText . length - <NUM_LIT:1> ] == '<CHAR_LIT:">' ) ; } private TextEdit findReplacement ( IDocument doc ) { try { int startQuote = literal . getStart ( ) ; int endQuote = literal . getEnd ( ) - <NUM_LIT:1> ; if ( startQuote >= endQuote ) { return null ; } return createEdit ( doc , startQuote , endQuote ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; return null ; } } private TextEdit createEdit ( IDocument doc , int startQuote , int endQuote ) throws BadLocationException { if ( startQuote < <NUM_LIT:0> || startQuote >= doc . getLength ( ) || endQuote < <NUM_LIT:0> || endQuote >= doc . getLength ( ) ) { return null ; } if ( ! ( doc . getChar ( startQuote ) == '<STR_LIT>' || doc . getChar ( startQuote ) == '<CHAR_LIT:">' ) ) { return null ; } if ( ! ( doc . getChar ( endQuote ) == '<STR_LIT>' || doc . getChar ( endQuote ) == '<CHAR_LIT:">' ) ) { return null ; } char quoteChar = doc . getChar ( startQuote ) ; char skipChar = '<STR_LIT>' ; String replaceQuotes = new String ( new char [ ] { quoteChar , quoteChar , quoteChar } ) ; TextEdit edit = new MultiTextEdit ( ) ; edit . addChild ( new ReplaceEdit ( startQuote , <NUM_LIT:1> , replaceQuotes ) ) ; edit . addChild ( new ReplaceEdit ( endQuote , <NUM_LIT:1> , replaceQuotes ) ) ; for ( int i = startQuote + <NUM_LIT:1> ; i < endQuote - <NUM_LIT:1> ; i ++ ) { if ( doc . getChar ( i ) == '<STR_LIT:\\>' ) { i ++ ; if ( doc . getChar ( i ) != skipChar ) { edit . addChild ( new ReplaceEdit ( i - <NUM_LIT:1> , <NUM_LIT:2> , unescaped ( doc . getChar ( i ) ) ) ) ; } } } return edit ; } private String unescaped ( char escaped ) { switch ( escaped ) { case '<CHAR_LIT>' : return "<STR_LIT>" ; case '<CHAR_LIT>' : return "<STR_LIT:t>" ; case '<CHAR_LIT:b>' : return "<STR_LIT>" ; case '<CHAR_LIT>' : return "<STR_LIT:n>" ; case '<CHAR_LIT>' : return "<STR_LIT:r>" ; case '<CHAR_LIT>' : return "<STR_LIT:n>" ; case '<STR_LIT>' : return "<STR_LIT:'>" ; case '<CHAR_LIT:">' : return "<STR_LIT:\">" ; case '<STR_LIT:\\>' : return "<STR_LIT:\\>" ; } return String . valueOf ( escaped ) ; } private boolean isMultiLineString ( String test ) { return ( test . startsWith ( "<STR_LIT>" ) && test . endsWith ( "<STR_LIT>" ) ) || ( test . startsWith ( "<STR_LIT>" ) && test . endsWith ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . Point ; public abstract class AbstractGroovyCompletionProposal implements IJavaCompletionProposal { private final IInvocationContext context ; public AbstractGroovyCompletionProposal ( IInvocationContext context ) { this . context = context ; } protected IInvocationContext getContext ( ) { return context ; } public Image getImage ( ) { String imageLocation = getImageBundleLocation ( ) ; if ( imageLocation != null ) { return JavaPluginImages . get ( imageLocation ) ; } return null ; } abstract protected String getImageBundleLocation ( ) ; abstract public boolean hasProposals ( ) ; public Point getSelection ( IDocument document ) { return new Point ( context . getSelectionOffset ( ) , context . getSelectionLength ( ) ) ; } public String getAdditionalProposalInfo ( ) { return null ; } public IContextInformation getContextInformation ( ) { return null ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . eclipse . refactoring . core . convert . AssignStatementToNewLocalRefactoring ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; public class AssignStatementToNewLocalProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private AssignStatementToNewLocalRefactoring assignStatementRefactoring ; public AssignStatementToNewLocalProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { assignStatementRefactoring . applyRefactoring ( document ) ; } public Point getSelection ( IDocument document ) { return assignStatementRefactoring . getNewSelection ( ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } assignStatementRefactoring = new AssignStatementToNewLocalRefactoring ( unit , offset ) ; return assignStatementRefactoring . isApplicable ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . refactoring . formatter . GroovyFormatter ; import org . codehaus . groovy . eclipse . refactoring . formatter . SemicolonRemover ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . ITextSelection ; import org . eclipse . jface . text . TextSelection ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; import org . eclipse . text . edits . TextEdit ; public class RemoveUnnecessarySemicolonsCompletionProposal extends AbstractGroovyCompletionProposal { private final int length ; private final int offset ; public RemoveUnnecessarySemicolonsCompletionProposal ( IInvocationContext context ) { super ( context ) ; length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { ITextSelection selection = new TextSelection ( offset , length ) ; GroovyFormatter formatter = new SemicolonRemover ( selection , document ) ; TextEdit textEdit = formatter . format ( ) ; try { if ( textEdit . getChildrenSize ( ) > <NUM_LIT:0> ) { textEdit . apply ( document ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public Point getSelection ( IDocument document ) { return new Point ( offset , <NUM_LIT:0> ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_REMOVE ; } @ Override public boolean hasProposals ( ) { return getContext ( ) . getCompilationUnit ( ) instanceof GroovyCompilationUnit ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IProblemLocation ; import org . eclipse . jdt . ui . text . java . IQuickAssistProcessor ; public class GroovyQuickAssist implements IQuickAssistProcessor { public boolean hasAssists ( IInvocationContext context ) throws CoreException { if ( context != null && isContentInGroovyProject ( context . getCompilationUnit ( ) ) ) { return new AddSuggestionsQuickAssistProposal ( context ) . hasProposals ( ) || new ConvertToClosureCompletionProposal ( context ) . hasProposals ( ) || new ConvertToMethodCompletionProposal ( context ) . hasProposals ( ) || new ConvertToMultiLineStringCompletionProposal ( context ) . hasProposals ( ) || new ConvertToSingleLineStringCompletionProposal ( context ) . hasProposals ( ) || new RemoveUnnecessarySemicolonsCompletionProposal ( context ) . hasProposals ( ) || new SwapOperandsCompletionProposal ( context ) . hasProposals ( ) || new SplitAssigmentCompletionProposal ( context ) . hasProposals ( ) || new AssignStatementToNewLocalProposal ( context ) . hasProposals ( ) ; } return false ; } public IJavaCompletionProposal [ ] getAssists ( IInvocationContext context , IProblemLocation [ ] locations ) throws CoreException { if ( ! ( context . getCompilationUnit ( ) instanceof GroovyCompilationUnit ) ) { return new IJavaCompletionProposal [ <NUM_LIT:0> ] ; } List < IJavaCompletionProposal > proposalList = new ArrayList < IJavaCompletionProposal > ( ) ; AddSuggestionsQuickAssistProposal javaProposal = new AddSuggestionsQuickAssistProposal ( context ) ; if ( javaProposal . hasProposals ( ) ) { proposalList . add ( javaProposal ) ; } ConvertToClosureCompletionProposal convertToClosure = new ConvertToClosureCompletionProposal ( context ) ; if ( convertToClosure . hasProposals ( ) ) { proposalList . add ( convertToClosure ) ; } ConvertToMethodCompletionProposal convertToMethod = new ConvertToMethodCompletionProposal ( context ) ; if ( convertToMethod . hasProposals ( ) ) { proposalList . add ( convertToMethod ) ; } ConvertToMultiLineStringCompletionProposal convertToMultiLineString = new ConvertToMultiLineStringCompletionProposal ( context ) ; if ( convertToMultiLineString . hasProposals ( ) ) { proposalList . add ( convertToMultiLineString ) ; } ConvertToSingleLineStringCompletionProposal convertToSingleLineString = new ConvertToSingleLineStringCompletionProposal ( context ) ; if ( convertToSingleLineString . hasProposals ( ) ) { proposalList . add ( convertToSingleLineString ) ; } RemoveUnnecessarySemicolonsCompletionProposal unnecessarySemicolons = new RemoveUnnecessarySemicolonsCompletionProposal ( context ) ; if ( unnecessarySemicolons . hasProposals ( ) ) { proposalList . add ( unnecessarySemicolons ) ; } SplitAssigmentCompletionProposal splitAssignment = new SplitAssigmentCompletionProposal ( context ) ; if ( splitAssignment . hasProposals ( ) ) { proposalList . add ( splitAssignment ) ; } SwapOperandsCompletionProposal swapOperands = new SwapOperandsCompletionProposal ( context ) ; if ( swapOperands . hasProposals ( ) ) { proposalList . add ( swapOperands ) ; } AssignStatementToNewLocalProposal assignStatement = new AssignStatementToNewLocalProposal ( context ) ; if ( assignStatement . hasProposals ( ) ) { proposalList . add ( assignStatement ) ; } return proposalList . toArray ( new IJavaCompletionProposal [ <NUM_LIT:0> ] ) ; } protected boolean isProblemInGroovyProject ( IInvocationContext context ) { if ( context == null ) { return false ; } return isContentInGroovyProject ( context . getCompilationUnit ( ) ) ; } protected boolean isContentInGroovyProject ( ICompilationUnit unit ) { if ( unit != null ) { IResource resource = unit . getResource ( ) ; if ( resource != null ) { IProject project = resource . getProject ( ) ; if ( project != null && project . isAccessible ( ) && GroovyNature . hasGroovyNature ( project ) ) { return true ; } } } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; import org . eclipse . text . edits . MultiTextEdit ; import org . eclipse . text . edits . ReplaceEdit ; import org . eclipse . text . edits . TextEdit ; public class ConvertToSingleLineStringCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private Expression literal ; public ConvertToSingleLineStringCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { TextEdit thisEdit = findReplacement ( document ) ; try { if ( thisEdit != null ) { thisEdit . apply ( document ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public Point getSelection ( IDocument document ) { return new Point ( offset , length + offset ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } boolean result = false ; Region region = new Region ( offset , length ) ; ASTNodeFinder finder = new StringConstantFinder ( region ) ; ModuleNode moduleNode = unit . getModuleNode ( ) ; ASTNode node = finder . doVisit ( moduleNode ) ; if ( ( node instanceof ConstantExpression && ( ( ConstantExpression ) node ) . getValue ( ) instanceof String ) || node instanceof GStringExpression ) { Expression expr = ( Expression ) node ; char [ ] contents = unit . getContents ( ) ; int start = expr . getStart ( ) ; int end = expr . getEnd ( ) ; char [ ] nodeText = new char [ end - start ] ; if ( end <= start ) { return false ; } System . arraycopy ( contents , start , nodeText , <NUM_LIT:0> , end - start ) ; if ( isMultiLineString ( String . valueOf ( nodeText ) ) ) { literal = expr ; result = true ; } } return result ; } private TextEdit findReplacement ( IDocument doc ) { try { int startQuote = literal . getStart ( ) ; int endQuote = literal . getEnd ( ) - <NUM_LIT:3> ; return createEdit ( doc , startQuote , endQuote ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; return null ; } } private TextEdit createEdit ( IDocument doc , int startQuote , int endQuote ) throws BadLocationException { if ( startQuote < <NUM_LIT:0> || startQuote + <NUM_LIT:3> >= doc . getLength ( ) || endQuote < <NUM_LIT:0> || endQuote + <NUM_LIT:3> > doc . getLength ( ) ) { return null ; } String startText = doc . get ( startQuote , <NUM_LIT:3> ) ; String endText = doc . get ( endQuote , <NUM_LIT:3> ) ; if ( ! ( startText . equals ( "<STR_LIT>" ) || startText . equals ( "<STR_LIT>" ) ) ) { return null ; } if ( ! ( endText . equals ( "<STR_LIT>" ) || endText . equals ( "<STR_LIT>" ) ) ) { return null ; } String replaceQuote = String . valueOf ( startText . charAt ( <NUM_LIT:0> ) ) ; TextEdit edit = new MultiTextEdit ( ) ; edit . addChild ( new ReplaceEdit ( startQuote , <NUM_LIT:3> , replaceQuote ) ) ; edit . addChild ( new ReplaceEdit ( endQuote , <NUM_LIT:3> , replaceQuote ) ) ; boolean isSingle = replaceQuote . startsWith ( "<STR_LIT:'>" ) ; for ( int i = startQuote + <NUM_LIT:3> ; i < endQuote - <NUM_LIT:3> ; i ++ ) { char toEscape = doc . getChar ( i ) ; String escaped = null ; switch ( toEscape ) { case '<STR_LIT:\t>' : escaped = "<STR_LIT>" ; break ; case '<STR_LIT>' : escaped = "<STR_LIT>" ; break ; case '<STR_LIT:\n>' : escaped = "<STR_LIT>" ; break ; case '<STR_LIT>' : escaped = "<STR_LIT>" ; break ; case '<STR_LIT>' : escaped = "<STR_LIT>" ; break ; case '<STR_LIT>' : if ( isSingle ) escaped = "<STR_LIT>" ; break ; case '<CHAR_LIT:">' : if ( ! isSingle ) escaped = "<STR_LIT>" ; break ; case '<STR_LIT:\\>' : escaped = "<STR_LIT>" ; break ; } if ( escaped != null ) { edit . addChild ( new ReplaceEdit ( i , <NUM_LIT:1> , escaped ) ) ; } } return edit ; } private boolean isMultiLineString ( String test ) { return ( test . startsWith ( "<STR_LIT>" ) && test . endsWith ( "<STR_LIT>" ) ) || ( test . startsWith ( "<STR_LIT>" ) && test . endsWith ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; class StringConstantFinder extends ASTNodeFinder { public StringConstantFinder ( Region r ) { super ( r ) ; } @ Override public void visitGStringExpression ( GStringExpression node ) { check ( node ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . eclipse . dsl . inferencing . suggestions . SuggestionCompilationUnitHelper ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; public class AddSuggestionsQuickAssistProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; static final String LABEL = "<STR_LIT>" ; public AddSuggestionsQuickAssistProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public void apply ( IDocument document ) { IProject project = getProject ( ) ; if ( project != null ) { new SuggestionCompilationUnitHelper ( length , offset , unit , project ) . addSuggestion ( ) ; } } public boolean hasProposals ( ) { return unit != null && new SuggestionCompilationUnitHelper ( length , offset , unit , getProject ( ) ) . canAddSuggestion ( ) ; } protected IProject getProject ( ) { if ( unit != null ) { IResource resource = unit . getResource ( ) ; if ( resource != null ) { return resource . getProject ( ) ; } } return null ; } public String getDisplayString ( ) { return LABEL ; } protected String getImageBundleLocation ( ) { return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . syntax . Token ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; import org . eclipse . text . edits . MultiTextEdit ; import org . eclipse . text . edits . ReplaceEdit ; import org . eclipse . text . edits . TextEdit ; public class SwapOperandsCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private BinaryExpression binaryExpression ; public SwapOperandsCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { TextEdit thisEdit = findReplacement ( document ) ; try { if ( thisEdit != null ) { thisEdit . apply ( document ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public Point getSelection ( IDocument document ) { return new Point ( offset , <NUM_LIT:0> ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } boolean result = false ; Region region = new Region ( offset , length ) ; ASTNodeFinder finder = new ASTNodeFinder ( region ) ; ModuleNode moduleNode = unit . getModuleNode ( ) ; ASTNode node = finder . doVisit ( moduleNode ) ; if ( node instanceof BinaryExpression ) { BinaryExpression expr = ( BinaryExpression ) node ; Token operation = expr . getOperation ( ) ; if ( isApplicableInfixOperator ( operation . getText ( ) ) ) { binaryExpression = expr ; result = true ; } } return result ; } private TextEdit findReplacement ( IDocument doc ) { try { return createEdit ( doc , binaryExpression . getLeftExpression ( ) , binaryExpression . getRightExpression ( ) ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; return null ; } } private TextEdit createEdit ( IDocument doc , Expression left , Expression right ) throws BadLocationException { TextEdit edit = new MultiTextEdit ( ) ; int leftStart = left . getStart ( ) ; int rightStart = right . getStart ( ) ; char [ ] contents = unit . getContents ( ) ; char [ ] leftChars = CharOperation . subarray ( contents , leftStart , left . getEnd ( ) ) ; char [ ] rightChars = CharOperation . subarray ( contents , rightStart , right . getEnd ( ) ) ; String leftText = new String ( leftChars ) . trim ( ) ; String rightText = new String ( rightChars ) . trim ( ) ; edit . addChild ( new ReplaceEdit ( rightStart , rightText . length ( ) , leftText ) ) ; edit . addChild ( new ReplaceEdit ( leftStart , leftText . length ( ) , rightText ) ) ; return edit ; } private boolean isApplicableInfixOperator ( String test ) { return test . equals ( "<STR_LIT:*>" ) || test . equals ( "<STR_LIT:/>" ) || test . equals ( "<STR_LIT:%>" ) || test . equals ( "<STR_LIT:+>" ) || test . equals ( "<STR_LIT:->" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT:<>" ) || test . equals ( "<STR_LIT:>>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT:&>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT:|>" ) || test . equals ( "<STR_LIT>" ) || test . equals ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . eclipse . refactoring . core . convert . ConvertToClosureRefactoring ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; public class ConvertToClosureCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private ConvertToClosureRefactoring convertToClosureRefactoring ; public ConvertToClosureCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { convertToClosureRefactoring . applyRefactoring ( document ) ; } public Point getSelection ( IDocument document ) { return new Point ( offset , length + offset ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } convertToClosureRefactoring = new ConvertToClosureRefactoring ( unit , offset ) ; return convertToClosureRefactoring . isApplicable ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . quickassist ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . ASTNodeFinder ; import org . codehaus . groovy . eclipse . codebrowsing . requestor . Region ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . refactoring . formatter . GroovyIndentationService ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . ui . text . java . IInvocationContext ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . contentassist . ContextInformation ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . swt . graphics . Point ; import org . eclipse . text . edits . ReplaceEdit ; import org . eclipse . text . edits . TextEdit ; public class SplitAssigmentCompletionProposal extends AbstractGroovyCompletionProposal { private final GroovyCompilationUnit unit ; private final int length ; private final int offset ; private DeclarationExpression expr ; public SplitAssigmentCompletionProposal ( IInvocationContext context ) { super ( context ) ; ICompilationUnit compUnit = context . getCompilationUnit ( ) ; if ( compUnit instanceof GroovyCompilationUnit ) { this . unit = ( GroovyCompilationUnit ) compUnit ; } else { this . unit = null ; } length = context . getSelectionLength ( ) ; offset = context . getSelectionOffset ( ) ; } public int getRelevance ( ) { return <NUM_LIT:0> ; } public void apply ( IDocument document ) { Expression left = expr . getLeftExpression ( ) ; int insertAt = left . getEnd ( ) ; try { int lineNr = document . getLineOfOffset ( insertAt ) ; String space = GroovyIndentationService . getLineLeadingWhiteSpace ( document , lineNr ) ; TextEdit edits = ( new ReplaceEdit ( insertAt , <NUM_LIT:0> , "<STR_LIT:n>" + space + left . getText ( ) ) ) ; if ( edits != null ) { edits . apply ( document ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public Point getSelection ( IDocument document ) { return new Point ( offset , length + offset ) ; } public String getAdditionalProposalInfo ( ) { return getDisplayString ( ) ; } public String getDisplayString ( ) { return "<STR_LIT>" ; } public IContextInformation getContextInformation ( ) { return new ContextInformation ( getImage ( ) , getDisplayString ( ) , getDisplayString ( ) ) ; } @ Override protected String getImageBundleLocation ( ) { return JavaPluginImages . IMG_CORRECTION_CHANGE ; } @ Override public boolean hasProposals ( ) { if ( unit == null ) { return false ; } Region region = new Region ( offset , length ) ; ASTNodeFinder finder = new ASTNodeFinder ( region ) ; ModuleNode moduleNode = unit . getModuleNode ( ) ; ASTNode node = finder . doVisit ( moduleNode ) ; if ( node instanceof DeclarationExpression ) { expr = ( DeclarationExpression ) node ; return expr . getRightExpression ( ) != null && ! ( expr . getLeftExpression ( ) instanceof TupleExpression ) ; } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . ant ; import java . io . File ; import org . apache . tools . ant . taskdefs . Javac ; import org . apache . tools . ant . util . GlobPatternMapper ; import org . apache . tools . ant . util . SourceFileScanner ; public class GroovyJDTCompileTask extends Javac { public GroovyJDTCompileTask ( ) { } protected void scanDir ( File srcDir , File destDir , String [ ] files ) { GlobPatternMapper m = new GlobPatternMapper ( ) ; m . setFrom ( "<STR_LIT>" ) ; m . setTo ( "<STR_LIT>" ) ; SourceFileScanner sfs = new SourceFileScanner ( this ) ; File [ ] newJavaFiles = sfs . restrictAsFiles ( files , srcDir , destDir , m ) ; m . setFrom ( "<STR_LIT>" ) ; File [ ] newGroovyFiles = sfs . restrictAsFiles ( files , srcDir , destDir , m ) ; if ( newJavaFiles . length > <NUM_LIT:0> || newGroovyFiles . length > <NUM_LIT:0> ) { File [ ] newCompileList = new File [ compileList . length + newJavaFiles . length + newGroovyFiles . length ] ; System . arraycopy ( compileList , <NUM_LIT:0> , newCompileList , <NUM_LIT:0> , compileList . length ) ; System . arraycopy ( newJavaFiles , <NUM_LIT:0> , newCompileList , compileList . length , newJavaFiles . length ) ; System . arraycopy ( newGroovyFiles , <NUM_LIT:0> , newCompileList , compileList . length + newJavaFiles . length , newGroovyFiles . length ) ; compileList = newCompileList ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . ant ; import java . io . File ; import java . lang . reflect . Method ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . DirectoryScanner ; import org . apache . tools . ant . taskdefs . Javac ; import org . apache . tools . ant . taskdefs . MatchingTask ; import org . apache . tools . ant . taskdefs . compilers . CompilerAdapter ; import org . apache . tools . ant . util . FileNameMapper ; import org . apache . tools . ant . util . SourceFileScanner ; import org . eclipse . jdt . core . JDTCompilerAdapter ; public class GroovyCompilerAdapter extends JDTCompilerAdapter implements CompilerAdapter { @ Override public void setJavac ( Javac javac ) { super . setJavac ( javac ) ; File [ ] groovyFiles = getGroovyFiles ( javac ) ; if ( groovyFiles . length > <NUM_LIT:0> ) { for ( int i = <NUM_LIT:0> ; i < groovyFiles . length ; i ++ ) { javac . log ( "<STR_LIT>" + groovyFiles . length + "<STR_LIT>" + ( groovyFiles . length == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) + ( destDir != null ? "<STR_LIT:U+0020toU+0020>" + destDir : "<STR_LIT>" ) ) ; String filename = groovyFiles [ i ] . getAbsolutePath ( ) ; javac . log ( filename ) ; } File [ ] newCompileList = new File [ groovyFiles . length + compileList . length ] ; System . arraycopy ( compileList , <NUM_LIT:0> , newCompileList , <NUM_LIT:0> , compileList . length ) ; System . arraycopy ( groovyFiles , <NUM_LIT:0> , newCompileList , compileList . length , groovyFiles . length ) ; compileList = newCompileList ; } } protected File [ ] getGroovyFiles ( Javac javac ) { String [ ] list = javac . getSrcdir ( ) . list ( ) ; File destDir = javac . getDestdir ( ) ; File [ ] sourceFiles = new File [ <NUM_LIT:0> ] ; for ( int i = <NUM_LIT:0> ; i < list . length ; i ++ ) { File srcDir = javac . getProject ( ) . resolveFile ( list [ i ] ) ; if ( ! srcDir . exists ( ) ) { throw new BuildException ( "<STR_LIT>" + srcDir . getPath ( ) + "<STR_LIT>" , javac . getLocation ( ) ) ; } DirectoryScanner ds = getDirectoryScanner ( srcDir , javac ) ; String [ ] files = ds . getIncludedFiles ( ) ; GroovyFileNameMapper m = new GroovyFileNameMapper ( ) ; SourceFileScanner sfs = new SourceFileScanner ( javac ) ; File [ ] moreFiles = sfs . restrictAsFiles ( files , srcDir , destDir , m ) ; if ( moreFiles != null ) { File [ ] origFiles = sourceFiles ; sourceFiles = new File [ origFiles . length + moreFiles . length ] ; System . arraycopy ( origFiles , <NUM_LIT:0> , sourceFiles , <NUM_LIT:0> , origFiles . length ) ; System . arraycopy ( moreFiles , <NUM_LIT:0> , sourceFiles , origFiles . length , moreFiles . length ) ; } } return sourceFiles ; } private DirectoryScanner getDirectoryScanner ( File srcDir , Javac javac ) { try { Method getDirectoryScannerMethod = MatchingTask . class . getDeclaredMethod ( "<STR_LIT>" , File . class ) ; getDirectoryScannerMethod . setAccessible ( true ) ; return ( DirectoryScanner ) getDirectoryScannerMethod . invoke ( javac , srcDir ) ; } catch ( Exception e ) { throw new BuildException ( "<STR_LIT>" + srcDir . getPath ( ) + "<STR_LIT:\">" , e ) ; } } } class GroovyFileNameMapper implements FileNameMapper { public String [ ] mapFileName ( String sourceFileName ) { if ( sourceFileName != null ) { if ( sourceFileName . endsWith ( "<STR_LIT>" ) ) { return new String [ ] { extractVariablePart ( sourceFileName , "<STR_LIT>" . length ( ) ) + "<STR_LIT:.class>" } ; } } return null ; } private String extractVariablePart ( String name , int postfixLength ) { return name . substring ( <NUM_LIT:0> , name . length ( ) - postfixLength ) ; } public void setFrom ( String from ) { } public void setTo ( String to ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . ant ; import org . eclipse . core . runtime . Plugin ; import org . osgi . framework . BundleContext ; public class Activator extends Plugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static Activator plugin ; public Activator ( ) { } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; plugin = this ; } public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static Activator getDefault ( ) { return plugin ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Platform ; import org . eclipse . core . runtime . Status ; public class GroovyCore { static boolean trace ; static { String value = Platform . getDebugOption ( "<STR_LIT>" ) ; if ( value != null && value . equalsIgnoreCase ( "<STR_LIT:true>" ) ) trace = true ; } public static void logException ( String message , Throwable throwable ) { log ( IStatus . ERROR , message , throwable ) ; } public static void logWarning ( final String message ) { log ( IStatus . WARNING , message , null ) ; } public static void logWarning ( final String message , final Throwable t ) { log ( IStatus . WARNING , message , t ) ; } public static void logTraceMessage ( String message ) { log ( IStatus . INFO , message , null ) ; } private static void log ( int severity , String message , Throwable throwable ) { final IStatus status = new Status ( severity , GroovyCoreActivator . getDefault ( ) . getBundle ( ) . getSymbolicName ( ) , <NUM_LIT:0> , message , throwable ) ; GroovyCoreActivator . getDefault ( ) . getLog ( ) . log ( status ) ; } public static void trace ( String message ) { if ( trace ) { logTraceMessage ( "<STR_LIT>" + message ) ; } } public static void errorRunningGroovyFile ( IFile file , Exception exception ) { logException ( "<STR_LIT>" + file . getName ( ) , exception ) ; } public static void errorRunningGroovy ( Exception exception ) { logException ( "<STR_LIT>" , exception ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . model ; import static org . codehaus . groovy . eclipse . core . util . ListUtil . newList ; import java . util . LinkedList ; import java . util . List ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . internal . core . SourceType ; public class GroovyProjectFacade { public static boolean isGroovyProject ( IProject proj ) { try { return proj . hasNature ( GroovyNature . GROOVY_NATURE ) ; } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" + proj . getName ( ) , e ) ; return false ; } } private IJavaProject project ; public GroovyProjectFacade ( IJavaProject project ) { this . project = project ; } public GroovyProjectFacade ( IJavaElement elt ) { this . project = elt . getJavaProject ( ) ; } public IJavaElement groovyNodeToJavaElement ( ASTNode node , IFile file ) { ICompilationUnit unit = JavaCore . createCompilationUnitFrom ( file ) ; if ( ! ( unit instanceof GroovyCompilationUnit ) ) { GroovyCore . logWarning ( "<STR_LIT>" + file . getName ( ) ) ; return unit ; } try { int start = node . getStart ( ) ; IJavaElement elt = unit . getElementAt ( start ) ; if ( node instanceof DeclarationExpression ) { int end = node . getEnd ( ) ; return ReflectionUtils . createLocalVariable ( elt , ( ( DeclarationExpression ) node ) . getVariableExpression ( ) . getName ( ) , start , Signature . createTypeSignature ( ( ( DeclarationExpression ) node ) . getVariableExpression ( ) . getType ( ) . getName ( ) , false ) ) ; } else { return elt ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" + node . getText ( ) , e ) ; } return null ; } public IType groovyClassToJavaType ( ClassNode node ) { try { String name = node . getName ( ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:.>' ) ; return project . findType ( name , new NullProgressMonitor ( ) ) ; } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" + node . getName ( ) , e ) ; return null ; } } GroovyCompilationUnit groovyModuleToCompilationUnit ( ModuleNode node ) { List classes = node . getClasses ( ) ; ClassNode classNode = classes . size ( ) > <NUM_LIT:0> ? ( ClassNode ) classes . get ( <NUM_LIT:0> ) : null ; if ( classNode != null ) { IType type = groovyClassToJavaType ( classNode ) ; if ( type instanceof SourceType ) { return ( GroovyCompilationUnit ) type . getCompilationUnit ( ) ; } } GroovyCore . logWarning ( "<STR_LIT>" + node . getDescription ( ) ) ; return null ; } public ClassNode getClassNodeForName ( String name ) { try { IType type = project . findType ( name , new NullProgressMonitor ( ) ) ; if ( type instanceof SourceType ) { return javaTypeToGroovyClass ( type ) ; } } catch ( JavaModelException e ) { GroovyCore . logException ( e . getMessage ( ) , e ) ; } return null ; } private ClassNode javaTypeToGroovyClass ( IType type ) { ICompilationUnit unit = type . getCompilationUnit ( ) ; if ( unit instanceof GroovyCompilationUnit ) { ModuleNode module = ( ( GroovyCompilationUnit ) unit ) . getModuleNode ( ) ; List < ClassNode > classes = module . getClasses ( ) ; for ( ClassNode classNode : classes ) { if ( classNode . getNameWithoutPackage ( ) . equals ( type . getElementName ( ) ) ) { return classNode ; } } } return null ; } public List < IType > findAllRunnableTypes ( ) throws JavaModelException { final List < IType > results = newList ( ) ; IPackageFragmentRoot [ ] roots = project . getAllPackageFragmentRoots ( ) ; for ( IPackageFragmentRoot root : roots ) { if ( ! root . isReadOnly ( ) ) { IJavaElement [ ] children = root . getChildren ( ) ; for ( IJavaElement child : children ) { if ( child . getElementType ( ) == IJavaElement . PACKAGE_FRAGMENT ) { ICompilationUnit [ ] units = ( ( IPackageFragment ) child ) . getCompilationUnits ( ) ; for ( ICompilationUnit unit : units ) { results . addAll ( findAllRunnableTypes ( unit ) ) ; } } } } } return results ; } public static List < IType > findAllRunnableTypes ( ICompilationUnit unit ) throws JavaModelException { List < IType > results = new LinkedList < IType > ( ) ; IType [ ] types = unit . getAllTypes ( ) ; for ( IType type : types ) { if ( hasRunnableMain ( type ) ) { results . add ( type ) ; } } return results ; } public static boolean hasRunnableMain ( IType type ) { try { IMethod [ ] allMethods = type . getMethods ( ) ; for ( IMethod method : allMethods ) { if ( method . getElementName ( ) . equals ( "<STR_LIT>" ) && Flags . isStatic ( method . getFlags ( ) ) && ( method . getReturnType ( ) . equals ( "<STR_LIT>" ) || method . getReturnType ( ) . endsWith ( "<STR_LIT>" ) ) && hasAppropriateArrayArgsForMain ( method . getParameterTypes ( ) ) ) { return true ; } } } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" + type , e ) ; } return false ; } private static boolean hasAppropriateArrayArgsForMain ( final String [ ] params ) { if ( params == null || params . length != <NUM_LIT:1> ) { return false ; } int array = Signature . getArrayCount ( params [ <NUM_LIT:0> ] ) ; String typeName ; if ( array == <NUM_LIT:1> ) { typeName = "<STR_LIT:String>" ; } else if ( array == <NUM_LIT:0> ) { typeName = "<STR_LIT>" ; } else { return false ; } String sigNoArray = Signature . getElementType ( params [ <NUM_LIT:0> ] ) ; String name = Signature . getSignatureSimpleName ( sigNoArray ) ; String qual = Signature . getSignatureQualifier ( sigNoArray ) ; return ( name . equals ( typeName ) ) && ( qual == null || qual . equals ( "<STR_LIT>" ) || qual . equals ( "<STR_LIT>" ) ) ; } public IJavaProject getProject ( ) { return project ; } public boolean isGroovyScript ( IType type ) { ClassNode node = javaTypeToGroovyClass ( type ) ; if ( node != null ) { return node . isScript ( ) ; } return false ; } public List < IType > findAllScripts ( ) throws JavaModelException { final List < IType > results = newList ( ) ; IPackageFragmentRoot [ ] roots = project . getAllPackageFragmentRoots ( ) ; for ( IPackageFragmentRoot root : roots ) { if ( ! root . isReadOnly ( ) ) { IJavaElement [ ] children = root . getChildren ( ) ; for ( IJavaElement child : children ) { if ( child . getElementType ( ) == IJavaElement . PACKAGE_FRAGMENT ) { ICompilationUnit [ ] units = ( ( IPackageFragment ) child ) . getCompilationUnits ( ) ; for ( ICompilationUnit unit : units ) { if ( unit instanceof GroovyCompilationUnit ) { for ( IType type : unit . getTypes ( ) ) { if ( isGroovyScript ( type ) ) { results . add ( type ) ; } } } } } } } } return results ; } public boolean isGroovyScript ( ICompilationUnit unit ) { if ( unit instanceof GroovyCompilationUnit ) { GroovyCompilationUnit gunit = ( GroovyCompilationUnit ) unit ; ModuleNode module = gunit . getModuleNode ( ) ; if ( module != null ) { for ( ClassNode clazz : ( Iterable < ClassNode > ) module . getClasses ( ) ) { if ( clazz . isScript ( ) ) { return true ; } } } } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . model ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . builder . GroovyClasspathContainer ; import org . codehaus . groovy . eclipse . core . util . ArrayUtils ; import org . codehaus . groovy . eclipse . core . util . ObjectUtils ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . ClasspathEntry ; public class GroovyRuntime { public static void removeGroovyNature ( final IProject project ) throws CoreException { GroovyCore . trace ( "<STR_LIT>" ) ; final IProjectDescription description = project . getDescription ( ) ; final String [ ] ids = description . getNatureIds ( ) ; for ( int i = <NUM_LIT:0> ; i < ids . length ; ++ i ) { if ( ids [ i ] . equals ( GroovyNature . GROOVY_NATURE ) ) { final String [ ] newIds = ( String [ ] ) ArrayUtils . remove ( ids , i ) ; description . setNatureIds ( newIds ) ; project . setDescription ( description , null ) ; return ; } } } public static void removeLibraryFromClasspath ( final IJavaProject javaProject , final IPath libraryPath ) throws JavaModelException { final IClasspathEntry [ ] oldEntries = javaProject . getRawClasspath ( ) ; for ( int i = <NUM_LIT:0> ; i < oldEntries . length ; i ++ ) { final IClasspathEntry entry = oldEntries [ i ] ; if ( entry . getPath ( ) . equals ( libraryPath ) ) { final IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) ArrayUtils . remove ( oldEntries , i ) ; javaProject . setRawClasspath ( newEntries , null ) ; return ; } } } public static IPath DSLD_CONTAINER_ID = new Path ( "<STR_LIT>" ) ; public static void addGroovyRuntime ( final IProject project ) { GroovyCore . trace ( "<STR_LIT>" ) ; try { if ( project == null || ! project . hasNature ( JavaCore . NATURE_ID ) ) return ; if ( project . hasNature ( GroovyNature . GROOVY_NATURE ) ) return ; addGroovyNature ( project ) ; final IJavaProject javaProject = JavaCore . create ( project ) ; addGroovyClasspathContainer ( javaProject ) ; addLibraryToClasspath ( javaProject , DSLD_CONTAINER_ID , true ) ; } catch ( final Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } public static boolean hasGroovyClasspathContainer ( final IJavaProject javaProject ) throws CoreException { return hasClasspathContainer ( javaProject , GroovyClasspathContainer . CONTAINER_ID ) ; } public static boolean hasClasspathContainer ( final IJavaProject javaProject , final IPath libraryPath ) throws CoreException { if ( javaProject == null || ! javaProject . getProject ( ) . isAccessible ( ) ) return false ; final IClasspathEntry [ ] entries = javaProject . getRawClasspath ( ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { final IClasspathEntry entry = entries [ i ] ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_CONTAINER ) { if ( ObjectUtils . equals ( entry . getPath ( ) , libraryPath ) || libraryPath . isPrefixOf ( entry . getPath ( ) ) ) { return true ; } } } return false ; } public static void addGroovyClasspathContainer ( final IJavaProject javaProject ) { try { if ( javaProject == null || hasGroovyClasspathContainer ( javaProject ) ) { return ; } final IClasspathEntry containerEntry = JavaCore . newContainerEntry ( GroovyClasspathContainer . CONTAINER_ID , true ) ; addClassPathEntry ( javaProject , containerEntry ) ; } catch ( final CoreException ce ) { GroovyCore . logException ( "<STR_LIT>" + ce . getMessage ( ) , ce ) ; throw new RuntimeException ( ce ) ; } } public static void removeGroovyClasspathContainer ( final IJavaProject javaProject ) { removeClasspathContainer ( GroovyClasspathContainer . CONTAINER_ID , javaProject ) ; } public static void removeClasspathContainer ( IPath containerPath , IJavaProject javaProject ) { try { if ( ! hasGroovyClasspathContainer ( javaProject ) ) { return ; } IClasspathEntry [ ] entries = javaProject . getRawClasspath ( ) ; int removeIndex = - <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { if ( entries [ i ] . getPath ( ) . equals ( containerPath ) ) { removeIndex = i ; break ; } } IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) ArrayUtils . remove ( entries , removeIndex ) ; javaProject . setRawClasspath ( newEntries , null ) ; } catch ( final CoreException ce ) { GroovyCore . logException ( "<STR_LIT>" + ce . getMessage ( ) , ce ) ; throw new RuntimeException ( ce ) ; } } public static void addLibraryToClasspath ( final IJavaProject javaProject , final IPath libraryPath , boolean isExported ) throws JavaModelException { boolean alreadyExists = includesClasspathEntry ( javaProject , libraryPath . lastSegment ( ) ) ; if ( alreadyExists ) { return ; } addClassPathEntry ( javaProject , new ClasspathEntry ( IPackageFragmentRoot . K_BINARY , IClasspathEntry . CPE_CONTAINER , libraryPath , ClasspathEntry . INCLUDE_ALL , ClasspathEntry . EXCLUDE_NONE , null , null , null , true , ClasspathEntry . NO_ACCESS_RULES , false , ClasspathEntry . NO_EXTRA_ATTRIBUTES ) ) ; } public static void addGroovyNature ( final IProject project ) throws CoreException { GroovyCore . trace ( "<STR_LIT>" ) ; final IProjectDescription description = project . getDescription ( ) ; final String [ ] ids = description . getNatureIds ( ) ; final String [ ] newIds = new String [ ids == null ? <NUM_LIT:1> : ids . length + <NUM_LIT:1> ] ; newIds [ <NUM_LIT:0> ] = GroovyNature . GROOVY_NATURE ; if ( ids != null ) { for ( int i = <NUM_LIT:1> ; i < newIds . length ; i ++ ) { newIds [ i ] = ids [ i - <NUM_LIT:1> ] ; } } description . setNatureIds ( newIds ) ; project . setDescription ( description , null ) ; } public static void addClassPathEntry ( IJavaProject project , IClasspathEntry newEntry ) throws JavaModelException { IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) ArrayUtils . add ( project . getRawClasspath ( ) , newEntry ) ; project . setRawClasspath ( newEntries , null ) ; } public static void addClassPathEntryToFront ( IJavaProject project , IClasspathEntry newEntry ) throws JavaModelException { IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) ArrayUtils . add ( project . getRawClasspath ( ) , <NUM_LIT:0> , newEntry ) ; project . setRawClasspath ( newEntries , null ) ; } public static void removeClassPathEntry ( IJavaProject project , IClasspathEntry newEntry ) throws JavaModelException { IClasspathEntry [ ] newEntries = ( IClasspathEntry [ ] ) ArrayUtils . removeElement ( project . getRawClasspath ( ) , newEntry ) ; project . setRawClasspath ( newEntries , null ) ; } private static boolean includesClasspathEntry ( IJavaProject project , String entryName ) throws JavaModelException { IClasspathEntry [ ] entries = project . getRawClasspath ( ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { IClasspathEntry entry = entries [ i ] ; if ( entry . getPath ( ) . lastSegment ( ) . equals ( entryName ) ) { return true ; } } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . templates ; public class CodeTemplateConstants { public static final String CATCHBLOCK_CONTEXTTYPE = "<STR_LIT>" ; public static final String METHODBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String CONSTRUCTORBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String GETTERBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String SETTERBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String NEWTYPE_CONTEXTTYPE = "<STR_LIT>" ; public static final String CLASSBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String INTERFACEBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String ENUMBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String ANNOTATIONBODY_CONTEXTTYPE = "<STR_LIT>" ; public static final String FILECOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String TYPECOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String FIELDCOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String METHODCOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String CONSTRUCTORCOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String OVERRIDECOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String DELEGATECOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String GETTERCOMMENT_CONTEXTTYPE = "<STR_LIT>" ; public static final String SETTERCOMMENT_CONTEXTTYPE = "<STR_LIT>" ; private static final String CODETEMPLATES_PREFIX = "<STR_LIT>" ; public static final String COMMENT_SUFFIX = "<STR_LIT>" ; public static final String CATCHBLOCK_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String METHODSTUB_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String NEWTYPE_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String CONSTRUCTORSTUB_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String GETTERSTUB_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String SETTERSTUB_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String FILECOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT:file>" + COMMENT_SUFFIX ; public static final String TYPECOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT:type>" + COMMENT_SUFFIX ; public static final String CLASSBODY_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String INTERFACEBODY_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String ENUMBODY_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String ANNOTATIONBODY_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" ; public static final String FIELDCOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT:field>" + COMMENT_SUFFIX ; public static final String METHODCOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String CONSTRUCTORCOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String OVERRIDECOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String DELEGATECOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String GETTERCOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String SETTERCOMMENT_ID = CODETEMPLATES_PREFIX + "<STR_LIT>" + COMMENT_SUFFIX ; public static final String EXCEPTION_TYPE = "<STR_LIT>" ; public static final String EXCEPTION_VAR = "<STR_LIT>" ; public static final String ENCLOSING_METHOD = "<STR_LIT>" ; public static final String ENCLOSING_TYPE = "<STR_LIT>" ; public static final String BODY_STATEMENT = "<STR_LIT>" ; public static final String FIELD = "<STR_LIT:field>" ; public static final String FIELD_TYPE = "<STR_LIT>" ; public static final String BARE_FIELD_NAME = "<STR_LIT>" ; public static final String PARAM = "<STR_LIT>" ; public static final String RETURN_TYPE = "<STR_LIT>" ; public static final String SEE_TO_OVERRIDDEN_TAG = "<STR_LIT>" ; public static final String SEE_TO_TARGET_TAG = "<STR_LIT>" ; public static final String TAGS = "<STR_LIT>" ; public static final String TYPENAME = "<STR_LIT>" ; public static final String FILENAME = "<STR_LIT>" ; public static final String PACKAGENAME = "<STR_LIT>" ; public static final String PROJECTNAME = "<STR_LIT>" ; public static final String PACKAGE_DECLARATION = "<STR_LIT>" ; public static final String TYPE_DECLARATION = "<STR_LIT>" ; public static final String CLASS_BODY = "<STR_LIT>" ; public static final String INTERFACE_BODY = "<STR_LIT>" ; public static final String ENUM_BODY = "<STR_LIT>" ; public static final String ANNOTATION_BODY = "<STR_LIT>" ; public static final String TYPE_COMMENT = "<STR_LIT>" ; public static final String FILE_COMMENT = "<STR_LIT>" ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . templates ; import java . io . IOException ; import java . util . Map ; import org . codehaus . groovy . control . CompilationFailedException ; import org . eclipse . core . runtime . IProgressMonitor ; public interface IGroovyTemplateManager { public String processTemplate ( Map < String , Object > bindings , IProgressMonitor progressMonitor ) throws CompilationFailedException , IOException ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import static org . codehaus . groovy . frameworkadapter . util . SpecifiedVersion . UNSPECIFIED ; import static org . eclipse . core . runtime . FileLocator . resolve ; import groovy . lang . GroovySystem ; import java . io . File ; import java . io . FilenameFilter ; import java . io . IOException ; import java . net . URL ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Enumeration ; import java . util . List ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . GroovyCoreActivator ; import org . codehaus . groovy . frameworkadapter . util . CompilerLevelUtils ; import org . codehaus . groovy . frameworkadapter . util . SpecifiedVersion ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IStatus ; import org . eclipse . core . runtime . Platform ; import org . eclipse . core . runtime . Status ; import org . eclipse . jdt . groovy . core . Activator ; import org . eclipse . osgi . framework . internal . core . FrameworkProperties ; import org . eclipse . osgi . internal . baseadaptor . StateManager ; import org . eclipse . osgi . service . resolver . BundleDescription ; import org . eclipse . osgi . service . resolver . DisabledInfo ; import org . eclipse . osgi . service . resolver . State ; import org . osgi . framework . Bundle ; import org . osgi . framework . BundleException ; import org . osgi . framework . Version ; public class CompilerUtils { public static String getGroovyVersion ( ) { BundleDescription groovyBundle = getActiveGroovyBundleDescription ( ) ; return groovyBundle != null ? groovyBundle . getVersion ( ) . toString ( ) : "<STR_LIT>" ; } public static SpecifiedVersion getActiveGroovyVersion ( ) { BundleDescription groovyBundle = getActiveGroovyBundleDescription ( ) ; return SpecifiedVersion . findVersion ( groovyBundle . getVersion ( ) ) ; } public static boolean isGroovyVersionDisabledOrMissing ( SpecifiedVersion version ) { BundleDescription disabledBundle = null ; disabledBundle = getDisabledBundleDescription ( version ) ; if ( disabledBundle != null ) { return true ; } Bundle [ ] active = Platform . getBundles ( "<STR_LIT>" , version . toVersionString ( ) ) ; if ( active == null ) { return true ; } for ( Bundle bundle : active ) { Version bundleVersion = bundle . getVersion ( ) ; if ( bundleVersion . getMajor ( ) == version . majorVersion && bundleVersion . getMajor ( ) == version . majorVersion ) { return false ; } } return true ; } public static BundleDescription getBundleDescription ( SpecifiedVersion version ) { BundleDescription [ ] active = getAllGroovyBundleDescriptions ( ) ; for ( BundleDescription bundle : active ) { if ( bundle . getVersion ( ) . getMajor ( ) == version . majorVersion && bundle . getVersion ( ) . getMinor ( ) == version . minorVersion ) { return bundle ; } } return null ; } private static BundleDescription getActiveGroovyBundleDescription ( ) { BundleDescription [ ] active = getAllGroovyBundleDescriptions ( ) ; if ( active == null || active . length == <NUM_LIT:0> ) { return null ; } BundleDescription [ ] disabled = Platform . getPlatformAdmin ( ) . getState ( false ) . getDisabledBundles ( ) ; for ( BundleDescription bundle : active ) { boolean isAvailable = true ; for ( BundleDescription d : disabled ) { if ( d . getVersion ( ) . equals ( bundle . getVersion ( ) ) && d . getSymbolicName ( ) . equals ( bundle . getSymbolicName ( ) ) ) { isAvailable = false ; break ; } } if ( isAvailable ) { return bundle ; } } return null ; } public static Bundle getActiveGroovyBundle ( ) { BundleDescription bundleDesc = getActiveGroovyBundleDescription ( ) ; if ( bundleDesc == null ) { return null ; } Bundle [ ] allBundles = Platform . getBundles ( "<STR_LIT>" , bundleDesc . getVersion ( ) . toString ( ) ) ; if ( allBundles == null || allBundles . length == <NUM_LIT:0> ) { return null ; } return allBundles [ <NUM_LIT:0> ] ; } public static URL getExportedGroovyAllJar ( ) { try { Bundle groovyBundle = CompilerUtils . getActiveGroovyBundle ( ) ; if ( groovyBundle == null ) { throw new RuntimeException ( "<STR_LIT>" ) ; } Enumeration < URL > enu = groovyBundle . findEntries ( "<STR_LIT>" , "<STR_LIT>" , false ) ; if ( enu == null ) { enu = groovyBundle . findEntries ( "<STR_LIT>" , "<STR_LIT>" , false ) ; } while ( enu . hasMoreElements ( ) ) { URL jar = enu . nextElement ( ) ; if ( jar . getFile ( ) . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> && jar . getFile ( ) . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> && jar . getFile ( ) . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> ) { jar = resolve ( jar ) ; return jar ; } } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } throw new RuntimeException ( "<STR_LIT>" ) ; } public static URL [ ] getExtraJarsForClasspath ( ) { try { Bundle groovyBundle = CompilerUtils . getActiveGroovyBundle ( ) ; Enumeration < URL > enu = groovyBundle . findEntries ( "<STR_LIT>" , "<STR_LIT>" , false ) ; if ( enu == null ) { enu = groovyBundle . findEntries ( "<STR_LIT>" , "<STR_LIT>" , false ) ; } List < URL > urls = new ArrayList < URL > ( <NUM_LIT:9> ) ; while ( enu . hasMoreElements ( ) ) { URL jar = enu . nextElement ( ) ; if ( ! jar . getFile ( ) . contains ( "<STR_LIT>" ) ) { jar = resolve ( jar ) ; urls . add ( jar ) ; } } return urls . toArray ( new URL [ urls . size ( ) ] ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } public static URL getJarInGroovyLib ( String jarName ) throws IOException { Bundle groovyBundle = CompilerUtils . getActiveGroovyBundle ( ) ; Enumeration < URL > enu = groovyBundle . findEntries ( "<STR_LIT>" , jarName , false ) ; if ( enu == null ) { enu = groovyBundle . findEntries ( "<STR_LIT>" , jarName , false ) ; } if ( enu . hasMoreElements ( ) ) { URL jar = enu . nextElement ( ) ; jar = resolve ( jar ) ; return jar ; } return null ; } public static URL findDSLDFolder ( ) { Bundle groovyBundle = CompilerUtils . getActiveGroovyBundle ( ) ; Enumeration < URL > enu = groovyBundle . findEntries ( "<STR_LIT:.>" , "<STR_LIT>" , false ) ; if ( enu != null && enu . hasMoreElements ( ) ) { URL folder = enu . nextElement ( ) ; try { folder = resolve ( folder ) ; return folder ; } catch ( IOException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } return null ; } public static IStatus switchVersions ( SpecifiedVersion fromVersion , SpecifiedVersion toVersion ) { try { State state = ( ( StateManager ) Platform . getPlatformAdmin ( ) ) . getSystemState ( ) ; BundleDescription toBundle = getBundleDescription ( toVersion ) ; BundleDescription [ ] allBundles = getAllGroovyBundleDescriptions ( ) ; if ( toBundle == null ) { throw new Exception ( "<STR_LIT>" + toVersion + "<STR_LIT>" ) ; } for ( BundleDescription bundle : allBundles ) { DisabledInfo info = createDisabledInfo ( state , bundle . getBundleId ( ) ) ; if ( bundle . equals ( toBundle ) ) { Platform . getPlatformAdmin ( ) . removeDisabledInfo ( info ) ; } else { Platform . getPlatformAdmin ( ) . addDisabledInfo ( info ) ; } } CompilerLevelUtils . writeConfigurationVersion ( toVersion , GroovyCoreActivator . getDefault ( ) . getBundle ( ) . getBundleContext ( ) . getBundle ( <NUM_LIT:0> ) . getBundleContext ( ) ) ; return Status . OK_STATUS ; } catch ( Exception e ) { GroovyCore . logException ( e . getMessage ( ) , e ) ; return new Status ( IStatus . ERROR , GroovyCoreActivator . PLUGIN_ID , e . getMessage ( ) + "<STR_LIT>" , e ) ; } } public static String getDotGroovyLocation ( ) { String home = FrameworkProperties . getProperty ( "<STR_LIT>" ) ; if ( home != null ) { home += "<STR_LIT>" ; } return home ; } public static File [ ] findJarsInDotGroovyLocation ( ) { String home = getDotGroovyLibLocation ( ) ; if ( home != null ) { File libDir = new File ( home ) ; if ( libDir . isDirectory ( ) ) { File [ ] files = libDir . listFiles ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return ! ( new File ( dir , name ) . isDirectory ( ) ) && name . endsWith ( "<STR_LIT>" ) ; } } ) ; return files ; } } return new File [ <NUM_LIT:0> ] ; } private static BundleDescription [ ] getAllGroovyBundleDescriptions ( ) { BundleDescription [ ] bundles = Platform . getPlatformAdmin ( ) . getState ( false ) . getBundles ( "<STR_LIT>" ) ; Arrays . sort ( bundles , new Comparator < BundleDescription > ( ) { public int compare ( BundleDescription l , BundleDescription r ) { return r . getVersion ( ) . compareTo ( l . getVersion ( ) ) ; } } ) ; return bundles ; } private static BundleDescription getDisabledBundleDescription ( SpecifiedVersion version ) { BundleDescription [ ] bundles = Platform . getPlatformAdmin ( ) . getState ( false ) . getDisabledBundles ( ) ; for ( BundleDescription bundle : bundles ) { if ( bundle . getSymbolicName ( ) . equals ( "<STR_LIT>" ) && bundle . getVersion ( ) . getMajor ( ) == version . majorVersion && bundle . getVersion ( ) . getMinor ( ) == version . minorVersion ) { return bundle ; } } return null ; } private static DisabledInfo createDisabledInfo ( State state , long bundleId ) { BundleDescription desc = state . getBundle ( bundleId ) ; DisabledInfo info = new DisabledInfo ( "<STR_LIT>" , "<STR_LIT>" , desc ) ; return info ; } private static String getDotGroovyLibLocation ( ) { String home = getDotGroovyLocation ( ) ; if ( home != null ) { home += "<STR_LIT>" ; } return home ; } public static SpecifiedVersion getCompilerLevel ( IProject project ) { SpecifiedVersion version = UNSPECIFIED ; if ( GroovyNature . hasGroovyNature ( project ) ) { String groovyCompilerLevelStr = Activator . getDefault ( ) . getGroovyCompilerLevel ( project ) ; if ( groovyCompilerLevelStr != null ) { version = SpecifiedVersion . findVersionFromString ( groovyCompilerLevelStr ) ; } } return version ; } public static void setCompilerLevel ( IProject project , SpecifiedVersion version ) { Activator . getDefault ( ) . setGroovyCompilerLevel ( project , version . versionName ) ; } public static boolean projectVersionMatchesWorkspaceVersion ( SpecifiedVersion version ) { if ( version == UNSPECIFIED ) { return true ; } else { SpecifiedVersion workspaceCompilerLevel = getWorkspaceCompilerLevel ( ) ; return version == workspaceCompilerLevel ; } } static SpecifiedVersion getWorkspaceCompilerLevel ( ) { String groovyVersion = GroovySystem . getVersion ( ) ; int dotIndex = groovyVersion . lastIndexOf ( '<CHAR_LIT:.>' ) ; if ( dotIndex > <NUM_LIT:0> ) { groovyVersion = groovyVersion . substring ( <NUM_LIT:0> , dotIndex ) ; } return SpecifiedVersion . findVersionFromString ( groovyVersion ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import java . util . Iterator ; import java . util . Map ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . model . GroovyProjectFacade ; import org . codehaus . jdt . groovy . internal . compiler . ast . GroovyCompilationUnitDeclaration ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . WorkingCopyOwner ; import org . eclipse . jdt . core . dom . CompilationUnitResolver ; import org . eclipse . jdt . groovy . core . util . ContentTypeUtils ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . Compiler ; import org . eclipse . jdt . internal . compiler . DefaultErrorHandlingPolicies ; import org . eclipse . jdt . internal . compiler . ICompilerRequestor ; import org . eclipse . jdt . internal . compiler . env . INameEnvironment ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . problem . DefaultProblemFactory ; import org . eclipse . jdt . internal . core . JavaProject ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . objectweb . asm . Opcodes ; public class GroovySnippetCompiler { private static class Requestor implements ICompilerRequestor { public void acceptResult ( CompilationResult result ) { } } private INameEnvironment nameEnvironment ; public GroovySnippetCompiler ( GroovyProjectFacade project ) { try { nameEnvironment = new SearchableEnvironment ( ( JavaProject ) project . getProject ( ) , ( WorkingCopyOwner ) null ) ; } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" + project . getProject ( ) . getElementName ( ) , e ) ; } } public ModuleNode compile ( String source , String sourcePath ) { GroovyCompilationUnitDeclaration decl = internalCompile ( source , sourcePath ) ; ModuleNode node = decl . getModuleNode ( ) ; for ( ClassNode classNode : ( Iterable < ClassNode > ) node . getClasses ( ) ) { for ( Iterator < MethodNode > methodIter = classNode . getMethods ( ) . iterator ( ) ; methodIter . hasNext ( ) ; ) { MethodNode method = methodIter . next ( ) ; if ( ( method . getModifiers ( ) & Opcodes . ACC_SYNTHETIC ) != <NUM_LIT:0> ) { methodIter . remove ( ) ; } } } return node ; } public CompilationResult compileForErrors ( String source , String sourcePath ) { GroovyCompilationUnitDeclaration unit = internalCompile ( source , sourcePath ) ; return unit . compilationResult ( ) ; } @ SuppressWarnings ( { "<STR_LIT:unchecked>" } ) private GroovyCompilationUnitDeclaration internalCompile ( String source , String sourcePath ) { if ( sourcePath == null ) { sourcePath = "<STR_LIT>" ; } else if ( ! ContentTypeUtils . isGroovyLikeFileName ( sourcePath ) ) { sourcePath = sourcePath . concat ( "<STR_LIT>" ) ; } Map options = JavaCore . getOptions ( ) ; options . put ( CompilerOptions . OPTIONG_BuildGroovyFiles , CompilerOptions . ENABLED ) ; Compiler compiler = new CompilationUnitResolver ( nameEnvironment , DefaultErrorHandlingPolicies . proceedWithAllProblems ( ) , new CompilerOptions ( options ) , new Requestor ( ) , new DefaultProblemFactory ( ) , null , true ) ; GroovyCompilationUnitDeclaration decl = ( GroovyCompilationUnitDeclaration ) compiler . resolve ( new MockCompilationUnit ( source . toCharArray ( ) , sourcePath . toCharArray ( ) ) , true , false , false ) ; return decl ; } public void cleanup ( ) { nameEnvironment . cleanup ( ) ; } public ModuleNode compile ( String source ) { return compile ( source , null ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import org . eclipse . jdt . internal . compiler . env . ICompilationUnit ; class MockCompilationUnit implements ICompilationUnit { private char [ ] contents ; private char [ ] fileName ; MockCompilationUnit ( char [ ] contents , char [ ] fileName ) { this . contents = contents ; this . fileName = fileName ; } public char [ ] getContents ( ) { return contents ; } public char [ ] getMainTypeName ( ) { return new char [ <NUM_LIT:0> ] ; } public char [ ] [ ] getPackageName ( ) { return new char [ <NUM_LIT:0> ] [ ] ; } public char [ ] getFileName ( ) { return fileName ; } public boolean ignoreOptionalProblems ( ) { return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . frameworkadapter . util . SpecifiedVersion ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . core . runtime . preferences . InstanceScope ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . compiler . CompilationParticipant ; import org . eclipse . jdt . groovy . core . Activator ; public class CompilerCheckerParticipant extends CompilationParticipant { public static final String COMPILER_MISMATCH_PROBLEM = "<STR_LIT>" ; private static IEclipsePreferences store ; private static IEclipsePreferences getPreferences ( ) { IScopeContext scope = InstanceScope . INSTANCE ; return scope . getNode ( Activator . PLUGIN_ID ) ; } @ Override public boolean isActive ( IJavaProject javaProject ) { if ( store == null ) { store = getPreferences ( ) ; } return store . getBoolean ( Activator . GROOVY_CHECK_FOR_COMPILER_MISMATCH , true ) && GroovyNature . hasGroovyNature ( javaProject . getProject ( ) ) ; } @ Override public int aboutToBuild ( IJavaProject javaProject ) { IProject project = javaProject . getProject ( ) ; SpecifiedVersion projectLevel = CompilerUtils . getCompilerLevel ( project ) ; if ( projectLevel == SpecifiedVersion . UNSPECIFIED ) { SpecifiedVersion workspaceLevel = CompilerUtils . getWorkspaceCompilerLevel ( ) ; CompilerUtils . setCompilerLevel ( project , workspaceLevel ) ; } else { try { boolean compilerMatch = CompilerUtils . projectVersionMatchesWorkspaceVersion ( projectLevel ) ; IMarker [ ] findMarkers = project . findMarkers ( COMPILER_MISMATCH_PROBLEM , true , IResource . DEPTH_ZERO ) ; if ( compilerMatch ) { for ( IMarker marker : findMarkers ) { marker . delete ( ) ; } } else if ( findMarkers . length == <NUM_LIT:0> ) { SpecifiedVersion workspaceLevel = CompilerUtils . getWorkspaceCompilerLevel ( ) ; IMarker marker = project . getProject ( ) . createMarker ( COMPILER_MISMATCH_PROBLEM ) ; marker . setAttribute ( IMarker . MESSAGE , "<STR_LIT>" + "<STR_LIT>" + projectLevel . toReadableVersionString ( ) + "<STR_LIT>" + workspaceLevel . toReadableVersionString ( ) + "<STR_LIT>" ) ; marker . setAttribute ( IMarker . SEVERITY , IMarker . SEVERITY_ERROR ) ; marker . setAttribute ( IMarker . LOCATION , project . getName ( ) ) ; } } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } return super . aboutToBuild ( javaProject ) ; } @ Override public void cleanStarting ( IJavaProject javaProject ) { } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . compiler ; import java . util . Hashtable ; import java . util . Iterator ; import org . codehaus . groovy . antlr . AntlrParserPlugin ; import org . codehaus . groovy . antlr . GroovySourceAST ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . control . ParserPlugin ; import org . codehaus . groovy . control . SourceUnit ; import org . codehaus . jdt . groovy . internal . compiler . ast . GroovyCompilationUnitDeclaration ; import org . codehaus . jdt . groovy . internal . compiler . ast . GroovyParser ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . compiler . CategorizedProblem ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . DefaultErrorHandlingPolicies ; import org . eclipse . jdt . internal . compiler . env . ICompilationUnit ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . problem . DefaultProblemFactory ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; import org . objectweb . asm . Opcodes ; public class GroovySnippetParser { private static class MockCompilationUnit implements ICompilationUnit { private char [ ] contents ; private char [ ] fileName ; MockCompilationUnit ( char [ ] contents , char [ ] fileName ) { this . contents = contents ; this . fileName = fileName ; } public char [ ] getContents ( ) { return contents ; } public char [ ] getMainTypeName ( ) { return new char [ <NUM_LIT:0> ] ; } public char [ ] [ ] getPackageName ( ) { return new char [ <NUM_LIT:0> ] [ ] ; } public char [ ] getFileName ( ) { return fileName ; } public boolean ignoreOptionalProblems ( ) { return false ; } } private CategorizedProblem [ ] problems ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public ModuleNode parse ( String source ) { Hashtable table = JavaCore . getOptions ( ) ; table . put ( CompilerOptions . OPTIONG_BuildGroovyFiles , CompilerOptions . ENABLED ) ; CompilerOptions options = new CompilerOptions ( table ) ; ProblemReporter reporter = new ProblemReporter ( DefaultErrorHandlingPolicies . proceedWithAllProblems ( ) , options , new DefaultProblemFactory ( ) ) ; GroovyParser parser = new GroovyParser ( options , reporter , false , true ) ; ICompilationUnit unit = new MockCompilationUnit ( source . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) ) ; CompilationResult compilationResult = new CompilationResult ( unit , <NUM_LIT:0> , <NUM_LIT:0> , options . maxProblemsPerUnit ) ; GroovyCompilationUnitDeclaration decl = ( GroovyCompilationUnitDeclaration ) parser . dietParse ( unit , compilationResult ) ; ModuleNode node = decl . getModuleNode ( ) ; if ( node == null ) { return null ; } for ( ClassNode classNode : ( Iterable < ClassNode > ) node . getClasses ( ) ) { for ( Iterator < MethodNode > methodIter = classNode . getMethods ( ) . iterator ( ) ; methodIter . hasNext ( ) ; ) { MethodNode method = methodIter . next ( ) ; if ( ( method . getModifiers ( ) & Opcodes . ACC_SYNTHETIC ) != <NUM_LIT:0> ) { methodIter . remove ( ) ; } } } problems = compilationResult . getErrors ( ) ; return node ; } public CategorizedProblem [ ] getProblems ( ) { return problems ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public GroovySourceAST parseForCST ( String source ) { Hashtable < String , String > table = JavaCore . getOptions ( ) ; table . put ( CompilerOptions . OPTIONG_BuildGroovyFiles , CompilerOptions . ENABLED ) ; CompilerOptions options = new CompilerOptions ( table ) ; ProblemReporter reporter = new ProblemReporter ( DefaultErrorHandlingPolicies . proceedWithAllProblems ( ) , options , new DefaultProblemFactory ( ) ) ; GroovyParser parser = new GroovyParser ( null , reporter , false , true ) ; ICompilationUnit unit = new MockCompilationUnit ( source . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) ) ; CompilationResult compilationResult = new CompilationResult ( unit , <NUM_LIT:0> , <NUM_LIT:0> , options . maxProblemsPerUnit ) ; GroovyCompilationUnitDeclaration decl = ( GroovyCompilationUnitDeclaration ) parser . dietParse ( unit , compilationResult ) ; SourceUnit sourceUnit = decl . getSourceUnit ( ) ; ParserPlugin parserPlugin = ( ParserPlugin ) ReflectionUtils . getPrivateField ( SourceUnit . class , "<STR_LIT>" , sourceUnit ) ; if ( parserPlugin instanceof AntlrParserPlugin ) { return ( GroovySourceAST ) ReflectionUtils . getPrivateField ( AntlrParserPlugin . class , "<STR_LIT>" , parserPlugin ) ; } else { return null ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . codehaus . groovy . eclipse . core . ISourceBuffer ; import org . codehaus . groovy . eclipse . core . impl . ReverseSourceBuffer ; public class TokenStream { private static final Token TOKEN_EOF = new Token ( Token . EOF , - <NUM_LIT:1> , - <NUM_LIT:1> , null ) ; private ISourceBuffer buffer ; private int offset ; private char ch ; private Token last ; private Token next = null ; public TokenStream ( ISourceBuffer buffer , int offset ) { this . buffer = buffer ; this . offset = offset ; this . ch = buffer . charAt ( offset ) ; } public Token peek ( ) throws TokenStreamException { int offset = this . offset ; char ch = this . ch ; Token last = this . last ; Token next = this . next ; Token ret = next ( ) ; this . offset = offset ; this . ch = ch ; this . last = last ; this . next = next ; return ret ; } public char getCurrentChar ( ) { return ch ; } public Token next ( ) throws TokenStreamException { if ( next != null ) { last = next ; next = null ; return last ; } if ( offset == - <NUM_LIT:1> ) { return TOKEN_EOF ; } if ( Character . isWhitespace ( ch ) ) { skipWhite ( ) ; if ( offset == - <NUM_LIT:1> ) { return TOKEN_EOF ; } } if ( isLineBreakChar ( ) ) { last = skipLineBreak ( ) ; next = skipLineComment ( ) ; return last ; } if ( ch == '<CHAR_LIT:/>' && la ( <NUM_LIT:1> ) == '<CHAR_LIT>' ) { last = scanBlockComment ( ) ; return last ; } if ( Character . isJavaIdentifierPart ( ch ) ) { last = scanIdent ( ) ; } else { switch ( ch ) { case '<CHAR_LIT:.>' : last = scanDot ( ) ; break ; case '<CHAR_LIT:;>' : nextChar ( ) ; last = new Token ( Token . SEMI , offset + <NUM_LIT:1> , offset + <NUM_LIT:2> , buffer . subSequence ( offset + <NUM_LIT:1> , offset + <NUM_LIT:2> ) . toString ( ) ) ; break ; case '<CHAR_LIT:}>' : last = scanPair ( '<CHAR_LIT>' , '<CHAR_LIT:}>' , Token . BRACE_BLOCK ) ; break ; case '<CHAR_LIT:)>' : last = scanPair ( '<CHAR_LIT:(>' , '<CHAR_LIT:)>' , Token . PAREN_BLOCK ) ; break ; case '<CHAR_LIT:]>' : last = scanPair ( '<CHAR_LIT:[>' , '<CHAR_LIT:]>' , Token . BRACK_BLOCK ) ; break ; case '<STR_LIT>' : last = scanQuote ( '<STR_LIT>' ) ; break ; case '<CHAR_LIT:">' : last = scanQuote ( '<CHAR_LIT:">' ) ; break ; default : throw new TokenStreamException ( ch ) ; } } return last ; } private Token scanDot ( ) { nextChar ( ) ; if ( offset == - <NUM_LIT:1> ) { return TOKEN_EOF ; } if ( ch == '<CHAR_LIT:.>' ) { nextChar ( ) ; return new Token ( Token . DOUBLE_DOT , offset + <NUM_LIT:1> , offset + <NUM_LIT:3> , buffer . subSequence ( offset + <NUM_LIT:1> , offset + <NUM_LIT:3> ) . toString ( ) ) ; } if ( ch == '<CHAR_LIT>' ) { nextChar ( ) ; return new Token ( Token . SAFE_DEREF , offset + <NUM_LIT:1> , offset + <NUM_LIT:3> , buffer . subSequence ( offset + <NUM_LIT:1> , offset + <NUM_LIT:3> ) . toString ( ) ) ; } if ( ch == '<CHAR_LIT>' ) { nextChar ( ) ; return new Token ( Token . SPREAD , offset + <NUM_LIT:1> , offset + <NUM_LIT:3> , buffer . subSequence ( offset + <NUM_LIT:1> , offset + <NUM_LIT:3> ) . toString ( ) ) ; } return new Token ( Token . DOT , offset + <NUM_LIT:1> , offset + <NUM_LIT:2> , buffer . subSequence ( offset + <NUM_LIT:1> , offset + <NUM_LIT:2> ) . toString ( ) ) ; } private Token skipLineBreak ( ) { int endOffset = offset + <NUM_LIT:1> ; char firstChar = ch ; nextChar ( ) ; if ( offset != - <NUM_LIT:1> && isLineBreakChar ( ) ) { char secondChar = ch ; nextChar ( ) ; return new Token ( Token . LINE_BREAK , offset + <NUM_LIT:1> , endOffset , new String ( new char [ ] { firstChar , secondChar } ) ) ; } return new Token ( Token . LINE_BREAK , offset + <NUM_LIT:1> , endOffset , new String ( new char [ ] { firstChar } ) ) ; } private boolean isLineBreakChar ( ) { return ch == '<STR_LIT:\n>' || ch == '<STR_LIT>' ; } public Token last ( ) { return last ; } private void nextChar ( ) { if ( offset == - <NUM_LIT:1> ) throw new IllegalStateException ( "<STR_LIT>" ) ; if ( offset == <NUM_LIT:0> ) { offset = - <NUM_LIT:1> ; } else { ch = buffer . charAt ( -- offset ) ; } } private Token scanPair ( char open , char close , int type ) throws TokenStreamException { int endOffset = offset + <NUM_LIT:1> ; int pairCount = <NUM_LIT:1> ; while ( pairCount > <NUM_LIT:0> && offset > <NUM_LIT:0> ) { ch = buffer . charAt ( -- offset ) ; if ( ch == open ) { -- pairCount ; } else if ( ch == close ) { ++ pairCount ; } } if ( offset != <NUM_LIT:0> ) { ch = buffer . charAt ( -- offset ) ; } else { offset = - <NUM_LIT:1> ; if ( pairCount != <NUM_LIT:0> ) { throw new TokenStreamException ( "<STR_LIT>" ) ; } } return new Token ( type , offset + <NUM_LIT:1> , endOffset , buffer . subSequence ( offset + <NUM_LIT:1> , endOffset ) . toString ( ) ) ; } private Token scanIdent ( ) { int endOffset = offset + <NUM_LIT:1> ; do { nextChar ( ) ; } while ( offset > - <NUM_LIT:1> && Character . isJavaIdentifierPart ( ch ) ) ; return new Token ( Token . IDENT , offset + <NUM_LIT:1> , endOffset , buffer . subSequence ( offset + <NUM_LIT:1> , endOffset ) . toString ( ) ) ; } private Token scanQuote ( char quote ) throws TokenStreamException { Pattern singleQuote ; Pattern tripleQuote ; if ( quote == '<STR_LIT>' ) { singleQuote = Pattern . compile ( "<STR_LIT>" ) ; tripleQuote = Pattern . compile ( "<STR_LIT>" ) ; } else { singleQuote = Pattern . compile ( "<STR_LIT>" ) ; tripleQuote = Pattern . compile ( "<STR_LIT>" ) ; } Token token = matchQuote ( tripleQuote ) ; if ( token != null ) { return token ; } token = matchQuote ( singleQuote ) ; if ( token != null ) { return token ; } throw new TokenStreamException ( "<STR_LIT>" + offset ) ; } private Token matchQuote ( Pattern quotePattern ) { ISourceBuffer matchBuffer = new ReverseSourceBuffer ( this . buffer , offset ) ; Matcher matcher = quotePattern . matcher ( matchBuffer ) ; if ( matcher . find ( ) ) { String match = matcher . group ( <NUM_LIT:0> ) ; int endOffset = offset + <NUM_LIT:1> ; int startOffset = offset - match . length ( ) + <NUM_LIT:1> ; offset = startOffset ; if ( offset == <NUM_LIT:0> ) { offset = - <NUM_LIT:1> ; } if ( offset != - <NUM_LIT:1> ) { -- offset ; ch = buffer . charAt ( offset ) ; } return new Token ( Token . QUOTED_STRING , startOffset , endOffset , match ) ; } return null ; } private void skipWhite ( ) { if ( isLineBreakChar ( ) ) return ; do { nextChar ( ) ; } while ( Character . isWhitespace ( ch ) && ! isLineBreakChar ( ) && offset > - <NUM_LIT:1> ) ; } private Token skipLineComment ( ) { ISourceBuffer matchBuffer = new ReverseSourceBuffer ( this . buffer , offset ) ; Pattern pattern = Pattern . compile ( "<STR_LIT>" ) ; Matcher matcher = pattern . matcher ( matchBuffer ) ; if ( matcher . find ( ) && matcher . start ( ) == <NUM_LIT:0> ) { String match = matcher . group ( <NUM_LIT:0> ) ; int endOffset = offset + <NUM_LIT:1> ; int startOffset = offset - match . length ( ) + <NUM_LIT:1> ; offset = startOffset ; if ( offset != <NUM_LIT:0> ) { ch = buffer . charAt ( -- offset ) ; } else { ch = buffer . charAt ( offset -- ) ; } return new Token ( Token . LINE_COMMENT , startOffset , endOffset , match ) ; } return null ; } private Token scanBlockComment ( ) { ISourceBuffer matchBuffer = new ReverseSourceBuffer ( this . buffer , offset ) ; Pattern pattern = Pattern . compile ( "<STR_LIT>" ) ; Matcher matcher = pattern . matcher ( matchBuffer ) ; if ( matcher . find ( ) ) { String match = matcher . group ( <NUM_LIT:0> ) ; int endOffset = offset + <NUM_LIT:1> ; int startOffset = offset - match . length ( ) + <NUM_LIT:1> ; offset = startOffset ; if ( offset != <NUM_LIT:0> ) { ch = buffer . charAt ( -- offset ) ; } else { ch = buffer . charAt ( offset -- ) ; } return new Token ( Token . BLOCK_COMMENT , startOffset , endOffset , match ) ; } else { ch = buffer . charAt ( -- offset ) ; } return null ; } private char la ( int index ) { if ( offset - index >= <NUM_LIT:0> ) { return buffer . charAt ( offset - index ) ; } return <NUM_LIT:0> ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . io . Serializable ; public class Token implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; private static final String [ ] names = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; public static final int EOF = <NUM_LIT:0> ; public static final int IDENT = <NUM_LIT:1> ; public static final int DOT = <NUM_LIT:2> ; public static final int SEMI = <NUM_LIT:3> ; public static final int QUOTED_STRING = <NUM_LIT:4> ; public static final int PAREN_BLOCK = <NUM_LIT:5> ; public static final int BRACE_BLOCK = <NUM_LIT:6> ; public static final int BRACK_BLOCK = <NUM_LIT:7> ; public static final int LINE_COMMENT = <NUM_LIT:8> ; public static final int BLOCK_COMMENT = <NUM_LIT:9> ; public static final int LINE_BREAK = <NUM_LIT:10> ; public static final int DOUBLE_DOT = <NUM_LIT:11> ; public static final int SAFE_DEREF = <NUM_LIT:12> ; public static final int SPREAD = <NUM_LIT> ; public int type ; public int startOffset ; public int endOffset ; public String text ; public Token ( int type , int startOffset , int endOffset , String text ) { this . type = type ; this . startOffset = startOffset ; this . endOffset = endOffset ; this . text = text ; } public boolean equals ( Object obj ) { try { if ( obj != null ) { return type == ( ( Token ) obj ) . type ; } } catch ( ClassCastException e ) { } return false ; } public int hashCode ( ) { return names [ type ] . hashCode ( ) + type ; } public String toString ( ) { return names [ type ] + "<STR_LIT:[>" + startOffset + "<STR_LIT::>" + endOffset + "<STR_LIT>" + text ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; public class ParseException extends Exception { private static final long serialVersionUID = - <NUM_LIT> ; private Token token ; public ParseException ( Token token ) { super ( "<STR_LIT>" + token . toString ( ) ) ; this . token = token ; } public Token getToken ( ) { return token ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . eclipse . core . GroovyCore ; @ Deprecated public class ReflectionUtils { private static Map < String , Field > fieldMap = new HashMap < String , Field > ( ) ; @ Deprecated public static < T > Object getPrivateField ( Class < T > clazz , String fieldName , Object target ) { String key = clazz . getCanonicalName ( ) + fieldName ; Field field = fieldMap . get ( key ) ; try { if ( field == null ) { field = clazz . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; fieldMap . put ( key , field ) ; } return field . get ( target ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } return null ; } @ Deprecated public static < T > void setPrivateField ( Class < T > clazz , String fieldName , Object target , Object newValue ) { String key = clazz . getCanonicalName ( ) + fieldName ; Field field = fieldMap . get ( key ) ; try { if ( field == null ) { field = clazz . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; fieldMap . put ( key , field ) ; } field . set ( target , newValue ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } @ Deprecated public static < T > Object executePrivateMethod ( Class < T > clazz , String methodName , Class < ? > [ ] types , Object target , Object [ ] args ) { try { Method method = clazz . getDeclaredMethod ( methodName , types ) ; method . setAccessible ( true ) ; return method . invoke ( target , args ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . util . ArrayList ; import java . util . Collection ; import java . util . LinkedList ; import java . util . List ; public class ListUtil { public static < T > List < T > array ( final T ... objects ) { final List < T > list = new ArrayList < T > ( ) ; add ( list , objects ) ; return list ; } public static < T > List < T > array ( final Collection < T > collection ) { final List < T > list = new ArrayList < T > ( ) ; if ( collection != null && collection . size ( ) > <NUM_LIT:0> ) list . addAll ( collection ) ; return list ; } public static < T > List < T > linked ( final T ... objects ) { final List < T > list = new LinkedList < T > ( ) ; add ( list , objects ) ; return list ; } public static < T > List < T > linked ( final Collection < T > collection ) { final List < T > list = new LinkedList < T > ( ) ; if ( collection != null && collection . size ( ) > <NUM_LIT:0> ) list . addAll ( collection ) ; return list ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static < T > List < T > newEmptyList ( ) { return newList ( ) ; } public static < T > List < T > newList ( final T ... objects ) { return array ( objects ) ; } public static < T > List < T > newList ( final Collection < T > objects ) { return array ( objects ) ; } public static < T > List < T > list ( final T ... objects ) { return array ( objects ) ; } public static < T > List < T > list ( final Collection < T > collection ) { final List < T > list = new ArrayList < T > ( ) ; if ( collection != null && collection . size ( ) > <NUM_LIT:0> ) list . addAll ( collection ) ; return list ; } public static < T > List < T > add ( final List < T > list , final T ... objects ) { if ( objects == null ) return list ; for ( final T object : objects ) list . add ( object ) ; return list ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; public class ObjectUtils { public static boolean equals ( Object o1 , Object o2 ) { return o1 == null ? o2 == null : o1 . equals ( o2 ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import org . codehaus . groovy . eclipse . core . ISourceBuffer ; import org . codehaus . groovy . eclipse . core . impl . StringSourceBuffer ; public class ExpressionFinder { public String findForCompletions ( ISourceBuffer sourceBuffer , int offset ) throws ParseException { Token token = null ; int endOffset = <NUM_LIT:0> ; TokenStream stream = new TokenStream ( sourceBuffer , offset ) ; try { token = stream . peek ( ) ; if ( token . type == Token . EOF ) { return null ; } endOffset = token . endOffset ; boolean offsetIsWhitespace = Character . isWhitespace ( stream . getCurrentChar ( ) ) ; boolean offsetIsQuote = stream . getCurrentChar ( ) == '<STR_LIT:\">' || stream . getCurrentChar ( ) == '<STR_LIT>' ; if ( offsetIsQuote ) { return null ; } skipLineBreaksAndComments ( stream ) ; token = stream . next ( ) ; if ( offsetIsWhitespace && token . type != Token . DOT && token . type != Token . DOUBLE_DOT && token . type != Token . SAFE_DEREF && token . type != Token . SPREAD ) { return "<STR_LIT>" ; } if ( token . type == Token . EOF ) { return null ; } switch ( token . type ) { case Token . DOT : case Token . DOUBLE_DOT : case Token . SAFE_DEREF : case Token . SPREAD : token = dot ( stream ) ; break ; case Token . IDENT : token = ident ( stream ) ; break ; case Token . BRACK_BLOCK : token = null ; break ; default : throw new ParseException ( token ) ; } } catch ( TokenStreamException e ) { Token last = stream . last ( ) ; if ( last != null ) { token = last ; } } catch ( IllegalStateException e ) { } if ( token != null ) { return sourceBuffer . subSequence ( token . startOffset , endOffset ) . toString ( ) ; } return "<STR_LIT>" ; } public int findTokenEnd ( ISourceBuffer buffer , int initialOffset ) { int candidate = initialOffset ; while ( buffer . length ( ) > candidate ) { if ( ! Character . isJavaIdentifierPart ( buffer . charAt ( candidate ) ) ) { break ; } candidate ++ ; } return candidate ; } public String [ ] splitForCompletion ( String expression ) { String [ ] split = splitForCompletionNoTrim ( expression ) ; if ( split [ <NUM_LIT:0> ] != null ) { split [ <NUM_LIT:0> ] = split [ <NUM_LIT:0> ] . trim ( ) ; if ( split [ <NUM_LIT:0> ] . startsWith ( "<STR_LIT:$>" ) ) { split [ <NUM_LIT:0> ] = split [ <NUM_LIT:0> ] . substring ( <NUM_LIT:1> ) ; } } if ( split [ <NUM_LIT:1> ] != null ) { split [ <NUM_LIT:1> ] = split [ <NUM_LIT:1> ] . trim ( ) ; if ( split [ <NUM_LIT:1> ] . startsWith ( "<STR_LIT:$>" ) ) { split [ <NUM_LIT:1> ] = split [ <NUM_LIT:1> ] . substring ( <NUM_LIT:1> ) ; } } return split ; } public String [ ] splitForCompletionNoTrim ( String expression ) { String [ ] ret = new String [ <NUM_LIT:2> ] ; if ( expression == null || expression . trim ( ) . length ( ) < <NUM_LIT:1> ) { ret [ <NUM_LIT:0> ] = "<STR_LIT>" ; ret [ <NUM_LIT:1> ] = null ; return ret ; } StringSourceBuffer sb = new StringSourceBuffer ( expression ) ; TokenStream stream = new TokenStream ( sb , expression . length ( ) - <NUM_LIT:1> ) ; Token token0 , token1 , token2 ; try { skipLineBreaksAndComments ( stream ) ; token0 = stream . next ( ) ; skipLineBreaksAndComments ( stream ) ; token1 = stream . next ( ) ; skipLineBreaksAndComments ( stream ) ; token2 = stream . next ( ) ; if ( ( token0 . type == Token . DOT || token0 . type == Token . SAFE_DEREF || token0 . type == Token . SPREAD ) && isValidBeforeDot ( token1 . type ) ) { ret [ <NUM_LIT:0> ] = expression . substring ( <NUM_LIT:0> , token1 . endOffset ) ; ret [ <NUM_LIT:1> ] = "<STR_LIT>" ; } else if ( token0 . type == Token . IDENT && ( token1 . type == Token . DOT || token1 . type == Token . SAFE_DEREF || token1 . type == Token . SPREAD ) && isValidBeforeDot ( token2 . type ) ) { ret [ <NUM_LIT:0> ] = expression . substring ( <NUM_LIT:0> , token2 . endOffset ) ; ret [ <NUM_LIT:1> ] = expression . substring ( token0 . startOffset , expression . length ( ) ) ; } else if ( token0 . type == Token . IDENT ) { ret [ <NUM_LIT:0> ] = expression ; } else { ret = new String [ ] { "<STR_LIT>" , null } ; } } catch ( TokenStreamException e ) { ret = new String [ ] { "<STR_LIT>" , null } ; } catch ( IllegalStateException e ) { ret = new String [ ] { "<STR_LIT>" , null } ; } return ret ; } public class NameAndLocation { public final String name ; public final int location ; public NameAndLocation ( String name , int locaiton ) { this . name = name ; this . location = locaiton ; } public String toTypeName ( ) { StringBuilder sb = new StringBuilder ( ) ; int i = <NUM_LIT:0> ; while ( i < name . length ( ) && Character . isJavaIdentifierPart ( name . charAt ( i ) ) ) { sb . append ( name . charAt ( i ++ ) ) ; } return sb . toString ( ) ; } public int dims ( ) { int i = <NUM_LIT:0> ; int dims = <NUM_LIT:0> ; while ( i < name . length ( ) ) { if ( name . charAt ( i ++ ) == '<CHAR_LIT:]>' ) { dims ++ ; } } return dims ; } } public NameAndLocation findPreviousTypeNameToken ( ISourceBuffer buffer , int start ) { int current = start ; current -- ; while ( current >= <NUM_LIT:0> && ! Character . isWhitespace ( buffer . charAt ( current ) ) && Character . isJavaIdentifierPart ( buffer . charAt ( current ) ) ) { current -- ; } if ( current < <NUM_LIT:0> || ! Character . isWhitespace ( buffer . charAt ( current ) ) ) { return null ; } StringBuilder sb = new StringBuilder ( ) ; while ( current >= <NUM_LIT:0> && ( Character . isWhitespace ( buffer . charAt ( current ) ) || buffer . charAt ( current ) == '<CHAR_LIT:[>' || buffer . charAt ( current ) == '<CHAR_LIT:]>' ) && buffer . charAt ( current ) != '<STR_LIT:\n>' && buffer . charAt ( current ) != '<STR_LIT>' ) { sb . append ( buffer . charAt ( current -- ) ) ; } if ( current < <NUM_LIT:0> || ! Character . isJavaIdentifierPart ( buffer . charAt ( current ) ) ) { return null ; } while ( current >= <NUM_LIT:0> && Character . isJavaIdentifierPart ( buffer . charAt ( current ) ) ) { sb . append ( buffer . charAt ( current -- ) ) ; } if ( sb . length ( ) > <NUM_LIT:0> ) { return new NameAndLocation ( sb . reverse ( ) . toString ( ) , current + <NUM_LIT:1> ) ; } else { return null ; } } private void skipLineBreaksAndComments ( TokenStream stream ) throws TokenStreamException { skipLineBreaks ( stream ) ; skipLineComments ( stream ) ; } private boolean isValidBeforeDot ( int type ) { int beforeDot [ ] = new int [ ] { Token . IDENT , Token . QUOTED_STRING , Token . BRACE_BLOCK , Token . BRACK_BLOCK , Token . PAREN_BLOCK } ; for ( int i = <NUM_LIT:0> ; i < beforeDot . length ; ++ i ) { if ( type == beforeDot [ i ] ) { return true ; } } return false ; } private Token dot ( TokenStream stream ) throws TokenStreamException , ParseException { skipLineBreaksAndComments ( stream ) ; Token token = stream . next ( ) ; switch ( token . type ) { case Token . IDENT : return ident ( stream ) ; case Token . QUOTED_STRING : return quotedString ( stream ) ; case Token . PAREN_BLOCK : return parenBlock ( stream ) ; case Token . BRACE_BLOCK : return braceBlock ( stream ) ; case Token . BRACK_BLOCK : return brackBlock ( stream ) ; default : throw new ParseException ( token ) ; } } private void skipLineComments ( TokenStream stream ) throws TokenStreamException { while ( stream . peek ( ) . type == Token . LINE_COMMENT ) { stream . next ( ) ; } } private void skipLineBreaks ( TokenStream stream ) throws TokenStreamException { while ( stream . peek ( ) . type == Token . LINE_BREAK ) { stream . next ( ) ; } } private Token ident ( TokenStream stream ) throws TokenStreamException , ParseException { Token token = stream . peek ( ) ; Token last = stream . last ( ) ; switch ( token . type ) { case Token . LINE_BREAK : skipLineBreaksAndComments ( stream ) ; token = stream . peek ( ) ; if ( token . type != Token . DOT && token . type != Token . SAFE_DEREF && token . type != Token . SPREAD ) { return new Token ( Token . EOF , last . startOffset , last . endOffset , null ) ; } stream . next ( ) ; return dot ( stream ) ; case Token . DOUBLE_DOT : return new Token ( Token . EOF , last . startOffset , last . endOffset , null ) ; case Token . SAFE_DEREF : case Token . SPREAD : case Token . DOT : { stream . next ( ) ; return dot ( stream ) ; } case Token . IDENT : if ( token . text . equals ( "<STR_LIT>" ) ) { Token next = stream . next ( ) ; return new Token ( Token . EOF , next . startOffset , next . endOffset , null ) ; } default : return new Token ( Token . EOF , last . startOffset , last . endOffset , null ) ; } } private Token quotedString ( TokenStream stream ) throws TokenStreamException , ParseException { Token token = stream . peek ( ) ; Token last ; switch ( token . type ) { case Token . EOF : case Token . LINE_BREAK : last = stream . last ( ) ; return new Token ( Token . EOF , last . startOffset , last . startOffset , null ) ; case Token . SEMI : last = stream . last ( ) ; return new Token ( Token . EOF , last . startOffset , last . startOffset , null ) ; case Token . IDENT : last = stream . last ( ) ; return new Token ( Token . EOF , last . startOffset , last . startOffset , null ) ; default : throw new ParseException ( token ) ; } } private Token parenBlock ( TokenStream stream ) throws TokenStreamException , ParseException { Token token = stream . peek ( ) ; switch ( token . type ) { case Token . IDENT : stream . next ( ) ; return ident ( stream ) ; case Token . EOF : case Token . SEMI : case Token . LINE_BREAK : return stream . last ( ) ; default : throw new ParseException ( token ) ; } } private Token braceBlock ( TokenStream stream ) throws TokenStreamException , ParseException { Token token = stream . next ( ) ; switch ( token . type ) { case Token . IDENT : return ident ( stream ) ; case Token . PAREN_BLOCK : return parenBlock ( stream ) ; default : throw new ParseException ( token ) ; } } private Token brackBlock ( TokenStream stream ) throws TokenStreamException , ParseException { Token last = stream . last ( ) ; Token token = stream . next ( ) ; switch ( token . type ) { case Token . EOF : return new Token ( Token . EOF , last . startOffset , last . startOffset , null ) ; case Token . IDENT : return ident ( stream ) ; case Token . PAREN_BLOCK : return parenBlock ( stream ) ; case Token . BRACE_BLOCK : return braceBlock ( stream ) ; case Token . BRACK_BLOCK : return brackBlock ( stream ) ; case Token . SEMI : case Token . LINE_BREAK : return stream . last ( ) ; default : throw new ParseException ( token ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; public class TokenStreamException extends Exception { private static final long serialVersionUID = - <NUM_LIT> ; TokenStreamException ( char ch ) { super ( "<STR_LIT>" + ch ) ; } public TokenStreamException ( String message ) { super ( message ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; import java . lang . reflect . Array ; import java . util . ArrayList ; import java . util . List ; import org . eclipse . core . runtime . Assert ; public class ArrayUtils { public static Object [ ] remove ( Object [ ] arr , int i ) { Assert . isNotNull ( arr ) ; Assert . isTrue ( arr . length > i ) ; List < Object > l = new ArrayList < Object > ( ) ; for ( int j = <NUM_LIT:0> ; j < arr . length ; j ++ ) { if ( j != i ) { l . add ( arr [ j ] ) ; } } Object [ ] newArr = ( Object [ ] ) Array . newInstance ( arr . getClass ( ) . getComponentType ( ) , arr . length - <NUM_LIT:1> ) ; return l . toArray ( newArr ) ; } public static Object [ ] add ( Object [ ] arr , Object val ) { return add ( arr , arr . length , val ) ; } public static Object [ ] add ( Object [ ] arr , int index , Object val ) { Assert . isNotNull ( arr ) ; Assert . isTrue ( index >= <NUM_LIT:0> && index <= arr . length ) ; Object [ ] newArr = ( Object [ ] ) Array . newInstance ( arr . getClass ( ) . getComponentType ( ) , arr . length + <NUM_LIT:1> ) ; System . arraycopy ( arr , <NUM_LIT:0> , newArr , <NUM_LIT:0> , index ) ; newArr [ index ] = val ; if ( arr . length > index ) { System . arraycopy ( arr , index , newArr , index + <NUM_LIT:1> , arr . length - index ) ; } return newArr ; } public static Object [ ] removeElement ( Object [ ] arr , Object toRemove ) { Assert . isNotNull ( arr ) ; int index = - <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < arr . length ; i ++ ) { if ( arr [ i ] . equals ( toRemove ) ) { index = i ; break ; } } if ( index >= <NUM_LIT:0> ) { Object [ ] newArr = ( Object [ ] ) Array . newInstance ( arr . getClass ( ) . getComponentType ( ) , arr . length - <NUM_LIT:1> ) ; if ( index > <NUM_LIT:0> ) { System . arraycopy ( arr , <NUM_LIT:0> , newArr , <NUM_LIT:0> , index ) ; } System . arraycopy ( arr , index + <NUM_LIT:1> , newArr , index , arr . length - index - <NUM_LIT:1> ) ; return newArr ; } else { Object [ ] newArr = ( Object [ ] ) Array . newInstance ( arr . getClass ( ) . getComponentType ( ) , arr . length ) ; System . arraycopy ( arr , <NUM_LIT:0> , newArr , <NUM_LIT:0> , arr . length ) ; return newArr ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; public class UnsupportedVisitException extends RuntimeException { private static final long serialVersionUID = <NUM_LIT> ; public UnsupportedVisitException ( String message ) { super ( message ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . util ; public class VisitCompleteException extends RuntimeException { public VisitCompleteException ( ) { } public VisitCompleteException ( String message ) { super ( message ) ; } private static final long serialVersionUID = <NUM_LIT> ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . adapters ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . runtime . IAdapterFactory ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . groovy . core . util . ContentTypeUtils ; public class GroovyFileAdapterFactory implements IAdapterFactory { private static final Class [ ] classes = new Class [ ] { ClassNode . class , ClassNode [ ] . class } ; public Object getAdapter ( Object adaptableObject , Class adapterType ) { Object returnValue = null ; if ( adaptableObject instanceof IFile ) { IFile file = ( IFile ) adaptableObject ; if ( ContentTypeUtils . isGroovyLikeFileName ( file . getName ( ) ) ) { if ( ClassNode . class . equals ( adapterType ) || ClassNode [ ] . class . equals ( adapterType ) ) { try { GroovyCompilationUnit unit = ( GroovyCompilationUnit ) JavaCore . createCompilationUnitFrom ( file ) ; ModuleNode module = unit . getModuleNode ( ) ; if ( module != null ) { List < ClassNode > classNodeList = module . getClasses ( ) ; if ( classNodeList != null && ! classNodeList . isEmpty ( ) ) { if ( ClassNode . class . equals ( adapterType ) ) { returnValue = classNodeList . get ( <NUM_LIT:0> ) ; } else if ( ClassNode [ ] . class . equals ( adapterType ) ) { returnValue = classNodeList . toArray ( new ClassNode [ <NUM_LIT:0> ] ) ; } } } } catch ( Exception ex ) { GroovyCore . logException ( "<STR_LIT>" , ex ) ; } } } } return returnValue ; } public Class [ ] getAdapterList ( ) { return classes ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . builder ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . internal . core . ClassFile ; import org . eclipse . jdt . internal . core . IJavaElementRequestor ; import org . eclipse . jdt . internal . core . NameLookup ; import org . eclipse . jdt . internal . core . util . HashtableOfArrayToObject ; import org . eclipse . jdt . internal . core . util . Util ; public class GroovyNameLookup extends NameLookup { public GroovyNameLookup ( NameLookup other ) { this ( new IPackageFragmentRoot [ <NUM_LIT:0> ] , new HashtableOfArrayToObject ( ) , new ICompilationUnit [ <NUM_LIT:0> ] , new HashMap ( ) ) ; this . packageFragmentRoots = ( IPackageFragmentRoot [ ] ) ReflectionUtils . getPrivateField ( NameLookup . class , "<STR_LIT>" , other ) ; this . packageFragments = ( HashtableOfArrayToObject ) ReflectionUtils . getPrivateField ( NameLookup . class , "<STR_LIT>" , other ) ; this . typesInWorkingCopies = ( HashMap ) ReflectionUtils . getPrivateField ( NameLookup . class , "<STR_LIT>" , other ) ; this . rootToResolvedEntries = ( Map ) ReflectionUtils . getPrivateField ( NameLookup . class , "<STR_LIT>" , other ) ; } public GroovyNameLookup ( IPackageFragmentRoot [ ] packageFragmentRoots , HashtableOfArrayToObject packageFragments , ICompilationUnit [ ] workingCopies , Map rootToResolvedEntries ) { super ( packageFragmentRoots , packageFragments , workingCopies , rootToResolvedEntries ) ; } @ Override protected void seekTypesInSourcePackage ( String name , IPackageFragment pkg , int firstDot , boolean partialMatch , String topLevelTypeName , int acceptFlags , IJavaElementRequestor requestor ) { long start = - <NUM_LIT:1> ; if ( VERBOSE ) start = System . currentTimeMillis ( ) ; try { if ( ! partialMatch ) { try { IJavaElement [ ] compilationUnits = pkg . getChildren ( ) ; for ( int i = <NUM_LIT:0> , length = compilationUnits . length ; i < length ; i ++ ) { if ( requestor . isCanceled ( ) ) return ; ICompilationUnit cu = ( ICompilationUnit ) compilationUnits [ i ] ; IType [ ] allTypes = cu . getAllTypes ( ) ; IType type = cu . getType ( name ) ; if ( type . exists ( ) && acceptType ( type , acceptFlags , true ) ) { requestor . acceptType ( type ) ; break ; } String mainType = cu . getElementName ( ) ; int dotIndex = mainType . indexOf ( '<CHAR_LIT:.>' ) ; mainType = mainType . substring ( <NUM_LIT:0> , dotIndex ) ; type = cu . getType ( mainType ) ; if ( type . exists ( ) ) { type = getMemberType ( type , name , firstDot ) ; if ( type . exists ( ) && acceptType ( type , acceptFlags , true ) ) { requestor . acceptType ( type ) ; break ; } } } } catch ( JavaModelException e ) { } } else { try { String cuPrefix = firstDot == - <NUM_LIT:1> ? name : name . substring ( <NUM_LIT:0> , firstDot ) ; IJavaElement [ ] compilationUnits = pkg . getChildren ( ) ; for ( int i = <NUM_LIT:0> , length = compilationUnits . length ; i < length ; i ++ ) { if ( requestor . isCanceled ( ) ) return ; IJavaElement cu = compilationUnits [ i ] ; if ( ! cu . getElementName ( ) . toLowerCase ( ) . startsWith ( cuPrefix ) ) continue ; try { IType [ ] types = ( ( ICompilationUnit ) cu ) . getTypes ( ) ; for ( int j = <NUM_LIT:0> , typeLength = types . length ; j < typeLength ; j ++ ) seekTypesInTopLevelType ( name , firstDot , types [ j ] , requestor , acceptFlags ) ; } catch ( JavaModelException e ) { } } } catch ( JavaModelException e ) { } } } finally { if ( VERBOSE ) this . timeSpentInSeekTypesInSourcePackage += System . currentTimeMillis ( ) - start ; } } private IType getMemberType ( IType type , String name , int dot ) { type = type . getType ( name ) ; return type ; } @ Override protected void seekTypesInBinaryPackage ( String name , IPackageFragment pkg , boolean partialMatch , int acceptFlags , IJavaElementRequestor requestor ) { long start = - <NUM_LIT:1> ; if ( VERBOSE ) start = System . currentTimeMillis ( ) ; try { if ( ! name . endsWith ( "<STR_LIT:.class>" ) ) { name += "<STR_LIT:.class>" ; } if ( ! partialMatch ) { if ( requestor . isCanceled ( ) ) return ; ClassFile classFile = ( ClassFile ) pkg . getClassFile ( name ) ; if ( classFile . existsUsingJarTypeCache ( ) ) { IType type = classFile . getType ( ) ; if ( acceptType ( type , acceptFlags , false ) ) { requestor . acceptType ( type ) ; } } IJavaElement [ ] classFiles = null ; try { classFiles = pkg . getChildren ( ) ; } catch ( JavaModelException npe ) { return ; } for ( IJavaElement elt : classFiles ) { classFile = ( ClassFile ) elt ; if ( classFile . getElementName ( ) . endsWith ( "<STR_LIT:$>" + name ) ) { IType type = classFile . getType ( ) ; if ( acceptType ( type , acceptFlags , false ) ) { requestor . acceptType ( type ) ; } } } } else { IJavaElement [ ] classFiles = null ; try { classFiles = pkg . getChildren ( ) ; } catch ( JavaModelException npe ) { return ; } int length = classFiles . length ; String unqualifiedName = name ; int index = name . lastIndexOf ( '<CHAR_LIT>' ) ; if ( index != - <NUM_LIT:1> ) { unqualifiedName = Util . localTypeName ( name , index , name . length ( ) ) ; } int matchLength = name . length ( ) ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { if ( requestor . isCanceled ( ) ) return ; IJavaElement classFile = classFiles [ i ] ; String elementName = classFile . getElementName ( ) ; if ( elementName . regionMatches ( true , <NUM_LIT:0> , name , <NUM_LIT:0> , matchLength ) ) { IType type = ( ( ClassFile ) classFile ) . getType ( ) ; String typeName = type . getElementName ( ) ; if ( typeName . length ( ) > <NUM_LIT:0> && ! Character . isDigit ( typeName . charAt ( <NUM_LIT:0> ) ) ) { if ( nameMatches ( unqualifiedName , type , true ) && acceptType ( type , acceptFlags , false ) ) requestor . acceptType ( type ) ; } } } } } finally { if ( VERBOSE ) this . timeSpentInSeekTypesInBinaryPackage += System . currentTimeMillis ( ) - start ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . builder ; import java . util . ArrayList ; import java . util . List ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . ClasspathContainerInitializer ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . JavaCore ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . JavaModelManager ; public class GroovyClasspathContainerInitializer extends ClasspathContainerInitializer { public void initialize ( IPath containerPath , IJavaProject project ) throws CoreException { IClasspathContainer container = new GroovyClasspathContainer ( project . getProject ( ) ) ; JavaCore . setClasspathContainer ( containerPath , new IJavaProject [ ] { project } , new IClasspathContainer [ ] { container } , null ) ; } @ Override public boolean canUpdateClasspathContainer ( IPath containerPath , IJavaProject project ) { return true ; } @ Override public void requestClasspathContainerUpdate ( IPath containerPath , IJavaProject javaProject , IClasspathContainer containerSuggestion ) throws CoreException { if ( containerSuggestion instanceof GroovyClasspathContainer ) { ( ( GroovyClasspathContainer ) containerSuggestion ) . reset ( ) ; } IClasspathContainer gcc = JavaCore . getClasspathContainer ( GroovyClasspathContainer . CONTAINER_ID , javaProject ) ; if ( gcc instanceof GroovyClasspathContainer ) { ( ( GroovyClasspathContainer ) gcc ) . reset ( ) ; } } public static void updateAllGroovyClasspathContainers ( ) throws JavaModelException { IJavaProject [ ] projects = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) . getJavaProjects ( ) ; updateSomeGroovyClasspathContainers ( projects ) ; } public static void updateGroovyClasspathContainer ( IJavaProject project ) throws JavaModelException { updateSomeGroovyClasspathContainers ( new IJavaProject [ ] { project } ) ; } private static void updateSomeGroovyClasspathContainers ( IJavaProject [ ] projects ) throws JavaModelException { List < IJavaProject > affectedProjects = new ArrayList < IJavaProject > ( projects . length ) ; List < IClasspathContainer > affectedContainers = new ArrayList < IClasspathContainer > ( projects . length ) ; for ( IJavaProject elt : projects ) { IJavaProject project = ( IJavaProject ) elt ; IClasspathContainer gcc = JavaCore . getClasspathContainer ( GroovyClasspathContainer . CONTAINER_ID , project ) ; if ( gcc instanceof GroovyClasspathContainer ) { ( ( GroovyClasspathContainer ) gcc ) . reset ( ) ; affectedProjects . add ( project ) ; affectedContainers . add ( null ) ; } } JavaCore . setClasspathContainer ( GroovyClasspathContainer . CONTAINER_ID , affectedProjects . toArray ( new IJavaProject [ <NUM_LIT:0> ] ) , affectedContainers . toArray ( new IClasspathContainer [ <NUM_LIT:0> ] ) , new NullProgressMonitor ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . builder ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . LinkedList ; import java . util . List ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . eclipse . core . internal . events . BuildCommand ; import org . eclipse . core . resources . ICommand ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . JavaCore ; public class ConvertLegacyProject { public static final String OLD_NATURE = "<STR_LIT>" ; public static final String OLD_BUILDER = "<STR_LIT>" ; public static final String GROOVY_NATURE = "<STR_LIT>" ; public void convertProjects ( IProject [ ] projects ) { for ( IProject project : projects ) { convertProject ( project ) ; } } public void convertProject ( IProject project ) { try { IProjectDescription desc = project . getDescription ( ) ; String [ ] natures = desc . getNatureIds ( ) ; List < String > newNatures = new LinkedList < String > ( ) ; for ( String nature : natures ) { if ( ! nature . equals ( OLD_NATURE ) && ! nature . equals ( GROOVY_NATURE ) ) { newNatures . add ( nature ) ; } } newNatures . add ( <NUM_LIT:0> , GROOVY_NATURE ) ; desc . setNatureIds ( newNatures . toArray ( new String [ newNatures . size ( ) ] ) ) ; List < ICommand > builders = Arrays . asList ( desc . getBuildSpec ( ) ) ; List < ICommand > newBuilders = new ArrayList < ICommand > ( builders . size ( ) ) ; boolean javaBuilderFound = false ; for ( ICommand builder : builders ) { if ( ! builder . getBuilderName ( ) . equals ( OLD_BUILDER ) ) { newBuilders . add ( builder ) ; if ( builder . getBuilderName ( ) . equals ( JavaCore . BUILDER_ID ) ) { javaBuilderFound = true ; } } } if ( ! javaBuilderFound ) { ICommand newCommand = new BuildCommand ( ) ; newCommand . setBuilderName ( JavaCore . BUILDER_ID ) ; newBuilders . add ( newCommand ) ; } desc . setBuildSpec ( newBuilders . toArray ( new ICommand [ newBuilders . size ( ) ] ) ) ; project . setDescription ( desc , null ) ; } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" + project . getName ( ) , e ) ; } } public IProject [ ] getAllOldProjects ( ) { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; List < IProject > legacyProjects = new ArrayList < IProject > ( ) ; for ( IProject project : projects ) { try { if ( project . isAccessible ( ) && project . hasNature ( OLD_NATURE ) ) { legacyProjects . add ( project ) ; } } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } return legacyProjects . toArray ( new IProject [ <NUM_LIT:0> ] ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . builder ; import static org . codehaus . groovy . eclipse . core . util . ListUtil . newList ; import static org . eclipse . jdt . core . JavaCore . newLibraryEntry ; import java . io . File ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . GroovyCoreActivator ; import org . codehaus . groovy . eclipse . core . compiler . CompilerUtils ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . jdt . core . IClasspathAttribute ; import org . eclipse . jdt . core . IClasspathContainer ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . internal . core . ClasspathAttribute ; public class GroovyClasspathContainer implements IClasspathContainer { public static Path CONTAINER_ID = new Path ( "<STR_LIT>" ) ; public static String DESC = "<STR_LIT>" ; private IClasspathEntry [ ] entries ; private IProject project ; public GroovyClasspathContainer ( IProject project ) { this . project = project ; } public synchronized IClasspathEntry [ ] getClasspathEntries ( ) { if ( entries == null ) { updateEntries ( ) ; } return entries ; } synchronized void reset ( ) { entries = null ; } private void updateEntries ( ) { final List < IClasspathEntry > newEntries = newList ( ) ; try { URL groovyURL = CompilerUtils . getExportedGroovyAllJar ( ) ; IPath runtimeJarPath = new Path ( groovyURL . getPath ( ) ) ; File srcJarFile = new File ( groovyURL . getPath ( ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; IPath srcJarPath = srcJarFile . exists ( ) ? new Path ( srcJarFile . getAbsolutePath ( ) ) : null ; File javadocJarFile = new File ( groovyURL . getPath ( ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ; IClasspathAttribute [ ] attrs ; if ( javadocJarFile . exists ( ) ) { String javadocJarPath = javadocJarFile . getAbsolutePath ( ) ; final IClasspathAttribute cpattr = new ClasspathAttribute ( IClasspathAttribute . JAVADOC_LOCATION_ATTRIBUTE_NAME , javadocJarPath ) ; attrs = new IClasspathAttribute [ ] { cpattr } ; } else { attrs = new IClasspathAttribute [ <NUM_LIT:0> ] ; } IClasspathEntry entry = newLibraryEntry ( runtimeJarPath , srcJarPath , null , null , attrs , true ) ; newEntries . add ( entry ) ; URL [ ] extraJars = CompilerUtils . getExtraJarsForClasspath ( ) ; for ( URL jar : extraJars ) { IPath jarPath = new Path ( jar . getPath ( ) ) ; newEntries . add ( newLibraryEntry ( jarPath , null , null ) ) ; } if ( useGroovyLibs ( ) ) { newEntries . addAll ( getGroovyJarsInDotGroovyLib ( ) ) ; } entries = newEntries . toArray ( new IClasspathEntry [ <NUM_LIT:0> ] ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; entries = new IClasspathEntry [ <NUM_LIT:0> ] ; } } private boolean useGroovyLibs ( ) { IScopeContext projectScope = new ProjectScope ( project ) ; IEclipsePreferences projectNode = projectScope . getNode ( GroovyCoreActivator . PLUGIN_ID ) ; String val = projectNode . get ( PreferenceConstants . GROOVY_CLASSPATH_USE_GROOVY_LIB , "<STR_LIT:default>" ) ; if ( val . equals ( Boolean . TRUE . toString ( ) ) ) { return true ; } else if ( val . equals ( Boolean . FALSE . toString ( ) ) ) { return false ; } else { return GroovyCoreActivator . getDefault ( ) . getPreference ( PreferenceConstants . GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL , true ) ; } } private Collection < IClasspathEntry > getGroovyJarsInDotGroovyLib ( ) { File [ ] files = CompilerUtils . findJarsInDotGroovyLocation ( ) ; final List < IClasspathEntry > newEntries = new ArrayList < IClasspathEntry > ( files . length ) ; for ( File file : files ) { IClasspathEntry entry = newLibraryEntry ( new Path ( file . getAbsolutePath ( ) ) , null , null , null , new IClasspathAttribute [ <NUM_LIT:0> ] , true ) ; newEntries . add ( entry ) ; } return newEntries ; } public String getDescription ( ) { return DESC ; } public int getKind ( ) { return K_APPLICATION ; } public IPath getPath ( ) { return CONTAINER_ID ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . impl ; import org . codehaus . groovy . eclipse . core . ISourceBuffer ; public class ReverseSourceBuffer implements ISourceBuffer { private ISourceBuffer buffer ; private int origin ; public ReverseSourceBuffer ( ISourceBuffer buffer , int origin ) { this . buffer = buffer ; this . origin = origin ; } public char charAt ( int offset ) { char ch = buffer . charAt ( origin - offset ) ; return ch ; } public int length ( ) { return origin + <NUM_LIT:1> ; } public CharSequence subSequence ( int start , int end ) { return buffer . subSequence ( origin - end + <NUM_LIT:1> , origin - start + <NUM_LIT:1> ) ; } public int [ ] toLineColumn ( int offset ) { throw new UnsupportedOperationException ( ) ; } public int toOffset ( int line , int column ) { throw new UnsupportedOperationException ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . impl ; import static org . codehaus . groovy . eclipse . core . util . ListUtil . newList ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . groovy . eclipse . core . ISourceBuffer ; public class StringSourceBuffer implements ISourceBuffer { private final char [ ] sourceCode ; private final List lineOffsets ; public StringSourceBuffer ( String sourceCode ) { this . sourceCode = new char [ sourceCode . length ( ) ] ; sourceCode . getChars ( <NUM_LIT:0> , sourceCode . length ( ) , this . sourceCode , <NUM_LIT:0> ) ; this . lineOffsets = createLineLookup ( this . sourceCode ) ; } private List createLineLookup ( char [ ] sourceCode ) { if ( sourceCode . length == <NUM_LIT:0> ) { return new ArrayList ( ) ; } List < Integer > offsets = newList ( ) ; offsets . add ( new Integer ( <NUM_LIT:0> ) ) ; int ch ; for ( int i = <NUM_LIT:0> ; i < sourceCode . length ; ++ i ) { ch = sourceCode [ i ] ; if ( ch == '<STR_LIT>' ) { if ( i + <NUM_LIT:1> < sourceCode . length ) { ch = sourceCode [ i + <NUM_LIT:1> ] ; if ( ch == '<STR_LIT:\n>' ) { offsets . add ( new Integer ( ++ i + <NUM_LIT:1> ) ) ; } else { offsets . add ( new Integer ( i + <NUM_LIT:1> ) ) ; } } else { offsets . add ( new Integer ( i + <NUM_LIT:1> ) ) ; } } else if ( ch == '<STR_LIT:\n>' ) { offsets . add ( new Integer ( i + <NUM_LIT:1> ) ) ; } } return offsets ; } public char charAt ( int offset ) { try { return sourceCode [ offset ] ; } catch ( ArrayIndexOutOfBoundsException e ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + offset + "<STR_LIT>" + ( sourceCode . length - <NUM_LIT:1> ) + "<STR_LIT:]>" ) ; } } public int length ( ) { return sourceCode . length ; } public CharSequence subSequence ( int start , int end ) { return new String ( sourceCode , start , end - start ) ; } public int [ ] toLineColumn ( int offset ) { try { for ( int i = <NUM_LIT:0> ; i < lineOffsets . size ( ) ; ++ i ) { int lineOffset = ( ( Integer ) lineOffsets . get ( i ) ) . intValue ( ) ; if ( offset < lineOffset ) { lineOffset = ( ( Integer ) lineOffsets . get ( i - <NUM_LIT:1> ) ) . intValue ( ) ; return new int [ ] { i , offset - lineOffset + <NUM_LIT:1> } ; } } int line = lineOffsets . size ( ) ; int lineOffset = ( ( Integer ) lineOffsets . get ( line - <NUM_LIT:1> ) ) . intValue ( ) ; return new int [ ] { line , offset - lineOffset + <NUM_LIT:1> } ; } catch ( ArrayIndexOutOfBoundsException e ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + offset + "<STR_LIT>" + ( sourceCode . length - <NUM_LIT:1> ) + "<STR_LIT:]>" ) ; } } public int toOffset ( int line , int column ) { int offset = ( ( Integer ) lineOffsets . get ( line - <NUM_LIT:1> ) ) . intValue ( ) ; return offset + column - <NUM_LIT:1> ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; import org . eclipse . core . runtime . Plugin ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . core . runtime . preferences . InstanceScope ; import org . osgi . framework . BundleContext ; public class GroovyCoreActivator extends Plugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static GroovyCoreActivator plugin ; private IEclipsePreferences instanceScope ; public GroovyCoreActivator ( ) { plugin = this ; } @ Override public void start ( BundleContext context ) throws Exception { super . start ( context ) ; } @ Override public void stop ( BundleContext context ) throws Exception { plugin = null ; } public static GroovyCoreActivator getDefault ( ) { return plugin ; } public IEclipsePreferences getPreferences ( ) { if ( instanceScope == null ) { instanceScope = ( ( IScopeContext ) InstanceScope . INSTANCE ) . getNode ( GroovyCoreActivator . PLUGIN_ID ) ; } return instanceScope ; } public boolean getPreference ( String key , boolean def ) { return getPreferences ( ) . getBoolean ( key , def ) ; } public void setPreference ( String key , boolean val ) { getPreferences ( ) . putBoolean ( key , val ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core ; public interface ISourceBuffer extends CharSequence { public char charAt ( int offset ) ; public int length ( ) ; public CharSequence subSequence ( int start , int end ) ; public int [ ] toLineColumn ( int offset ) ; public int toOffset ( int line , int column ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . inference ; import java . util . HashMap ; import java . util . Map ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup ; import org . eclipse . jdt . groovy . search . ITypeLookup ; import org . eclipse . jdt . groovy . search . VariableScope ; public class StandardASTTransformInference extends AbstractSimplifiedTypeLookup implements ITypeLookup { private Map < String , BuiltInASTTransform [ ] > annotationCache ; public void initialize ( GroovyCompilationUnit unit , VariableScope topLevelScope ) { annotationCache = new HashMap < String , BuiltInASTTransform [ ] > ( ) ; } @ Override protected TypeAndDeclaration lookupTypeAndDeclaration ( ClassNode declaringType , String name , VariableScope scope ) { BuiltInASTTransform [ ] transforms = annotationCache . get ( declaringType . getName ( ) ) ; if ( transforms == null ) { transforms = BuiltInASTTransform . createAll ( declaringType ) ; annotationCache . put ( declaringType . getName ( ) , transforms ) ; } return getType ( transforms , name ) ; } private TypeAndDeclaration getType ( BuiltInASTTransform [ ] transforms , String name ) { for ( BuiltInASTTransform transform : transforms ) { TypeAndDeclaration tAndD = transform . symbolToDeclaration ( name ) ; if ( tAndD != null ) { return tAndD ; } } return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . inference ; import java . util . Collection ; import java . util . LinkedList ; import java . util . List ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . AnnotationNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . util . ListUtil ; import org . eclipse . jdt . groovy . search . AbstractSimplifiedTypeLookup . TypeAndDeclaration ; import org . objectweb . asm . Opcodes ; public abstract class BuiltInASTTransform { private static class SingletonASTTransform extends BuiltInASTTransform { static final String NAME = "<STR_LIT>" ; private MethodNode singletonMethod ; private FieldNode singletonField ; private SingletonASTTransform ( ClassNode thisNode ) { super ( thisNode ) ; } static BuiltInASTTransform create ( ClassNode declaringType ) { if ( declaringType != null ) { try { List < AnnotationNode > annotations = declaringType . getAnnotations ( ) ; for ( AnnotationNode annotation : annotations ) { if ( annotation . getClassNode ( ) . getName ( ) . equals ( SingletonASTTransform . NAME ) ) { return new SingletonASTTransform ( declaringType ) ; } } } catch ( Throwable t ) { GroovyCore . logException ( "<STR_LIT>" + declaringType . getName ( ) , t ) ; } } return null ; } @ Override public TypeAndDeclaration symbolToDeclaration ( String symbol ) { if ( thisClass instanceof ClassNode ) { if ( symbol . equals ( "<STR_LIT>" ) ) { return new TypeAndDeclaration ( getSingletonMethod ( ) . getReturnType ( ) , getSingletonMethod ( ) ) ; } if ( symbol . equals ( "<STR_LIT>" ) ) { getSingletonMethod ( ) ; return new TypeAndDeclaration ( getSingletonField ( ) . getType ( ) , getSingletonField ( ) ) ; } } return null ; } @ Override public Collection < ? extends AnnotatedNode > allIntroducedDeclarations ( ) { return ListUtil . linked ( ( AnnotatedNode ) getSingletonField ( ) , ( AnnotatedNode ) getSingletonMethod ( ) ) ; } private MethodNode getSingletonMethod ( ) { if ( singletonMethod == null ) { singletonMethod = createSingletonMethod ( ) ; } return singletonMethod ; } private FieldNode getSingletonField ( ) { if ( singletonField == null ) { singletonField = createSingletonField ( ) ; } return singletonField ; } private FieldNode createSingletonField ( ) { FieldNode f = new FieldNode ( "<STR_LIT>" , Opcodes . ACC_PUBLIC | Opcodes . ACC_STATIC , ( ClassNode ) thisClass , ( ClassNode ) thisClass , null ) ; f . setDeclaringClass ( thisClass ) ; return f ; } private MethodNode createSingletonMethod ( ) { MethodNode m = new MethodNode ( "<STR_LIT>" , Opcodes . ACC_PUBLIC | Opcodes . ACC_STATIC , ( ClassNode ) thisClass , new Parameter [ <NUM_LIT:0> ] , new ClassNode [ <NUM_LIT:0> ] , new BlockStatement ( ) ) ; m . setDeclaringClass ( thisClass ) ; return m ; } @ Override public String prettyName ( ) { return "<STR_LIT>" ; } } final ClassNode thisClass ; BuiltInASTTransform ( ClassNode thisClass ) { this . thisClass = thisClass ; } public abstract TypeAndDeclaration symbolToDeclaration ( String symbol ) ; public abstract Collection < ? extends AnnotatedNode > allIntroducedDeclarations ( ) ; public abstract String prettyName ( ) ; public static BuiltInASTTransform [ ] createAll ( ClassNode declaringType ) { List < BuiltInASTTransform > transforms = new LinkedList < BuiltInASTTransform > ( ) ; BuiltInASTTransform candidate = SingletonASTTransform . create ( declaringType ) ; if ( candidate != null ) { transforms . add ( candidate ) ; } return transforms . toArray ( new BuiltInASTTransform [ transforms . size ( ) ] ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . preferences ; public class PreferenceConstants { private PreferenceConstants ( ) { } public static final String GROOVY_EDITOR_HIGHLIGHT = "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_JAVAKEYWORDS_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_GROOVYKEYWORDS_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_JAVATYPES_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_STRINGS_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_NUMBERS_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_ANNOTATION_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_BRACKET_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_RETURN_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_OPERATOR_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_DEFAULT_COLOR = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_HIGHLIGHT_SLASHY_STRINGS = GROOVY_EDITOR_HIGHLIGHT + "<STR_LIT>" ; public static final String GROOVY_EDITOR_BOLD_SUFFIX = "<STR_LIT>" ; public static final String GROOVY_LOG_TRACE_MESSAGES_ENABLED = "<STR_LIT>" ; public static final String GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL = "<STR_LIT>" ; public static final String GROOVY_CLASSPATH_USE_GROOVY_LIB = "<STR_LIT>" ; public static final String GROOVY_JUNIT_MONOSPACE_FONT = "<STR_LIT>" ; public static final String GROOVY_ASK_TO_CONVERT_LEGACY_PROJECTS = "<STR_LIT>" ; public static final String GROOVY_SEMANTIC_HIGHLIGHTING = "<STR_LIT>" ; public static final String GROOVY_CONTENT_ASSIST_NOPARENS = "<STR_LIT>" ; public static final String GROOVY_CONTENT_ASSIST_BRACKETS = "<STR_LIT>" ; public static final String GROOVY_CONTENT_NAMED_ARGUMENTS = "<STR_LIT>" ; public static final String GROOVY_CONTENT_PARAMETER_GUESSING = "<STR_LIT>" ; public static final String GROOVY_DEBUG_FILTER_STACK = "<STR_LIT>" ; public static final String GROOVY_DEBUG_FILTER_LIST = "<STR_LIT>" ; public static final String GROOVY_DEBUG_FORCE_DEBUG_OPTIONS_ON_STARTUP = "<STR_LIT>" ; public static final String GROOVY_SCRIPT_DEFAULT_WORKING_DIRECTORY = "<STR_LIT>" ; public static final String GROOVY_SCRIPT_PROJECT_HOME = "<STR_LIT>" ; public static final String GROOVY_SCRIPT_SCRIPT_LOC = "<STR_LIT>" ; public static final String GROOVY_SCRIPT_ECLIPSE_HOME = "<STR_LIT>" ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . search ; import java . util . Comparator ; import java . util . Map ; import java . util . TreeMap ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . InnerClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTClassNode ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTMethodNode ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . groovy . search . EqualityVisitor ; import org . eclipse . jdt . groovy . search . ITypeRequestor ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; public class FindAllReferencesRequestor implements ITypeRequestor { private final AnnotatedNode declaration ; private final Map < ASTNode , Integer > references ; public FindAllReferencesRequestor ( AnnotatedNode declaration ) { this . declaration = declaration ; this . references = new TreeMap < ASTNode , Integer > ( new Comparator < ASTNode > ( ) { public int compare ( ASTNode o1 , ASTNode o2 ) { return o1 . getStart ( ) - o2 . getStart ( ) ; } } ) ; } public VisitStatus acceptASTNode ( ASTNode node , TypeLookupResult result , IJavaElement enclosingElement ) { if ( node . getLength ( ) == <NUM_LIT:0> ) { return VisitStatus . CONTINUE ; } if ( node instanceof AnnotatedNode ) { ASTNode maybeDeclaration = result . declaration ; if ( maybeDeclaration == null ) { return VisitStatus . CONTINUE ; } if ( maybeDeclaration instanceof ClassNode ) { if ( ! ( node instanceof ClassExpression || node instanceof ClassNode || node instanceof ImportNode ) ) { return VisitStatus . CONTINUE ; } if ( node instanceof ClassNode ) { ClassNode script = ( ClassNode ) node ; if ( script . isScript ( ) ) { if ( script . getNameWithoutPackage ( ) . length ( ) != script . getLength ( ) ) { return VisitStatus . CONTINUE ; } } } maybeDeclaration = ( ( ClassNode ) maybeDeclaration ) . redirect ( ) ; } if ( maybeDeclaration instanceof PropertyNode && ( ( PropertyNode ) maybeDeclaration ) . getField ( ) != null ) { maybeDeclaration = ( ( PropertyNode ) maybeDeclaration ) . getField ( ) ; } if ( node instanceof ImportNode && ( ( ImportNode ) node ) . getType ( ) != null ) { ImportNode imp = ( ( ImportNode ) node ) ; node = imp . getType ( ) ; if ( imp . isStatic ( ) ) { boolean isStaticDecl = ( declaration instanceof FieldNode && ( ( FieldNode ) declaration ) . isStatic ( ) ) || ( declaration instanceof FieldNode && ( ( FieldNode ) declaration ) . isStatic ( ) ) ; if ( isStaticDecl ) { String declarationName = getDeclarationName ( ) ; ClassNode declaringClass = declaration . getDeclaringClass ( ) ; if ( declarationName . equals ( imp . getFieldName ( ) ) && declaringClass . equals ( imp . getType ( ) ) ) { } return VisitStatus . CONTINUE ; } } } if ( isEquivalent ( maybeDeclaration ) ) { int flag = EqualityVisitor . checkForAssignment ( node , result . getEnclosingAssignment ( ) ) ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE ; references . put ( node , flag ) ; } } return VisitStatus . CONTINUE ; } private String getDeclarationName ( ) { if ( declaration instanceof FieldNode ) { return ( ( FieldNode ) declaration ) . getName ( ) ; } else if ( declaration instanceof MethodNode ) { return ( ( MethodNode ) declaration ) . getName ( ) ; } else if ( declaration instanceof ClassNode ) { return ( ( ClassNode ) declaration ) . getName ( ) ; } else { return declaration . getText ( ) ; } } public static final int F_WRITE_OCCURRENCE = <NUM_LIT:1> ; public static final int F_READ_OCCURRENCE = <NUM_LIT:2> ; private boolean isEquivalent ( ASTNode maybeDeclaration ) { if ( maybeDeclaration == declaration ) { return true ; } if ( maybeDeclaration instanceof FieldNode && declaration instanceof FieldNode ) { FieldNode maybeField = ( FieldNode ) maybeDeclaration ; FieldNode field = ( FieldNode ) declaration ; return maybeField . getName ( ) . equals ( field . getName ( ) ) && maybeField . getDeclaringClass ( ) . equals ( field . getDeclaringClass ( ) ) ; } else if ( declaration instanceof MethodNode ) { if ( maybeDeclaration instanceof JDTMethodNode ) { MethodNode maybeMethod = ( MethodNode ) maybeDeclaration ; MethodNode method = ( MethodNode ) declaration ; return maybeMethod . getName ( ) . equals ( method . getName ( ) ) && maybeMethod . getDeclaringClass ( ) . equals ( method . getDeclaringClass ( ) ) ; } else if ( maybeDeclaration instanceof MethodNode ) { MethodNode maybeMethod = ( MethodNode ) maybeDeclaration ; MethodNode method = ( MethodNode ) declaration ; return checkParamLength ( maybeMethod , method ) && maybeMethod . getName ( ) . equals ( method . getName ( ) ) && maybeMethod . getDeclaringClass ( ) . equals ( method . getDeclaringClass ( ) ) && checkParams ( maybeMethod , method ) ; } } if ( ( maybeDeclaration instanceof InnerClassNode && declaration instanceof JDTClassNode ) || ( declaration instanceof InnerClassNode && maybeDeclaration instanceof JDTClassNode ) ) { return ( ( ClassNode ) maybeDeclaration ) . getName ( ) . equals ( ( ( ClassNode ) declaration ) . getName ( ) ) ; } return false ; } private boolean checkParams ( MethodNode maybeMethod , MethodNode method ) { Parameter [ ] maybeParameters = maybeMethod . getParameters ( ) ; Parameter [ ] parameters = method . getParameters ( ) ; for ( int i = <NUM_LIT:0> ; i < parameters . length ; i ++ ) { if ( ! maybeParameters [ i ] . getName ( ) . equals ( parameters [ i ] . getName ( ) ) || ! typeEquals ( maybeParameters [ i ] , parameters [ i ] ) ) { return false ; } } return true ; } private boolean typeEquals ( Parameter maybeParameter , Parameter parameter ) { ClassNode maybeType = maybeParameter . getType ( ) ; ClassNode type = parameter . getType ( ) ; if ( maybeType == null ) { return type == null ; } else if ( type == null ) { return false ; } return maybeType . getName ( ) . equals ( type . getName ( ) ) ; } private boolean checkParamLength ( MethodNode maybeMethod , MethodNode method ) { Parameter [ ] maybeParameters = maybeMethod . getParameters ( ) ; Parameter [ ] parameters = method . getParameters ( ) ; if ( maybeParameters == null ) { return parameters == null ; } else if ( parameters == null ) { return false ; } if ( maybeParameters . length != parameters . length ) { return false ; } return true ; } public Map < ASTNode , Integer > getReferences ( ) { return references ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . search ; import java . util . PriorityQueue ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassCodeVisitorSupport ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ConstructorNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . PackageNode ; import org . codehaus . groovy . ast . expr . ArgumentListExpression ; import org . codehaus . groovy . ast . expr . ArrayExpression ; import org . codehaus . groovy . ast . expr . AttributeExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . BitwiseNegationExpression ; import org . codehaus . groovy . ast . expr . BooleanExpression ; import org . codehaus . groovy . ast . expr . CastExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . ClosureExpression ; import org . codehaus . groovy . ast . expr . ClosureListExpression ; import org . codehaus . groovy . ast . expr . ConstantExpression ; import org . codehaus . groovy . ast . expr . ConstructorCallExpression ; import org . codehaus . groovy . ast . expr . DeclarationExpression ; import org . codehaus . groovy . ast . expr . ElvisOperatorExpression ; import org . codehaus . groovy . ast . expr . FieldExpression ; import org . codehaus . groovy . ast . expr . GStringExpression ; import org . codehaus . groovy . ast . expr . ListExpression ; import org . codehaus . groovy . ast . expr . MapEntryExpression ; import org . codehaus . groovy . ast . expr . MapExpression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . MethodPointerExpression ; import org . codehaus . groovy . ast . expr . NotExpression ; import org . codehaus . groovy . ast . expr . PostfixExpression ; import org . codehaus . groovy . ast . expr . PrefixExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . RangeExpression ; import org . codehaus . groovy . ast . expr . SpreadExpression ; import org . codehaus . groovy . ast . expr . SpreadMapExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . TernaryExpression ; import org . codehaus . groovy . ast . expr . TupleExpression ; import org . codehaus . groovy . ast . expr . UnaryMinusExpression ; import org . codehaus . groovy . ast . expr . UnaryPlusExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . ast . stmt . AssertStatement ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . ast . stmt . BreakStatement ; import org . codehaus . groovy . ast . stmt . CaseStatement ; import org . codehaus . groovy . ast . stmt . CatchStatement ; import org . codehaus . groovy . ast . stmt . ContinueStatement ; import org . codehaus . groovy . ast . stmt . DoWhileStatement ; import org . codehaus . groovy . ast . stmt . EmptyStatement ; import org . codehaus . groovy . ast . stmt . ExpressionStatement ; import org . codehaus . groovy . ast . stmt . ForStatement ; import org . codehaus . groovy . ast . stmt . IfStatement ; import org . codehaus . groovy . ast . stmt . ReturnStatement ; import org . codehaus . groovy . ast . stmt . SwitchStatement ; import org . codehaus . groovy . ast . stmt . SynchronizedStatement ; import org . codehaus . groovy . ast . stmt . ThrowStatement ; import org . codehaus . groovy . ast . stmt . TryCatchStatement ; import org . codehaus . groovy . ast . stmt . WhileStatement ; import org . codehaus . groovy . classgen . BytecodeExpression ; import org . codehaus . groovy . control . SourceUnit ; public class LexicalClassVisitor { private class LexicalPrevisitor extends ClassCodeVisitorSupport { @ Override public void visitClass ( ClassNode node ) { maybeAddNode ( node ) ; visitObjectInitializerStatements ( node ) ; node . visitContents ( this ) ; } private void maybeAddNode ( ASTNode node ) { if ( node . getEnd ( ) > <NUM_LIT:0> ) { nodeList . add ( new ComparableNode ( node ) ) ; } } @ Override protected void visitObjectInitializerStatements ( ClassNode node ) { maybeAddNode ( node ) ; super . visitObjectInitializerStatements ( node ) ; } @ Override public void visitVariableExpression ( VariableExpression node ) { maybeAddNode ( node ) ; super . visitVariableExpression ( node ) ; } @ Override public void visitConstructor ( ConstructorNode node ) { maybeAddNode ( node ) ; super . visitConstructor ( node ) ; } @ Override public void visitMethod ( MethodNode node ) { maybeAddNode ( node ) ; super . visitMethod ( node ) ; } @ Override public void visitField ( FieldNode node ) { super . visitField ( node ) ; } @ Override protected SourceUnit getSourceUnit ( ) { return null ; } @ Override public void visitAssertStatement ( AssertStatement node ) { maybeAddNode ( node ) ; super . visitAssertStatement ( node ) ; } @ Override public void visitBlockStatement ( BlockStatement node ) { maybeAddNode ( node ) ; super . visitBlockStatement ( node ) ; } @ Override public void visitBreakStatement ( BreakStatement node ) { maybeAddNode ( node ) ; super . visitBreakStatement ( node ) ; } @ Override public void visitCaseStatement ( CaseStatement node ) { maybeAddNode ( node ) ; super . visitCaseStatement ( node ) ; } @ Override public void visitCatchStatement ( CatchStatement node ) { maybeAddNode ( node ) ; super . visitCatchStatement ( node ) ; } @ Override public void visitContinueStatement ( ContinueStatement node ) { maybeAddNode ( node ) ; super . visitContinueStatement ( node ) ; } @ Override public void visitDoWhileLoop ( DoWhileStatement node ) { maybeAddNode ( node ) ; super . visitDoWhileLoop ( node ) ; } @ Override public void visitExpressionStatement ( ExpressionStatement node ) { maybeAddNode ( node ) ; super . visitExpressionStatement ( node ) ; } @ Override public void visitForLoop ( ForStatement node ) { maybeAddNode ( node ) ; super . visitForLoop ( node ) ; } @ Override public void visitIfElse ( IfStatement node ) { maybeAddNode ( node ) ; super . visitIfElse ( node ) ; } @ Override public void visitReturnStatement ( ReturnStatement node ) { maybeAddNode ( node ) ; super . visitReturnStatement ( node ) ; } @ Override public void visitSwitch ( SwitchStatement node ) { maybeAddNode ( node ) ; super . visitSwitch ( node ) ; } @ Override public void visitSynchronizedStatement ( SynchronizedStatement node ) { maybeAddNode ( node ) ; super . visitSynchronizedStatement ( node ) ; } @ Override public void visitThrowStatement ( ThrowStatement node ) { maybeAddNode ( node ) ; super . visitThrowStatement ( node ) ; } @ Override public void visitTryCatchFinally ( TryCatchStatement node ) { maybeAddNode ( node ) ; super . visitTryCatchFinally ( node ) ; } @ Override public void visitWhileLoop ( WhileStatement node ) { maybeAddNode ( node ) ; super . visitWhileLoop ( node ) ; } @ Override protected void visitEmptyStatement ( EmptyStatement node ) { maybeAddNode ( node ) ; super . visitEmptyStatement ( node ) ; } @ Override public void visitMethodCallExpression ( MethodCallExpression node ) { maybeAddNode ( node ) ; super . visitMethodCallExpression ( node ) ; } @ Override public void visitStaticMethodCallExpression ( StaticMethodCallExpression node ) { maybeAddNode ( node ) ; super . visitStaticMethodCallExpression ( node ) ; } @ Override public void visitConstructorCallExpression ( ConstructorCallExpression node ) { maybeAddNode ( node ) ; super . visitConstructorCallExpression ( node ) ; } @ Override public void visitBinaryExpression ( BinaryExpression node ) { maybeAddNode ( node ) ; super . visitBinaryExpression ( node ) ; } @ Override public void visitTernaryExpression ( TernaryExpression node ) { maybeAddNode ( node ) ; super . visitTernaryExpression ( node ) ; } @ Override public void visitShortTernaryExpression ( ElvisOperatorExpression node ) { maybeAddNode ( node ) ; super . visitShortTernaryExpression ( node ) ; } @ Override public void visitPostfixExpression ( PostfixExpression node ) { maybeAddNode ( node ) ; super . visitPostfixExpression ( node ) ; } @ Override public void visitPrefixExpression ( PrefixExpression node ) { maybeAddNode ( node ) ; super . visitPrefixExpression ( node ) ; } @ Override public void visitBooleanExpression ( BooleanExpression node ) { maybeAddNode ( node ) ; super . visitBooleanExpression ( node ) ; } @ Override public void visitNotExpression ( NotExpression node ) { maybeAddNode ( node ) ; super . visitNotExpression ( node ) ; } @ Override public void visitClosureExpression ( ClosureExpression node ) { maybeAddNode ( node ) ; super . visitClosureExpression ( node ) ; } @ Override public void visitTupleExpression ( TupleExpression node ) { maybeAddNode ( node ) ; super . visitTupleExpression ( node ) ; } @ Override public void visitListExpression ( ListExpression node ) { maybeAddNode ( node ) ; super . visitListExpression ( node ) ; } @ Override public void visitArrayExpression ( ArrayExpression node ) { maybeAddNode ( node ) ; super . visitArrayExpression ( node ) ; } @ Override public void visitMapExpression ( MapExpression node ) { maybeAddNode ( node ) ; super . visitMapExpression ( node ) ; } @ Override public void visitMapEntryExpression ( MapEntryExpression node ) { maybeAddNode ( node ) ; super . visitMapEntryExpression ( node ) ; } @ Override public void visitRangeExpression ( RangeExpression node ) { maybeAddNode ( node ) ; super . visitRangeExpression ( node ) ; } @ Override public void visitSpreadExpression ( SpreadExpression node ) { maybeAddNode ( node ) ; super . visitSpreadExpression ( node ) ; } @ Override public void visitSpreadMapExpression ( SpreadMapExpression node ) { maybeAddNode ( node ) ; super . visitSpreadMapExpression ( node ) ; } @ Override public void visitMethodPointerExpression ( MethodPointerExpression node ) { maybeAddNode ( node ) ; super . visitMethodPointerExpression ( node ) ; } @ Override public void visitUnaryMinusExpression ( UnaryMinusExpression node ) { maybeAddNode ( node ) ; super . visitUnaryMinusExpression ( node ) ; } @ Override public void visitUnaryPlusExpression ( UnaryPlusExpression node ) { maybeAddNode ( node ) ; super . visitUnaryPlusExpression ( node ) ; } @ Override public void visitBitwiseNegationExpression ( BitwiseNegationExpression node ) { maybeAddNode ( node ) ; super . visitBitwiseNegationExpression ( node ) ; } @ Override public void visitCastExpression ( CastExpression node ) { maybeAddNode ( node ) ; super . visitCastExpression ( node ) ; } @ Override public void visitConstantExpression ( ConstantExpression node ) { maybeAddNode ( node ) ; super . visitConstantExpression ( node ) ; } @ Override public void visitClassExpression ( ClassExpression node ) { maybeAddNode ( node ) ; super . visitClassExpression ( node ) ; } @ Override public void visitDeclarationExpression ( DeclarationExpression node ) { maybeAddNode ( node ) ; super . visitDeclarationExpression ( node ) ; } @ Override public void visitPropertyExpression ( PropertyExpression node ) { maybeAddNode ( node ) ; super . visitPropertyExpression ( node ) ; } @ Override public void visitAttributeExpression ( AttributeExpression node ) { maybeAddNode ( node ) ; super . visitAttributeExpression ( node ) ; } @ Override public void visitFieldExpression ( FieldExpression node ) { maybeAddNode ( node ) ; super . visitFieldExpression ( node ) ; } @ Override public void visitGStringExpression ( GStringExpression node ) { maybeAddNode ( node ) ; super . visitGStringExpression ( node ) ; } @ Override public void visitArgumentlistExpression ( ArgumentListExpression node ) { maybeAddNode ( node ) ; super . visitArgumentlistExpression ( node ) ; } @ Override public void visitClosureListExpression ( ClosureListExpression node ) { maybeAddNode ( node ) ; super . visitClosureListExpression ( node ) ; } @ Override public void visitBytecodeExpression ( BytecodeExpression node ) { maybeAddNode ( node ) ; super . visitBytecodeExpression ( node ) ; } void doVisit ( ModuleNode module ) { for ( ClassNode node : ( Iterable < ClassNode > ) module . getClasses ( ) ) { visitClass ( node ) ; } } } private class ComparableNode implements Comparable < ComparableNode > { final ASTNode thisNode ; ComparableNode ( ASTNode thisNode ) { this . thisNode = thisNode ; } public int compareTo ( ComparableNode o ) { if ( thisNode . getStart ( ) != o . thisNode . getStart ( ) ) { return thisNode . getStart ( ) - o . thisNode . getStart ( ) ; } else { return o . thisNode . getEnd ( ) - thisNode . getEnd ( ) ; } } } private final ModuleNode module ; private PriorityQueue < ComparableNode > nodeList ; public LexicalClassVisitor ( ModuleNode module ) { super ( ) ; this . module = module ; } public ASTNode getNextNode ( ) { if ( ! hasNextNode ( ) ) { return null ; } return nodeList . remove ( ) . thisNode ; } private void initialize ( ) { nodeList = new PriorityQueue < ComparableNode > ( ) ; LexicalPrevisitor visitor = new LexicalPrevisitor ( ) ; visitor . doVisit ( module ) ; } public boolean hasNextNode ( ) { if ( nodeList == null ) { initialize ( ) ; } return ! nodeList . isEmpty ( ) ; } public void reset ( ) { nodeList = null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . core . search ; import org . eclipse . jdt . core . search . SearchMatch ; public interface ISearchRequestor { void acceptMatch ( SearchMatch match ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . core . search ; import java . util . ArrayList ; import java . util . List ; import org . codehaus . jdt . groovy . model . GroovyNature ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . jobs . ISchedulingRule ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IAnnotatable ; import org . eclipse . jdt . core . IAnnotation ; import org . eclipse . jdt . core . IClassFile ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModel ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . ILocalVariable ; import org . eclipse . jdt . core . IMember ; import org . eclipse . jdt . core . IMemberValuePair ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IOpenable ; import org . eclipse . jdt . core . ISourceRange ; import org . eclipse . jdt . core . ISourceReference ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . ITypeParameter ; import org . eclipse . jdt . core . ITypeRoot ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . SearchEngine ; import org . eclipse . jdt . core . search . SearchMatch ; import org . eclipse . jdt . core . search . SearchParticipant ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . core . search . SearchRequestor ; import org . eclipse . jdt . internal . core . search . JavaSearchParticipant ; public class SyntheticAccessorSearchRequestor { public class MethodWrapper implements IMethod { private final IMethod delegate ; private final String [ ] parameterNames ; public MethodWrapper ( IMethod method , String [ ] parameterNames ) { delegate = method ; this . parameterNames = parameterNames ; } public String [ ] getCategories ( ) throws JavaModelException { return ( ( IMember ) delegate . getParent ( ) ) . getCategories ( ) ; } public IClassFile getClassFile ( ) { return delegate . getClassFile ( ) ; } public ICompilationUnit getCompilationUnit ( ) { return delegate . getCompilationUnit ( ) ; } public IType getDeclaringType ( ) { return delegate . getDeclaringType ( ) ; } public int getFlags ( ) throws JavaModelException { return ( ( IMember ) delegate . getParent ( ) ) . getFlags ( ) ; } public ISourceRange getJavadocRange ( ) throws JavaModelException { return ( ( IMember ) delegate . getParent ( ) ) . getJavadocRange ( ) ; } public int getOccurrenceCount ( ) { return delegate . getOccurrenceCount ( ) ; } public ITypeRoot getTypeRoot ( ) { return delegate . getTypeRoot ( ) ; } public IType getType ( String name , int occurrenceCount ) { return delegate . getType ( name , occurrenceCount ) ; } public boolean isBinary ( ) { return delegate . isBinary ( ) ; } public boolean exists ( ) { return true ; } public IJavaElement getAncestor ( int ancestorType ) { return delegate . getAncestor ( ancestorType ) ; } public String getAttachedJavadoc ( IProgressMonitor monitor ) throws JavaModelException { return delegate . getParent ( ) . getAttachedJavadoc ( monitor ) ; } public IResource getCorrespondingResource ( ) throws JavaModelException { return delegate . getParent ( ) . getCorrespondingResource ( ) ; } public int getElementType ( ) { return delegate . getElementType ( ) ; } public String getHandleIdentifier ( ) { return delegate . getHandleIdentifier ( ) ; } public IJavaModel getJavaModel ( ) { return delegate . getJavaModel ( ) ; } public IJavaProject getJavaProject ( ) { return delegate . getJavaProject ( ) ; } public IOpenable getOpenable ( ) { return delegate . getOpenable ( ) ; } public IJavaElement getParent ( ) { return delegate . getParent ( ) ; } public IPath getPath ( ) { return delegate . getPath ( ) ; } public IJavaElement getPrimaryElement ( ) { return delegate . getPrimaryElement ( ) ; } public IResource getResource ( ) { return delegate . getResource ( ) ; } public ISchedulingRule getSchedulingRule ( ) { return delegate . getSchedulingRule ( ) ; } public IResource getUnderlyingResource ( ) throws JavaModelException { return delegate . getParent ( ) . getUnderlyingResource ( ) ; } public boolean isReadOnly ( ) { return delegate . isReadOnly ( ) ; } public boolean isStructureKnown ( ) throws JavaModelException { return delegate . getParent ( ) . isStructureKnown ( ) ; } public Object getAdapter ( Class adapter ) { return delegate . getAdapter ( adapter ) ; } public String getSource ( ) throws JavaModelException { return ( ( ISourceReference ) delegate . getParent ( ) ) . getSource ( ) ; } public ISourceRange getSourceRange ( ) throws JavaModelException { return ( ( ISourceReference ) delegate . getParent ( ) ) . getSourceRange ( ) ; } public ISourceRange getNameRange ( ) throws JavaModelException { return ( ( IMethod ) delegate . getParent ( ) ) . getNameRange ( ) ; } public void copy ( IJavaElement container , IJavaElement sibling , String rename , boolean replace , IProgressMonitor monitor ) throws JavaModelException { delegate . copy ( container , sibling , rename , replace , monitor ) ; } public void delete ( boolean force , IProgressMonitor monitor ) throws JavaModelException { delegate . delete ( force , monitor ) ; } public void move ( IJavaElement container , IJavaElement sibling , String rename , boolean replace , IProgressMonitor monitor ) throws JavaModelException { delegate . move ( container , sibling , rename , replace , monitor ) ; } public void rename ( String name , boolean replace , IProgressMonitor monitor ) throws JavaModelException { delegate . rename ( name , replace , monitor ) ; } public IJavaElement [ ] getChildren ( ) throws JavaModelException { return new IJavaElement [ <NUM_LIT:0> ] ; } public boolean hasChildren ( ) throws JavaModelException { return false ; } public IAnnotation getAnnotation ( String name ) { return delegate . getAnnotation ( name ) ; } public IAnnotation [ ] getAnnotations ( ) throws JavaModelException { return ( ( IAnnotatable ) delegate . getParent ( ) ) . getAnnotations ( ) ; } public IMemberValuePair getDefaultValue ( ) throws JavaModelException { return null ; } public String getElementName ( ) { return delegate . getElementName ( ) ; } public String [ ] getExceptionTypes ( ) throws JavaModelException { return new String [ <NUM_LIT:0> ] ; } public String [ ] getTypeParameterSignatures ( ) throws JavaModelException { return new String [ <NUM_LIT:0> ] ; } public ITypeParameter [ ] getTypeParameters ( ) throws JavaModelException { return new ITypeParameter [ <NUM_LIT:0> ] ; } public int getNumberOfParameters ( ) { return delegate . getNumberOfParameters ( ) ; } public ILocalVariable [ ] getParameters ( ) throws JavaModelException { return new ILocalVariable [ <NUM_LIT:0> ] ; } public String getKey ( ) { return delegate . getKey ( ) ; } public String [ ] getParameterNames ( ) throws JavaModelException { return parameterNames ; } public String [ ] getParameterTypes ( ) { return delegate . getParameterTypes ( ) ; } public String [ ] getRawParameterNames ( ) throws JavaModelException { return parameterNames ; } public String getReturnType ( ) throws JavaModelException { return delegate . getReturnType ( ) ; } public String getSignature ( ) throws JavaModelException { return delegate . getSignature ( ) ; } public ITypeParameter getTypeParameter ( String name ) { return delegate . getTypeParameter ( name ) ; } public boolean isConstructor ( ) throws JavaModelException { return false ; } public boolean isMainMethod ( ) throws JavaModelException { return false ; } public boolean isResolved ( ) { return false ; } public boolean isSimilar ( IMethod method ) { return delegate . isSimilar ( method ) ; } public boolean reallyExists ( ) { return delegate . exists ( ) ; } } private class Requestor extends SearchRequestor { private final ISearchRequestor uiRequestor ; public Requestor ( ISearchRequestor uiRequestor ) { this . uiRequestor = uiRequestor ; } @ Override public void acceptSearchMatch ( SearchMatch match ) throws CoreException { uiRequestor . acceptMatch ( match ) ; } } public void findSyntheticMatches ( IJavaElement element , ISearchRequestor uiRequestor , IProgressMonitor monitor ) throws CoreException { findSyntheticMatches ( element , IJavaSearchConstants . REFERENCES , new SearchParticipant [ ] { new JavaSearchParticipant ( ) } , SearchEngine . createWorkspaceScope ( ) , uiRequestor , monitor ) ; } public void findSyntheticMatches ( IJavaElement element , int limitTo , SearchParticipant [ ] participants , IJavaSearchScope scope , ISearchRequestor uiRequestor , IProgressMonitor monitor ) throws CoreException { if ( ! isInteresting ( element ) ) { return ; } if ( limitTo == IJavaSearchConstants . DECLARATIONS ) { return ; } SearchPattern pattern = createPattern ( element ) ; if ( pattern == null ) { return ; } Requestor requestor = new Requestor ( uiRequestor ) ; SearchEngine engine = new SearchEngine ( ) ; engine . search ( pattern , participants , scope , requestor , monitor ) ; } private SearchPattern createPattern ( IJavaElement element ) throws JavaModelException { List < IJavaElement > toSearch = new ArrayList < IJavaElement > ( <NUM_LIT:4> ) ; toSearch . add ( findSyntheticMember ( element , "<STR_LIT>" ) ) ; toSearch . add ( findSyntheticMember ( element , "<STR_LIT:get>" ) ) ; toSearch . add ( findSyntheticMember ( element , "<STR_LIT>" ) ) ; toSearch . add ( findSyntheticProperty ( element ) ) ; SearchPattern pattern = null ; for ( IJavaElement searchElt : toSearch ) { if ( searchElt != null ) { SearchPattern newPattern = SearchPattern . createPattern ( searchElt , IJavaSearchConstants . ALL_OCCURRENCES | IJavaSearchConstants . IGNORE_RETURN_TYPE ) ; if ( pattern == null ) { pattern = newPattern ; } else { pattern = SearchPattern . createOrPattern ( pattern , newPattern ) ; } } } return pattern ; } private boolean isInteresting ( IJavaElement element ) { return element instanceof IMember && GroovyNature . hasGroovyNature ( element . getJavaProject ( ) . getProject ( ) ) ; } private IMethod findSyntheticMember ( IJavaElement element , String prefix ) throws JavaModelException { if ( element . getElementType ( ) != IJavaElement . FIELD ) { return null ; } IType parent = ( IType ) element . getParent ( ) ; String [ ] sigs ; String [ ] names ; if ( prefix . equals ( "<STR_LIT>" ) ) { sigs = new String [ ] { ( ( IField ) element ) . getTypeSignature ( ) } ; names = new String [ ] { element . getElementName ( ) } ; } else { sigs = new String [ <NUM_LIT:0> ] ; names = new String [ <NUM_LIT:0> ] ; } MethodWrapper method = new MethodWrapper ( parent . getMethod ( convertName ( prefix , element . getElementName ( ) ) , sigs ) , names ) ; return method . reallyExists ( ) ? null : method ; } private IField findSyntheticProperty ( IJavaElement element ) throws JavaModelException { if ( element . getElementType ( ) != IJavaElement . METHOD ) { return null ; } String name = element . getElementName ( ) ; if ( name . length ( ) <= <NUM_LIT:2> ) { return null ; } int prefixLength ; if ( name . startsWith ( "<STR_LIT>" ) ) { prefixLength = <NUM_LIT:2> ; } else { if ( name . length ( ) == <NUM_LIT:3> ) { return null ; } prefixLength = <NUM_LIT:3> ; } String fieldName = "<STR_LIT>" + Character . toLowerCase ( name . charAt ( prefixLength ) ) + name . substring ( prefixLength + <NUM_LIT:1> ) ; IType parent = ( IType ) element . getParent ( ) ; IField field = parent . getField ( fieldName ) ; return field . exists ( ) && Flags . isProtected ( field . getFlags ( ) ) ? null : field ; } private String convertName ( String prefix , String elementName ) { return prefix + Character . toUpperCase ( elementName . charAt ( <NUM_LIT:0> ) ) + elementName . subSequence ( <NUM_LIT:1> , elementName . length ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . frameworkadapter . util ; import static org . codehaus . groovy . frameworkadapter . util . SpecifiedVersion . UNSPECIFIED ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . IOException ; import java . util . Properties ; import org . eclipse . osgi . framework . internal . core . FrameworkProperties ; import org . osgi . framework . BundleContext ; public class CompilerLevelUtils { private static final String GROOVY_COMPILER_LEVEL = "<STR_LIT>" ; private static final String DASH_GROOVY_COMPILER_LEVEL = "<STR_LIT>" ; private static final String ECLIPSE_COMMANDS = "<STR_LIT>" ; private CompilerLevelUtils ( ) { } public static SpecifiedVersion findSysPropVersion ( ) { SpecifiedVersion version = SpecifiedVersion . findVersionFromString ( FrameworkProperties . getProperty ( GROOVY_COMPILER_LEVEL ) ) ; if ( version == UNSPECIFIED ) { version = internalFindCommandLineVersion ( FrameworkProperties . getProperty ( ECLIPSE_COMMANDS ) ) ; } return version ; } private static SpecifiedVersion internalFindCommandLineVersion ( String property ) { if ( property == null ) { return UNSPECIFIED ; } String [ ] split = property . split ( "<STR_LIT>" ) ; String versionText = null ; for ( int i = <NUM_LIT:0> ; i < split . length ; i ++ ) { if ( DASH_GROOVY_COMPILER_LEVEL . equals ( split [ i ] ) && i < split . length - <NUM_LIT:1> ) { versionText = split [ i + <NUM_LIT:1> ] ; break ; } } return SpecifiedVersion . findVersionFromString ( versionText ) ; } public static SpecifiedVersion findConfigurationVersion ( BundleContext context ) throws IOException { File properties = context . getDataFile ( "<STR_LIT>" ) ; if ( properties == null || ! properties . exists ( ) ) { return UNSPECIFIED ; } Properties props = new Properties ( ) ; try { props . load ( new FileInputStream ( properties ) ) ; } catch ( FileNotFoundException e ) { return UNSPECIFIED ; } return SpecifiedVersion . findVersionFromString ( ( String ) props . get ( GROOVY_COMPILER_LEVEL ) ) ; } public static void writeConfigurationVersion ( SpecifiedVersion version , BundleContext context ) throws IOException { if ( context == null ) { return ; } File properties = context . getDataFile ( "<STR_LIT>" ) ; if ( properties == null ) { throw new IOException ( "<STR_LIT>" ) ; } if ( ! properties . exists ( ) && ! properties . createNewFile ( ) ) { throw new IOException ( "<STR_LIT>" + properties . getPath ( ) ) ; } Properties props = new Properties ( ) ; try { props . load ( new FileInputStream ( properties ) ) ; } catch ( FileNotFoundException e ) { } props . setProperty ( GROOVY_COMPILER_LEVEL , version . versionName ) ; props . store ( new FileOutputStream ( properties ) , "<STR_LIT>" ) ; } } </s>
|
<s> package org . codehaus . groovy . frameworkadapter . util ; import org . osgi . framework . Version ; public enum SpecifiedVersion { _16 ( <NUM_LIT:1> , <NUM_LIT:6> , "<STR_LIT>" ) , _17 ( <NUM_LIT:1> , <NUM_LIT:7> , "<STR_LIT>" ) , _18 ( <NUM_LIT:1> , <NUM_LIT:8> , "<STR_LIT>" ) , _19 ( <NUM_LIT:1> , <NUM_LIT:9> , "<STR_LIT>" ) , _20 ( <NUM_LIT:2> , <NUM_LIT:0> , "<STR_LIT>" ) , UNSPECIFIED ( - <NUM_LIT:1> , - <NUM_LIT:1> , "<STR_LIT:0>" ) ; public final int majorVersion ; public final int minorVersion ; public final String versionName ; SpecifiedVersion ( int majorVersion , int minorVersion , String versionName ) { this . majorVersion = majorVersion ; this . minorVersion = minorVersion ; this . versionName = versionName ; } public String toVersionString ( ) { return "<STR_LIT:[>" + majorVersion + "<STR_LIT:.>" + minorVersion + "<STR_LIT:.>" + <NUM_LIT:0> + "<STR_LIT:U+002C>" + majorVersion + "<STR_LIT:.>" + minorVersion + "<STR_LIT:.>" + <NUM_LIT> + "<STR_LIT:)>" ; } public String toReadableVersionString ( ) { return majorVersion + "<STR_LIT:.>" + minorVersion + "<STR_LIT>" ; } public static SpecifiedVersion findVersionFromString ( String compilerLevel ) { if ( compilerLevel == null ) { return UNSPECIFIED ; } if ( "<STR_LIT>" . equals ( compilerLevel ) || "<STR_LIT>" . equals ( compilerLevel ) ) { return _16 ; } if ( "<STR_LIT>" . equals ( compilerLevel ) || "<STR_LIT>" . equals ( compilerLevel ) ) { return _17 ; } if ( "<STR_LIT>" . equals ( compilerLevel ) || "<STR_LIT>" . equals ( compilerLevel ) ) { return _18 ; } if ( "<STR_LIT>" . equals ( compilerLevel ) || "<STR_LIT>" . equals ( compilerLevel ) ) { return _19 ; } if ( "<STR_LIT>" . equals ( compilerLevel ) || "<STR_LIT:2.0>" . equals ( compilerLevel ) ) { return _20 ; } if ( "<STR_LIT:0>" . equals ( compilerLevel ) ) { return UNSPECIFIED ; } throw new IllegalArgumentException ( "<STR_LIT>" + compilerLevel + "<STR_LIT>" ) ; } public static SpecifiedVersion findVersion ( Version ver ) { if ( ver . getMajor ( ) == <NUM_LIT:2> ) { if ( ver . getMinor ( ) == <NUM_LIT:0> ) { return _20 ; } } if ( ver . getMajor ( ) == <NUM_LIT:1> ) { if ( ver . getMinor ( ) == <NUM_LIT:6> ) { return _16 ; } if ( ver . getMinor ( ) == <NUM_LIT:7> ) { return _17 ; } if ( ver . getMinor ( ) == <NUM_LIT:8> ) { return _18 ; } if ( ver . getMinor ( ) == <NUM_LIT:9> ) { return _19 ; } } return UNSPECIFIED ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . eclipse . jdt . core . CompletionContext ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . javaeditor . EditorHighlightingSynchronizer ; import org . eclipse . jdt . internal . ui . javaeditor . JavaEditor ; import org . eclipse . jdt . internal . ui . text . java . JavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . BadPositionCategoryException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IPositionUpdater ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . Position ; import org . eclipse . jface . text . Region ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . link . ILinkedModeListener ; import org . eclipse . jface . text . link . InclusivePositionUpdater ; import org . eclipse . jface . text . link . LinkedModeModel ; import org . eclipse . jface . text . link . LinkedModeUI ; import org . eclipse . jface . text . link . LinkedPosition ; import org . eclipse . jface . text . link . LinkedPositionGroup ; import org . eclipse . jface . text . link . ProposalPosition ; import org . eclipse . jface . viewers . StyledString ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . texteditor . link . EditorLinkedModeUI ; public class NamedParameterProposal extends JavaCompletionProposal { private static final ICompletionProposal [ ] NO_COMPLETIONS = new ICompletionProposal [ <NUM_LIT:0> ] ; private IRegion selectedRegion ; private final CompletionContext coreContext ; private final boolean tryParamGuessing ; private ICompletionProposal [ ] choices ; private Position paramNamePosition ; private IPositionUpdater updater ; private String paramSignature ; private final String paramName ; public NamedParameterProposal ( String paramName , String paramSignature , int replacementOffset , int replacementLength , Image image , StyledString displayString , int relevance , boolean inJavadoc , JavaContentAssistInvocationContext invocationContext , boolean tryParamGuessing ) { super ( computeReplacementString ( paramName ) , replacementOffset , replacementLength , image , displayString , relevance , inJavadoc , invocationContext ) ; this . tryParamGuessing = tryParamGuessing ; coreContext = invocationContext . getCoreContext ( ) ; this . paramName = paramName ; this . paramSignature = paramSignature ; this . setTriggerCharacters ( ProposalUtils . VAR_TRIGGER ) ; } private String computeReplacementChoices ( String name ) { if ( shouldDoGuessing ( ) ) { try { choices = guessParameters ( paramName . toCharArray ( ) ) ; } catch ( JavaModelException e ) { paramNamePosition = null ; choices = null ; JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } } return computeReplacementString ( name ) ; } private static String computeReplacementString ( String name ) { return name + "<STR_LIT>" ; } private IRegion calculateArgumentRegion ( ) { String repl = getReplacementString ( ) ; int replOffset = getReplacementOffset ( ) ; int start = replOffset + repl . indexOf ( "<STR_LIT::U+0020>" ) + <NUM_LIT:2> ; int end = replOffset + repl . indexOf ( "<STR_LIT:U+002C>" ) ; if ( start > <NUM_LIT:0> && end > <NUM_LIT:0> ) { return new Region ( start , end - start ) ; } else { return null ; } } private boolean shouldDoGuessing ( ) { return tryParamGuessing && coreContext . isExtended ( ) ; } private ICompletionProposal [ ] guessParameters ( char [ ] parameterName ) throws JavaModelException { if ( paramSignature == null ) { return NO_COMPLETIONS ; } String type = Signature . toString ( paramSignature ) ; IJavaElement [ ] assignableElements = getAssignableElements ( ) ; Position position = new Position ( selectedRegion . getOffset ( ) , selectedRegion . getLength ( ) ) ; ICompletionProposal [ ] argumentProposals = new ParameterGuesserDelegate ( getEnclosingElement ( ) ) . parameterProposals ( type , paramName , position , assignableElements , tryParamGuessing ) ; if ( argumentProposals . length == <NUM_LIT:0> ) { argumentProposals = new ICompletionProposal [ ] { new JavaCompletionProposal ( paramName , <NUM_LIT:0> , paramName . length ( ) , null , paramName , <NUM_LIT:0> ) } ; } paramNamePosition = position ; return choices = argumentProposals ; } private IJavaElement getEnclosingElement ( ) { return coreContext . getEnclosingElement ( ) ; } private IJavaElement [ ] getAssignableElements ( ) { return coreContext . getVisibleElements ( paramSignature ) ; } @ Override public void apply ( IDocument document , char trigger , int offset ) { super . apply ( document , trigger , offset ) ; if ( selectedRegion == null ) { selectedRegion = calculateArgumentRegion ( ) ; } setUpLinkedMode ( document , '<CHAR_LIT:U+002C>' ) ; } @ Override protected void setUpLinkedMode ( IDocument document , char closingCharacter ) { ITextViewer textViewer = getTextViewer ( ) ; if ( textViewer != null ) { int baseOffset = getReplacementOffset ( ) ; String replacement = computeReplacementChoices ( paramName ) ; try { LinkedModeModel model = new LinkedModeModel ( ) ; IRegion argRegion = calculateArgumentRegion ( ) ; LinkedPositionGroup group = new LinkedPositionGroup ( ) ; if ( shouldDoGuessing ( ) ) { ensurePositionCategoryInstalled ( document , model ) ; document . addPosition ( getCategory ( ) , paramNamePosition ) ; group . addPosition ( new ProposalPosition ( document , paramNamePosition . getOffset ( ) , paramNamePosition . getLength ( ) , LinkedPositionGroup . NO_STOP , choices ) ) ; } else { group . addPosition ( new LinkedPosition ( document , argRegion . getOffset ( ) , argRegion . getLength ( ) , LinkedPositionGroup . NO_STOP ) ) ; } model . addGroup ( group ) ; model . forceInstall ( ) ; JavaEditor editor = getJavaEditor ( ) ; if ( editor != null ) { model . addLinkingListener ( new EditorHighlightingSynchronizer ( editor ) ) ; } LinkedModeUI ui = new EditorLinkedModeUI ( model , textViewer ) ; ui . setExitPosition ( textViewer , baseOffset + replacement . length ( ) , <NUM_LIT:0> , Integer . MAX_VALUE ) ; ui . setExitPolicy ( new ExitPolicy ( closingCharacter , document ) ) ; ui . setDoContextInfo ( true ) ; ui . setCyclingMode ( LinkedModeUI . CYCLE_WHEN_NO_PARENT ) ; ui . enter ( ) ; selectedRegion = ui . getSelectedRegion ( ) ; } catch ( BadLocationException e ) { ensurePositionCategoryRemoved ( document ) ; JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } catch ( BadPositionCategoryException e ) { ensurePositionCategoryRemoved ( document ) ; JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } } } @ Override public Point getSelection ( IDocument document ) { if ( selectedRegion == null ) { return new Point ( getReplacementOffset ( ) , <NUM_LIT:0> ) ; } else { return new Point ( selectedRegion . getOffset ( ) , selectedRegion . getLength ( ) ) ; } } private JavaEditor getJavaEditor ( ) { IEditorPart part = JavaPlugin . getActivePage ( ) . getActiveEditor ( ) ; if ( part instanceof JavaEditor ) { return ( JavaEditor ) part ; } else { return null ; } } private void openErrorDialog ( Exception e ) { Shell shell = getTextViewer ( ) . getTextWidget ( ) . getShell ( ) ; MessageDialog . openError ( shell , "<STR_LIT>" , e . getMessage ( ) ) ; } private void ensurePositionCategoryInstalled ( final IDocument document , LinkedModeModel model ) { if ( ! document . containsPositionCategory ( getCategory ( ) ) ) { document . addPositionCategory ( getCategory ( ) ) ; updater = new InclusivePositionUpdater ( getCategory ( ) ) ; document . addPositionUpdater ( updater ) ; model . addLinkingListener ( new ILinkedModeListener ( ) { public void left ( LinkedModeModel environment , int flags ) { ensurePositionCategoryRemoved ( document ) ; } public void suspend ( LinkedModeModel environment ) { } public void resume ( LinkedModeModel environment , int flags ) { } } ) ; } } private void ensurePositionCategoryRemoved ( IDocument document ) { if ( document . containsPositionCategory ( getCategory ( ) ) ) { try { document . removePositionCategory ( getCategory ( ) ) ; } catch ( BadPositionCategoryException e ) { } document . removePositionUpdater ( updater ) ; } } private String getCategory ( ) { return "<STR_LIT>" + toString ( ) ; } public ICompletionProposal [ ] getChoices ( ) throws JavaModelException { selectedRegion = calculateArgumentRegion ( ) ; return guessParameters ( paramName . toCharArray ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import java . lang . reflect . Method ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . internal . ui . text . java . ParameterGuesser ; import org . eclipse . jdt . internal . ui . text . template . contentassist . PositionBasedCompletionProposal ; import org . eclipse . jface . text . Position ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class ParameterGuesserDelegate { private static final String CLOSURE_TEXT = "<STR_LIT>" ; private static final String EMPTY_STRING = "<STR_LIT>" ; private static final String NULL_TEXT = "<STR_LIT:null>" ; private ParameterGuesser guesser ; public ParameterGuesserDelegate ( IJavaElement enclosingElement ) { guesser = new ParameterGuesser ( enclosingElement ) ; } public ICompletionProposal [ ] parameterProposals ( String parameterType , String paramName , Position position , IJavaElement [ ] assignable , boolean fillBestGuess ) { parameterType = convertToPrimitive ( parameterType ) ; Method method = findParameterProposalsMethod ( ) ; try { ICompletionProposal [ ] allCompletions ; if ( method . getParameterTypes ( ) . length == <NUM_LIT:5> ) { allCompletions = ( ICompletionProposal [ ] ) method . invoke ( guesser , parameterType , paramName , position , assignable , fillBestGuess ) ; } else { allCompletions = ( ICompletionProposal [ ] ) method . invoke ( guesser , parameterType , paramName , position , assignable , fillBestGuess , false ) ; } if ( allCompletions != null && allCompletions . length > <NUM_LIT:0> && assignable != null && assignable . length > <NUM_LIT:0> ) { IType declaring = ( IType ) assignable [ <NUM_LIT:0> ] . getAncestor ( IJavaElement . TYPE ) ; if ( declaring != null && declaring . isEnum ( ) ) { boolean useFull = true ; for ( int i = <NUM_LIT:0> ; i < assignable . length && i < allCompletions . length ; i ++ ) { if ( assignable [ i ] . getElementType ( ) == IJavaElement . FIELD ) { if ( useFull ) { String newReplacement = declaring . getElementName ( ) + '<CHAR_LIT:.>' + assignable [ i ] . getElementName ( ) ; ReflectionUtils . setPrivateField ( PositionBasedCompletionProposal . class , "<STR_LIT>" , allCompletions [ i ] , newReplacement ) ; ReflectionUtils . setPrivateField ( PositionBasedCompletionProposal . class , "<STR_LIT>" , allCompletions [ i ] , newReplacement ) ; useFull = false ; } else { useFull = true ; } } } } } return addExtras ( allCompletions , parameterType , position ) ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; return ProposalUtils . NO_COMPLETIONS ; } } private String convertToPrimitive ( String parameterType ) { if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT:int>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT:long>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT:float>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT:double>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( parameterType ) ) { return "<STR_LIT:boolean>" ; } return parameterType ; } private static Method parameterProposalsMethod ; private static Method findParameterProposalsMethod ( ) { if ( parameterProposalsMethod == null ) { try { parameterProposalsMethod = ParameterGuesser . class . getMethod ( "<STR_LIT>" , String . class , String . class , Position . class , IJavaElement [ ] . class , boolean . class ) ; } catch ( SecurityException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } catch ( NoSuchMethodException e ) { try { parameterProposalsMethod = ParameterGuesser . class . getMethod ( "<STR_LIT>" , String . class , String . class , Position . class , IJavaElement [ ] . class , boolean . class , boolean . class ) ; } catch ( SecurityException e1 ) { GroovyCore . logException ( "<STR_LIT>" , e1 ) ; } catch ( NoSuchMethodException e1 ) { GroovyCore . logException ( "<STR_LIT>" , e1 ) ; } } } return parameterProposalsMethod ; } private ICompletionProposal [ ] addExtras ( ICompletionProposal [ ] parameterProposals , String expectedType , Position position ) { ICompletionProposal proposal = null ; if ( expectedType . equals ( VariableScope . STRING_CLASS_NODE . getName ( ) ) ) { proposal = new PositionBasedCompletionProposal ( EMPTY_STRING , position , <NUM_LIT:1> ) ; } else if ( expectedType . equals ( VariableScope . CLOSURE_CLASS . getName ( ) ) ) { proposal = new PositionBasedCompletionProposal ( CLOSURE_TEXT , position , <NUM_LIT:2> ) ; } if ( proposal != null ) { int origLen = parameterProposals . length ; if ( parameterProposals [ origLen - <NUM_LIT:1> ] . getDisplayString ( ) . equals ( NULL_TEXT ) ) { parameterProposals [ origLen - <NUM_LIT:1> ] = proposal ; } else { ICompletionProposal [ ] newProps = new ICompletionProposal [ origLen + <NUM_LIT:1> ] ; System . arraycopy ( parameterProposals , <NUM_LIT:0> , newProps , <NUM_LIT:0> , origLen ) ; parameterProposals = newProps ; parameterProposals [ origLen ] = proposal ; } } return parameterProposals ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . processors . GroovyCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . ProposalFormattingOptions ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . javaeditor . EditorHighlightingSynchronizer ; import org . eclipse . jdt . internal . ui . javaeditor . JavaEditor ; import org . eclipse . jdt . internal . ui . text . java . JavaMethodCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . ProposalContextInformation ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . Region ; import org . eclipse . jface . text . contentassist . IContextInformation ; import org . eclipse . jface . text . link . LinkedModeModel ; import org . eclipse . jface . text . link . LinkedModeUI ; import org . eclipse . jface . text . link . LinkedPosition ; import org . eclipse . jface . text . link . LinkedPositionGroup ; import org . eclipse . jface . viewers . StyledString ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . texteditor . link . EditorLinkedModeUI ; public class GroovyJavaMethodCompletionProposal extends JavaMethodCompletionProposal { private static final String CLOSURE_TEXT = "<STR_LIT>" ; private int [ ] fArgumentOffsets ; private int [ ] fArgumentLengths ; private IRegion fSelectedRegion ; private final ProposalFormattingOptions proposalOptions ; private String contributor ; private boolean contextOnly ; public GroovyJavaMethodCompletionProposal ( GroovyCompletionProposal proposal , JavaContentAssistInvocationContext context , ProposalFormattingOptions groovyFormatterPrefs ) { super ( proposal , context ) ; this . proposalOptions = groovyFormatterPrefs ; this . contributor = "<STR_LIT>" ; this . setRelevance ( proposal . getRelevance ( ) ) ; if ( proposal . hasParameters ( ) ) { this . setTriggerCharacters ( ProposalUtils . METHOD_WITH_ARGUMENTS_TRIGGERS ) ; } else { this . setTriggerCharacters ( ProposalUtils . METHOD_TRIGGERS ) ; } } public GroovyJavaMethodCompletionProposal ( GroovyCompletionProposal proposal , JavaContentAssistInvocationContext context , ProposalFormattingOptions groovyFormatterPrefs , String contributor ) { this ( proposal , context , groovyFormatterPrefs ) ; this . contributor = contributor ; } public void contextOnly ( ) { contextOnly = true ; } @ Override protected StyledString computeDisplayString ( ) { return super . computeDisplayString ( ) . append ( getStyledGroovy ( ) ) ; } @ Override protected IContextInformation computeContextInformation ( ) { if ( ( fProposal . getKind ( ) == CompletionProposal . METHOD_REF || fProposal . getKind ( ) == CompletionProposal . CONSTRUCTOR_INVOCATION ) && hasParameters ( ) ) { ProposalContextInformation contextInformation = new ProposalContextInformation ( fProposal ) ; if ( fContextInformationPosition != <NUM_LIT:0> && fProposal . getCompletion ( ) . length == <NUM_LIT:0> ) contextInformation . setContextInformationPosition ( fContextInformationPosition ) ; return contextInformation ; } return super . computeContextInformation ( ) ; } private StyledString getStyledGroovy ( ) { return new StyledString ( "<STR_LIT:U+0020(>" + contributor + "<STR_LIT:)>" , StyledString . DECORATIONS_STYLER ) ; } @ Override public void apply ( IDocument document , char trigger , int offset ) { super . apply ( document , trigger , offset ) ; int baseOffset = getReplacementOffset ( ) ; String replacement = getReplacementString ( ) ; fSelectedRegion = new Region ( baseOffset + replacement . length ( ) , <NUM_LIT:0> ) ; } @ Override protected void setUpLinkedMode ( IDocument document , char closingCharacter ) { if ( fArgumentOffsets != null && getTextViewer ( ) != null ) { int baseOffset = getReplacementOffset ( ) ; String replacement = getReplacementString ( ) ; try { LinkedModeModel model = new LinkedModeModel ( ) ; for ( int i = <NUM_LIT:0> ; i != fArgumentOffsets . length ; i ++ ) { LinkedPositionGroup group = new LinkedPositionGroup ( ) ; group . addPosition ( new LinkedPosition ( document , baseOffset + fArgumentOffsets [ i ] , fArgumentLengths [ i ] , LinkedPositionGroup . NO_STOP ) ) ; model . addGroup ( group ) ; } model . forceInstall ( ) ; JavaEditor editor = getJavaEditor ( ) ; if ( editor != null ) { model . addLinkingListener ( new EditorHighlightingSynchronizer ( editor ) ) ; } LinkedModeUI ui = new EditorLinkedModeUI ( model , getTextViewer ( ) ) ; ui . setExitPosition ( getTextViewer ( ) , baseOffset + replacement . length ( ) , <NUM_LIT:0> , Integer . MAX_VALUE ) ; ui . setExitPolicy ( new ExitPolicy ( '<CHAR_LIT:)>' , document ) ) ; ui . setDoContextInfo ( true ) ; ui . setCyclingMode ( LinkedModeUI . CYCLE_WHEN_NO_PARENT ) ; ui . enter ( ) ; fSelectedRegion = ui . getSelectedRegion ( ) ; } catch ( BadLocationException e ) { JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } } } @ Override protected String computeReplacementString ( ) { if ( contextOnly ) { return "<STR_LIT>" ; } char [ ] proposalName = fProposal . getName ( ) ; boolean hasWhitespace = false ; for ( int i = <NUM_LIT:0> ; i < proposalName . length ; i ++ ) { if ( CharOperation . isWhitespace ( proposalName [ i ] ) ) { hasWhitespace = true ; } } if ( ( ! hasParameters ( ) || ! hasArgumentList ( ) ) && ! hasWhitespace ) { return super . computeReplacementString ( ) ; } StringBuffer buffer = new StringBuffer ( ) ; char [ ] newProposalName ; if ( hasWhitespace ) { newProposalName = CharOperation . concat ( new char [ ] { '<CHAR_LIT:">' } , CharOperation . append ( proposalName , '<CHAR_LIT:">' ) ) ; } else { newProposalName = proposalName ; } fProposal . setName ( newProposalName ) ; appendMethodNameReplacement ( buffer ) ; fProposal . setName ( proposalName ) ; FormatterPrefs prefs = getFormatterPrefs ( ) ; if ( hasParameters ( ) ) { int indexOfLastClosure = - <NUM_LIT:1> ; char [ ] [ ] regularParameterTypes = ( ( GroovyCompletionProposal ) fProposal ) . getRegularParameterTypeNames ( ) ; char [ ] [ ] namedParameterTypes = ( ( GroovyCompletionProposal ) fProposal ) . getNamedParameterTypeNames ( ) ; if ( proposalOptions . noParensAroundClosures ) { if ( lastArgIsClosure ( regularParameterTypes , namedParameterTypes ) ) { indexOfLastClosure = regularParameterTypes . length + namedParameterTypes . length - <NUM_LIT:1> ; } if ( indexOfLastClosure == <NUM_LIT:0> ) { buffer . replace ( buffer . length ( ) - <NUM_LIT:1> , buffer . length ( ) , "<STR_LIT>" ) ; if ( ! prefs . beforeOpeningParen ) { buffer . append ( SPACE ) ; } } } else { if ( prefs . afterOpeningParen ) buffer . append ( SPACE ) ; } char [ ] [ ] namedParameterNames = ( ( GroovyCompletionProposal ) fProposal ) . getNamedParameterNames ( ) ; char [ ] [ ] regularParameterNames = ( ( GroovyCompletionProposal ) fProposal ) . getRegularParameterNames ( ) ; int namedCount = namedParameterNames . length ; int argCount = regularParameterNames . length ; int allCount = argCount + namedCount ; fArgumentOffsets = new int [ allCount ] ; fArgumentLengths = new int [ allCount ] ; for ( int i = <NUM_LIT:0> ; i < allCount ; i ++ ) { char [ ] nextName ; char [ ] nextTypeName ; if ( i < namedCount ) { nextName = namedParameterNames [ i ] ; nextTypeName = namedParameterNames [ i ] ; } else { nextTypeName = regularParameterTypes [ i - namedCount ] ; nextName = regularParameterNames [ i - namedCount ] ; } if ( proposalOptions . useNamedArguments || i < namedCount ) { buffer . append ( nextName ) . append ( "<STR_LIT::>" ) ; } fArgumentOffsets [ i ] = buffer . length ( ) ; if ( i == <NUM_LIT:0> ) { setCursorPosition ( buffer . length ( ) ) ; } if ( proposalOptions . useBracketsForClosures && CharOperation . equals ( "<STR_LIT>" . toCharArray ( ) , nextTypeName ) ) { fArgumentOffsets [ i ] = buffer . length ( ) + <NUM_LIT:2> ; fArgumentLengths [ i ] = <NUM_LIT:0> ; buffer . append ( CLOSURE_TEXT ) ; } else { fArgumentOffsets [ i ] = buffer . length ( ) ; buffer . append ( nextName ) ; fArgumentLengths [ i ] = nextName . length ; } if ( i == indexOfLastClosure - <NUM_LIT:1> || ( i != indexOfLastClosure && i == allCount - <NUM_LIT:1> ) ) { if ( prefs . beforeClosingParen ) { buffer . append ( SPACE ) ; } buffer . append ( RPAREN ) ; if ( i == indexOfLastClosure - <NUM_LIT:1> ) { buffer . append ( SPACE ) ; } } else if ( i < allCount - <NUM_LIT:1> ) { if ( prefs . beforeComma ) buffer . append ( SPACE ) ; buffer . append ( COMMA ) ; if ( prefs . afterComma ) buffer . append ( SPACE ) ; } } } else { if ( prefs . inEmptyList ) { buffer . append ( SPACE ) ; } buffer . append ( RPAREN ) ; } return buffer . toString ( ) ; } private boolean lastArgIsClosure ( char [ ] [ ] regularparameterTypes , char [ ] [ ] namedParameterTypes ) { char [ ] lastArgType ; if ( namedParameterTypes != null && namedParameterTypes . length > <NUM_LIT:0> ) { lastArgType = namedParameterTypes [ namedParameterTypes . length - <NUM_LIT:1> ] ; } else if ( regularparameterTypes != null && regularparameterTypes . length > <NUM_LIT:0> ) { lastArgType = regularparameterTypes [ regularparameterTypes . length - <NUM_LIT:1> ] ; } else { return false ; } return CharOperation . equals ( "<STR_LIT>" . toCharArray ( ) , lastArgType ) ; } @ Override protected boolean needsLinkedMode ( ) { return super . needsLinkedMode ( ) ; } private JavaEditor getJavaEditor ( ) { IEditorPart part = JavaPlugin . getActivePage ( ) . getActiveEditor ( ) ; if ( part instanceof JavaEditor ) return ( JavaEditor ) part ; else return null ; } @ Override public Point getSelection ( IDocument document ) { if ( fSelectedRegion == null ) return new Point ( getReplacementOffset ( ) , <NUM_LIT:0> ) ; return new Point ( fSelectedRegion . getOffset ( ) , fSelectedRegion . getLength ( ) ) ; } private void openErrorDialog ( BadLocationException e ) { Shell shell = getTextViewer ( ) . getTextWidget ( ) . getShell ( ) ; MessageDialog . openError ( shell , "<STR_LIT>" , e . getMessage ( ) ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . stmt . Statement ; public class NamedArgsMethodNode extends MethodNode { private static final Parameter [ ] NO_PARAMETERS = new Parameter [ <NUM_LIT:0> ] ; private final Parameter [ ] regularParams ; private final Parameter [ ] namedParams ; private final Parameter [ ] optionalParams ; private Parameter [ ] visibleParams ; public NamedArgsMethodNode ( String name , int modifiers , ClassNode returnType , Parameter [ ] regularParams , Parameter [ ] namedParams , Parameter [ ] optionalParams , ClassNode [ ] exceptions , Statement code ) { super ( name , modifiers , returnType , concatParams ( regularParams , namedParams , optionalParams ) , exceptions , code ) ; this . regularParams = regularParams ; this . namedParams = namedParams ; this . optionalParams = optionalParams ; } private static Parameter [ ] concatParams ( Parameter [ ] regularParams , Parameter [ ] namedParams , Parameter [ ] optionalParams ) { regularParams = regularParams == null ? NO_PARAMETERS : regularParams ; namedParams = namedParams == null ? NO_PARAMETERS : namedParams ; optionalParams = optionalParams == null ? NO_PARAMETERS : optionalParams ; Parameter [ ] allParams = new Parameter [ regularParams . length + namedParams . length + optionalParams . length ] ; System . arraycopy ( regularParams , <NUM_LIT:0> , allParams , <NUM_LIT:0> , regularParams . length ) ; System . arraycopy ( namedParams , <NUM_LIT:0> , allParams , regularParams . length , namedParams . length ) ; System . arraycopy ( optionalParams , <NUM_LIT:0> , allParams , regularParams . length + namedParams . length , optionalParams . length ) ; return allParams ; } public Parameter [ ] getRegularParams ( ) { return regularParams ; } public Parameter [ ] getNamedParams ( ) { return namedParams ; } public Parameter [ ] getOptionalParams ( ) { return optionalParams ; } public Parameter [ ] getVisibleParams ( ) { if ( visibleParams == null ) { visibleParams = new Parameter [ regularParams . length + namedParams . length ] ; System . arraycopy ( regularParams , <NUM_LIT:0> , visibleParams , <NUM_LIT:0> , regularParams . length ) ; System . arraycopy ( namedParams , <NUM_LIT:0> , visibleParams , regularParams . length , namedParams . length ) ; } return visibleParams ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import java . util . HashMap ; import java . util . Iterator ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . model . GroovyProjectFacade ; import org . codehaus . jdt . groovy . internal . SimplifiedExtendedCompletionContext ; import org . eclipse . jdt . core . IField ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . ITypeHierarchy ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . groovy . search . VariableScope . VariableInfo ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . SourceField ; public class GroovyExtendedCompletionContext extends SimplifiedExtendedCompletionContext { class PropertyVariant extends SourceField implements IField { private final IMethod baseMethod ; PropertyVariant ( IMethod method ) { super ( ( JavaElement ) method . getParent ( ) , toFieldName ( method ) ) ; baseMethod = method ; } @ Override public boolean exists ( ) { return true ; } @ Override public String getTypeSignature ( ) throws JavaModelException { return baseMethod . getReturnType ( ) ; } @ Override public int getFlags ( ) throws JavaModelException { return baseMethod . getFlags ( ) ; } } private static String toFieldName ( IMethod method ) { return ProposalUtils . createMockFieldName ( method . getElementName ( ) ) ; } private static final IJavaElement [ ] NO_ELEMENTS = new IJavaElement [ <NUM_LIT:0> ] ; private final ContentAssistContext context ; private final VariableScope currentScope ; private IJavaElement enclosingElement ; private final Map < String , IJavaElement [ ] > visibleElements ; public GroovyExtendedCompletionContext ( ContentAssistContext context , VariableScope currentScope ) { this . context = context ; this . currentScope = currentScope ; this . visibleElements = new HashMap < String , IJavaElement [ ] > ( ) ; } @ Override public IJavaElement getEnclosingElement ( ) { if ( enclosingElement == null ) { try { enclosingElement = context . unit . getElementAt ( context . completionLocation ) ; } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } if ( enclosingElement == null ) { enclosingElement = context . unit ; } } return enclosingElement ; } @ Override public IJavaElement [ ] getVisibleElements ( String typeSignature ) { typeSignature = Signature . getTypeErasure ( typeSignature ) ; IJavaElement [ ] elements = visibleElements . get ( typeSignature ) ; if ( elements == null ) { elements = computeVisibleElements ( typeSignature ) ; visibleElements . put ( typeSignature , elements ) ; } return elements ; } private IJavaElement [ ] computeVisibleElements ( String typeSignature ) { ClassNode targetType = toClassNode ( typeSignature ) ; boolean isInterface = targetType . isInterface ( ) ; boolean isEnum = targetType . isEnum ( ) ; Map < String , IJavaElement > nameElementMap = new LinkedHashMap < String , IJavaElement > ( ) ; Iterator < Entry < String , VariableInfo > > variablesIter = currentScope . variablesIterator ( ) ; while ( variablesIter . hasNext ( ) ) { Entry < String , VariableInfo > entry = variablesIter . next ( ) ; String varName = entry . getKey ( ) ; if ( ! varName . startsWith ( "<STR_LIT:get>" ) && ! varName . startsWith ( "<STR_LIT>" ) && ! varName . equals ( "<STR_LIT>" ) && ! varName . startsWith ( "<STR_LIT:<>" ) && ! nameElementMap . containsKey ( varName ) ) { ClassNode type = entry . getValue ( ) . type ; if ( isAssignableTo ( type , targetType , isInterface ) ) { nameElementMap . put ( varName , ReflectionUtils . createLocalVariable ( getEnclosingElement ( ) , varName , <NUM_LIT:0> , typeSignature ) ) ; } } } IType enclosingType = ( IType ) getEnclosingElement ( ) . getAncestor ( IJavaElement . TYPE ) ; if ( enclosingType != null ) { try { addFields ( targetType , isInterface , nameElementMap , enclosingType ) ; ITypeHierarchy typeHierarchy = enclosingType . newSupertypeHierarchy ( null ) ; IType [ ] allTypes = typeHierarchy . getAllSupertypes ( enclosingType ) ; for ( IType superType : allTypes ) { addFields ( targetType , isInterface , nameElementMap , superType ) ; } } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } if ( isEnum ) { IType targetIType = new GroovyProjectFacade ( enclosingElement ) . groovyClassToJavaType ( targetType ) ; List < FieldNode > fields = targetType . getFields ( ) ; for ( FieldNode enumVal : fields ) { String name = enumVal . getName ( ) ; if ( name . equals ( "<STR_LIT>" ) || name . equals ( "<STR_LIT>" ) ) { continue ; } if ( ! enumVal . getType ( ) . equals ( targetType ) ) { continue ; } nameElementMap . put ( targetIType . getElementName ( ) + "<STR_LIT:.>" + name , targetIType . getField ( name ) ) ; nameElementMap . put ( name , targetIType . getField ( name ) ) ; } } return nameElementMap . values ( ) . toArray ( NO_ELEMENTS ) ; } public void addFields ( ClassNode targetType , boolean isInterface , Map < String , IJavaElement > nameElementMap , IType type ) throws JavaModelException { IField [ ] fields = type . getFields ( ) ; for ( IField field : fields ) { ClassNode fieldTypeClassNode = toClassNode ( field . getTypeSignature ( ) ) ; if ( isAssignableTo ( fieldTypeClassNode , targetType , isInterface ) ) { nameElementMap . put ( field . getElementName ( ) , field ) ; } } IMethod [ ] methods = type . getMethods ( ) ; for ( IMethod method : methods ) { ClassNode methodReturnTypeClassNode = toClassNode ( method . getReturnType ( ) ) ; if ( isAssignableTo ( methodReturnTypeClassNode , targetType , isInterface ) ) { if ( ( method . getParameterTypes ( ) == null || method . getParameterTypes ( ) . length == <NUM_LIT:0> ) && ( method . getElementName ( ) . startsWith ( "<STR_LIT:get>" ) || method . getElementName ( ) . startsWith ( "<STR_LIT>" ) ) ) { nameElementMap . put ( method . getElementName ( ) , method ) ; IField field = new PropertyVariant ( method ) ; nameElementMap . put ( field . getElementName ( ) , field ) ; } } } } private ClassNode toClassNode ( String typeSignature ) { int dims = Signature . getArrayCount ( typeSignature ) ; String noArray = Signature . getElementType ( typeSignature ) ; String qualifiedName = getQualifiedName ( noArray ) ; ClassNode resolved ; if ( typeSignature . length ( ) == <NUM_LIT:1> + dims ) { resolved = ClassHelper . getWrapper ( ClassHelper . make ( qualifiedName ) ) ; } else { try { resolved = context . unit . getModuleInfo ( false ) . resolver . resolve ( qualifiedName ) ; } catch ( NullPointerException e ) { resolved = VariableScope . OBJECT_CLASS_NODE ; } } for ( int i = <NUM_LIT:0> ; i < dims ; i ++ ) { resolved = resolved . makeArray ( ) ; } return resolved ; } private boolean isAssignableTo ( ClassNode type , ClassNode superType , boolean isInterface ) { while ( type . isArray ( ) && superType . isArray ( ) ) { type = type . getComponentType ( ) ; superType = superType . getComponentType ( ) ; } if ( type . isArray ( ) || superType . isArray ( ) ) { return false ; } type = ClassHelper . getWrapper ( type ) ; if ( type . equals ( superType ) ) { return true ; } if ( isInterface ) { return type . implementsInterface ( superType ) ; } else { return type . isDerivedFrom ( superType ) ; } } private String getQualifiedName ( String typeSignature ) { String qualifier = Signature . getSignatureQualifier ( typeSignature ) ; String qualifiedName = Signature . getSignatureSimpleName ( typeSignature ) ; if ( qualifier . length ( ) > <NUM_LIT:0> ) { qualifiedName = qualifier + "<STR_LIT:.>" + qualifiedName ; } return qualifiedName ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . completions ; import org . codehaus . groovy . eclipse . codeassist . processors . GroovyCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . ProposalFormattingOptions ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jdt . core . CompletionContext ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . corext . template . java . SignatureUtil ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . javaeditor . EditorHighlightingSynchronizer ; import org . eclipse . jdt . internal . ui . javaeditor . JavaEditor ; import org . eclipse . jdt . internal . ui . text . java . JavaCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . JavaMethodCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . ParameterGuessingProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . text . BadLocationException ; import org . eclipse . jface . text . BadPositionCategoryException ; import org . eclipse . jface . text . IDocument ; import org . eclipse . jface . text . IPositionUpdater ; import org . eclipse . jface . text . IRegion ; import org . eclipse . jface . text . Position ; import org . eclipse . jface . text . Region ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . link . ILinkedModeListener ; import org . eclipse . jface . text . link . InclusivePositionUpdater ; import org . eclipse . jface . text . link . LinkedModeModel ; import org . eclipse . jface . text . link . LinkedModeUI ; import org . eclipse . jface . text . link . LinkedPosition ; import org . eclipse . jface . text . link . LinkedPositionGroup ; import org . eclipse . jface . text . link . ProposalPosition ; import org . eclipse . jface . viewers . StyledString ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorPart ; import org . eclipse . ui . texteditor . link . EditorLinkedModeUI ; public class GroovyJavaGuessingCompletionProposal extends JavaMethodCompletionProposal { public static GroovyJavaGuessingCompletionProposal createProposal ( CompletionProposal proposal , JavaContentAssistInvocationContext context , boolean fillBestGuess , String contributor , ProposalFormattingOptions options ) { CompletionContext coreContext = context . getCoreContext ( ) ; if ( coreContext != null && coreContext . isExtended ( ) ) { return new GroovyJavaGuessingCompletionProposal ( proposal , context , coreContext , fillBestGuess , contributor , options ) ; } return null ; } private static final boolean DEBUG = "<STR_LIT:true>" . equalsIgnoreCase ( Platform . getDebugOption ( "<STR_LIT>" ) ) ; private static final String LAST_CLOSURE_TEXT = "<STR_LIT:{>" ; private ICompletionProposal [ ] [ ] fChoices ; private Position [ ] fPositions ; private IRegion fSelectedRegion ; private IPositionUpdater fUpdater ; private final boolean fFillBestGuess ; private final CompletionContext fCoreContext ; private final ProposalFormattingOptions proposalOptions ; private final String contributor ; private GroovyJavaGuessingCompletionProposal ( CompletionProposal proposal , JavaContentAssistInvocationContext context , CompletionContext coreContext , boolean fillBestGuess , String contributor , ProposalFormattingOptions proposalOptions ) { super ( proposal , context ) ; fCoreContext = coreContext ; fFillBestGuess = fillBestGuess ; this . contributor = contributor ; this . proposalOptions = proposalOptions ; } @ Override protected int computeRelevance ( ) { return fProposal . getRelevance ( ) ; } private IJavaElement getEnclosingElement ( ) { return fCoreContext . getEnclosingElement ( ) ; } private String [ ] cachedVisibleParameterTypes = null ; private String [ ] getParameterTypes ( ) { if ( cachedVisibleParameterTypes == null ) { char [ ] signature = SignatureUtil . fix83600 ( fProposal . getSignature ( ) ) ; char [ ] [ ] types = Signature . getParameterTypes ( signature ) ; String [ ] ret = new String [ types . length ] ; for ( int i = <NUM_LIT:0> ; i < types . length ; i ++ ) { ret [ i ] = new String ( Signature . toCharArray ( types [ i ] ) ) ; } cachedVisibleParameterTypes = ret ; } return cachedVisibleParameterTypes ; } private IJavaElement [ ] [ ] getAssignableElements ( ) { String [ ] parameterTypes = getParameterTypes ( ) ; IJavaElement [ ] [ ] assignableElements = new IJavaElement [ parameterTypes . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < parameterTypes . length ; i ++ ) { String typeName = new String ( parameterTypes [ i ] ) ; assignableElements [ i ] = fCoreContext . getVisibleElements ( Signature . createTypeSignature ( typeName , true ) ) ; } return assignableElements ; } @ Override public void apply ( IDocument document , char trigger , int offset ) { try { super . apply ( document , trigger , offset ) ; int baseOffset = getReplacementOffset ( ) ; String replacement = getReplacementString ( ) ; if ( fPositions != null && getTextViewer ( ) != null ) { LinkedModeModel model = new LinkedModeModel ( ) ; for ( int i = <NUM_LIT:0> ; i < fPositions . length ; i ++ ) { LinkedPositionGroup group = new LinkedPositionGroup ( ) ; int positionOffset = fPositions [ i ] . getOffset ( ) ; int positionLength = fPositions [ i ] . getLength ( ) ; if ( fChoices [ i ] . length < <NUM_LIT:2> ) { group . addPosition ( new LinkedPosition ( document , positionOffset , positionLength , LinkedPositionGroup . NO_STOP ) ) ; } else { ensurePositionCategoryInstalled ( document , model ) ; document . addPosition ( getCategory ( ) , fPositions [ i ] ) ; group . addPosition ( new ProposalPosition ( document , positionOffset , positionLength , LinkedPositionGroup . NO_STOP , fChoices [ i ] ) ) ; } model . addGroup ( group ) ; } model . forceInstall ( ) ; JavaEditor editor = getJavaEditor ( ) ; if ( editor != null ) { model . addLinkingListener ( new EditorHighlightingSynchronizer ( editor ) ) ; } LinkedModeUI ui = new EditorLinkedModeUI ( model , getTextViewer ( ) ) ; ui . setExitPosition ( getTextViewer ( ) , baseOffset + replacement . length ( ) , <NUM_LIT:0> , Integer . MAX_VALUE ) ; ui . setExitPolicy ( new ExitPolicy ( '<CHAR_LIT:)>' , document ) ) ; ui . setCyclingMode ( LinkedModeUI . CYCLE_WHEN_NO_PARENT ) ; ui . setDoContextInfo ( true ) ; ui . enter ( ) ; fSelectedRegion = ui . getSelectedRegion ( ) ; } else { fSelectedRegion = new Region ( baseOffset + replacement . length ( ) , <NUM_LIT:0> ) ; } } catch ( BadLocationException e ) { ensurePositionCategoryRemoved ( document ) ; JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } catch ( BadPositionCategoryException e ) { ensurePositionCategoryRemoved ( document ) ; JavaPlugin . log ( e ) ; openErrorDialog ( e ) ; } } @ Override protected boolean needsLinkedMode ( ) { return false ; } @ Override protected StyledString computeDisplayString ( ) { return super . computeDisplayString ( ) . append ( getStyledGroovy ( ) ) ; } private StyledString getStyledGroovy ( ) { return new StyledString ( "<STR_LIT:U+0020(>" + contributor + "<STR_LIT:)>" , StyledString . DECORATIONS_STYLER ) ; } @ Override protected String computeReplacementString ( ) { if ( ! hasParameters ( ) || ! hasArgumentList ( ) ) { if ( proposalOptions . noParens ) { char [ ] proposalName = fProposal . getName ( ) ; boolean hasWhitespace = false ; for ( int i = <NUM_LIT:0> ; i < proposalName . length ; i ++ ) { if ( CharOperation . isWhitespace ( proposalName [ i ] ) ) { hasWhitespace = true ; } } String newProposalName ; if ( hasWhitespace ) { newProposalName = "<STR_LIT:\">" + String . valueOf ( proposalName ) + "<STR_LIT:\">" ; } else { newProposalName = String . valueOf ( proposalName ) ; } return newProposalName ; } else { return super . computeReplacementString ( ) ; } } long millis = DEBUG ? System . currentTimeMillis ( ) : <NUM_LIT:0> ; String replacement ; try { replacement = computeGuessingCompletion ( ) ; } catch ( JavaModelException x ) { fPositions = null ; fChoices = null ; JavaPlugin . log ( x ) ; openErrorDialog ( x ) ; return super . computeReplacementString ( ) ; } if ( DEBUG ) System . err . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - millis ) ) ; return replacement ; } private String computeGuessingCompletion ( ) throws JavaModelException { StringBuffer buffer = new StringBuffer ( ) ; char [ ] proposalName = fProposal . getName ( ) ; boolean hasWhitespace = false ; for ( int i = <NUM_LIT:0> ; i < proposalName . length ; i ++ ) { if ( CharOperation . isWhitespace ( proposalName [ i ] ) ) { hasWhitespace = true ; } } char [ ] newProposalName ; if ( hasWhitespace ) { newProposalName = CharOperation . concat ( new char [ ] { '<CHAR_LIT:">' } , CharOperation . append ( proposalName , '<CHAR_LIT:">' ) ) ; } else { newProposalName = proposalName ; } fProposal . setName ( newProposalName ) ; appendMethodNameReplacement ( buffer ) ; fProposal . setName ( proposalName ) ; FormatterPrefs prefs = getFormatterPrefs ( ) ; if ( proposalOptions . noParens ) { buffer . replace ( buffer . length ( ) - <NUM_LIT:1> , buffer . length ( ) , prefs . beforeOpeningParen ? "<STR_LIT>" : "<STR_LIT:U+0020>" ) ; } setCursorPosition ( buffer . length ( ) ) ; char [ ] [ ] regularParameterTypes = ( ( GroovyCompletionProposal ) fProposal ) . getRegularParameterTypeNames ( ) ; boolean lastArgIsClosure = lastArgIsClosure ( regularParameterTypes ) ; int indexOfLastClosure = lastArgIsClosure ? regularParameterTypes . length - <NUM_LIT:1> : - <NUM_LIT:1> ; char [ ] [ ] namedParameterNames = ( ( GroovyCompletionProposal ) fProposal ) . getNamedParameterNames ( ) ; char [ ] [ ] regularParameterNames = ( ( GroovyCompletionProposal ) fProposal ) . getRegularParameterNames ( ) ; int namedCount = namedParameterNames . length ; int argCount = regularParameterNames . length ; int allCount = argCount + namedCount ; if ( proposalOptions . noParensAroundClosures ) { if ( indexOfLastClosure == <NUM_LIT:0> && namedCount == <NUM_LIT:0> ) { buffer . replace ( buffer . length ( ) - <NUM_LIT:1> , buffer . length ( ) , "<STR_LIT>" ) ; if ( ! prefs . beforeOpeningParen ) { buffer . append ( SPACE ) ; } } else { if ( prefs . afterOpeningParen ) buffer . append ( SPACE ) ; } } else { if ( prefs . afterOpeningParen ) buffer . append ( SPACE ) ; } int replacementOffset = getReplacementOffset ( ) ; fChoices = guessParameters ( namedParameterNames , regularParameterNames ) ; for ( int i = <NUM_LIT:0> ; i < allCount ; i ++ ) { if ( i == indexOfLastClosure ) { continue ; } char [ ] nextName ; if ( i < argCount ) { nextName = regularParameterNames [ i ] ; } else { nextName = namedParameterNames [ i - argCount ] ; } if ( i >= argCount || proposalOptions . useNamedArguments ) { buffer . append ( nextName ) . append ( "<STR_LIT::>" ) ; } ICompletionProposal proposal = fChoices [ i ] [ <NUM_LIT:0> ] ; String argument = proposal . getDisplayString ( ) ; Position position = fPositions [ i ] ; position . setOffset ( replacementOffset + buffer . length ( ) ) ; position . setLength ( argument . length ( ) ) ; if ( proposal instanceof JavaCompletionProposal ) { ( ( JavaCompletionProposal ) proposal ) . setReplacementOffset ( replacementOffset + buffer . length ( ) ) ; } buffer . append ( argument ) ; if ( i == allCount - <NUM_LIT:1> || ( i == allCount - <NUM_LIT:2> && i == indexOfLastClosure - <NUM_LIT:1> ) ) { if ( prefs . beforeClosingParen || proposalOptions . noParens ) { buffer . append ( SPACE ) ; } if ( ! proposalOptions . noParens ) { buffer . append ( RPAREN ) ; } } else if ( i < allCount - <NUM_LIT:1> ) { if ( prefs . beforeComma ) buffer . append ( SPACE ) ; buffer . append ( COMMA ) ; if ( prefs . afterComma ) buffer . append ( SPACE ) ; } } if ( indexOfLastClosure >= <NUM_LIT:0> ) { if ( allCount > <NUM_LIT:1> ) { if ( ! proposalOptions . noParensAroundClosures ) { buffer . append ( COMMA ) ; } buffer . append ( SPACE ) ; } Position position = fPositions [ indexOfLastClosure ] ; position . setOffset ( replacementOffset + buffer . length ( ) ) ; position . setLength ( LAST_CLOSURE_TEXT . length ( ) ) ; buffer . append ( LAST_CLOSURE_TEXT ) ; if ( ! proposalOptions . noParensAroundClosures ) { buffer . append ( "<STR_LIT>" ) ; buffer . append ( RPAREN ) ; } } return buffer . toString ( ) ; } private boolean lastArgIsClosure ( char [ ] [ ] regularParameterTypes ) { if ( regularParameterTypes != null && regularParameterTypes . length > <NUM_LIT:0> ) { char [ ] lastArgType = regularParameterTypes [ regularParameterTypes . length - <NUM_LIT:1> ] ; return CharOperation . equals ( "<STR_LIT>" . toCharArray ( ) , lastArgType ) ; } else { return false ; } } private JavaEditor getJavaEditor ( ) { IEditorPart part = JavaPlugin . getActivePage ( ) . getActiveEditor ( ) ; if ( part instanceof JavaEditor ) return ( JavaEditor ) part ; else return null ; } private ICompletionProposal [ ] [ ] guessParameters ( char [ ] [ ] firstParameterNames , char [ ] [ ] secondParameterNames ) throws JavaModelException { char [ ] [ ] parameterNames = new char [ firstParameterNames . length + secondParameterNames . length ] [ ] ; System . arraycopy ( firstParameterNames , <NUM_LIT:0> , parameterNames , <NUM_LIT:0> , firstParameterNames . length ) ; System . arraycopy ( secondParameterNames , <NUM_LIT:0> , parameterNames , firstParameterNames . length , secondParameterNames . length ) ; int count = parameterNames . length ; fPositions = new Position [ count ] ; fChoices = new ICompletionProposal [ count ] [ ] ; String [ ] parameterTypes = getParameterTypes ( ) ; IJavaElement [ ] [ ] assignableElements = getAssignableElements ( ) ; for ( int i = count - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { String paramName = new String ( parameterNames [ i ] ) ; Position position = new Position ( <NUM_LIT:0> , <NUM_LIT:0> ) ; ICompletionProposal [ ] argumentProposals = new ParameterGuesserDelegate ( getEnclosingElement ( ) ) . parameterProposals ( parameterTypes [ i ] , paramName , position , assignableElements [ i ] , fFillBestGuess ) ; if ( argumentProposals . length == <NUM_LIT:0> ) argumentProposals = new ICompletionProposal [ ] { new JavaCompletionProposal ( paramName , <NUM_LIT:0> , paramName . length ( ) , null , paramName , <NUM_LIT:0> ) } ; fPositions [ i ] = position ; fChoices [ i ] = argumentProposals ; } return fChoices ; } @ Override public Point getSelection ( IDocument document ) { if ( fSelectedRegion == null ) return new Point ( getReplacementOffset ( ) , <NUM_LIT:0> ) ; return new Point ( fSelectedRegion . getOffset ( ) , fSelectedRegion . getLength ( ) ) ; } private void openErrorDialog ( Exception e ) { Shell shell = getTextViewer ( ) . getTextWidget ( ) . getShell ( ) ; MessageDialog . openError ( shell , "<STR_LIT>" , e . getMessage ( ) ) ; } private void ensurePositionCategoryInstalled ( final IDocument document , LinkedModeModel model ) { if ( ! document . containsPositionCategory ( getCategory ( ) ) ) { document . addPositionCategory ( getCategory ( ) ) ; fUpdater = new InclusivePositionUpdater ( getCategory ( ) ) ; document . addPositionUpdater ( fUpdater ) ; model . addLinkingListener ( new ILinkedModeListener ( ) { public void left ( LinkedModeModel environment , int flags ) { ensurePositionCategoryRemoved ( document ) ; } public void suspend ( LinkedModeModel environment ) { } public void resume ( LinkedModeModel environment , int flags ) { } } ) ; } } private void ensurePositionCategoryRemoved ( IDocument document ) { if ( document . containsPositionCategory ( getCategory ( ) ) ) { try { document . removePositionCategory ( getCategory ( ) ) ; } catch ( BadPositionCategoryException e ) { } document . removePositionUpdater ( fUpdater ) ; } } private String getCategory ( ) { return "<STR_LIT>" + toString ( ) ; } public ICompletionProposal [ ] [ ] getChoices ( ) { return fChoices ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist ; import static org . codehaus . groovy . eclipse . core . util . ListUtil . newEmptyList ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . eclipse . codeassist . completions . NamedArgsMethodNode ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . IClasspathEntry ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . env . AccessRuleSet ; import org . eclipse . jdt . internal . core . ClasspathEntry ; import org . eclipse . jdt . internal . core . PackageFragmentRoot ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . internal . ui . viewsupport . ImageDescriptorRegistry ; import org . eclipse . jdt . ui . text . java . CompletionProposalLabelProvider ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . viewers . StyledString ; import org . eclipse . swt . graphics . Image ; public class ProposalUtils { public final static char [ ] METHOD_TRIGGERS = new char [ ] { '<CHAR_LIT:;>' , '<CHAR_LIT:U+002C>' , '<CHAR_LIT:.>' , '<STR_LIT:\t>' , '<CHAR_LIT:[>' , '<CHAR_LIT:U+0020>' } ; public final static char [ ] METHOD_WITH_ARGUMENTS_TRIGGERS = new char [ ] { '<CHAR_LIT:(>' , '<CHAR_LIT:->' , '<CHAR_LIT:U+0020>' } ; public final static char [ ] TYPE_TRIGGERS = new char [ ] { '<CHAR_LIT:.>' , '<STR_LIT:\t>' , '<CHAR_LIT:[>' , '<CHAR_LIT:(>' , '<CHAR_LIT:U+0020>' , '<STR_LIT:\t>' , '<CHAR_LIT:U+0020>' , '<CHAR_LIT:;>' } ; public final static char [ ] VAR_TRIGGER = new char [ ] { '<STR_LIT:\t>' , '<CHAR_LIT:U+0020>' , '<CHAR_LIT:=>' , '<CHAR_LIT:;>' , '<CHAR_LIT:.>' } ; public static final List < IGroovyProposal > NO_PROPOSALS = Collections . emptyList ( ) ; public static final ICompletionProposal [ ] NO_COMPLETIONS = new ICompletionProposal [ <NUM_LIT:0> ] ; private static ImageDescriptorRegistry registry ; static { try { registry = JavaPlugin . getImageDescriptorRegistry ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; registry = null ; } } private static final CompletionProposalLabelProvider labelProvider = new CompletionProposalLabelProvider ( ) ; public static char [ ] createTypeSignature ( ClassNode node ) { return createTypeSignatureStr ( node ) . toCharArray ( ) ; } public static String createTypeSignatureStr ( ClassNode node ) { if ( node == null ) { node = VariableScope . OBJECT_CLASS_NODE ; } String name = node . getName ( ) ; if ( name . startsWith ( "<STR_LIT:[>" ) ) { return name ; } else { return Signature . createTypeSignature ( name , true ) ; } } public static String createUnresolvedTypeSignatureStr ( ClassNode node ) { String name = node . getNameWithoutPackage ( ) ; if ( name . startsWith ( "<STR_LIT:[>" ) ) { return name ; } else { return Signature . createTypeSignature ( name , false ) ; } } public static AccessRestriction getTypeAccessibility ( IType type ) { PackageFragmentRoot root = ( PackageFragmentRoot ) type . getAncestor ( IJavaElement . PACKAGE_FRAGMENT_ROOT ) ; try { IClasspathEntry entry = root . getResolvedClasspathEntry ( ) ; if ( entry instanceof ClasspathEntry ) { AccessRuleSet accessRuleSet = ( ( ClasspathEntry ) entry ) . getAccessRuleSet ( ) ; if ( accessRuleSet != null ) { char [ ] packageName = type . getPackageFragment ( ) . getElementName ( ) . toCharArray ( ) ; char [ ] [ ] packageChars = CharOperation . splitOn ( '<CHAR_LIT:.>' , packageName ) ; char [ ] fileWithoutExtension = type . getElementName ( ) . toCharArray ( ) ; return accessRuleSet . getViolatedRestriction ( CharOperation . concatWith ( packageChars , fileWithoutExtension , '<CHAR_LIT:/>' ) ) ; } } } catch ( JavaModelException e ) { } return null ; } public static char [ ] createMethodSignature ( MethodNode node ) { return createMethodSignatureStr ( node , <NUM_LIT:0> ) . toCharArray ( ) ; } public static String createMethodSignatureStr ( MethodNode node ) { return createMethodSignatureStr ( node , <NUM_LIT:0> ) ; } public static char [ ] createMethodSignature ( MethodNode node , int ignoreParameters ) { return createMethodSignatureStr ( node , ignoreParameters ) . toCharArray ( ) ; } public static String createMethodSignatureStr ( MethodNode node , int ignoreParameters ) { String returnType = createTypeSignatureStr ( node . getReturnType ( ) ) ; Parameter [ ] parameters ; if ( node instanceof NamedArgsMethodNode ) { parameters = ( ( NamedArgsMethodNode ) node ) . getVisibleParams ( ) ; } else { parameters = node . getParameters ( ) ; } String [ ] parameterTypes = new String [ parameters . length - ignoreParameters ] ; for ( int i = <NUM_LIT:0> ; i < parameterTypes . length ; i ++ ) { parameterTypes [ i ] = createTypeSignatureStr ( parameters [ i + ignoreParameters ] . getType ( ) ) ; } return Signature . createMethodSignature ( parameterTypes , returnType ) ; } public static char [ ] createSimpleTypeName ( ClassNode node ) { String name = node . getName ( ) ; if ( name . startsWith ( "<STR_LIT:[>" ) ) { int arrayCount = Signature . getArrayCount ( name ) ; String noArrayName = Signature . getElementType ( name ) ; String simpleName = Signature . getSignatureSimpleName ( noArrayName ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( simpleName ) ; for ( int i = <NUM_LIT:0> ; i < arrayCount ; i ++ ) { sb . append ( "<STR_LIT:[]>" ) ; } return sb . toString ( ) . toCharArray ( ) ; } else { return node . getNameWithoutPackage ( ) . toCharArray ( ) ; } } public static Image getImage ( CompletionProposal proposal ) { return registry . get ( labelProvider . createImageDescriptor ( proposal ) ) ; } public static Image getParameterImage ( ) { return registry . get ( JavaPluginImages . DESC_OBJS_LOCAL_VARIABLE ) ; } public static StyledString createDisplayString ( CompletionProposal proposal ) { return labelProvider . createStyledLabel ( proposal ) ; } public static boolean looselyMatches ( String prefix , String target ) { if ( target == null || prefix == null ) { return false ; } if ( prefix . length ( ) == <NUM_LIT:0> ) { return true ; } if ( prefix . charAt ( <NUM_LIT:0> ) != target . charAt ( <NUM_LIT:0> ) ) { return false ; } if ( target . startsWith ( prefix ) ) { return true ; } String lowerCase = target . toLowerCase ( ) ; if ( lowerCase . startsWith ( prefix ) ) { return true ; } if ( prefix . equals ( prefix . toLowerCase ( ) ) ) { return false ; } String [ ] prefixParts = toCamelCaseParts ( prefix ) ; String [ ] targetParts = toCamelCaseParts ( target ) ; if ( prefixParts . length > targetParts . length ) { return false ; } for ( int i = <NUM_LIT:0> ; i < prefixParts . length ; ++ i ) { if ( ! targetParts [ i ] . startsWith ( prefixParts [ i ] ) ) { return false ; } } return true ; } private static String [ ] toCamelCaseParts ( String str ) { List < String > parts = newEmptyList ( ) ; for ( int i = str . length ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; -- i ) { if ( Character . isUpperCase ( str . charAt ( i ) ) ) { parts . add ( str . substring ( i ) ) ; str = str . substring ( <NUM_LIT:0> , i ) ; } } if ( str . length ( ) != <NUM_LIT:0> ) { parts . add ( str ) ; } Collections . reverse ( parts ) ; return parts . toArray ( new String [ parts . size ( ) ] ) ; } public static String createMockFieldName ( String methodName ) { int prefix = methodName . startsWith ( "<STR_LIT>" ) ? <NUM_LIT:2> : <NUM_LIT:3> ; return methodName . length ( ) > prefix ? Character . toLowerCase ( methodName . charAt ( prefix ) ) + methodName . substring ( prefix + <NUM_LIT:1> ) : "<STR_LIT>" ; } public static String createCapitalMockFieldName ( String methodName ) { return methodName . length ( ) > <NUM_LIT:3> ? methodName . substring ( <NUM_LIT:3> ) : "<STR_LIT>" ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . ModifiersCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class ModifiersCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new ModifiersCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . NewFieldCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class NewFieldCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new NewFieldCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . LocalVariableCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class LocalVariableCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new LocalVariableCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . ConstructorCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class ConstructorCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new ConstructorCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . TypeCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class TypeCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new TypeCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . StatementAndExpressionCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class ExpressionCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new StatementAndExpressionCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class NewVariableCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public interface IGroovyCompletionProcessorFactory { IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . NewMethodCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class NewMethodCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new NewMethodCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . factories ; import org . codehaus . groovy . eclipse . codeassist . processors . IGroovyCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . processors . PackageCompletionProcessor ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public class PackageCompletionProcessorFactory implements IGroovyCompletionProcessorFactory { public IGroovyCompletionProcessor createProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { return new PackageCompletionProcessor ( context , javaContext , nameEnvironment ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . eclipse . jdt . core . ICompilationUnit ; import org . objectweb . asm . Opcodes ; public class GroovyCategoryMethodProposal extends GroovyMethodProposal { public GroovyCategoryMethodProposal ( MethodNode method ) { super ( method , "<STR_LIT>" + method . getDeclaringClass ( ) . getNameWithoutPackage ( ) ) ; } public GroovyCategoryMethodProposal ( MethodNode method , String contributor ) { super ( method , contributor ) ; } public GroovyCategoryMethodProposal ( MethodNode method , String contributor , ProposalFormattingOptions options ) { super ( method , contributor , options ) ; } @ Override protected int getModifiers ( ) { return method . getModifiers ( ) & ~ Opcodes . ACC_STATIC ; } @ Override protected char [ ] createMethodSignature ( ) { return ProposalUtils . createMethodSignature ( method , <NUM_LIT:1> ) ; } @ Override protected char [ ] [ ] createAllParameterNames ( ICompilationUnit unit ) { return removeFirst ( super . createAllParameterNames ( unit ) ) ; } @ Override protected char [ ] [ ] getParameterTypeNames ( Parameter [ ] parameters ) { return removeFirst ( super . getParameterTypeNames ( parameters ) ) ; } private char [ ] [ ] removeFirst ( char [ ] [ ] array ) { if ( array . length > <NUM_LIT:0> ) { char [ ] [ ] newArray = new char [ array . length - <NUM_LIT:1> ] [ ] ; System . arraycopy ( array , <NUM_LIT:1> , newArray , <NUM_LIT:0> , array . length - <NUM_LIT:1> ) ; return newArray ; } else { return array ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . internal . codeassist . InternalCompletionProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . viewers . StyledString ; public class GroovyFieldProposal extends AbstractGroovyProposal { private final FieldNode field ; private final String contributor ; public GroovyFieldProposal ( FieldNode field ) { this . field = field ; this . contributor = "<STR_LIT>" ; } public GroovyFieldProposal ( FieldNode field , String contributor ) { this . field = field ; this . contributor = contributor ; } public GroovyFieldProposal ( FieldNode field , int relevanceMultiplier ) { this . field = field ; setRelevanceMultiplier ( relevanceMultiplier ) ; this . contributor = "<STR_LIT>" ; } public GroovyFieldProposal ( FieldNode field , int relevanceMultiplier , String contributor ) { this . field = field ; setRelevanceMultiplier ( relevanceMultiplier ) ; this . contributor = contributor ; } public IJavaCompletionProposal createJavaProposal ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { if ( context . location == ContentAssistLocation . METHOD_CONTEXT ) { return null ; } CompletionProposal proposal = createProposal ( context ) ; return new GroovyJavaFieldCompletionProposal ( proposal , ProposalUtils . getImage ( proposal ) , createDisplayString ( field ) ) ; } @ Override public AnnotatedNode getAssociatedNode ( ) { return field ; } protected StyledString createDisplayString ( FieldNode field ) { StyledString ss = new StyledString ( ) ; ss . append ( field . getName ( ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) . append ( ProposalUtils . createSimpleTypeName ( field . getType ( ) ) ) . append ( "<STR_LIT:U+0020-U+0020>" ) . append ( ProposalUtils . createSimpleTypeName ( field . getDeclaringClass ( ) ) , StyledString . QUALIFIER_STYLER ) . append ( "<STR_LIT:U+0020(>" + contributor + "<STR_LIT:)>" , StyledString . DECORATIONS_STYLER ) ; return ss ; } private CompletionProposal createProposal ( ContentAssistContext context ) { InternalCompletionProposal proposal = ( InternalCompletionProposal ) CompletionProposal . create ( CompletionProposal . FIELD_REF , context . completionLocation ) ; proposal . setFlags ( field . getModifiers ( ) ) ; proposal . setName ( field . getName ( ) . toCharArray ( ) ) ; proposal . setCompletion ( proposal . getName ( ) ) ; proposal . setSignature ( ProposalUtils . createTypeSignature ( field . getType ( ) ) ) ; proposal . setDeclarationSignature ( ProposalUtils . createTypeSignature ( field . getDeclaringClass ( ) ) ) ; proposal . setRelevance ( computeRelevance ( ) ) ; int startIndex = context . completionLocation - context . completionExpression . length ( ) ; proposal . setReplaceRange ( startIndex , context . completionEnd ) ; return proposal ; } public FieldNode getField ( ) { return field ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . ConstructorNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . GroovyPlugin ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . jface . preference . IPreferenceStore ; public class ProposalFormattingOptions { public static ProposalFormattingOptions newFromOptions ( ) { IPreferenceStore prefs = GroovyPlugin . getDefault ( ) . getPreferenceStore ( ) ; return new ProposalFormattingOptions ( prefs . getBoolean ( PreferenceConstants . GROOVY_CONTENT_ASSIST_NOPARENS ) , prefs . getBoolean ( PreferenceConstants . GROOVY_CONTENT_ASSIST_BRACKETS ) , prefs . getBoolean ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS ) , prefs . getBoolean ( PreferenceConstants . GROOVY_CONTENT_PARAMETER_GUESSING ) , false ) ; } public final boolean noParensAroundClosures ; public final boolean useBracketsForClosures ; public final boolean useNamedArguments ; public final boolean doParameterGuessing ; public final boolean noParens ; public ProposalFormattingOptions ( boolean noParensAroundArgs , boolean useBracketsForClosures , boolean useNamedArguments , boolean doParameterGuessing , boolean noParens ) { this . noParensAroundClosures = noParensAroundArgs ; this . useBracketsForClosures = useBracketsForClosures ; this . useNamedArguments = useNamedArguments ; this . doParameterGuessing = doParameterGuessing ; this . noParens = noParens ; } public ProposalFormattingOptions newFromExisting ( boolean overrideUseNamedArgs , boolean overrideNoParens , MethodNode method ) { if ( overrideUseNamedArgs || overrideNoParens ) { return new ProposalFormattingOptions ( noParensAroundClosures , useBracketsForClosures , overrideUseNamedArgs , doParameterGuessing , overrideNoParens ) ; } else if ( useNamedArguments && ! ( method instanceof ConstructorNode ) ) { return new ProposalFormattingOptions ( noParensAroundClosures , useBracketsForClosures , false , doParameterGuessing , overrideNoParens ) ; } else { return this ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . internal . codeassist . InternalCompletionProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . viewers . StyledString ; public class GroovyPropertyProposal extends AbstractGroovyProposal { private final PropertyNode property ; private final String contributor ; public GroovyPropertyProposal ( PropertyNode property ) { this . property = property ; this . contributor = "<STR_LIT>" ; } public GroovyPropertyProposal ( PropertyNode property , String contributor ) { this . property = property ; this . contributor = contributor ; } public IJavaCompletionProposal createJavaProposal ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { if ( context . location == ContentAssistLocation . METHOD_CONTEXT ) { return null ; } CompletionProposal proposal = createProposal ( context ) ; return new GroovyJavaFieldCompletionProposal ( proposal , ProposalUtils . getImage ( proposal ) , createDisplayString ( property ) ) ; } protected StyledString createDisplayString ( PropertyNode property ) { StyledString ss = new StyledString ( ) ; ss . append ( property . getName ( ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) . append ( ProposalUtils . createSimpleTypeName ( property . getType ( ) ) ) . append ( "<STR_LIT:U+0020-U+0020>" ) . append ( ProposalUtils . createSimpleTypeName ( property . getDeclaringClass ( ) ) , StyledString . QUALIFIER_STYLER ) . append ( "<STR_LIT:U+0020(>" + contributor + "<STR_LIT:)>" , StyledString . DECORATIONS_STYLER ) ; return ss ; } private CompletionProposal createProposal ( ContentAssistContext context ) { InternalCompletionProposal proposal = ( InternalCompletionProposal ) CompletionProposal . create ( CompletionProposal . FIELD_REF , context . completionLocation ) ; proposal . setFlags ( property . getModifiers ( ) ) ; proposal . setName ( property . getName ( ) . toCharArray ( ) ) ; proposal . setCompletion ( proposal . getName ( ) ) ; proposal . setSignature ( ProposalUtils . createTypeSignature ( property . getType ( ) ) ) ; proposal . setDeclarationSignature ( ProposalUtils . createTypeSignature ( property . getDeclaringClass ( ) ) ) ; proposal . setRelevance ( computeRelevance ( ) ) ; int startIndex = context . completionLocation - context . completionExpression . length ( ) ; proposal . setReplaceRange ( startIndex , context . completionEnd ) ; return proposal ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . JavaCompletionProposal ; import org . eclipse . jface . viewers . StyledString ; import org . eclipse . swt . graphics . Image ; public class GroovyJavaFieldCompletionProposal extends JavaCompletionProposal { private final CompletionProposal proposal ; public GroovyJavaFieldCompletionProposal ( CompletionProposal proposal , Image image , StyledString displayString ) { super ( String . valueOf ( proposal . getName ( ) ) , proposal . getReplaceStart ( ) , proposal . getReplaceEnd ( ) - proposal . getReplaceStart ( ) , image , displayString , proposal . getRelevance ( ) ) ; this . proposal = proposal ; this . setRelevance ( proposal . getRelevance ( ) ) ; this . setTriggerCharacters ( ProposalUtils . VAR_TRIGGER ) ; } public CompletionProposal getProposal ( ) { return proposal ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public interface IGroovyProposal { IJavaCompletionProposal createJavaProposal ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ConstructorNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyJavaGuessingCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyJavaMethodCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . completions . NamedArgsMethodNode ; import org . codehaus . groovy . eclipse . codeassist . processors . GroovyCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . MethodInfoContentAssistContext ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . groovy . eclipse . core . preferences . PreferenceConstants ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . jdt . core . CompletionFlags ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . ui . text . java . LazyJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . preference . IPreferenceStore ; import org . eclipse . jface . text . BadLocationException ; public class GroovyMethodProposal extends AbstractGroovyProposal { protected final MethodNode method ; private String contributor ; private boolean useNamedArguments ; private ProposalFormattingOptions options ; private IType cachedDeclaringType ; private boolean noParens ; public GroovyMethodProposal ( MethodNode method ) { super ( ) ; this . method = method ; contributor = "<STR_LIT>" ; useNamedArguments = false ; noParens = false ; } public GroovyMethodProposal ( MethodNode method , String contributor ) { this ( method ) ; this . contributor = contributor ; } public GroovyMethodProposal ( MethodNode method , String contributor , ProposalFormattingOptions options ) { this ( method , contributor ) ; this . options = options ; } public void setUseNamedArguments ( boolean useNamedArguments ) { this . useNamedArguments = useNamedArguments ; } public void setNoParens ( boolean noParens ) { this . noParens = noParens ; } @ Override public AnnotatedNode getAssociatedNode ( ) { return method ; } public IJavaCompletionProposal createJavaProposal ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { GroovyCompletionProposal proposal = new GroovyCompletionProposal ( CompletionProposal . METHOD_REF , context . completionLocation ) ; if ( context . location == ContentAssistLocation . METHOD_CONTEXT ) { MethodInfoContentAssistContext methodContext = ( MethodInfoContentAssistContext ) context ; if ( ! methodContext . methodName . equals ( method . getName ( ) ) ) { return null ; } proposal . setReplaceRange ( context . completionLocation , context . completionLocation ) ; proposal . setCompletion ( CharOperation . NO_CHAR ) ; } else { proposal . setCompletion ( completionName ( ! isParens ( context , javaContext ) ) ) ; proposal . setReplaceRange ( context . completionLocation - context . completionExpression . length ( ) , context . completionEnd ) ; } proposal . setDeclarationSignature ( ProposalUtils . createTypeSignature ( method . getDeclaringClass ( ) ) ) ; proposal . setName ( method . getName ( ) . toCharArray ( ) ) ; if ( method instanceof NamedArgsMethodNode ) { fillInExtraParameters ( ( NamedArgsMethodNode ) method , proposal ) ; } else { proposal . setParameterNames ( createAllParameterNames ( context . unit ) ) ; proposal . setParameterTypeNames ( getParameterTypeNames ( method . getParameters ( ) ) ) ; } proposal . setFlags ( getModifiers ( ) ) ; proposal . setAdditionalFlags ( CompletionFlags . Default ) ; char [ ] methodSignature = createMethodSignature ( ) ; proposal . setKey ( methodSignature ) ; proposal . setSignature ( methodSignature ) ; proposal . setRelevance ( computeRelevance ( ) ) ; LazyJavaCompletionProposal lazyProposal = null ; ProposalFormattingOptions groovyProposalOptions = getGroovyProposalOptions ( ) ; if ( groovyProposalOptions . doParameterGuessing ) { lazyProposal = GroovyJavaGuessingCompletionProposal . createProposal ( proposal , javaContext , true , contributor , groovyProposalOptions ) ; } if ( lazyProposal == null ) { lazyProposal = new GroovyJavaMethodCompletionProposal ( proposal , javaContext , groovyProposalOptions , contributor ) ; if ( context . location == ContentAssistLocation . METHOD_CONTEXT ) { ( ( GroovyJavaMethodCompletionProposal ) lazyProposal ) . contextOnly ( ) ; } } if ( context . location == ContentAssistLocation . METHOD_CONTEXT ) { lazyProposal . setContextInformationPosition ( ( ( MethodInfoContentAssistContext ) context ) . methodNameEnd + <NUM_LIT:1> ) ; } return lazyProposal ; } private void fillInExtraParameters ( NamedArgsMethodNode namedArgsMethod , GroovyCompletionProposal proposal ) { proposal . setParameterNames ( getSpecialParameterNames ( namedArgsMethod . getParameters ( ) ) ) ; proposal . setRegularParameterNames ( getSpecialParameterNames ( namedArgsMethod . getRegularParams ( ) ) ) ; proposal . setNamedParameterNames ( getSpecialParameterNames ( namedArgsMethod . getNamedParams ( ) ) ) ; proposal . setOptionalParameterNames ( getSpecialParameterNames ( namedArgsMethod . getOptionalParams ( ) ) ) ; proposal . setParameterTypeNames ( getParameterTypeNames ( namedArgsMethod . getParameters ( ) ) ) ; proposal . setRegularParameterTypeNames ( getParameterTypeNames ( namedArgsMethod . getRegularParams ( ) ) ) ; proposal . setNamedParameterTypeNames ( getParameterTypeNames ( namedArgsMethod . getNamedParams ( ) ) ) ; proposal . setOptionalParameterTypeNames ( getParameterTypeNames ( namedArgsMethod . getOptionalParams ( ) ) ) ; } private ProposalFormattingOptions getGroovyProposalOptions ( ) { if ( options == null ) { options = ProposalFormattingOptions . newFromOptions ( ) ; } return options . newFromExisting ( useNamedArguments , noParens , method ) ; } private boolean isParens ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { if ( javaContext . getDocument ( ) . getLength ( ) > context . completionEnd ) { try { return javaContext . getDocument ( ) . getChar ( context . completionEnd ) == '<CHAR_LIT:(>' ; } catch ( BadLocationException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } return false ; } protected boolean shouldUseNamedArguments ( IPreferenceStore prefs ) { return ( prefs . getBoolean ( PreferenceConstants . GROOVY_CONTENT_NAMED_ARGUMENTS ) && method instanceof ConstructorNode ) || useNamedArguments ; } protected char [ ] createMethodSignature ( ) { return ProposalUtils . createMethodSignature ( method ) ; } protected int getModifiers ( ) { return method . getModifiers ( ) ; } protected char [ ] completionName ( boolean includeParens ) { String name = method . getName ( ) ; char [ ] nameArr = name . toCharArray ( ) ; boolean hasWhitespace = false ; for ( int i = <NUM_LIT:0> ; i < nameArr . length ; i ++ ) { if ( Character . isWhitespace ( nameArr [ i ] ) ) { hasWhitespace = true ; break ; } } if ( hasWhitespace ) { name = "<STR_LIT:\">" + name + "<STR_LIT:\">" ; } if ( includeParens ) { return ( name + "<STR_LIT>" ) . toCharArray ( ) ; } else { return name . toCharArray ( ) ; } } protected char [ ] [ ] createAllParameterNames ( ICompilationUnit unit ) { Parameter [ ] params = method . getParameters ( ) ; int numParams = params == null ? <NUM_LIT:0> : params . length ; if ( numParams == <NUM_LIT:0> ) { return new char [ <NUM_LIT:0> ] [ ] ; } char [ ] [ ] paramNames = null ; if ( params [ <NUM_LIT:0> ] . getName ( ) . equals ( "<STR_LIT>" ) || params [ <NUM_LIT:0> ] . getName ( ) . equals ( "<STR_LIT>" ) ) { paramNames = calculateAllParameterNames ( unit , method ) ; } if ( paramNames == null ) { paramNames = new char [ params . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < params . length ; i ++ ) { String name = params [ i ] . getName ( ) ; if ( name != null ) { paramNames [ i ] = name . toCharArray ( ) ; } else { paramNames [ i ] = ( "<STR_LIT>" + i ) . toCharArray ( ) ; } } } return paramNames ; } protected char [ ] [ ] getParameterTypeNames ( Parameter [ ] parameters ) { char [ ] [ ] typeNames = new char [ parameters . length ] [ ] ; int i = <NUM_LIT:0> ; for ( Parameter param : parameters ) { typeNames [ i ] = ProposalUtils . createSimpleTypeName ( param . getType ( ) ) ; i ++ ; } return typeNames ; } protected char [ ] [ ] calculateAllParameterNames ( ICompilationUnit unit , MethodNode method ) { try { IType declaringType = findDeclaringType ( unit , method ) ; if ( declaringType != null && declaringType . exists ( ) ) { Parameter [ ] params = method . getParameters ( ) ; int numParams = params == null ? <NUM_LIT:0> : params . length ; if ( numParams == <NUM_LIT:0> ) { return new char [ <NUM_LIT:0> ] [ ] ; } String [ ] parameterTypeSignatures = new String [ numParams ] ; boolean doResolved = declaringType . isBinary ( ) ; for ( int i = <NUM_LIT:0> ; i < parameterTypeSignatures . length ; i ++ ) { if ( doResolved ) { parameterTypeSignatures [ i ] = ProposalUtils . createTypeSignatureStr ( params [ i ] . getType ( ) ) ; } else { parameterTypeSignatures [ i ] = ProposalUtils . createUnresolvedTypeSignatureStr ( params [ i ] . getType ( ) ) ; } } IMethod jdtMethod = null ; IMethod maybeMethod = declaringType . getMethod ( method . getName ( ) , parameterTypeSignatures ) ; if ( maybeMethod != null && maybeMethod . exists ( ) ) { jdtMethod = maybeMethod ; } else { IMethod [ ] methods = declaringType . getMethods ( ) ; for ( IMethod maybeMethod2 : methods ) { if ( maybeMethod2 . getElementName ( ) . equals ( method . getName ( ) ) && maybeMethod2 . getNumberOfParameters ( ) == numParams ) { jdtMethod = maybeMethod2 ; } } } if ( jdtMethod != null ) { String [ ] paramNames = jdtMethod . getParameterNames ( ) ; char [ ] [ ] paramNamesChar = new char [ paramNames . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < paramNames . length ; i ++ ) { paramNamesChar [ i ] = paramNames [ i ] . toCharArray ( ) ; } return paramNamesChar ; } } } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" + method . getName ( ) , e ) ; } return null ; } private char [ ] [ ] getSpecialParameterNames ( Parameter [ ] params ) { char [ ] [ ] paramNames = new char [ params . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < params . length ; i ++ ) { paramNames [ i ] = params [ i ] . getName ( ) . toCharArray ( ) ; } return paramNames ; } private IType findDeclaringType ( ICompilationUnit unit , MethodNode method ) throws JavaModelException { if ( cachedDeclaringType == null ) { cachedDeclaringType = unit . getJavaProject ( ) . findType ( method . getDeclaringClass ( ) . getName ( ) , new NullProgressMonitor ( ) ) ; } return cachedDeclaringType ; } public MethodNode getMethod ( ) { return method ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . completions . NamedParameterProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . MethodInfoContentAssistContext ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . viewers . StyledString ; public class GroovyNamedArgumentProposal extends AbstractGroovyProposal { private final String paramName ; private final String paramSignature ; private final MethodNode ownerMethod ; private final String contributor ; private ProposalFormattingOptions options ; public GroovyNamedArgumentProposal ( String paramName , String paramSignature , MethodNode ownerMethod , String contributor ) { this . paramName = paramName ; this . paramSignature = paramSignature ; ; this . ownerMethod = ownerMethod ; this . contributor = contributor ; setRelevanceMultiplier ( <NUM_LIT:100> ) ; } public GroovyNamedArgumentProposal ( String paramName , ClassNode paramType , MethodNode ownerMethod , String contributor ) { this . paramName = paramName ; this . paramSignature = ProposalUtils . createTypeSignatureStr ( unbox ( paramType ) ) ; ; this . ownerMethod = ownerMethod ; this . contributor = contributor ; setRelevanceMultiplier ( <NUM_LIT:100> ) ; } @ Override public AnnotatedNode getAssociatedNode ( ) { return ownerMethod ; } public IJavaCompletionProposal createJavaProposal ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) { if ( context . location != ContentAssistLocation . METHOD_CONTEXT ) { return null ; } MethodInfoContentAssistContext methodContext = ( MethodInfoContentAssistContext ) context ; int startIndex = methodContext . completionLocation - methodContext . completionExpression . length ( ) ; int length = methodContext . completionEnd - startIndex ; return new NamedParameterProposal ( paramName , paramSignature , startIndex , length , ProposalUtils . getParameterImage ( ) , createDisplayString ( ) , computeRelevance ( ) , false , javaContext , getGroovyProposalOptions ( ) . doParameterGuessing ) ; } private ProposalFormattingOptions getGroovyProposalOptions ( ) { if ( options == null ) { options = ProposalFormattingOptions . newFromOptions ( ) ; } return options . newFromExisting ( true , false , null ) ; } protected StyledString createDisplayString ( ) { StyledString ss = new StyledString ( ) ; ss . append ( paramName ) . append ( "<STR_LIT:U+0020:U+0020>" ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT:U+0020-U+0020>" ) . append ( Signature . toString ( paramSignature ) ) . append ( "<STR_LIT>" , StyledString . QUALIFIER_STYLER ) . append ( "<STR_LIT:U+0020(>" + contributor + "<STR_LIT:)>" , StyledString . DECORATIONS_STYLER ) ; return ss ; } private ClassNode unbox ( ClassNode maybeBoxed ) { if ( ClassHelper . isPrimitiveType ( maybeBoxed ) ) { return maybeBoxed ; } String name = maybeBoxed . getName ( ) ; if ( ClassHelper . Boolean_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . boolean_TYPE ; } else if ( ClassHelper . Byte_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . byte_TYPE ; } else if ( ClassHelper . Character_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . char_TYPE ; } else if ( ClassHelper . Short_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . short_TYPE ; } else if ( ClassHelper . Integer_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . int_TYPE ; } else if ( ClassHelper . Long_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . long_TYPE ; } else if ( ClassHelper . Float_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . float_TYPE ; } else if ( ClassHelper . Double_TYPE . getName ( ) . equals ( name ) ) { return ClassHelper . double_TYPE ; } else { return maybeBoxed ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . proposals ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . internal . ui . JavaPlugin ; import org . eclipse . jdt . internal . ui . JavaPluginImages ; import org . eclipse . jdt . internal . ui . viewsupport . ImageDescriptorRegistry ; import org . eclipse . jdt . ui . text . java . CompletionProposalLabelProvider ; import org . eclipse . swt . graphics . Image ; import org . objectweb . asm . Opcodes ; public abstract class AbstractGroovyProposal implements IGroovyProposal { private final static ImageDescriptorRegistry registry = JavaPlugin . getImageDescriptorRegistry ( ) ; private float relevanceMultiplier = <NUM_LIT:1> ; protected Image getImage ( CompletionProposal proposal , CompletionProposalLabelProvider labelProvider ) { return registry . get ( labelProvider . createImageDescriptor ( proposal ) ) ; } @ Deprecated protected Image getImageFor ( ASTNode node ) { if ( node instanceof FieldNode ) { int mods = ( ( FieldNode ) node ) . getModifiers ( ) ; if ( test ( mods , Opcodes . ACC_PUBLIC ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PUBLIC ) ; } else if ( test ( mods , Opcodes . ACC_PROTECTED ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PROTECTED ) ; } else if ( test ( mods , Opcodes . ACC_PRIVATE ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PRIVATE ) ; } return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_DEFAULT ) ; } else if ( node instanceof PropertyNode ) { int mods = ( ( PropertyNode ) node ) . getModifiers ( ) ; if ( test ( mods , Opcodes . ACC_PUBLIC ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PUBLIC ) ; } else if ( test ( mods , Opcodes . ACC_PROTECTED ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PROTECTED ) ; } else if ( test ( mods , Opcodes . ACC_PRIVATE ) ) { return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_PRIVATE ) ; } return JavaPluginImages . get ( JavaPluginImages . IMG_FIELD_DEFAULT ) ; } return null ; } private boolean test ( int flags , int mask ) { return ( flags & mask ) != <NUM_LIT:0> ; } @ Deprecated protected int getRelevance ( char [ ] name ) { switch ( name [ <NUM_LIT:0> ] ) { case '<CHAR_LIT>' : return <NUM_LIT:1> ; case '<CHAR_LIT:_>' : return <NUM_LIT:5> ; default : return <NUM_LIT:1000> ; } } public AnnotatedNode getAssociatedNode ( ) { return null ; } protected int computeRelevance ( ) { return Relevance . calculateRelevance ( this , relevanceMultiplier ) ; } public void setRelevanceMultiplier ( float relevanceMultiplier ) { this . relevanceMultiplier = relevanceMultiplier ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . CharArraySourceBuffer ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . core . util . ExpressionFinder ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class TypeCompletionProcessor extends AbstractGroovyCompletionProcessor { public TypeCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { ContentAssistContext context = getContext ( ) ; String toSearch = context . completionExpression . startsWith ( "<STR_LIT>" ) ? context . completionExpression . substring ( <NUM_LIT:4> ) : context . completionExpression ; if ( shouldShowTypes ( context , toSearch ) ) { return Collections . emptyList ( ) ; } int expressionStart = findExpressionStart ( context ) ; GroovyProposalTypeSearchRequestor requestor = new GroovyProposalTypeSearchRequestor ( context , getJavaContext ( ) , expressionStart , context . completionEnd - expressionStart , getNameEnvironment ( ) . nameLookup , monitor ) ; getNameEnvironment ( ) . findTypes ( toSearch . toCharArray ( ) , true , true , getSearchFor ( ) , requestor , monitor ) ; List < ICompletionProposal > typeProposals = requestor . processAcceptedTypes ( ) ; return typeProposals ; } private boolean shouldShowTypes ( ContentAssistContext context , String toSearch ) { return ( toSearch . length ( ) == <NUM_LIT:0> && context . location != ContentAssistLocation . IMPORT ) || context . fullCompletionExpression . contains ( "<STR_LIT:.>" ) || isBeforeTypeName ( context . location , context . unit , context . completionLocation ) ; } private int findExpressionStart ( ContentAssistContext context ) { int completionLength ; if ( context . completionExpression . startsWith ( "<STR_LIT>" ) ) { completionLength = context . completionExpression . substring ( "<STR_LIT>" . length ( ) ) . trim ( ) . length ( ) ; } else { completionLength = context . completionExpression . length ( ) ; } int expressionStart = context . completionLocation - completionLength ; return expressionStart ; } private int getSearchFor ( ) { switch ( getContext ( ) . location ) { case EXTENDS : return IJavaSearchConstants . CLASS ; case IMPLEMENTS : return IJavaSearchConstants . INTERFACE ; case EXCEPTIONS : return IJavaSearchConstants . CLASS ; case ANNOTATION : return IJavaSearchConstants . ANNOTATION_TYPE ; default : return IJavaSearchConstants . TYPE ; } } private boolean isBeforeTypeName ( ContentAssistLocation location , GroovyCompilationUnit unit , int completionLocation ) { return location == ContentAssistLocation . CLASS_BODY && new ExpressionFinder ( ) . findPreviousTypeNameToken ( new CharArraySourceBuffer ( unit . getContents ( ) ) , completionLocation ) != null ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import org . eclipse . jdt . core . compiler . CharOperation ; public class CharArraySequence implements CharSequence { private final char [ ] chars ; public CharArraySequence ( char [ ] chars ) { this . chars = chars ; } public CharArraySequence ( String contents ) { this . chars = contents . toCharArray ( ) ; } public char [ ] chars ( ) { return chars ; } public int length ( ) { return chars . length ; } public char charAt ( int index ) { return chars [ index ] ; } public CharArraySequence subSequence ( int start , int end ) { return new CharArraySequence ( CharOperation . subarray ( chars , start , end ) ) ; } @ Override public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < chars . length ; i ++ ) { sb . append ( chars [ i ] ) ; } return sb . toString ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . Collections ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . ConstructorNode ; import org . codehaus . groovy . ast . ImportNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . PropertyNode ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyJavaMethodCompletionProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyNamedArgumentProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . ProposalFormattingOptions ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . relevance . RelevanceRules ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . codeassist . requestor . MethodInfoContentAssistContext ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . internal . compiler . ast . JDTResolver ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . CompletionRequestor ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IAccessRule ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . internal . codeassist . CompletionEngine ; import org . eclipse . jdt . internal . codeassist . ISearchRequestor ; import org . eclipse . jdt . internal . codeassist . RelevanceConstants ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . util . HashtableOfObject ; import org . eclipse . jdt . internal . compiler . util . ObjectVector ; import org . eclipse . jdt . internal . core . NameLookup ; import org . eclipse . jdt . internal . ui . text . java . JavaTypeCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . LazyGenericTypeProposal ; import org . eclipse . jdt . internal . ui . text . java . LazyJavaCompletionProposal ; import org . eclipse . jdt . internal . ui . text . java . LazyJavaTypeCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class GroovyProposalTypeSearchRequestor implements ISearchRequestor , RelevanceConstants { private static final char [ ] [ ] DEFAULT_GROOVY_IMPORTS = { "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) } ; private static final char [ ] [ ] DEFAULT_GROOVY_IMPORTS_SIMPLE_NAMES = { "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) } ; private static final char [ ] [ ] DEFAULT_GROOVY_ON_DEMAND_IMPORTS = { "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) , "<STR_LIT>" . toCharArray ( ) } ; private static class AcceptedConstructor { public int modifiers ; public char [ ] simpleTypeName ; public int parameterCount ; public char [ ] signature ; public char [ ] [ ] parameterTypes ; public char [ ] [ ] parameterNames ; public int typeModifiers ; public char [ ] packageName ; public int extraFlags ; public int accessibility ; public AcceptedConstructor ( int modifiers , char [ ] simpleTypeName , int parameterCount , char [ ] signature , char [ ] [ ] parameterTypes , char [ ] [ ] parameterNames , int typeModifiers , char [ ] packageName , int extraFlags , int accessibility ) { this . modifiers = modifiers ; this . simpleTypeName = simpleTypeName ; this . parameterCount = parameterCount ; this . signature = signature ; this . parameterTypes = parameterTypes ; this . parameterNames = parameterNames ; this . typeModifiers = typeModifiers ; this . packageName = packageName ; this . extraFlags = extraFlags ; this . accessibility = accessibility ; } @ Override public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( '<CHAR_LIT>' ) ; buffer . append ( this . packageName ) ; buffer . append ( '<CHAR_LIT:U+002C>' ) ; buffer . append ( this . simpleTypeName ) ; buffer . append ( '<CHAR_LIT:}>' ) ; return buffer . toString ( ) ; } } private class AcceptedType { public char [ ] packageName ; public char [ ] simpleTypeName ; public char [ ] [ ] enclosingTypeNames ; public int modifiers ; public int accessibility ; public boolean mustBeQualified = false ; public char [ ] fullyQualifiedName = null ; public char [ ] qualifiedTypeName = null ; AcceptedType ( char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , int modifiers , int accessibility ) { this . packageName = packageName ; this . simpleTypeName = simpleTypeName ; this . enclosingTypeNames = enclosingTypeNames ; this . modifiers = modifiers ; this . accessibility = accessibility ; } @ Override public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( '<CHAR_LIT>' ) ; buffer . append ( this . packageName ) ; buffer . append ( '<CHAR_LIT:U+002C>' ) ; buffer . append ( this . simpleTypeName ) ; buffer . append ( '<CHAR_LIT:U+002C>' ) ; buffer . append ( CharOperation . concatWith ( this . enclosingTypeNames , '<CHAR_LIT:.>' ) ) ; buffer . append ( '<CHAR_LIT:}>' ) ; return buffer . toString ( ) ; } } private final static int CHECK_CANCEL_FREQUENCY = <NUM_LIT> ; private int foundTypesCount = <NUM_LIT:0> ; private int foundConstructorsCount = <NUM_LIT:0> ; private final IProgressMonitor monitor ; private ObjectVector acceptedTypes ; private Set < String > acceptedPackages ; private ObjectVector acceptedConstructors ; private boolean importCachesInitialized ; private final int offset ; private final int replaceLength ; private final int actualCompletionPosition ; private char [ ] [ ] [ ] imports ; private char [ ] [ ] onDemandimports ; private final boolean isImport ; private final JavaContentAssistInvocationContext javaContext ; private final ModuleNode module ; private final GroovyCompilationUnit unit ; private final NameLookup nameLookup ; private final String completionExpression ; private GroovyImportRewriteFactory groovyRewriter ; private boolean shouldAcceptConstructors ; private CompletionEngine mockEngine ; private IType [ ] allTypesInUnit ; private boolean contextOnly ; private final ContentAssistContext context ; public GroovyProposalTypeSearchRequestor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , int exprStart , int replaceLength , NameLookup nameLookup , IProgressMonitor monitor ) { this . context = context ; this . offset = exprStart ; this . javaContext = javaContext ; this . module = context . unit . getModuleNode ( ) ; this . unit = context . unit ; this . replaceLength = replaceLength ; this . actualCompletionPosition = context . completionLocation ; this . monitor = monitor ; this . acceptedTypes = new ObjectVector ( ) ; importCachesInitialized = false ; this . nameLookup = nameLookup ; this . isImport = context . location == ContentAssistLocation . IMPORT ; this . shouldAcceptConstructors = context . location == ContentAssistLocation . CONSTRUCTOR || context . location == ContentAssistLocation . METHOD_CONTEXT ; this . contextOnly = context . location == ContentAssistLocation . METHOD_CONTEXT ; this . completionExpression = context . location == ContentAssistLocation . METHOD_CONTEXT ? ( ( MethodInfoContentAssistContext ) context ) . methodName : context . completionExpression ; groovyRewriter = new GroovyImportRewriteFactory ( this . unit , this . module ) ; try { allTypesInUnit = unit . getAllTypes ( ) ; } catch ( JavaModelException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; allTypesInUnit = new IType [ <NUM_LIT:0> ] ; } } public void acceptConstructor ( int modifiers , char [ ] simpleTypeName , int parameterCount , char [ ] signature , char [ ] [ ] parameterTypes , char [ ] [ ] parameterNames , int typeModifiers , char [ ] packageName , int extraFlags , String path , AccessRestriction accessRestriction ) { if ( shouldAcceptConstructors ) { if ( ( this . foundConstructorsCount % ( CHECK_CANCEL_FREQUENCY ) ) == <NUM_LIT:0> ) checkCancel ( ) ; this . foundConstructorsCount ++ ; if ( ( typeModifiers & ClassFileConstants . AccEnum ) != <NUM_LIT:0> ) return ; int accessibility = IAccessRule . K_ACCESSIBLE ; if ( accessRestriction != null ) { switch ( accessRestriction . getProblemId ( ) ) { case IProblem . ForbiddenReference : return ; case IProblem . DiscouragedReference : accessibility = IAccessRule . K_DISCOURAGED ; break ; } } if ( signature == null ) { } if ( this . acceptedConstructors == null ) { this . acceptedConstructors = new ObjectVector ( ) ; } this . acceptedConstructors . add ( new AcceptedConstructor ( modifiers , simpleTypeName , parameterCount , signature , parameterTypes , parameterNames , typeModifiers , packageName , extraFlags , accessibility ) ) ; } } public void acceptPackage ( char [ ] packageName ) { this . checkCancel ( ) ; if ( acceptedPackages == null ) { acceptedPackages = new HashSet < String > ( ) ; } acceptedPackages . add ( String . valueOf ( packageName ) ) ; } public void acceptType ( char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , int modifiers , AccessRestriction accessRestriction ) { if ( ( this . foundTypesCount % CHECK_CANCEL_FREQUENCY ) == <NUM_LIT:0> ) checkCancel ( ) ; this . foundTypesCount ++ ; if ( CharOperation . contains ( '<CHAR_LIT>' , simpleTypeName ) ) { return ; } int accessibility = IAccessRule . K_ACCESSIBLE ; if ( accessRestriction != null ) { switch ( accessRestriction . getProblemId ( ) ) { case IProblem . ForbiddenReference : return ; case IProblem . DiscouragedReference : accessibility = IAccessRule . K_DISCOURAGED ; break ; } } if ( this . acceptedTypes == null ) { this . acceptedTypes = new ObjectVector ( ) ; } this . acceptedTypes . add ( new AcceptedType ( packageName , simpleTypeName , enclosingTypeNames , modifiers , accessibility ) ) ; } private void checkCancel ( ) { if ( this . monitor != null && this . monitor . isCanceled ( ) ) { throw new OperationCanceledException ( ) ; } } List < ICompletionProposal > processAcceptedTypes ( ) { this . checkCancel ( ) ; if ( this . acceptedTypes == null ) return Collections . EMPTY_LIST ; int length = this . acceptedTypes . size ( ) ; if ( length == <NUM_LIT:0> ) return Collections . EMPTY_LIST ; HashtableOfObject onDemandFound = new HashtableOfObject ( ) ; String thisPackageName = module . getPackageName ( ) == null ? "<STR_LIT>" : module . getPackageName ( ) ; List < ICompletionProposal > proposals = new LinkedList < ICompletionProposal > ( ) ; try { next : for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { if ( ( i % CHECK_CANCEL_FREQUENCY ) == <NUM_LIT:0> ) { checkCancel ( ) ; } AcceptedType acceptedType = ( AcceptedType ) this . acceptedTypes . elementAt ( i ) ; char [ ] packageName = acceptedType . packageName ; char [ ] simpleTypeName = acceptedType . simpleTypeName ; char [ ] [ ] enclosingTypeNames = acceptedType . enclosingTypeNames ; int modifiers = acceptedType . modifiers ; int accessibility = acceptedType . accessibility ; char [ ] typeName ; char [ ] flatEnclosingTypeNames ; if ( enclosingTypeNames == null || enclosingTypeNames . length == <NUM_LIT:0> ) { flatEnclosingTypeNames = null ; typeName = simpleTypeName ; } else { flatEnclosingTypeNames = CharOperation . concatWith ( acceptedType . enclosingTypeNames , '<CHAR_LIT:.>' ) ; typeName = CharOperation . concat ( flatEnclosingTypeNames , simpleTypeName , '<CHAR_LIT:.>' ) ; } char [ ] fullyQualifiedName = CharOperation . concat ( packageName , typeName , '<CHAR_LIT:.>' ) ; if ( ! this . importCachesInitialized ) { initializeImportCaches ( ) ; } for ( int j = <NUM_LIT:0> ; j < imports . length ; j ++ ) { char [ ] [ ] importName = imports [ j ] ; if ( CharOperation . equals ( typeName , importName [ <NUM_LIT:0> ] ) ) { proposals . add ( proposeType ( packageName , simpleTypeName , modifiers , accessibility , typeName , fullyQualifiedName , ! CharOperation . equals ( fullyQualifiedName , importName [ <NUM_LIT:1> ] ) ) ) ; continue next ; } } if ( ( enclosingTypeNames == null || enclosingTypeNames . length == <NUM_LIT:0> ) && CharOperation . equals ( thisPackageName . toCharArray ( ) , packageName ) ) { proposals . add ( proposeType ( packageName , simpleTypeName , modifiers , accessibility , typeName , fullyQualifiedName , false ) ) ; continue next ; } else { char [ ] fullyQualifiedEnclosingTypeOrPackageName = null ; if ( ( ( AcceptedType ) onDemandFound . get ( simpleTypeName ) ) == null ) { for ( int j = <NUM_LIT:0> ; j < this . onDemandimports . length ; j ++ ) { char [ ] importFlatName = onDemandimports [ j ] ; if ( fullyQualifiedEnclosingTypeOrPackageName == null ) { if ( enclosingTypeNames != null && enclosingTypeNames . length != <NUM_LIT:0> ) { fullyQualifiedEnclosingTypeOrPackageName = CharOperation . concat ( packageName , flatEnclosingTypeNames , '<CHAR_LIT:.>' ) ; } else { fullyQualifiedEnclosingTypeOrPackageName = packageName ; } } if ( CharOperation . equals ( fullyQualifiedEnclosingTypeOrPackageName , importFlatName ) ) { acceptedType . qualifiedTypeName = typeName ; acceptedType . fullyQualifiedName = fullyQualifiedName ; onDemandFound . put ( simpleTypeName , acceptedType ) ; continue next ; } } proposals . add ( proposeType ( fullyQualifiedEnclosingTypeOrPackageName != null ? fullyQualifiedEnclosingTypeOrPackageName : packageName , simpleTypeName , modifiers , accessibility , typeName , fullyQualifiedName , true ) ) ; } } } char [ ] [ ] keys = onDemandFound . keyTable ; Object [ ] values = onDemandFound . valueTable ; int max = keys . length ; for ( int i = <NUM_LIT:0> ; i < max ; i ++ ) { if ( ( i % CHECK_CANCEL_FREQUENCY ) == <NUM_LIT:0> ) checkCancel ( ) ; if ( keys [ i ] != null ) { AcceptedType value = ( AcceptedType ) values [ i ] ; if ( value != null ) { proposals . add ( proposeType ( value . packageName , value . simpleTypeName , value . modifiers , value . accessibility , value . qualifiedTypeName , value . fullyQualifiedName , value . mustBeQualified ) ) ; } } } } finally { this . acceptedTypes = null ; } return proposals ; } private ICompletionProposal proposeNoImportType ( char [ ] packageName , char [ ] simpleTypeName , int modifiers , int accessibility , char [ ] qualifiedTypeName , char [ ] fullyQualifiedName , boolean isQualified ) { char [ ] completionName ; if ( isQualified ) { completionName = fullyQualifiedName ; } else { completionName = simpleTypeName ; } GroovyCompletionProposal proposal = createProposal ( CompletionProposal . TYPE_REF , this . actualCompletionPosition - this . offset ) ; proposal . setDeclarationSignature ( packageName ) ; proposal . setSignature ( CompletionEngine . createNonGenericTypeSignature ( packageName , simpleTypeName ) ) ; proposal . setCompletion ( completionName ) ; proposal . setFlags ( modifiers ) ; proposal . setReplaceRange ( this . offset , this . offset + this . replaceLength ) ; proposal . setTokenRange ( this . offset , this . actualCompletionPosition ) ; proposal . setRelevance ( RelevanceRules . ALL_RULES . getRelevance ( fullyQualifiedName , allTypesInUnit , accessibility , modifiers ) ) ; proposal . setTypeName ( simpleTypeName ) ; proposal . setAccessibility ( accessibility ) ; proposal . setPackageName ( packageName ) ; String completionString = new String ( completionName ) ; JavaTypeCompletionProposal javaCompletionProposal = new JavaTypeCompletionProposal ( completionString , null , this . offset , this . replaceLength , ProposalUtils . getImage ( proposal ) , ProposalUtils . createDisplayString ( proposal ) , proposal . getRelevance ( ) , completionString , javaContext ) ; javaCompletionProposal . setRelevance ( proposal . getRelevance ( ) ) ; return javaCompletionProposal ; } private ICompletionProposal proposeType ( char [ ] packageName , char [ ] simpleTypeName , int modifiers , int accessibility , char [ ] qualifiedTypeName , char [ ] fullyQualifiedName , boolean isQualified ) { return isImport ? proposeNoImportType ( packageName , simpleTypeName , modifiers , accessibility , qualifiedTypeName , fullyQualifiedName , isQualified ) : proposeImportableType ( packageName , simpleTypeName , modifiers , accessibility , qualifiedTypeName , fullyQualifiedName , isQualified ) ; } private ICompletionProposal proposeImportableType ( char [ ] packageName , char [ ] simpleTypeName , int modifiers , int accessibility , char [ ] qualifiedTypeName , char [ ] fullyQualifiedName , boolean isQualified ) { char [ ] completionName ; if ( isQualified ) { completionName = fullyQualifiedName ; } else { completionName = simpleTypeName ; } GroovyCompletionProposal proposal = createProposal ( CompletionProposal . TYPE_REF , this . actualCompletionPosition - this . offset ) ; proposal . setDeclarationSignature ( packageName ) ; proposal . setSignature ( CompletionEngine . createNonGenericTypeSignature ( packageName , simpleTypeName ) ) ; proposal . setCompletion ( completionName ) ; proposal . setFlags ( modifiers ) ; proposal . setReplaceRange ( this . offset , this . offset + this . replaceLength ) ; proposal . setTokenRange ( this . offset , this . actualCompletionPosition ) ; proposal . setRelevance ( RelevanceRules . ALL_RULES . getRelevance ( fullyQualifiedName , allTypesInUnit , accessibility , modifiers ) ) ; proposal . setNameLookup ( nameLookup ) ; proposal . setTypeName ( simpleTypeName ) ; proposal . setAccessibility ( accessibility ) ; proposal . setPackageName ( packageName ) ; LazyGenericTypeProposal javaCompletionProposal = new LazyGenericTypeProposal ( proposal , javaContext ) ; javaCompletionProposal . setTriggerCharacters ( ProposalUtils . TYPE_TRIGGERS ) ; javaCompletionProposal . setRelevance ( proposal . getRelevance ( ) ) ; ImportRewrite r = groovyRewriter . getImportRewrite ( monitor ) ; if ( r != null ) { ReflectionUtils . setPrivateField ( LazyJavaTypeCompletionProposal . class , "<STR_LIT>" , javaCompletionProposal , r ) ; } return javaCompletionProposal ; } private void initializeImportCaches ( ) { importCachesInitialized = true ; List < ImportNode > importPackages = ( List < ImportNode > ) module . getStarImports ( ) ; onDemandimports = new char [ importPackages . size ( ) + DEFAULT_GROOVY_ON_DEMAND_IMPORTS . length ] [ ] ; int i = <NUM_LIT:0> ; for ( ImportNode importPackage : importPackages ) { char [ ] onDemand = importPackage . getPackageName ( ) . toCharArray ( ) ; int length = onDemand . length ; if ( length > <NUM_LIT:0> && onDemand [ length - <NUM_LIT:1> ] == '<CHAR_LIT:.>' ) { onDemand = CharOperation . subarray ( onDemand , <NUM_LIT:0> , length - <NUM_LIT:1> ) ; } onDemandimports [ i ++ ] = onDemand ; } for ( char [ ] defaultOnDemand : DEFAULT_GROOVY_ON_DEMAND_IMPORTS ) { onDemandimports [ i ++ ] = defaultOnDemand ; } List < ImportNode > importClasses = module . getImports ( ) ; imports = new char [ importClasses . size ( ) + DEFAULT_GROOVY_IMPORTS . length ] [ ] [ ] ; i = <NUM_LIT:0> ; for ( ImportNode importNode : importClasses ) { imports [ i ] = new char [ <NUM_LIT:2> ] [ ] ; imports [ i ] [ <NUM_LIT:0> ] = importNode . getAlias ( ) . toCharArray ( ) ; imports [ i ] [ <NUM_LIT:1> ] = importNode . getType ( ) . getName ( ) . toCharArray ( ) ; i ++ ; } for ( int j = <NUM_LIT:0> ; j < DEFAULT_GROOVY_IMPORTS . length ; j ++ ) { imports [ i ] = new char [ <NUM_LIT:2> ] [ ] ; imports [ i ] [ <NUM_LIT:0> ] = DEFAULT_GROOVY_IMPORTS_SIMPLE_NAMES [ j ] ; imports [ i ] [ <NUM_LIT:1> ] = DEFAULT_GROOVY_IMPORTS [ j ] ; i ++ ; } } List < ICompletionProposal > processAcceptedPackages ( ) { this . checkCancel ( ) ; List < ICompletionProposal > proposals = new LinkedList < ICompletionProposal > ( ) ; if ( acceptedPackages != null && acceptedPackages . size ( ) > <NUM_LIT:0> ) { for ( String packageNameStr : acceptedPackages ) { char [ ] packageName = packageNameStr . toCharArray ( ) ; GroovyCompletionProposal proposal = createProposal ( CompletionProposal . PACKAGE_REF , this . actualCompletionPosition ) ; proposal . setDeclarationSignature ( packageName ) ; proposal . setPackageName ( packageName ) ; proposal . setCompletion ( packageName ) ; proposal . setReplaceRange ( this . offset , this . actualCompletionPosition ) ; proposal . setTokenRange ( this . offset , this . actualCompletionPosition ) ; proposal . setRelevance ( Relevance . LOWEST . getRelavance ( ) ) ; LazyJavaCompletionProposal javaProposal = new LazyJavaCompletionProposal ( proposal , javaContext ) ; proposals . add ( javaProposal ) ; javaProposal . setRelevance ( proposal . getRelevance ( ) ) ; } } return proposals ; } List < ICompletionProposal > processAcceptedConstructors ( Set < String > usedParams , JDTResolver resolver ) { this . checkCancel ( ) ; if ( this . acceptedConstructors == null ) return Collections . emptyList ( ) ; int length = this . acceptedConstructors . size ( ) ; if ( length == <NUM_LIT:0> ) return Collections . emptyList ( ) ; String currentPackageNameStr = this . module . getPackageName ( ) ; char [ ] currentPackageName ; if ( currentPackageNameStr == null ) { currentPackageName = CharOperation . NO_CHAR ; } else { currentPackageName = currentPackageNameStr . toCharArray ( ) ; if ( currentPackageName [ currentPackageName . length - <NUM_LIT:1> ] == '<CHAR_LIT:.>' ) { char [ ] newPackageName = new char [ currentPackageName . length - <NUM_LIT:1> ] ; System . arraycopy ( currentPackageName , <NUM_LIT:0> , newPackageName , <NUM_LIT:0> , newPackageName . length ) ; currentPackageName = newPackageName ; } } List < ICompletionProposal > proposals = new LinkedList < ICompletionProposal > ( ) ; try { for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { if ( ( i % CHECK_CANCEL_FREQUENCY ) == <NUM_LIT:0> ) checkCancel ( ) ; AcceptedConstructor acceptedConstructor = ( AcceptedConstructor ) this . acceptedConstructors . elementAt ( i ) ; final int typeModifiers = acceptedConstructor . typeModifiers ; if ( isInterfaceAnnotationAbstractOrEnum ( typeModifiers ) ) { continue ; } final char [ ] packageName = acceptedConstructor . packageName ; final char [ ] simpleTypeName = acceptedConstructor . simpleTypeName ; final int modifiers = acceptedConstructor . modifiers ; final int parameterCount = acceptedConstructor . parameterCount ; final char [ ] signature = acceptedConstructor . signature ; final char [ ] [ ] parameterTypes = acceptedConstructor . parameterTypes ; final char [ ] [ ] parameterNames = acceptedConstructor . parameterNames ; final int extraFlags = acceptedConstructor . extraFlags ; final int accessibility = acceptedConstructor . accessibility ; char [ ] fullyQualifiedName = CharOperation . concat ( packageName , simpleTypeName , '<CHAR_LIT:.>' ) ; if ( ! this . importCachesInitialized ) { initializeImportCaches ( ) ; } if ( ! Flags . isEnum ( typeModifiers ) ) { ICompletionProposal constructorProposal = proposeConstructor ( simpleTypeName , parameterCount , signature , parameterTypes , parameterNames , modifiers , packageName , typeModifiers , accessibility , simpleTypeName , fullyQualifiedName , false , extraFlags ) ; if ( constructorProposal != null ) { proposals . add ( constructorProposal ) ; if ( contextOnly ) { ClassNode resolved = resolver . resolve ( String . valueOf ( fullyQualifiedName ) ) ; if ( resolved != null ) { List < ConstructorNode > constructors = resolved . getDeclaredConstructors ( ) ; if ( constructors != null && constructors . size ( ) == <NUM_LIT:1> ) { ConstructorNode constructor = constructors . get ( <NUM_LIT:0> ) ; Parameter [ ] parameters = constructor . getParameters ( ) ; if ( constructor . getStart ( ) <= <NUM_LIT:0> && ( parameters == null || parameters . length == <NUM_LIT:0> ) ) { for ( PropertyNode prop : resolved . getProperties ( ) ) { if ( ! prop . getName ( ) . equals ( "<STR_LIT>" ) && ! usedParams . contains ( prop . getName ( ) ) ) { GroovyNamedArgumentProposal namedProp = new GroovyNamedArgumentProposal ( prop . getName ( ) , prop . getType ( ) , null , null ) ; proposals . add ( namedProp . createJavaProposal ( context , javaContext ) ) ; } } } } } } } } } } finally { this . acceptedTypes = null ; } return proposals ; } private boolean isInterfaceAnnotationAbstractOrEnum ( int typeModifiers ) { return ( typeModifiers & ( ClassFileConstants . AccInterface | ClassFileConstants . AccEnum | ClassFileConstants . AccAnnotation ) ) != <NUM_LIT:0> ; } private ICompletionProposal proposeConstructor ( char [ ] simpleTypeName , int parameterCount , char [ ] signature , char [ ] [ ] parameterTypes , char [ ] [ ] parameterNames , int modifiers , char [ ] packageName , int typeModifiers , int accessibility , char [ ] typeName , char [ ] fullyQualifiedName , boolean isQualified , int extraFlags ) { String simpleTypeNameStr = String . valueOf ( simpleTypeName ) ; String fullyQualifiedNameStr = String . valueOf ( fullyQualifiedName ) ; if ( contextOnly && ! completionExpression . equals ( simpleTypeNameStr ) && ! completionExpression . equals ( fullyQualifiedNameStr ) ) { return null ; } char [ ] typeCompletion ; if ( isQualified ) { typeCompletion = fullyQualifiedName ; if ( packageName == null || packageName . length == <NUM_LIT:0> ) { typeCompletion = simpleTypeName ; } } else { typeCompletion = simpleTypeName ; } float relevanceMultiplier = <NUM_LIT:1> ; relevanceMultiplier += accessibility == IAccessRule . K_ACCESSIBLE ? <NUM_LIT:2> : - <NUM_LIT:1> ; relevanceMultiplier += computeRelevanceForCaseMatching ( this . completionExpression . toCharArray ( ) , simpleTypeName ) ; int augmentedModifiers = modifiers ; if ( Flags . isDeprecated ( typeModifiers ) ) { augmentedModifiers |= Flags . AccDeprecated ; } if ( parameterCount == - <NUM_LIT:1> ) { parameterNames = CharOperation . NO_CHAR_CHAR ; parameterTypes = CharOperation . NO_CHAR_CHAR ; } else { int parameterNamesLength = parameterNames == null ? <NUM_LIT:0> : parameterNames . length ; if ( parameterCount != parameterNamesLength ) { parameterNames = null ; } } GroovyCompletionProposal proposal = createProposal ( contextOnly ? CompletionProposal . METHOD_REF : CompletionProposal . CONSTRUCTOR_INVOCATION , offset - <NUM_LIT:1> ) ; char [ ] declarationSignature = CompletionEngine . createNonGenericTypeSignature ( packageName , typeName ) ; proposal . setDeclarationSignature ( declarationSignature ) ; if ( contextOnly ) { proposal . setReplaceRange ( actualCompletionPosition , actualCompletionPosition ) ; proposal . setTokenRange ( actualCompletionPosition , actualCompletionPosition ) ; proposal . setCompletion ( CharOperation . NO_CHAR ) ; } else { proposal . setCompletion ( this . completionExpression . toCharArray ( ) ) ; proposal . setReplaceRange ( this . offset + this . replaceLength , this . offset + this . replaceLength ) ; proposal . setTokenRange ( this . offset , this . actualCompletionPosition ) ; proposal . setCompletion ( new char [ ] { '<CHAR_LIT:(>' , '<CHAR_LIT:)>' } ) ; GroovyCompletionProposal typeProposal = createTypeProposal ( packageName , typeModifiers , accessibility , typeName , fullyQualifiedName , isQualified , typeCompletion , augmentedModifiers , declarationSignature ) ; proposal . setRequiredProposals ( new CompletionProposal [ ] { typeProposal } ) ; } if ( signature == null ) { proposal . setSignature ( createConstructorSignature ( parameterTypes , isQualified ) ) ; } else { char [ ] copy = new char [ signature . length ] ; System . arraycopy ( signature , <NUM_LIT:0> , copy , <NUM_LIT:0> , copy . length ) ; CharOperation . replace ( copy , '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ; proposal . setSignature ( copy ) ; } if ( parameterNames != null ) { proposal . setParameterNames ( parameterNames ) ; } else { proposal . setHasNoParameterNamesFromIndex ( true ) ; if ( mockEngine == null ) { mockEngine = new CompletionEngine ( null , new CompletionRequestor ( ) { @ Override public void accept ( CompletionProposal proposal ) { } } , null , null , null , null ) ; } proposal . setCompletionEngine ( mockEngine ) ; } proposal . setDeclarationPackageName ( packageName ) ; proposal . setDeclarationTypeName ( simpleTypeName ) ; proposal . setParameterTypeNames ( parameterTypes ) ; proposal . setName ( simpleTypeName ) ; proposal . setIsContructor ( true ) ; proposal . setRelevance ( Relevance . MEDIUM_HIGH . getRelevance ( relevanceMultiplier ) ) ; proposal . setFlags ( augmentedModifiers ) ; proposal . setTypeName ( simpleTypeName ) ; proposal . setAccessibility ( typeModifiers ) ; proposal . setPackageName ( packageName ) ; LazyJavaCompletionProposal lazyProposal = new GroovyJavaMethodCompletionProposal ( proposal , javaContext , getProposalOptions ( ) ) ; lazyProposal . setRelevance ( proposal . getRelevance ( ) ) ; if ( proposal . hasParameters ( ) ) { lazyProposal . setTriggerCharacters ( ProposalUtils . METHOD_WITH_ARGUMENTS_TRIGGERS ) ; } else { lazyProposal . setTriggerCharacters ( ProposalUtils . METHOD_TRIGGERS ) ; } ImportRewrite r = groovyRewriter . getImportRewrite ( monitor ) ; if ( r != null ) { ReflectionUtils . setPrivateField ( LazyJavaTypeCompletionProposal . class , "<STR_LIT>" , lazyProposal , r ) ; } if ( contextOnly ) { ( ( GroovyJavaMethodCompletionProposal ) lazyProposal ) . contextOnly ( ) ; } return lazyProposal ; } private GroovyCompletionProposal createTypeProposal ( char [ ] packageName , int typeModifiers , int accessibility , char [ ] typeName , char [ ] fullyQualifiedName , boolean isQualified , char [ ] typeCompletion , int augmentedModifiers , char [ ] declarationSignature ) { GroovyCompletionProposal typeProposal = createProposal ( CompletionProposal . TYPE_REF , this . actualCompletionPosition - <NUM_LIT:1> ) ; typeProposal . setNameLookup ( nameLookup ) ; typeProposal . setDeclarationSignature ( declarationSignature ) ; typeProposal . setSignature ( CompletionEngine . createNonGenericTypeSignature ( packageName , typeName ) ) ; typeProposal . setPackageName ( packageName ) ; typeProposal . setTypeName ( typeName ) ; typeProposal . setFlags ( typeModifiers ) ; typeProposal . setCompletion ( typeCompletion ) ; typeProposal . setReplaceRange ( this . offset , this . offset + this . replaceLength ) ; typeProposal . setTokenRange ( this . offset , this . offset + this . replaceLength ) ; typeProposal . setRelevance ( RelevanceRules . ALL_RULES . getRelevance ( fullyQualifiedName , allTypesInUnit , accessibility , augmentedModifiers ) ) ; return typeProposal ; } private ProposalFormattingOptions getProposalOptions ( ) { if ( groovyProposalPrefs == null ) { groovyProposalPrefs = ProposalFormattingOptions . newFromOptions ( ) ; } return groovyProposalPrefs ; } private char [ ] createConstructorSignature ( char [ ] [ ] parameterTypes , boolean isQualified ) { char [ ] [ ] parameterTypeSigs ; if ( parameterTypes == null ) { parameterTypeSigs = CharOperation . NO_CHAR_CHAR ; } else { parameterTypeSigs = new char [ parameterTypes . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < parameterTypes . length ; i ++ ) { char [ ] copy = new char [ parameterTypes [ i ] . length ] ; System . arraycopy ( parameterTypes [ i ] , <NUM_LIT:0> , copy , <NUM_LIT:0> , copy . length ) ; CharOperation . replace ( copy , '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ; parameterTypeSigs [ i ] = Signature . createCharArrayTypeSignature ( copy , isQualified ) ; } } return Signature . createMethodSignature ( parameterTypeSigs , new char [ ] { '<CHAR_LIT>' } ) ; } int computeRelevanceForCaseMatching ( char [ ] token , char [ ] proposalName ) { if ( CharOperation . equals ( token , proposalName , true ) ) { return R_CASE + R_EXACT_NAME ; } else if ( CharOperation . equals ( token , proposalName , false ) ) { return R_EXACT_NAME ; } return <NUM_LIT:0> ; } protected final GroovyCompletionProposal createProposal ( int kind , int completionOffset ) { GroovyCompletionProposal proposal = new GroovyCompletionProposal ( kind , completionOffset ) ; proposal . setNameLookup ( nameLookup ) ; return proposal ; } private ProposalFormattingOptions groovyProposalPrefs ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . createDisplayString ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . createMethodSignatureStr ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . createTypeSignature ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . getImage ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . groovy . search . GenericsMapper ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . internal . ui . text . java . OverrideCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . objectweb . asm . Opcodes ; public class NewMethodCompletionProcessor extends AbstractGroovyCompletionProcessor { public NewMethodCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { List < MethodNode > unimplementedMethods = getAllUnimplementedMethods ( getClassNode ( ) ) ; List < ICompletionProposal > proposals = new LinkedList < ICompletionProposal > ( ) ; ContentAssistContext context = getContext ( ) ; IType enclosingType = context . getEnclosingType ( ) ; if ( enclosingType != null ) { for ( MethodNode method : unimplementedMethods ) { proposals . add ( createProposal ( method , context , enclosingType ) ) ; } } try { List < IProposalProvider > providers = ProposalProviderRegistry . getRegistry ( ) . getProvidersFor ( context . unit ) ; for ( IProposalProvider provider : providers ) { List < MethodNode > newProposals = provider . getNewMethodProposals ( context ) ; if ( newProposals != null ) { for ( MethodNode methodNode : newProposals ) { proposals . add ( createProposal ( methodNode , context , enclosingType ) ) ; } } } } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" + context . unit . getElementName ( ) , e ) ; } return proposals ; } private ClassNode getClassNode ( ) { return getContext ( ) . containingCodeBlock instanceof ClassNode ? ( ClassNode ) getContext ( ) . containingCodeBlock : getScript ( ) ; } private ClassNode getScript ( ) { ModuleNode module = getContext ( ) . unit . getModuleNode ( ) ; for ( ClassNode clazz : ( Iterable < ClassNode > ) module . getClasses ( ) ) { if ( clazz . isScript ( ) ) { return clazz ; } } throw new IllegalArgumentException ( "<STR_LIT>" + module . getPackageName ( ) ) ; } private ICompletionProposal createProposal ( MethodNode method , ContentAssistContext context , IType enclosingType ) { int relevance = Relevance . VERY_HIGH . getRelavance ( ) ; GroovyCompletionProposal proposal = createProposal ( CompletionProposal . METHOD_DECLARATION , context . completionLocation ) ; String methodSignature = createMethodSignatureStr ( method ) ; proposal . setSignature ( methodSignature . toCharArray ( ) ) ; proposal . setDeclarationSignature ( createTypeSignature ( method . getDeclaringClass ( ) ) ) ; proposal . setName ( method . getName ( ) . toCharArray ( ) ) ; proposal . setDeclarationTypeName ( method . getDeclaringClass ( ) . getName ( ) . toCharArray ( ) ) ; proposal . setTypeName ( method . getReturnType ( ) . getName ( ) . toCharArray ( ) ) ; proposal . setParameterNames ( getParameterNames ( method ) ) ; String [ ] parameterTypeNamesStr = getParameterTypeNames ( method ) ; char [ ] [ ] parameterTypeNames = new char [ parameterTypeNamesStr . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < parameterTypeNames . length ; i ++ ) { parameterTypeNames [ i ] = parameterTypeNamesStr [ i ] . toCharArray ( ) ; } proposal . setParameterTypeNames ( parameterTypeNames ) ; StringBuffer completion = new StringBuffer ( ) ; createMethod ( method , completion ) ; proposal . setCompletion ( completion . toString ( ) . toCharArray ( ) ) ; proposal . setDeclarationKey ( method . getDeclaringClass ( ) . getName ( ) . toCharArray ( ) ) ; proposal . setReplaceRange ( context . completionLocation - context . completionExpression . length ( ) , context . completionEnd ) ; proposal . setFlags ( method . getModifiers ( ) ) ; proposal . setRelevance ( relevance ) ; OverrideCompletionProposal override = new OverrideCompletionProposal ( context . unit . getJavaProject ( ) , context . unit , method . getName ( ) , parameterTypeNamesStr , context . completionLocation , context . completionExpression . length ( ) , createDisplayString ( proposal ) , String . valueOf ( proposal . getCompletion ( ) ) ) ; override . setImage ( getImage ( proposal ) ) ; override . setRelevance ( relevance ) ; override . setReplacementOffset ( context . completionLocation - context . completionExpression . length ( ) ) ; override . setReplacementLength ( context . completionExpression . length ( ) ) ; override . setRelevance ( proposal . getRelevance ( ) ) ; return override ; } private char [ ] [ ] getParameterNames ( MethodNode method ) { Parameter [ ] parameters = method . getParameters ( ) ; char [ ] [ ] paramNames = new char [ parameters . length ] [ ] ; for ( int i = <NUM_LIT:0> ; i < paramNames . length ; i ++ ) { paramNames [ i ] = parameters [ i ] . getName ( ) . toCharArray ( ) ; } return paramNames ; } private Map < ClassNode , GenericsMapper > mappers = new HashMap < ClassNode , GenericsMapper > ( ) ; private String [ ] getParameterTypeNames ( MethodNode method ) { GenericsMapper mapper = null ; ClassNode declaringClass = method . getDeclaringClass ( ) ; if ( declaringClass . getGenericsTypes ( ) != null && declaringClass . getGenericsTypes ( ) . length > <NUM_LIT:0> ) { if ( ! mappers . containsKey ( declaringClass ) ) { ClassNode thiz = getClassNode ( ) ; mapper = GenericsMapper . gatherGenerics ( findResolvedType ( thiz , declaringClass ) , declaringClass ) ; } else { mapper = mappers . get ( declaringClass ) ; } } Parameter [ ] parameters = method . getParameters ( ) ; String [ ] paramTypeNames = new String [ parameters . length ] ; for ( int i = <NUM_LIT:0> ; i < paramTypeNames . length ; i ++ ) { ClassNode paramType = parameters [ i ] . getType ( ) ; if ( mapper != null && paramType . getGenericsTypes ( ) != null && paramType . getGenericsTypes ( ) . length > <NUM_LIT:0> ) { paramType = VariableScope . resolveTypeParameterization ( mapper , VariableScope . clone ( paramType ) ) ; } paramTypeNames [ i ] = paramType . getName ( ) ; if ( paramTypeNames [ i ] . startsWith ( "<STR_LIT:[>" ) ) { int cnt = Signature . getArrayCount ( paramTypeNames [ i ] ) ; String sig = Signature . getElementType ( paramTypeNames [ i ] ) ; String qualifier = Signature . getSignatureQualifier ( sig ) ; String simple = Signature . getSignatureSimpleName ( sig ) ; StringBuilder sb = new StringBuilder ( ) ; if ( qualifier . length ( ) > <NUM_LIT:0> ) { sb . append ( qualifier ) . append ( "<STR_LIT:.>" ) ; } sb . append ( simple ) ; for ( int j = <NUM_LIT:0> ; j < cnt ; j ++ ) { sb . append ( "<STR_LIT:[]>" ) ; } paramTypeNames [ i ] = sb . toString ( ) ; } } return paramTypeNames ; } private ClassNode findResolvedType ( ClassNode target , ClassNode toResolve ) { if ( target != null ) { if ( target . equals ( toResolve ) ) { return target ; } ClassNode result = findResolvedType ( target . getUnresolvedSuperClass ( false ) , toResolve ) ; if ( result != null ) { return result ; } for ( ClassNode inter : target . getUnresolvedInterfaces ( false ) ) { result = findResolvedType ( inter , toResolve ) ; if ( result != null ) { return result ; } } ClassNode redirect = target . redirect ( ) ; if ( redirect != target ) { return findResolvedType ( redirect , toResolve ) ; } } return null ; } private List < MethodNode > getAllUnimplementedMethods ( ClassNode declaring ) { List < MethodNode > allMethods = declaring . getAllDeclaredMethods ( ) ; List < MethodNode > thisClassMethods = declaring . getMethods ( ) ; List < MethodNode > unimplementedMethods = new ArrayList < MethodNode > ( allMethods . size ( ) - thisClassMethods . size ( ) ) ; for ( MethodNode allMethodNode : allMethods ) { if ( allMethodNode . getName ( ) . startsWith ( getContext ( ) . completionExpression ) ) { if ( isOverridableMethod ( allMethodNode ) ) { boolean found = false ; inner : for ( MethodNode thisClassMethod : thisClassMethods ) { if ( allMethodNode . getParameters ( ) . length == thisClassMethod . getParameters ( ) . length && allMethodNode . getName ( ) . equals ( thisClassMethod . getName ( ) ) ) { Parameter [ ] allMethodParams = allMethodNode . getParameters ( ) ; Parameter [ ] thisClassParams = thisClassMethod . getParameters ( ) ; for ( int i = <NUM_LIT:0> ; i < thisClassParams . length ; i ++ ) { if ( ! allMethodParams [ i ] . getType ( ) . getName ( ) . equals ( thisClassParams [ i ] . getType ( ) . getName ( ) ) ) { continue inner ; } } found = true ; break inner ; } } if ( ! found ) { unimplementedMethods . add ( allMethodNode ) ; } found = false ; } } } return unimplementedMethods ; } private boolean isOverridableMethod ( MethodNode methodNode ) { String name = methodNode . getName ( ) ; return ! name . contains ( "<STR_LIT:$>" ) && ! name . contains ( "<STR_LIT:<>" ) && ! methodNode . isPrivate ( ) && ! methodNode . isStatic ( ) && ( methodNode . getModifiers ( ) & Opcodes . ACC_FINAL ) == <NUM_LIT:0> ; } private void createMethod ( MethodNode method , StringBuffer completion ) { int insertedModifiers = method . getModifiers ( ) & ~ ( Opcodes . ACC_NATIVE | Opcodes . ACC_ABSTRACT | Opcodes . ACC_PUBLIC ) ; ASTNode . printModifiers ( insertedModifiers , completion ) ; createType ( method . getReturnType ( ) , completion , false ) ; completion . append ( '<CHAR_LIT:U+0020>' ) ; completion . append ( method . getName ( ) ) ; completion . append ( '<CHAR_LIT:(>' ) ; Parameter [ ] parameters = method . getParameters ( ) ; int length = parameters . length ; for ( int i = <NUM_LIT:0> ; i < length ; i ++ ) { if ( i != <NUM_LIT:0> ) { completion . append ( '<CHAR_LIT:U+002C>' ) ; completion . append ( '<CHAR_LIT:U+0020>' ) ; } createType ( parameters [ i ] . getType ( ) , completion , true ) ; completion . append ( '<CHAR_LIT:U+0020>' ) ; completion . append ( parameters [ i ] . getName ( ) ) ; } completion . append ( '<CHAR_LIT:)>' ) ; ClassNode [ ] exceptions = method . getExceptions ( ) ; if ( exceptions != null && exceptions . length > <NUM_LIT:0> ) { completion . append ( '<CHAR_LIT:U+0020>' ) ; completion . append ( "<STR_LIT>" ) ; completion . append ( '<CHAR_LIT:U+0020>' ) ; for ( int i = <NUM_LIT:0> ; i < exceptions . length ; i ++ ) { if ( i != <NUM_LIT:0> ) { completion . append ( '<CHAR_LIT:U+0020>' ) ; completion . append ( '<CHAR_LIT:U+002C>' ) ; } createType ( exceptions [ i ] , completion , false ) ; } } } private void createType ( ClassNode type , StringBuffer completion , boolean isParameter ) { int arrayCount = <NUM_LIT:0> ; while ( type . getComponentType ( ) != null ) { arrayCount ++ ; type = type . getComponentType ( ) ; } if ( type . getName ( ) . equals ( "<STR_LIT>" ) && arrayCount == <NUM_LIT:0> ) { if ( ! isParameter ) { completion . append ( "<STR_LIT>" ) ; } } else { completion . append ( type . getNameWithoutPackage ( ) ) ; for ( int i = <NUM_LIT:0> ; i < arrayCount ; i ++ ) { completion . append ( "<STR_LIT:[]>" ) ; } } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . List ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public interface IGroovyCompletionProcessor { List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Parameter ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . VariableScope ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . ast . stmt . BlockStatement ; import org . codehaus . groovy . eclipse . codeassist . ProposalUtils ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyFieldProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . GroovyMethodProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . groovy . search . VariableScope . VariableInfo ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . internal . ui . text . java . LazyJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . objectweb . asm . Opcodes ; public class LocalVariableCompletionProcessor extends AbstractGroovyCompletionProcessor { private final int offset ; private final int replaceLength ; private final JavaContentAssistInvocationContext javaContext ; public LocalVariableCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; this . javaContext = javaContext ; this . replaceLength = context . completionExpression . length ( ) ; this . offset = context . completionLocation ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { Map < String , ClassNode > localNames = findLocalNames ( extractVariableNameStart ( ) ) ; List < ICompletionProposal > proposals = createProposals ( localNames ) ; proposals . addAll ( createClosureProposals ( ) ) ; return proposals ; } private List < ICompletionProposal > createClosureProposals ( ) { if ( getContext ( ) . currentScope . getEnclosingClosure ( ) != null ) { List < ICompletionProposal > proposals = new ArrayList < ICompletionProposal > ( <NUM_LIT:1> ) ; VariableInfo ownerInfo = getContext ( ) . currentScope . lookupName ( "<STR_LIT>" ) ; VariableInfo delegateInfo = getContext ( ) . currentScope . lookupName ( "<STR_LIT>" ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , ownerInfo . declaringType , ownerInfo . type , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , ownerInfo . declaringType , ownerInfo . type , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , delegateInfo . declaringType , delegateInfo . type , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , delegateInfo . declaringType , delegateInfo . type , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . OBJECT_CLASS_NODE , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . OBJECT_CLASS_NODE , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . INTEGER_CLASS_NODE , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . OBJECT_CLASS_NODE , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . INTEGER_CLASS_NODE , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . OBJECT_CLASS_NODE , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . INTEGER_CLASS_NODE , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . OBJECT_CLASS_NODE , true ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . CLASS_ARRAY_CLASS_NODE , false ) ; maybeAddClosureProperty ( proposals , "<STR_LIT>" , org . eclipse . jdt . groovy . search . VariableScope . CLOSURE_CLASS , org . eclipse . jdt . groovy . search . VariableScope . CLASS_ARRAY_CLASS_NODE , true ) ; return proposals ; } else { return Collections . emptyList ( ) ; } } private void maybeAddClosureProperty ( List < ICompletionProposal > proposals , String name , ClassNode type , ClassNode declaringType , boolean isMethod ) { if ( ProposalUtils . looselyMatches ( getContext ( ) . completionExpression , name ) ) { IGroovyProposal proposal ; if ( isMethod ) { proposal = createMethodProposal ( name , declaringType , type ) ; } else { proposal = createFieldProposal ( name , declaringType , type ) ; } proposals . add ( proposal . createJavaProposal ( getContext ( ) , getJavaContext ( ) ) ) ; } } private GroovyFieldProposal createFieldProposal ( String name , ClassNode declaring , ClassNode type ) { FieldNode field = new FieldNode ( name , Opcodes . ACC_PUBLIC , type , declaring , null ) ; field . setDeclaringClass ( declaring ) ; return new GroovyFieldProposal ( field ) ; } private GroovyMethodProposal createMethodProposal ( String name , ClassNode declaring , ClassNode returnType ) { MethodNode method = new MethodNode ( name , Opcodes . ACC_PUBLIC , returnType , new Parameter [ <NUM_LIT:0> ] , new ClassNode [ <NUM_LIT:0> ] , null ) ; method . setDeclaringClass ( declaring ) ; return new GroovyMethodProposal ( method ) ; } private String extractVariableNameStart ( ) { String fullExpression = getContext ( ) . completionExpression ; if ( fullExpression . length ( ) == <NUM_LIT:0> ) { return "<STR_LIT>" ; } int end = fullExpression . length ( ) - <NUM_LIT:1> ; while ( end >= <NUM_LIT:0> && Character . isJavaIdentifierPart ( fullExpression . charAt ( end ) ) ) { end -- ; } if ( end >= <NUM_LIT:0> ) { return fullExpression . substring ( ++ end ) ; } else { return fullExpression ; } } private Map < String , ClassNode > findLocalNames ( String prefix ) { Map < String , ClassNode > nameTypeMap = new HashMap < String , ClassNode > ( ) ; VariableScope scope = getVariableScope ( getContext ( ) . containingCodeBlock ) ; while ( scope != null ) { for ( Iterator < Variable > varIter = scope . getDeclaredVariablesIterator ( ) ; varIter . hasNext ( ) ; ) { Variable var = ( Variable ) varIter . next ( ) ; boolean inBounds ; if ( var instanceof Parameter ) { inBounds = ( ( Parameter ) var ) . getEnd ( ) < offset ; } else if ( var instanceof VariableExpression ) { inBounds = ( ( VariableExpression ) var ) . getEnd ( ) < offset ; } else { inBounds = true ; } if ( inBounds && ProposalUtils . looselyMatches ( prefix , var . getName ( ) ) ) { nameTypeMap . put ( var . getName ( ) , var . getOriginType ( ) != null ? var . getOriginType ( ) : var . getType ( ) ) ; } } scope = scope . getParent ( ) ; } return nameTypeMap ; } private VariableScope getVariableScope ( ASTNode astNode ) { if ( astNode instanceof BlockStatement ) { return ( ( BlockStatement ) astNode ) . getVariableScope ( ) ; } else if ( astNode instanceof ClassNode && ( ( ClassNode ) astNode ) . isScript ( ) ) { ClassNode clazz = ( ClassNode ) astNode ; MethodNode method = clazz . getMethod ( "<STR_LIT>" , new Parameter [ <NUM_LIT:0> ] ) ; if ( method != null && ( BlockStatement ) method . getCode ( ) instanceof BlockStatement ) { return ( ( BlockStatement ) method . getCode ( ) ) . getVariableScope ( ) ; } } return null ; } private List < ICompletionProposal > createProposals ( Map < String , ClassNode > nameTypes ) { List < ICompletionProposal > proposals = new ArrayList < ICompletionProposal > ( ) ; for ( Entry < String , ClassNode > nameType : nameTypes . entrySet ( ) ) { proposals . add ( createProposal ( nameType . getKey ( ) , nameType . getValue ( ) ) ) ; } return proposals ; } private ICompletionProposal createProposal ( String replaceName , ClassNode type ) { CompletionProposal proposal = CompletionProposal . create ( CompletionProposal . LOCAL_VARIABLE_REF , offset ) ; proposal . setCompletion ( replaceName . toCharArray ( ) ) ; proposal . setReplaceRange ( offset - replaceLength , getContext ( ) . completionEnd ) ; proposal . setSignature ( ProposalUtils . createTypeSignature ( type ) ) ; proposal . setRelevance ( Relevance . HIGH . getRelavance ( ) ) ; LazyJavaCompletionProposal completion = new LazyJavaCompletionProposal ( proposal , javaContext ) ; completion . setRelevance ( proposal . getRelevance ( ) ) ; return completion ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; public interface IProposalProvider { List < IGroovyProposal > getStatementAndExpressionProposals ( ContentAssistContext context , ClassNode completionType , boolean isStatic , Set < ClassNode > categories ) ; List < MethodNode > getNewMethodProposals ( ContentAssistContext context ) ; List < String > getNewFieldProposals ( ContentAssistContext context ) ; String NONSTATIC_FIELD = "<STR_LIT>" ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import org . codehaus . groovy . eclipse . codeassist . creators . CategoryProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . creators . FieldProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . creators . IProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . creators . MethodProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public abstract class AbstractGroovyCompletionProcessor implements IGroovyCompletionProcessor { private final ContentAssistContext context ; private final SearchableEnvironment nameEnvironment ; private final JavaContentAssistInvocationContext javaContext ; public AbstractGroovyCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { this . context = context ; this . nameEnvironment = nameEnvironment ; this . javaContext = javaContext ; } public SearchableEnvironment getNameEnvironment ( ) { return nameEnvironment ; } public ContentAssistContext getContext ( ) { return context ; } public JavaContentAssistInvocationContext getJavaContext ( ) { return javaContext ; } protected final GroovyCompletionProposal createProposal ( int kind , int completionOffset ) { GroovyCompletionProposal proposal = new GroovyCompletionProposal ( kind , completionOffset ) ; proposal . setNameLookup ( this . nameEnvironment . nameLookup ) ; return proposal ; } protected IProposalCreator [ ] getAllProposalCreators ( ) { return new IProposalCreator [ ] { new MethodProposalCreator ( ) , new FieldProposalCreator ( ) , new CategoryProposalCreator ( ) } ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . codehaus . groovy . ast . ModuleNode ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . dom . AST ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . ASTParser ; import org . eclipse . jdt . core . dom . CompilationUnit ; import org . eclipse . jdt . core . dom . rewrite . ImportRewrite ; import org . eclipse . jdt . ui . CodeStyleConfiguration ; public class GroovyImportRewriteFactory { private static final Pattern IMPORTS_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern PACKAGE_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern EOL_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private ImportRewrite rewrite ; private boolean cantCreateRewrite = false ; private GroovyCompilationUnit unit ; private ModuleNode module ; public GroovyImportRewriteFactory ( GroovyCompilationUnit unit , ModuleNode module ) { this . unit = unit ; this . module = module ; } public GroovyImportRewriteFactory ( GroovyCompilationUnit unit ) { this . unit = unit ; } public ImportRewrite getImportRewrite ( IProgressMonitor monitor ) { if ( module != null && ! module . encounteredUnrecoverableError ( ) ) { return null ; } if ( rewrite == null && ! cantCreateRewrite ) { CharArraySequence contents = new CharArraySequence ( unit . getContents ( ) ) ; CharArraySequence imports = findImportsRegion ( contents ) ; ASTParser parser = ASTParser . newParser ( AST . JLS3 ) ; parser . setSource ( unit . cloneCachingContents ( CharOperation . concat ( imports . chars ( ) , "<STR_LIT>" . toCharArray ( ) ) ) ) ; parser . setKind ( ASTParser . K_COMPILATION_UNIT ) ; ASTNode result = null ; try { result = parser . createAST ( monitor ) ; } catch ( IllegalStateException e ) { GroovyCore . logException ( "<STR_LIT>" + imports , e ) ; } if ( result instanceof CompilationUnit ) { rewrite = CodeStyleConfiguration . createImportRewrite ( ( CompilationUnit ) result , true ) ; } else { cantCreateRewrite = true ; } } return rewrite ; } public static CharArraySequence findImportsRegion ( String contents ) { return findImportsRegion ( new CharArraySequence ( contents ) ) ; } public static CharArraySequence findImportsRegion ( CharArraySequence contents ) { Matcher matcher = IMPORTS_PATTERN . matcher ( contents ) ; int importsEnd = <NUM_LIT:0> ; while ( matcher . find ( importsEnd ) ) { importsEnd = matcher . end ( ) ; } if ( importsEnd == <NUM_LIT:0> ) { matcher = PACKAGE_PATTERN . matcher ( contents ) ; if ( matcher . find ( ) ) { importsEnd = matcher . end ( ) ; } } if ( importsEnd > <NUM_LIT:0> ) { matcher = EOL_PATTERN . matcher ( contents ) ; if ( matcher . find ( importsEnd ) ) { importsEnd = matcher . end ( ) ; } } return contents . subSequence ( <NUM_LIT:0> , importsEnd ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . ArrayList ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import org . codehaus . groovy . ast . ASTNode ; import org . codehaus . groovy . ast . AnnotatedNode ; import org . codehaus . groovy . ast . ClassHelper ; import org . codehaus . groovy . ast . ClassNode ; import org . codehaus . groovy . ast . FieldNode ; import org . codehaus . groovy . ast . MethodNode ; import org . codehaus . groovy . ast . Variable ; import org . codehaus . groovy . ast . expr . ArgumentListExpression ; import org . codehaus . groovy . ast . expr . BinaryExpression ; import org . codehaus . groovy . ast . expr . ClassExpression ; import org . codehaus . groovy . ast . expr . Expression ; import org . codehaus . groovy . ast . expr . MethodCallExpression ; import org . codehaus . groovy . ast . expr . PropertyExpression ; import org . codehaus . groovy . ast . expr . StaticMethodCallExpression ; import org . codehaus . groovy . ast . expr . VariableExpression ; import org . codehaus . groovy . ast . stmt . Statement ; import org . codehaus . groovy . eclipse . codeassist . completions . GroovyExtendedCompletionContext ; import org . codehaus . groovy . eclipse . codeassist . creators . AbstractProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . creators . CategoryProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . creators . IProposalCreator ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistLocation ; import org . codehaus . groovy . eclipse . core . GroovyCore ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . CompletionContext ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . ISourceRange ; import org . eclipse . jdt . core . ISourceReference ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . groovy . core . util . ReflectionUtils ; import org . eclipse . jdt . groovy . search . ITypeRequestor ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorFactory ; import org . eclipse . jdt . groovy . search . TypeInferencingVisitorWithRequestor ; import org . eclipse . jdt . groovy . search . TypeLookupResult ; import org . eclipse . jdt . groovy . search . VariableScope ; import org . eclipse . jdt . groovy . search . VariableScope . VariableInfo ; import org . eclipse . jdt . internal . codeassist . InternalCompletionContext ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . internal . core . util . Util ; import org . eclipse . jdt . ui . text . java . IJavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class StatementAndExpressionCompletionProcessor extends AbstractGroovyCompletionProcessor { class ExpressionCompletionRequestor implements ITypeRequestor { boolean visitSuccessful = false ; boolean isStatic = false ; ClassNode resultingType ; ClassNode lhsType ; Set < ClassNode > categories ; VariableScope currentScope ; private Expression arrayAccessLHS ; private int derefCount = <NUM_LIT:0> ; public ExpressionCompletionRequestor ( ) { ASTNode maybeLHS = getContext ( ) . getPerceivedCompletionNode ( ) ; while ( maybeLHS != null ) { if ( maybeLHS instanceof BinaryExpression ) { maybeLHS = arrayAccessLHS = ( ( BinaryExpression ) maybeLHS ) . getLeftExpression ( ) ; derefCount ++ ; } else if ( maybeLHS instanceof PropertyExpression ) { arrayAccessLHS = ( ( PropertyExpression ) maybeLHS ) . getObjectExpression ( ) ; maybeLHS = ( ( PropertyExpression ) maybeLHS ) . getProperty ( ) ; } else if ( maybeLHS instanceof MethodCallExpression ) { arrayAccessLHS = ( ( MethodCallExpression ) maybeLHS ) . getObjectExpression ( ) ; maybeLHS = ( ( MethodCallExpression ) maybeLHS ) . getMethod ( ) ; } else { if ( maybeLHS instanceof Expression ) { arrayAccessLHS = ( Expression ) maybeLHS ; } maybeLHS = null ; } } } public VisitStatus acceptASTNode ( ASTNode node , TypeLookupResult result , IJavaElement enclosingElement ) { if ( ! interestingElement ( enclosingElement ) ) { return VisitStatus . CANCEL_MEMBER ; } if ( node instanceof ClassNode ) { ClassNode clazz = ( ClassNode ) node ; if ( clazz . redirect ( ) == clazz && clazz . isScript ( ) ) { return VisitStatus . CONTINUE ; } } else if ( node instanceof MethodNode ) { MethodNode run = ( MethodNode ) node ; if ( run . getName ( ) . equals ( "<STR_LIT>" ) && run . getDeclaringClass ( ) . isScript ( ) && ( run . getParameters ( ) == null || run . getParameters ( ) . length == <NUM_LIT:0> ) ) { return VisitStatus . CONTINUE ; } } boolean success = doTest ( node ) ; boolean derefList = false ; if ( ! success ) { derefList = success = doTestForAfterArrayAccess ( node ) ; } if ( success ) { maybeRememberLHSType ( result ) ; resultingType = findResultingType ( result , derefList ) ; categories = result . scope . getCategoryNames ( ) ; visitSuccessful = true ; isStatic = node instanceof StaticMethodCallExpression || ( node instanceof ClassExpression && resultingType != VariableScope . CLASS_CLASS_NODE ) ; currentScope = result . scope ; return VisitStatus . STOP_VISIT ; } return VisitStatus . CONTINUE ; } private ClassNode findResultingType ( TypeLookupResult result , boolean derefList ) { ClassNode candidate = getContext ( ) . location == ContentAssistLocation . METHOD_CONTEXT ? result . declaringType : result . type ; if ( derefList ) { for ( int i = <NUM_LIT:0> ; i < derefCount ; i ++ ) { boolean getAtFound = false ; List < MethodNode > getAts = candidate . getMethods ( "<STR_LIT>" ) ; for ( MethodNode getAt : getAts ) { if ( getAt . getParameters ( ) != null && getAt . getParameters ( ) . length == <NUM_LIT:1> ) { candidate = getAt . getReturnType ( ) ; getAtFound = true ; } } if ( ! getAtFound ) { if ( VariableScope . MAP_CLASS_NODE . equals ( candidate ) ) { candidate = candidate . getGenericsTypes ( ) [ <NUM_LIT:1> ] . getType ( ) ; } else { for ( int j = <NUM_LIT:0> ; j < derefCount ; j ++ ) { candidate = VariableScope . extractElementType ( candidate ) ; } } } } } boolean extractElementType = false ; ASTNode enclosing = result . scope . getEnclosingNode ( ) ; if ( enclosing instanceof MethodCallExpression ) { extractElementType = ( ( MethodCallExpression ) enclosing ) . isSpreadSafe ( ) ; } else if ( enclosing instanceof PropertyExpression ) { extractElementType = ( ( PropertyExpression ) enclosing ) . isSpreadSafe ( ) ; } if ( extractElementType ) { candidate = VariableScope . extractElementType ( candidate ) ; } if ( ClassHelper . isPrimitiveType ( candidate ) ) { candidate = ClassHelper . getWrapper ( candidate ) ; } return candidate ; } private boolean doTestForAfterArrayAccess ( ASTNode node ) { return node == arrayAccessLHS ; } private void maybeRememberLHSType ( TypeLookupResult result ) { if ( isAssignmentOfLhs ( result . getEnclosingAssignment ( ) ) ) { if ( lhsNode instanceof Variable ) { Variable variable = ( Variable ) lhsNode ; VariableInfo info = result . scope . lookupName ( variable . getName ( ) ) ; ClassNode maybeType ; if ( info != null ) { maybeType = info . type ; } else { maybeType = variable . getType ( ) ; } if ( maybeType != null && ! maybeType . equals ( VariableScope . OBJECT_CLASS_NODE ) ) { lhsType = ClassHelper . getUnwrapper ( maybeType ) ; } } } } private boolean isAssignmentOfLhs ( BinaryExpression node ) { if ( node != null && lhsNode != null ) { Expression expression = node . getLeftExpression ( ) ; return expression . getClass ( ) == lhsNode . getClass ( ) && expression . getStart ( ) == lhsNode . getStart ( ) && expression . getEnd ( ) == lhsNode . getEnd ( ) ; } return false ; } private boolean doTest ( ASTNode node ) { if ( node instanceof ArgumentListExpression ) { return false ; } else if ( node instanceof BinaryExpression ) { BinaryExpression bin = ( BinaryExpression ) node ; if ( bin . getLeftExpression ( ) == arrayAccessLHS ) { return false ; } } return isNotExpressionAndStatement ( completionNode , node ) && completionNode . getStart ( ) == node . getStart ( ) && completionNode . getEnd ( ) == node . getEnd ( ) ; } private boolean interestingElement ( IJavaElement enclosingElement ) { if ( enclosingElement . getElementName ( ) . equals ( "<STR_LIT>" ) ) { return true ; } if ( enclosingElement instanceof ISourceReference ) { try { ISourceRange range = ( ( ISourceReference ) enclosingElement ) . getSourceRange ( ) ; return range . getOffset ( ) <= completionNode . getStart ( ) && range . getOffset ( ) + range . getLength ( ) >= completionNode . getEnd ( ) ; } catch ( JavaModelException e ) { Util . log ( e ) ; } } return false ; } private boolean isNotExpressionAndStatement ( ASTNode thisNode , ASTNode otherNode ) { if ( thisNode instanceof Expression ) { return ! ( otherNode instanceof Statement ) ; } else if ( thisNode instanceof Statement ) { return ! ( otherNode instanceof Expression ) ; } else { return true ; } } public ClassNode getResultingType ( ) { return resultingType ; } public Set < ClassNode > getCategories ( ) { return categories ; } public boolean isVisitSuccessful ( ) { return visitSuccessful ; } } final ASTNode completionNode ; final Expression lhsNode ; public StatementAndExpressionCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; this . completionNode = context . getPerceivedCompletionNode ( ) ; this . lhsNode = context . lhsNode ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { TypeInferencingVisitorFactory factory = new TypeInferencingVisitorFactory ( ) ; ContentAssistContext context = getContext ( ) ; TypeInferencingVisitorWithRequestor visitor = factory . createVisitor ( context . unit ) ; ExpressionCompletionRequestor requestor = new ExpressionCompletionRequestor ( ) ; if ( completionNode != null ) { visitor . visitCompilationUnit ( requestor ) ; } ClassNode completionType ; boolean isStatic ; List < IGroovyProposal > groovyProposals = new LinkedList < IGroovyProposal > ( ) ; if ( requestor . isVisitSuccessful ( ) ) { isStatic = isStatic ( ) || requestor . isStatic ; IProposalCreator [ ] creators = getAllProposalCreators ( ) ; completionType = getCompletionType ( requestor ) ; proposalCreatorLoop ( context , requestor , completionType , isStatic , groovyProposals , creators , false ) ; if ( ContentAssistLocation . STATEMENT == context . location ) { ClassNode closureThis = requestor . currentScope . getThis ( ) ; if ( closureThis != null && ! closureThis . equals ( completionType ) ) { proposalCreatorLoop ( context , requestor , closureThis , isStatic , groovyProposals , creators , true ) ; } } } else { AnnotatedNode node = context . containingDeclaration ; ClassNode containingClass ; if ( node instanceof ClassNode ) { containingClass = ( ClassNode ) node ; } else if ( node instanceof MethodNode ) { containingClass = ( ( MethodNode ) node ) . getDeclaringClass ( ) ; } else { containingClass = null ; } if ( containingClass != null ) { groovyProposals . addAll ( new CategoryProposalCreator ( ) . findAllProposals ( containingClass , VariableScope . ALL_DEFAULT_CATEGORIES , context . getPerceivedCompletionExpression ( ) , false , ContentAssistLocation . STATEMENT == context . location ) ) ; } completionType = context . containingDeclaration instanceof ClassNode ? ( ClassNode ) context . containingDeclaration : context . unit . getModuleNode ( ) . getScriptClassDummy ( ) ; isStatic = false ; } try { context . currentScope = requestor . currentScope != null ? requestor . currentScope : createTopLevelScope ( completionType ) ; List < IProposalProvider > providers = ProposalProviderRegistry . getRegistry ( ) . getProvidersFor ( context . unit ) ; for ( IProposalProvider provider : providers ) { try { List < IGroovyProposal > otherProposals = provider . getStatementAndExpressionProposals ( context , completionType , isStatic , requestor . categories ) ; if ( otherProposals != null ) { groovyProposals . addAll ( otherProposals ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" + provider . getClass ( ) . getCanonicalName ( ) , e ) ; } } } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } fillInExtendedContext ( requestor ) ; try { List < IProposalFilter > filters = ProposalProviderRegistry . getRegistry ( ) . getFiltersFor ( context . unit ) ; for ( IProposalFilter filter : filters ) { try { List < IGroovyProposal > newProposals = filter . filterProposals ( groovyProposals , context , getJavaContext ( ) ) ; groovyProposals = newProposals == null ? groovyProposals : newProposals ; } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" + filter . getClass ( ) . getCanonicalName ( ) , e ) ; } } } catch ( CoreException e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } List < ICompletionProposal > javaProposals = new ArrayList < ICompletionProposal > ( groovyProposals . size ( ) ) ; JavaContentAssistInvocationContext javaContext = getJavaContext ( ) ; for ( IGroovyProposal groovyProposal : groovyProposals ) { try { IJavaCompletionProposal javaProposal = groovyProposal . createJavaProposal ( context , javaContext ) ; if ( javaProposal != null ) { javaProposals . add ( javaProposal ) ; } } catch ( Exception e ) { GroovyCore . logException ( "<STR_LIT>" , e ) ; } } return javaProposals ; } private void proposalCreatorLoop ( ContentAssistContext context , ExpressionCompletionRequestor requestor , ClassNode completionType , boolean isStatic , List < IGroovyProposal > groovyProposals , IProposalCreator [ ] creators , boolean isClosureThis ) { for ( IProposalCreator creator : creators ) { if ( isClosureThis && ! creator . redoForLoopClosure ( ) ) { continue ; } if ( creator instanceof AbstractProposalCreator ) { ( ( AbstractProposalCreator ) creator ) . setLhsType ( requestor . lhsType ) ; ( ( AbstractProposalCreator ) creator ) . setCurrentScope ( requestor . currentScope ) ; } groovyProposals . addAll ( creator . findAllProposals ( completionType , requestor . categories , context . getPerceivedCompletionExpression ( ) , isStatic , ContentAssistLocation . STATEMENT == context . location ) ) ; } } private void fillInExtendedContext ( ExpressionCompletionRequestor requestor ) { JavaContentAssistInvocationContext javaContext = getJavaContext ( ) ; CompletionContext coreContext = javaContext . getCoreContext ( ) ; if ( coreContext != null && ! coreContext . isExtended ( ) ) { ReflectionUtils . setPrivateField ( InternalCompletionContext . class , "<STR_LIT>" , coreContext , true ) ; ReflectionUtils . setPrivateField ( InternalCompletionContext . class , "<STR_LIT>" , coreContext , new GroovyExtendedCompletionContext ( getContext ( ) , requestor . currentScope ) ) ; } } protected VariableScope createTopLevelScope ( ClassNode completionType ) { VariableScope scope = new VariableScope ( null , completionType , false ) ; return scope ; } private ClassNode getCompletionType ( ExpressionCompletionRequestor requestor ) { if ( getContext ( ) . location == ContentAssistLocation . EXPRESSION ) { return requestor . resultingType ; } else if ( getContext ( ) . location == ContentAssistLocation . METHOD_CONTEXT ) { return completionNode instanceof VariableExpression ? requestor . currentScope . getDelegateOrThis ( ) : requestor . resultingType ; } else { ClassNode type = requestor . currentScope . getDelegateOrThis ( ) ; if ( type != null ) { return type ; } else { return requestor . resultingType ; } } } private boolean isStatic ( ) { if ( getContext ( ) . location == ContentAssistLocation . STATEMENT ) { AnnotatedNode annotated = getContext ( ) . containingDeclaration ; if ( annotated instanceof FieldNode ) { return ( ( FieldNode ) annotated ) . isStatic ( ) ; } else if ( annotated instanceof MethodNode ) { return ( ( MethodNode ) annotated ) . isStatic ( ) ; } } return false ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . codehaus . jdt . groovy . model . GroovyCompilationUnit ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IConfigurationElement ; import org . eclipse . core . runtime . IExtension ; import org . eclipse . core . runtime . IExtensionPoint ; import org . eclipse . core . runtime . Platform ; import org . eclipse . jdt . internal . core . util . Util ; public class ProposalProviderRegistry { private static final String APPLIES_TO = "<STR_LIT>" ; private static final String NATURE = "<STR_LIT>" ; private static final String PROVIDER = "<STR_LIT>" ; private static final String FILTER = "<STR_LIT>" ; private static final String PROPOSAL_PROVIDER_EXTENSION = "<STR_LIT>" ; private static final String PROPOSAL_FILTER_EXTENSION = "<STR_LIT>" ; private final static ProposalProviderRegistry DEFAULT = new ProposalProviderRegistry ( ) ; public static ProposalProviderRegistry getRegistry ( ) { return DEFAULT ; } private Map < String , List < IConfigurationElement > > natureLookupMap = new HashMap < String , List < IConfigurationElement > > ( ) ; private Map < String , List < IConfigurationElement > > filterLookupMap = new HashMap < String , List < IConfigurationElement > > ( ) ; List < IProposalProvider > getProvidersFor ( IProject project ) throws CoreException { String [ ] natures = project . getDescription ( ) . getNatureIds ( ) ; List < IProposalProvider > lookups = new ArrayList < IProposalProvider > ( ) ; for ( String nature : natures ) { List < IConfigurationElement > configs = natureLookupMap . get ( nature ) ; if ( configs != null ) { for ( IConfigurationElement config : configs ) { try { lookups . add ( ( IProposalProvider ) config . createExecutableExtension ( PROVIDER ) ) ; } catch ( CoreException e ) { Util . log ( e , "<STR_LIT>" + config . getAttribute ( PROVIDER ) ) ; } } } } return lookups ; } List < IProposalProvider > getProvidersFor ( GroovyCompilationUnit unit ) throws CoreException { return getProvidersFor ( unit . getResource ( ) . getProject ( ) ) ; } List < IProposalFilter > getFiltersFor ( IProject project ) throws CoreException { String [ ] natures = project . getDescription ( ) . getNatureIds ( ) ; List < IProposalFilter > filters = new ArrayList < IProposalFilter > ( ) ; for ( String nature : natures ) { List < IConfigurationElement > configs = filterLookupMap . get ( nature ) ; if ( configs != null ) { for ( IConfigurationElement config : configs ) { try { filters . add ( ( IProposalFilter ) config . createExecutableExtension ( FILTER ) ) ; } catch ( CoreException e ) { Util . log ( e , "<STR_LIT>" + config . getAttribute ( PROVIDER ) ) ; } } } } return filters ; } public List < IProposalFilter > getFiltersFor ( GroovyCompilationUnit unit ) throws CoreException { return getFiltersFor ( unit . getResource ( ) . getProject ( ) ) ; } private ProposalProviderRegistry ( ) { initialize ( ) ; } private void initialize ( ) { IExtensionPoint extPoint = Platform . getExtensionRegistry ( ) . getExtensionPoint ( PROPOSAL_PROVIDER_EXTENSION ) ; IExtension [ ] exts = extPoint . getExtensions ( ) ; for ( IExtension ext : exts ) { IConfigurationElement [ ] configs = ext . getConfigurationElements ( ) ; for ( IConfigurationElement config : configs ) { createLookup ( config ) ; } } extPoint = Platform . getExtensionRegistry ( ) . getExtensionPoint ( PROPOSAL_FILTER_EXTENSION ) ; exts = extPoint . getExtensions ( ) ; for ( IExtension ext : exts ) { IConfigurationElement [ ] configs = ext . getConfigurationElements ( ) ; for ( IConfigurationElement config : configs ) { createFilter ( config ) ; } } } private void createLookup ( IConfigurationElement config ) { try { if ( config . getName ( ) . equals ( PROVIDER ) ) { if ( config . getAttribute ( PROVIDER ) != null ) { IConfigurationElement [ ] appliesTos = config . getChildren ( APPLIES_TO ) ; for ( IConfigurationElement appliesTo : appliesTos ) { String nature = appliesTo . getAttribute ( NATURE ) ; List < IConfigurationElement > elts ; if ( natureLookupMap . containsKey ( nature ) ) { elts = natureLookupMap . get ( nature ) ; } else { elts = new ArrayList < IConfigurationElement > ( <NUM_LIT:3> ) ; natureLookupMap . put ( nature , elts ) ; } elts . add ( config ) ; } } else { Util . log ( new RuntimeException ( ) , "<STR_LIT>" ) ; } } } catch ( Exception e ) { Util . log ( e , "<STR_LIT>" ) ; } } private void createFilter ( IConfigurationElement config ) { try { if ( config . getName ( ) . equals ( FILTER ) ) { if ( config . getAttribute ( FILTER ) != null ) { IConfigurationElement [ ] appliesTos = config . getChildren ( APPLIES_TO ) ; for ( IConfigurationElement appliesTo : appliesTos ) { String nature = appliesTo . getAttribute ( NATURE ) ; List < IConfigurationElement > elts ; if ( filterLookupMap . containsKey ( nature ) ) { elts = filterLookupMap . get ( nature ) ; } else { elts = new ArrayList < IConfigurationElement > ( <NUM_LIT:3> ) ; filterLookupMap . put ( nature , elts ) ; } elts . add ( config ) ; } } else { Util . log ( new RuntimeException ( ) , "<STR_LIT>" ) ; } } } catch ( Exception e ) { Util . log ( e , "<STR_LIT>" ) ; } } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . proposals . AbstractGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . proposals . IGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; public interface IProposalFilter { public List < IGroovyProposal > filterProposals ( List < IGroovyProposal > proposals , ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) ; } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . Collections ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public class NewVariableCompletionProcessor extends AbstractGroovyCompletionProcessor { public NewVariableCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { return Collections . emptyList ( ) ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . createDisplayString ; import static org . codehaus . groovy . eclipse . codeassist . ProposalUtils . getImage ; import java . util . LinkedList ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . internal . codeassist . InternalCompletionProposal ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; import org . eclipse . jdt . internal . ui . text . java . JavaCompletionProposal ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . viewers . StyledString ; public class ModifiersCompletionProcessor extends AbstractGroovyCompletionProcessor { private static String [ ] keywords = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; public ModifiersCompletionProcessor ( ContentAssistContext context , JavaContentAssistInvocationContext javaContext , SearchableEnvironment nameEnvironment ) { super ( context , javaContext , nameEnvironment ) ; } public List < ICompletionProposal > generateProposals ( IProgressMonitor monitor ) { String completionExpression = getContext ( ) . completionExpression ; List < ICompletionProposal > proposals = new LinkedList < ICompletionProposal > ( ) ; for ( String keyword : keywords ) { if ( keyword . startsWith ( completionExpression ) ) { proposals . add ( createProposal ( keyword , getContext ( ) ) ) ; } } return proposals ; } private ICompletionProposal createProposal ( String keyword , ContentAssistContext context ) { InternalCompletionProposal proposal = createProposal ( CompletionProposal . KEYWORD , context . completionLocation ) ; proposal . setName ( keyword . toCharArray ( ) ) ; proposal . setCompletion ( keyword . toCharArray ( ) ) ; proposal . setReplaceRange ( context . completionLocation - context . completionExpression . length ( ) , context . completionEnd ) ; String completion = String . valueOf ( proposal . getCompletion ( ) ) ; int start = proposal . getReplaceStart ( ) ; int length = context . completionExpression . length ( ) ; StyledString label = createDisplayString ( proposal ) ; int relevance = Relevance . LOWEST . getRelevance ( <NUM_LIT:5> ) ; JavaCompletionProposal jcp = new JavaCompletionProposal ( completion , start , length , null , label , relevance ) ; jcp . setImage ( getImage ( proposal ) ) ; return jcp ; } } </s>
|
<s> package org . codehaus . groovy . eclipse . codeassist . processors ; import java . util . List ; import org . codehaus . groovy . eclipse . codeassist . proposals . AbstractGroovyProposal ; import org . codehaus . groovy . eclipse . codeassist . relevance . Relevance ; import org . codehaus . groovy . eclipse . codeassist . requestor . ContentAssistContext ; import org . eclipse . jdt . ui . text . java . JavaContentAssistInvocationContext ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; public interface IProposalFilterExtension extends IProposalFilter { public List < ICompletionProposal > filterExtendedProposals ( List < ICompletionProposal > proposals , ContentAssistContext context , JavaContentAssistInvocationContext javaContext ) ; } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.