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

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


        List result = new ArrayList();
        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 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.drools.spi.KnowledgeHelper drools;" );
                javaTextWithParams.append( "org.kie.runtime.rule.RuleContext kcontext;" );
            }
            if (useContext) {
                javaTextWithParams.append( "org.drools.spi.ProcessContext context;" );
                javaTextWithParams.append( "org.drools.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 );
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

    this.project = project;
  }
 
  public IContentProposal[] getProposals(String contents, int position) {
    try {
      CompletionProposalCollector collector = new CompletionProposalCollector(project);
      ICompilationUnit unit = FieldAssistUtils.getTemporaryCompilationUnit(project);
      contents = contents.substring(0, position);
      String source = "public class _xxx { public static void hoge(){ " + contents + "}}";
      FieldAssistUtils.setContentsToCU(unit, source);
      unit.codeComplete(source.length() - 2, 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

   */
  public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int position) {
    try {
      setErrorMessage(null);
      try {
        fCollector = new CompletionProposalCollector(fEditor.getJavaProject());
        fEditor.codeComplete(fCollector);
      } catch (JavaModelException x) {
        Shell shell= viewer.getTextWidget().getShell();
        ErrorDialog.openError(shell, SnippetMessages.getString("CompletionProcessor.errorTitle"), SnippetMessages.getString("CompletionProcessor.errorMessage"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$
        JDIDebugUIPlugin.log(x);
View Full Code Here

        List result = new ArrayList();
        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 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.drools.spi.KnowledgeHelper drools;" );
                javaTextWithParams.append( "org.drools.runtime.rule.RuleContext kcontext;" );
            }
            if (useContext) {
                javaTextWithParams.append( "org.drools.spi.ProcessContext context;" );
                javaTextWithParams.append( "org.drools.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 );
View Full Code Here

        if (unit == null)
            return new ICompletionProposal[0];
       
        ICompletionProposal[] results;

        CompletionProposalCollector collector;
        // BEGIN HACK
        if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES)) {
            collector= new WojExperimentalResultCollector(unit);
        } else {
            collector= new WojCompletionProposalCollector(unit);
        }
        // END HACK

        try {
            Point selection= viewer.getSelectedRange();
            if (selection.y > 0)
                collector.setReplacementLength(selection.y);
           
                unit.codeComplete(offset, collector);
        } catch (JavaModelException x) {
            Shell shell= viewer.getTextWidget().getShell();
            if (x.isDoesNotExist() && !unit.getJavaProject().isOnClasspath(unit))
                MessageDialog.openInformation(shell, WojJavaTextMessages.CompletionProcessor_error_notOnBuildPath_title, WojJavaTextMessages.CompletionProcessor_error_notOnBuildPath_message);
            else
                ErrorDialog.openError(shell, WojJavaTextMessages.CompletionProcessor_error_accessing_title, WojJavaTextMessages.CompletionProcessor_error_accessing_message, x.getStatus());
        }

        results= collector.getJavaCompletionProposals();
        int contextInformationOffset= guessContextInformationPosition(viewer, offset);
        if (contextInformationOffset != offset) {
            for (int i= 0; i < results.length; i++) {
                if (results[i] instanceof JavaMethodCompletionProposal) {
                    JavaMethodCompletionProposal jmcp= (JavaMethodCompletionProposal) results[i];
                    jmcp.setContextInformationPosition(contextInformationOffset);
                }
            }
        }
        fErrorMsg= collector.getErrorMessage();

        if (fTemplateEngine != null) {
            fTemplateEngine.reset();
            fTemplateEngine.complete(viewer, offset, unit);

            TemplateProposal[] templateResults= fTemplateEngine.getResults();

            // update relevance of template proposals that match with a keyword
            // give those templates slightly more relevance than the keyword to
            // sort them first
            IJavaCompletionProposal[] keyWordResults= collector.getKeywordCompletionProposals();
            for (int i= 0; i < keyWordResults.length; i++) {
                String keyword= keyWordResults[i].getDisplayString();
                for (int k= 0; k < templateResults.length; k++) {
                    TemplateProposal curr= templateResults[k];
                    if (curr.getTemplate().getName().startsWith(keyword)) {
View Full Code Here

   */
  private ICompletionProposal[] getImportValues(String lastWord, int offset){
    try {
      if(this.file != null){
        IJavaProject project = JavaCore.create(file.getProject());
        CompletionProposalCollector collector = new CompletionProposalCollector(project);
        ICompilationUnit unit = HTMLUtil.getTemporaryCompilationUnit(project);
        String matchString = lastWord.replaceFirst("^\"", "");
        int lastIndex = matchString.lastIndexOf(',');
        if(lastIndex >= 0){
          //offset = offset + lastIndex;
          matchString = matchString.substring(lastIndex + 1);
        }
        String value = "import " + matchString;
        System.out.println(value); // TODO Debug
        HTMLUtil.setContentsToCU(unit, value);
        unit.codeComplete(value.length(), collector, DefaultWorkingCopyOwner.PRIMARY);
        IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
        List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
        for(int i=0;i<proposals.length;i++){
          if(proposals[i] instanceof AbstractJavaCompletionProposal){
            AbstractJavaCompletionProposal proposal = (AbstractJavaCompletionProposal)proposals[i];
            proposal.setReplacementOffset(offset - matchString.trim().length());
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.