Java源码示例:org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal

示例1
@Override
public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations)
		throws CoreException {
	return new IJavaCompletionProposal[] { new AbstractJavaCompletionProposal() {
		public org.eclipse.jface.viewers.StyledString getStyledDisplayString() {
			ICompilationUnit compilationUnit = context.getCompilationUnit();
			return new StyledString(
					"Generate Getter and setter for " + compilationUnit.findPrimaryType().getElementName());
		}
		
		protected int getPatternMatchRule(String pattern, String string) {
			// override the match rule since we do not work with a pattern, but just want to open the "Generate Getters and Setters..." dialog
			return -1;
		};
		
		public void apply(org.eclipse.jface.text.ITextViewer viewer, char trigger, int stateMask, int offset) {
			
			if(context instanceof AssistContext) {
				AssistContext assistContext = (AssistContext) context;
				AddGetterSetterAction addGetterSetterAction = new AddGetterSetterAction((CompilationUnitEditor)assistContext.getEditor());
				
				addGetterSetterAction.run();
			}
			
		}
	} };
}
 
示例2
/**
 * Create a proposal collector that's able to gather the passed completions/related java elements and adds
 * them to the passed 'ret' parameter
 *
 * @param filterCompletionName may be null or a name to which we want to match the java element name (so, only
 * a java element with an exact match of its name to filterCompletionName is added).
 *
 * @param ret the placeholder for the found java elements and completion proposals
 * @param unit the ICompilationUnit that's used (must be passed in the CompletionProposalCollector constructor).
 * @return the collector that will gather the completions (note that it'll keep the 'ret' placeholder alive unti it's
 * garbage-collected.
 */
protected CompletionProposalCollector createCollector(final String filterCompletionName,
        final List<Tuple<IJavaElement, CompletionProposal>> ret, ICompilationUnit unit) {
    CompletionProposalCollector collector = new CompletionProposalCollector(unit) {

        /**
         * Override the java proposal creation to always return null, as we'll keep just what we actually need.
         */
        @SuppressWarnings("restriction")
        @Override
        public IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) {
            IJavaCompletionProposal javaCompletionProposal = super.createJavaCompletionProposal(proposal);
            if (javaCompletionProposal instanceof AbstractJavaCompletionProposal) {
                AbstractJavaCompletionProposal prop = (AbstractJavaCompletionProposal) javaCompletionProposal;
                IJavaElement javaElement = prop.getJavaElement();
                if (javaElement != null) {

                    if (filterCompletionName == null) {
                        ret.add(new Tuple<IJavaElement, CompletionProposal>(javaElement, proposal));
                        return null;
                    }

                    if (javaElement.getElementName().equals(filterCompletionName)) {
                        ret.add(new Tuple<IJavaElement, CompletionProposal>(javaElement, proposal));
                        return null;
                    }

                }
            }
            return null;
        }
    };
    return collector;
}
 
示例3
private String getSortKey(ICompletionProposal p) {
	if (p instanceof AbstractJavaCompletionProposal)
		return ((AbstractJavaCompletionProposal) p).getSortString();
	return p.getDisplayString();
}