public void computeProposals(List<ICompletionProposal> proposals) throws UiBinderException { IEvaluationContext evalContext = createEvaluationContext(); try { // Get proposals for instance methods and static methods by treating the // Java type as an instance. // Since the type does not necessarily have to have a zero-arg // constructor, we use a local variable in the completion request below JavaElExpressionCompletionRequestor requestor = new JavaElExpressionCompletionRequestor( CompletionProposal.METHOD_REF); String snippet = javaType.getFullyQualifiedName('.') + " tmpVar; tmpVar." + getEnteredText(); evalContext.codeComplete(snippet, snippet.length(), requestor); proposals.addAll(requestor.getProposals()); } catch (JavaModelException e) { throw new UiBinderException(e); } }
public void computeProposals(List<ICompletionProposal> proposals) throws UiBinderException { try { IEvaluationContext evalContext = createEvaluationContext(); // for <ui:import field='____'> autocomplete if (packageName != null) { evalContext.setPackageName(packageName); } ProposalGeneratingCompletionRequestor requestor = new ProposalGeneratingCompletionRequestor( getReplaceOffset(), getReplaceLength(), allowedCompletionTypes, getJavaProject(), forceFullyQualifiedFieldNames); if (getEnteredText().trim().length() == 0) { completeCodeUsingAlphabet(evalContext, requestor); } else { evalContext.codeComplete(getEnteredText(), getEnteredText().length(), requestor); } proposals.addAll(requestor.getProposals()); } catch (JavaModelException e) { throw new UiBinderException(e); } }
private IJavaCompletionProposal[] computePackageAndTypeProposals(String js, int lineStartOffset, int cursorOffset) throws JavaModelException { Matcher matcher = PACKAGE_OR_TYPE_REF_START.matcher(js); if (!matcher.find()) { // Bail if we're not inside a JSNI Java package/type reference return null; } // Extract from the match the (maybe partial) package/type reference int refOffset = matcher.start(1) + lineStartOffset; int refLength = cursorOffset - refOffset; String partialRef = matcher.group(1); CompletionProposalCollector requestor = JsniCompletionProposalCollector.createPackageAndTypeProposalCollector( cu, refOffset, refLength); IEvaluationContext evalContext = createEvaluationContext(); evalContext.codeComplete(partialRef, partialRef.length(), requestor); return requestor.getJavaCompletionProposals(); }
public void computeProposals(List<ICompletionProposal> proposals) throws UiBinderException { if (!isWidgetAllowed()) { return; } IEvaluationContext evalContext = createEvaluationContext(); String packageName = null; String prefix = XmlUtilities.getPrefix(enteredText); if (prefix != null) { packageName = packageManager.getPackageName(prefix); if (packageName == null) { // The user has specified a namespace prefix but there is not a matching // package, so no widgets here return; } } ProposalGeneratingCompletionRequestor requestor = new WidgetCompletionRequestor( packageName); String unprefixedEnteredText = XmlUtilities.getUnprefixed(enteredText); try { if (unprefixedEnteredText.trim().length() > 0) { evalContext.codeComplete(enteredText, enteredText.length(), requestor); } else { // Offer all possible types available to the project as // completions. See // http://code.google.com/p/google-plugin-for-eclipse/issues/detail?id=11 CodeCompleteProposalComputer.completeCodeUsingAlphabet(evalContext, requestor); } proposals.addAll(requestor.getProposals()); } catch (JavaModelException e) { throw new UiBinderException(e); } }
public static void completeCodeUsingAlphabet(IEvaluationContext evalContext, ProposalGeneratingCompletionRequestor requestor) throws JavaModelException { for (char letter = 'a'; letter <= 'z'; letter++) { evalContext.codeComplete(String.valueOf(letter), 1, requestor); if (requestor.getProposals().size() > 0) { /* * Once we've hit a letter that returns at least one valid proposal, * bail out. */ return; } } }
private IEvaluationContext createEvaluationContext() throws JavaModelException { IJavaProject project = cu.getJavaProject(); IEvaluationContext evalContext = project.newEvaluationContext(); String pckgName = cu.getPackageDeclarations()[0].getElementName(); // Scope evaluation to the containing package evalContext.setPackageName(pckgName); return evalContext; }
@Override public IEvaluationContext newEvaluationContext() { throw new UnsupportedOperationException(); }
public IEvaluationContext createEvaluationContext() { return javaProject.newEvaluationContext(); }
@Override public IEvaluationContext createEvaluationContext() { IEvaluationContext evalContext = super.createEvaluationContext(); evalContext.setPackageName(javaType.getPackageFragment().getElementName()); return evalContext; }
/** * @see IJavaProject#newEvaluationContext() */ public IEvaluationContext newEvaluationContext() { EvaluationContext context = new EvaluationContext(); context.setLineSeparator(Util.getLineSeparator(null/*no existing source*/, this)); return new EvaluationContextWrapper(context, this); }
/** * Creates a new evaluation context. * @return a new evaluation context. */ IEvaluationContext newEvaluationContext();