use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project bndtools by bndtools.
the class ImportPackageQuickFixProcessor method getSuggestions.
IJavaCompletionProposal[] getSuggestions(Set<String> pkgs, IInvocationContext context) throws CoreException {
List<RepositoryPlugin> ps = listRepositories();
final BndBuildPathHandler handler = getBuildPathHandler(context);
MultiMap<String, String> bundles = new MultiMap<>();
String wsName = null;
boolean loggedWorkspaceError = false;
for (String pkg : pkgs) {
for (RepositoryPlugin p : ps) {
Collection<Capability> caps = null;
if (p instanceof Repository) {
caps = searchRepository((Repository) p, pkg);
} else if (p instanceof WorkspaceRepository) {
try {
caps = searchRepository(getWorkspaceRepo(), pkg);
wsName = p.getName();
} catch (Exception e) {
if (!loggedWorkspaceError) {
logger.logError("Error trying to fetch the repository for the current workspace", e);
loggedWorkspaceError = true;
}
}
}
if (caps == null) {
continue;
}
for (Capability cap : caps) {
final String bsn = capabilityToBSN(cap);
if (bsn != null && !handler.containsBundle(bsn)) {
bundles.add(bsn, p.getName());
}
}
}
}
if (bundles.isEmpty()) {
return null;
}
IJavaCompletionProposal[] retval = new IJavaCompletionProposal[bundles.size()];
int i = 0;
for (Map.Entry<String, List<String>> bundle : bundles.entrySet()) {
// NOTE: The call to contains() here, based on the current MultiMap implementation, will
// do a linear search. Because a single bundle is unlikely to be found in more than a few
// repos in any given workspace this probably won't make a difference, but if any performance issues show up
// in the future this would be a place to look.
final int relevance = bundle.getValue().contains(wsName) ? ADD_BUNDLE_WORKSPACE : ADD_BUNDLE;
retval[i++] = new AddBundleCompletionProposal(bundle.getKey(), bundle.getValue(), relevance, context);
}
return retval;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project bndtools by bndtools.
the class PackageInfoBaselineQuickFixProcessor method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
ICompilationUnit compUnit = context.getCompilationUnit();
IResource resource = compUnit.getResource();
IMarker[] markers = resource.findMarkers(BndtoolsConstants.MARKER_JAVA_BASELINE, false, 1);
for (IProblemLocation location : locations) {
for (IMarker marker : markers) {
int markerStart = marker.getAttribute(IMarker.CHAR_START, -1);
int markerEnd = marker.getAttribute(IMarker.CHAR_END, -1);
int markerLength = markerEnd - markerStart;
if (location.getOffset() <= markerStart && markerStart < location.getOffset() + location.getLength()) {
String newVersion = marker.getAttribute("suggestedVersion", null);
if (newVersion != null) {
StringBuilder quotedVersion = new StringBuilder(newVersion.trim());
if (quotedVersion.charAt(0) != '"')
quotedVersion.insert(0, '"');
if (quotedVersion.charAt(quotedVersion.length() - 1) != '"')
quotedVersion.append('"');
CompilationUnitChange change = new CompilationUnitChange("Change package-info.java", compUnit);
change.setEdit(new ReplaceEdit(markerStart, markerLength, quotedVersion.toString()));
return new IJavaCompletionProposal[] { new ChangeCorrectionProposal("Change package version to " + newVersion, change, 1000) };
}
}
}
}
return null;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPProposalCollector method getJSPCompletionProposals.
/**
* Ensures that we only return JSPCompletionProposals.
* @return an array of JSPCompletionProposals
*/
public JSPCompletionProposal[] getJSPCompletionProposals() {
List results = new ArrayList();
IJavaCompletionProposal[] javaProposals = getJavaCompletionProposals();
// because their offsets haven't been translated
for (int i = 0; i < javaProposals.length; i++) {
if (javaProposals[i] instanceof JSPCompletionProposal)
results.add(javaProposals[i]);
}
Collections.sort(results, getComparator());
return (JSPCompletionProposal[]) results.toArray(new JSPCompletionProposal[results.size()]);
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPProposalCollector method createAutoImportProposal.
private JSPCompletionProposal createAutoImportProposal(CompletionProposal proposal) {
JSPCompletionProposal jspProposal = null;
String completion = new String(proposal.getCompletion());
// it's fully qualified so we should
// add an import statement
// create an autoimport proposal
String newCompletion = getTypeName(completion);
// java offset
int offset = proposal.getReplaceStart();
// replacement length
int length = proposal.getReplaceEnd() - offset;
// translate offset from Java > JSP
offset = fTranslation.getJspOffset(offset);
// cursor position after must be calculated
int positionAfter = calculatePositionAfter(proposal, newCompletion, offset);
// from java proposal
IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
proposal.getDeclarationSignature();
Image image = javaProposal.getImage();
String displayString = javaProposal.getDisplayString();
displayString = getTranslation().fixupMangledName(displayString);
IContextInformation contextInformation = javaProposal.getContextInformation();
// don't do this, it's slow
// String additionalInfo = javaProposal.getAdditionalProposalInfo();
int relevance = javaProposal.getRelevance();
boolean updateLengthOnValidate = true;
jspProposal = new AutoImportProposal(completion, fImportContainer, newCompletion, offset, length, positionAfter, image, displayString, contextInformation, null, relevance, updateLengthOnValidate);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
// set wrapped java proposal so additional info can be calculated on demand
jspProposal.setJavaCompletionProposal(javaProposal);
return jspProposal;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPELProposalCollector method createJavaCompletionProposal.
protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) {
JSPCompletionProposal jspProposal = null;
if (null == proposal || null == proposal.getName())
return (null);
String rawName = new String(proposal.getName());
String completion = null;
if (proposal.getKind() == CompletionProposal.METHOD_REF && proposal.findParameterNames(null).length == 0) {
if (rawName.length() > 3 && rawName.startsWith("get")) {
// $NON-NLS-1$
completion = rawName.substring(3, 4).toLowerCase() + rawName.substring(4, rawName.length());
} else {
return null;
}
// java offset
int offset = proposal.getReplaceStart();
// replacement length
// -3 for "get" pre text on the java proposal
int length = proposal.getReplaceEnd() - offset - 3;
// translate offset from Java > JSP
offset = getTranslation().getJspOffset(offset);
// cursor position after must be calculated
int positionAfter = offset + completion.length();
// from java proposal
IJavaCompletionProposal javaProposal = super.createJavaCompletionProposal(proposal);
Image image = null;
String longDisplayString = javaProposal.getDisplayString();
int fistSpaceIndex = longDisplayString.indexOf(' ');
String shortDisplayString = longDisplayString;
if (fistSpaceIndex != -1) {
shortDisplayString = longDisplayString.substring(fistSpaceIndex);
}
// $NON-NLS-1$
String displayString = completion + " " + shortDisplayString;
IContextInformation contextInformation = javaProposal.getContextInformation();
String additionalInfo = javaProposal.getAdditionalProposalInfo();
int relevance = javaProposal.getRelevance();
boolean updateLengthOnValidate = true;
jspProposal = new JSPCompletionProposal(completion, offset, length, positionAfter, image, displayString, contextInformation, additionalInfo, relevance, updateLengthOnValidate);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124483
// set wrapped java proposal so additional info can be calculated on demand
jspProposal.setJavaCompletionProposal(javaProposal);
return jspProposal;
} else {
return null;
}
}
Aggregations