use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withClassInMainNamespace_returnsNull.
@Test
public void getCorrections_forIsClassPath_withClassInMainNamespace_returnsNull() {
List<IProblemLocation> locs = getProblems("package other; public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, new String[] { "Test" }, true, JDT_PROBLEM));
assertThat(proposalsFor(locs)).isNull();
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessor method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
Set<String> pkgs = new HashSet<>(locations.length * 2 + 1);
for (IProblemLocation location : locations) {
Name name;
switch(location.getProblemId()) {
case IProblem.IsClassPathCorrect:
name = getPackageFromIsClassPathCorrect(context, location);
break;
case IProblem.ImportNotFound:
name = getPackageFromImportNotFound(context, location);
break;
case IProblem.UndefinedType:
name = getPackageFromUndefinedType(context, location);
break;
default:
continue;
}
if (name == null) {
continue;
}
final String pkg = name.getFullyQualifiedName();
// Don't suggest adding a bundle to fix missing package in import if current Compilation Unit
// is already part of that package.
final PackageDeclaration ourPkg = context.getASTRoot().getPackage();
if (ourPkg != null && pkg.equals(ourPkg.getName().getFullyQualifiedName())) {
continue;
}
pkgs.add(pkg);
}
if (pkgs.isEmpty()) {
return null;
}
return getSuggestions(pkgs, context);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation 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.IProblemLocation in project flux by eclipse.
the class QuickFixProcessor method getCorrections.
/* (non-Javadoc)
* @see IAssistProcessor#getCorrections(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[])
*/
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (locations == null || locations.length == 0) {
return null;
}
HashSet<Integer> handledProblems = new HashSet<Integer>(locations.length);
ArrayList<ICommandAccess> resultingCollections = new ArrayList<ICommandAccess>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
Integer id = new Integer(curr.getProblemId());
if (handledProblems.add(id)) {
process(context, curr, resultingCollections);
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
Aggregations