IJavaProject javaProject = getCurrentJavaProject();
if ( javaProject == null ) {
return;
}
CompletionProposalCollector collector = new CompletionProposalCollector( javaProject );
collector.acceptContext( new CompletionContext() );
try {
IEvaluationContext evalContext = javaProject.newEvaluationContext();
List<String> imports = getImports();
if ( imports != null && imports.size() > 0 ) {
evalContext.setImports(imports.toArray(new String[imports.size()]));
}
StringBuffer javaTextWithParams = new StringBuffer();
for (Entry<String, String> entry : params.entrySet()) {
// 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 = 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 );