IJavaProject javaProject = getCurrentJavaProject();
if ( javaProject == null ) {
return;
}
CompletionProposalCollector collector = new CompletionProposalCollector( javaProject );
collector.acceptContext( new CompletionContext() );
try {
IEvaluationContext evalContext = javaProject.newEvaluationContext();
List imports = getImports();
if ( imports != null && imports.size() > 0 ) {
evalContext.setImports( (String[]) imports.toArray( new String[imports.size()] ) );
}
StringBuffer javaTextWithParams = new StringBuffer();
Iterator iterator = params.entrySet().iterator();
while ( iterator.hasNext() ) {
Map.Entry entry = (Map.Entry) iterator.next();
// this does not seem to work, so adding variables manually
// evalContext.newVariable((String) entry.getValue(), (String) entry.getKey(), null);
javaTextWithParams.append( entry.getValue() + " " + entry.getKey() + ";\n" );
}
if (useDrools) {
javaTextWithParams.append( "org.kie.api.runtime.rule.RuleContext kcontext;" );
}
if (useContext) {
javaTextWithParams.append( "org.kie.api.runtime.process.ProcessContext kcontext;" );
}
javaTextWithParams.append( javaText );
String jtext = javaTextWithParams.toString();
String fixedText = new KnowledgeHelperFixer().fix( jtext );
evalContext.codeComplete( fixedText,
fixedText.length(),
collector );
IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
for ( int i = 0; i < proposals.length; i++ ) {
if ( proposals[i] instanceof AbstractJavaCompletionProposal ) {
AbstractJavaCompletionProposal javaProposal = (AbstractJavaCompletionProposal) proposals[i];
int replacementOffset = documentOffset - (fixedText.length() - javaProposal.getReplacementOffset());
javaProposal.setReplacementOffset( replacementOffset );