private String[] guessParameters(char[][] parameterNames, CompletionProposal proposal) throws JavaModelException { int count = parameterNames.length; String[] result = new String[count]; String[] parameterTypes = getParameterTypes(proposal); IJavaElement[][] assignableElements = getAssignableElements(proposal); ParameterGuesser guesser = new ParameterGuesser(compilationUnit); for (int i = count - 1; i >= 0; i--) { String paramName = new String(parameterNames[i]); String argumentProposal = guesser.parameterProposals(parameterTypes[i], paramName, assignableElements[i]); if (argumentProposal != null) { result[i] = argumentProposal; } else { result[i] = paramName; } } return result; }
/** * match the given <code>text</code> with the pattern * @return true if matched eitherwise false * @param text a String object */ public boolean match(String text) { return match(text, 0, text.length()); } /**
static int mapTypeParameterIndex(IType[] path, int pathIndex, int paramIndex) throws JavaModelException, ArrayIndexOutOfBoundsException { if (pathIndex == 0) { // break condition: we've reached the top of the hierarchy return paramIndex; } IType subType= path[pathIndex]; IType superType= path[pathIndex - 1]; String superSignature= findMatchingSuperTypeSignature(subType, superType); ITypeParameter param= subType.getTypeParameters()[paramIndex]; int index= findMatchingTypeArgumentIndex(superSignature, param.getElementName()); if (index == -1) { // not mapped through return -1; } return mapTypeParameterIndex(path, pathIndex - 1, index); }
public CompletionItem toCompletionItem(CompletionProposal proposal, int index) { final CompletionItem $ = new CompletionItem(); $.setKind(mapKind(proposal.getKind())); Map<String, String> data = new HashMap<>(); // append data field so that resolve request can use it. data.put(CompletionResolveHandler.DATA_FIELD_URI, JDTUtils.toURI(unit)); data.put(CompletionResolveHandler.DATA_FIELD_REQUEST_ID,String.valueOf(response.getId())); data.put(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID,String.valueOf(index)); $.setData(data); this.descriptionProvider.updateDescription(proposal, $); $.setSortText(SortTextHelper.computeSortText(proposal)); return $; }
private String createJavaDocTags(IDocument document, int offset, String indentation, String lineDelimiter, ICompilationUnit unit) throws CoreException, BadLocationException { IJavaElement element = unit.getElementAt(offset); if (element == null) { return null; } switch (element.getElementType()) { case IJavaElement.TYPE: return createTypeTags(document, offset, indentation, lineDelimiter, (IType) element); case IJavaElement.METHOD: return createMethodTags(document, offset, indentation, lineDelimiter, (IMethod) element); default: return null; } }
public CompletionProposalRequestor(ICompilationUnit aUnit, int offset) { this.unit = aUnit; response = new CompletionResponse(); response.setOffset(offset); fIsTestCodeExcluded = !isTestSource(unit.getJavaProject(), unit); setRequireExtendedContext(true); }
private String computeTypeProposal(ITypeBinding binding, ITypeParameter parameter) throws JavaModelException { final String name = TypeProposalUtils.getTypeQualifiedName(binding); if (binding.isWildcardType()) { if (binding.isUpperbound()) { // replace the wildcard ? with the type parameter name to get "E extends Bound" instead of "? extends Bound" // String contextName= name.replaceFirst("\\?", parameter.getElementName()); //$NON-NLS-1$ // upper bound - the upper bound is the bound itself return binding.getBound().getName(); } // no or upper bound - use the type parameter of the inserted type, as it may be more // restrictive (eg. List<?> list= new SerializableList<Serializable>()) return computeTypeProposal(parameter); } // not a wildcard but a type or type variable - this is unambigously the right thing to insert return name; }
@Override public void acceptContext(CompletionContext context) { super.acceptContext(context); response.setContext(context); this.descriptionProvider = new CompletionProposalDescriptionProvider(context); }
/** * @param text a simple regular expression that may only contain '?'(s) * @param start the starting index in the text for search, inclusive * @param end the stopping point of search, exclusive * @param p a simple regular expression that may contains '?' * @return the starting index in the text of the pattern , or -1 if not found */ protected int regExpPosIn(String text, int start, int end, String p) { int plen= p.length(); int max= end - plen; for (int i= start; i <= max; ++i) { if (regExpRegionMatches(text, i, p, 0, plen)) { return i; } } return -1; }
static String getTypeQualifiedName(ITypeBinding type) { List<String> result= new ArrayList<>(5); createName(type, false, result); return String.join(".",result); }
@Override public void setIgnored(int completionProposalKind, boolean ignore) { super.setIgnored(completionProposalKind, ignore); if (completionProposalKind == CompletionProposal.METHOD_DECLARATION && !ignore) { setRequireExtendedContext(true); } }
private void createJavadocSimpleProposalLabel(CompletionProposal proposal, CompletionItem item) { item.setLabel(createSimpleLabel(proposal).toString()); }
public SignatureHelpRequestor(ICompilationUnit aUnit, int offset) { this.unit = aUnit; response = new CompletionResponse(); response.setOffset(offset); setRequireExtendedContext(true); }
protected boolean hasArgumentList(CompletionProposal proposal) { if (CompletionProposal.METHOD_NAME_REFERENCE == proposal.getKind()) { return false; } char[] completion= proposal.getCompletion(); return !isInJavadoc() && completion.length > 0 && completion[completion.length - 1] == RPAREN; }
private final boolean shouldProposeGenerics(IJavaProject project) { String sourceVersion; if (project != null) { sourceVersion= project.getOption(JavaCore.COMPILER_SOURCE, true); } else { sourceVersion= JavaCore.getOption(JavaCore.COMPILER_SOURCE); } return !isVersionLessThan(sourceVersion, JavaCore.VERSION_1_5); }
private void createJavadocTypeProposalLabel(CompletionProposal typeProposal, CompletionItem item) { char[] fullName= Signature.toCharArray(typeProposal.getSignature()); createJavadocTypeProposalLabel(fullName, item); }
private boolean hasParameters(CompletionProposal proposal) throws IllegalArgumentException { return hasArgumentList(proposal) && Signature.getParameterCount(proposal.getSignature()) > 0; }
private IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException { int lineOffset = line.getOffset(); int lineEnd = lineOffset + line.getLength(); int indentEnd = findEndOfWhiteSpace(document, lineOffset, lineEnd); if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { indentEnd++; while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') { indentEnd++; } } return new Region(lineOffset, indentEnd - lineOffset); }
@Override public void acceptContext(CompletionContext context) { super.acceptContext(context); this.context = context; response.setContext(context); this.descriptionProvider = new CompletionProposalDescriptionProvider(context); }