Package org.eclipse.jdt.ui.text.java

Examples of org.eclipse.jdt.ui.text.java.CompletionProposalCollector


  public IContentProposal[] getProposals(String contents, int position) {
    if(this.project==null){
      return null;
    }
    try {
      CompletionProposalCollector collector = new CompletionProposalCollector(project);
      ICompilationUnit unit = FieldAssistUtils.getTemporaryCompilationUnit(project);
      contents = contents.substring(0, position);
      String source = "package " + contents;
      FieldAssistUtils.setContentsToCU(unit, source);
      unit.codeComplete(source.length(), collector, DefaultWorkingCopyOwner.PRIMARY);
      IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
      List<IContentProposal> result = new ArrayList<IContentProposal>();
     
      for(int j=0;j<proposals.length;j++){
        if(proposals[j].getImage()!=null){
          String replaceString = null;
View Full Code Here


        List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
        IJavaProject javaProject = getCurrentJavaProject();
        if ( javaProject == null ) {
            return result;
        }
        CompletionProposalCollector collector = new CompletionProposalCollector( javaProject ) {
            public void accept(CompletionProposal proposal) {
                if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF || proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF ) {
                    super.accept( proposal );
                }
            }
        };
        collector.acceptContext( new CompletionContext() );
        try {
            IEvaluationContext evalContext = javaProject.newEvaluationContext();
            evalContext.codeComplete( classNameStart,
                                      classNameStart.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 - (classNameStart.length() - javaProposal.getReplacementOffset());
                    javaProposal.setReplacementOffset( replacementOffset );
View Full Code Here

        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 );
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.ui.text.java.CompletionProposalCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.