1 11 package org.eclipse.jdt.internal.ui.text.javadoc; 12 13 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.IExtensionRegistry; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.Platform; 23 24 import org.eclipse.swt.graphics.Point; 25 26 27 import org.eclipse.jface.text.contentassist.IContextInformation; 28 29 import org.eclipse.jdt.core.ICompilationUnit; 30 31 import org.eclipse.jdt.ui.JavaUI; 32 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer; 33 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; 34 import org.eclipse.jdt.ui.text.java.IJavadocCompletionProcessor; 35 import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; 36 import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext; 37 38 import org.eclipse.jdt.internal.ui.JavaPlugin; 39 40 46 public class LegacyJavadocCompletionProposalComputer implements IJavaCompletionProposalComputer { 47 48 private static final String PROCESSOR_CONTRIBUTION_ID= "javadocCompletionProcessor"; 50 private IJavadocCompletionProcessor[] fSubProcessors; 51 52 private String fErrorMessage; 53 54 public LegacyJavadocCompletionProposalComputer() { 55 fSubProcessors= null; 56 } 57 58 59 private IJavadocCompletionProcessor[] getContributedProcessors() { 60 if (fSubProcessors == null) { 61 try { 62 IExtensionRegistry registry= Platform.getExtensionRegistry(); 63 IConfigurationElement[] elements= registry.getConfigurationElementsFor(JavaUI.ID_PLUGIN, PROCESSOR_CONTRIBUTION_ID); 64 IJavadocCompletionProcessor[] result= new IJavadocCompletionProcessor[elements.length]; 65 for (int i= 0; i < elements.length; i++) { 66 result[i]= (IJavadocCompletionProcessor) elements[i].createExecutableExtension("class"); } 68 fSubProcessors= result; 69 } catch (CoreException e) { 70 JavaPlugin.log(e); 71 fSubProcessors= new IJavadocCompletionProcessor[0]; 72 } 73 } 74 return fSubProcessors; 75 } 76 77 80 public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) { 81 if (context instanceof JavaContentAssistInvocationContext) { 82 JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context; 83 84 ICompilationUnit cu= javaContext.getCompilationUnit(); 85 int offset= javaContext.getInvocationOffset(); 86 87 ArrayList result= new ArrayList (); 88 89 IJavadocCompletionProcessor[] processors= getContributedProcessors(); 90 String error= null; 91 for (int i= 0; i < processors.length; i++) { 92 IJavadocCompletionProcessor curr= processors[i]; 93 IContextInformation[] contextInfos= curr.computeContextInformation(cu, offset); 94 if (contextInfos != null) { 95 for (int k= 0; k < contextInfos.length; k++) { 96 result.add(contextInfos[k]); 97 } 98 } else if (error == null) { 99 error= curr.getErrorMessage(); 100 } 101 } 102 fErrorMessage= error; 103 return result; 104 } 105 return Collections.EMPTY_LIST; 106 } 107 108 111 public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { 112 if (context instanceof JavadocContentAssistInvocationContext) { 113 JavadocContentAssistInvocationContext javaContext= (JavadocContentAssistInvocationContext) context; 114 115 ICompilationUnit cu= javaContext.getCompilationUnit(); 116 int offset= javaContext.getInvocationOffset(); 117 int length= javaContext.getSelectionLength(); 118 Point selection= javaContext.getViewer().getSelectedRange(); 119 if (selection.y > 0) { 120 offset= selection.x; 121 length= selection.y; 122 } 123 124 ArrayList result= new ArrayList (); 125 126 IJavadocCompletionProcessor[] processors= getContributedProcessors(); 127 for (int i= 0; i < processors.length; i++) { 128 IJavadocCompletionProcessor curr= processors[i]; 129 IJavaCompletionProposal[] proposals= curr.computeCompletionProposals(cu, offset, length, javaContext.getFlags()); 130 if (proposals != null) { 131 for (int k= 0; k < proposals.length; k++) { 132 result.add(proposals[k]); 133 } 134 } 135 } 136 return result; 137 } 138 return Collections.EMPTY_LIST; 139 } 140 141 142 145 public String getErrorMessage() { 146 return fErrorMessage; 147 } 148 149 150 153 public void sessionStarted() { 154 } 155 156 157 160 public void sessionEnded() { 161 fErrorMessage= null; 162 } 163 } 164 | Popular Tags |