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;
}
Aggregations