-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5969 from pkriens/issue/5828-quick-fix-version
Issue/5828 quick fix version
- Loading branch information
Showing
47 changed files
with
6,857 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
bndtools.core.test/src/bndtools/core/test/editors/quickfix/BaseModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package bndtools.core.test.editors.quickfix; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class BaseModelTest extends AbstractBuildpathQuickFixProcessorTest { | ||
|
||
@BeforeAll | ||
static void beforeAll() throws Exception { | ||
clearBuildpath(); | ||
} | ||
|
||
@Test | ||
void test() throws JavaModelException { | ||
ICompilationUnit icu = pack.createCompilationUnit("Test.java", "package foo;\n", true, null); | ||
assertThat(icu).isNotNull(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
bndtools.core/src/bndtools/editor/exports/AddExportProposal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package bndtools.editor.exports; | ||
|
||
import org.eclipse.jdt.core.IAnnotation; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IPackageDeclaration; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.dom.AST; | ||
import org.eclipse.jdt.core.dom.ASTParser; | ||
import org.eclipse.jdt.core.dom.Annotation; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.PackageDeclaration; | ||
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; | ||
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.jface.text.contentassist.IContextInformation; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.text.edits.TextEdit; | ||
|
||
public class AddExportProposal implements IJavaCompletionProposal { | ||
private static final String ORG_OSGI_ANNOTATION_BUNDLE_EXPORT = "org.osgi.annotation.bundle.Export"; | ||
|
||
final ICompilationUnit unit; | ||
|
||
public AddExportProposal(ICompilationUnit unit) { | ||
this.unit = unit; | ||
} | ||
|
||
boolean isApplicable() { | ||
if (unit.getElementName() | ||
.equals("package-info.java")) { | ||
IPackageDeclaration pd = unit.getPackageDeclaration(null); | ||
IAnnotation annotation = pd.getAnnotation(ORG_OSGI_ANNOTATION_BUNDLE_EXPORT); | ||
return annotation == null; | ||
} else | ||
return false; | ||
} | ||
|
||
@Override | ||
public void apply(IDocument document) { | ||
try { | ||
ASTParser parser = ASTParser.newParser(AST.getJLSLatest()); | ||
parser.setSource(unit); | ||
parser.setResolveBindings(true); | ||
|
||
CompilationUnit astRoot = (CompilationUnit) parser.createAST(null); | ||
AST ast = astRoot.getAST(); | ||
|
||
ASTRewrite rewriter = ASTRewrite.create(ast); | ||
PackageDeclaration packageDeclaration = astRoot.getPackage(); | ||
|
||
if (packageDeclaration != null) { | ||
Annotation annotation = ast.newMarkerAnnotation(); | ||
annotation.setTypeName(ast.newSimpleName(ORG_OSGI_ANNOTATION_BUNDLE_EXPORT)); | ||
rewriter.getListRewrite(packageDeclaration, PackageDeclaration.ANNOTATIONS_PROPERTY) | ||
.insertFirst(annotation, null); | ||
|
||
TextEdit edits = rewriter.rewriteAST(); | ||
unit.applyTextEdit(edits, null); | ||
unit.getBuffer() | ||
.setContents(astRoot.toString()); | ||
} | ||
} catch (JavaModelException e) { | ||
e.printStackTrace(); | ||
// Handle exception | ||
} | ||
} | ||
|
||
@Override | ||
public Point getSelection(IDocument document) { | ||
return null; // Return the new selection after insertion, if applicable | ||
} | ||
|
||
@Override | ||
public String getAdditionalProposalInfo() { | ||
return "Add Export & Version annotation"; | ||
} | ||
|
||
@Override | ||
public String getDisplayString() { | ||
return "Add Export annotation"; | ||
} | ||
|
||
@Override | ||
public Image getImage() { | ||
return null; // You can return an image to be displayed with the | ||
// proposal | ||
} | ||
|
||
@Override | ||
public IContextInformation getContextInformation() { | ||
return null; // Context information related to this proposal, if | ||
// applicable | ||
} | ||
|
||
@Override | ||
public int getRelevance() { | ||
return 1000; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package bndtools.utils; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.jobs.Job; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
import aQute.bnd.exceptions.ConsumerWithException; | ||
import aQute.bnd.exceptions.FunctionWithException; | ||
import bndtools.Plugin; | ||
|
||
public class JobSupport { | ||
public static <T> void background(String message, FunctionWithException<IProgressMonitor, ? extends T> background, | ||
ConsumerWithException<? super T> onDisplayThread) { | ||
|
||
Job job = new Job(message) { | ||
@Override | ||
protected IStatus run(IProgressMonitor monitor) { | ||
try { | ||
T result = background.apply(monitor); | ||
if (monitor.isCanceled()) | ||
return Status.CANCEL_STATUS; | ||
|
||
Display.getDefault() | ||
.asyncExec(() -> { | ||
try { | ||
onDisplayThread.accept(result); | ||
} catch (Exception e) { | ||
} | ||
}); | ||
return Status.OK_STATUS; | ||
} catch (Exception e) { | ||
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, message, e); | ||
} | ||
} | ||
}; | ||
job.schedule(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.