private DartElement getEnclosingMethod(CompilationUnit input, ITextSelection selection) { try { DartElement enclosingElement = input.getElementAt(selection.getOffset()); if (enclosingElement instanceof Method || enclosingElement instanceof Field) { // opening on the enclosing type would be too confusing (since the type resolves to the // constructors) return enclosingElement; } } catch (DartModelException e) { DartToolsPlugin.log(e); } return null; }
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) { try { DartElement enclosingElement = null; if (getContext().isExtended()) { enclosingElement = getContext().getEnclosingElement(); } else if (fCompilationUnit != null) { enclosingElement = fCompilationUnit.getElementAt(proposal.getCompletionLocation() + 1); } if (enclosingElement == null) { return; } Type type = enclosingElement.getAncestor(Type.class); if (type != null) { String prefix = String.valueOf(proposal.getName()); int completionStart = proposal.getReplaceStart(); int completionEnd = proposal.getReplaceEnd(); int relevance = computeRelevance(proposal); GetterSetterCompletionProposal.evaluateProposals( type, prefix, completionStart, completionEnd - completionStart, proposal.getReplaceEndIdentifier() - completionStart, relevance + 2, fSuggestedMethodNames, fDartProposals); MethodDeclarationCompletionProposal.evaluateProposals( type, prefix, completionStart, completionEnd - completionStart, proposal.getReplaceEndIdentifier() - completionStart, relevance, fSuggestedMethodNames, fDartProposals); } } catch (CoreException e) { DartToolsPlugin.log(e); } }