Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Code for ui/org.eclipse.pde.ui.templates #1661

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.ui.templates/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.pde.ui.templates;singleton:=true
Bundle-Version: 3.9.0.qualifier
Bundle-Version: 3.9.100.qualifier
Bundle-Vendor: %bundleVendor
Bundle-RequiredExecutionEnvironment: JavaSE-21
Export-Package: org.eclipse.pde.internal.ui.templates;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
String[] candidates = getDirectoryCandidates();
for (String candidate : candidates) {
if (bundle.getEntry(candidate) != null) {
return new URL(getInstallURL(), candidate);

Check warning on line 60 in ui/org.eclipse.pde.ui.templates/src/org/eclipse/pde/internal/ui/templates/PDETemplateSection.java

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Deprecation

NORMAL: The constructor URL(URL, String) is deprecated since version 20
}
}
} catch (MalformedURLException e) { // do nothing
Expand All @@ -68,16 +68,21 @@
private String[] getDirectoryCandidates() {
double version = getTargetVersion();
ArrayList<String> result = new ArrayList<>();
if (version >= 3.5)
if (version >= 3.5) {
result.add("templates_3.5" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (version >= 3.4)
}
if (version >= 3.4) {
result.add("templates_3.4" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (version >= 3.3)
}
if (version >= 3.3) {
result.add("templates_3.3" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (version >= 3.2)
}
if (version >= 3.2) {
result.add("templates_3.2" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (version >= 3.1)
}
if (version >= 3.1) {
result.add("templates_3.1" + "/" + getSectionId() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return result.toArray(new String[result.size()]);
}

Expand All @@ -91,11 +96,13 @@
for (int i = 0; i < id.length(); i++) {
char ch = id.charAt(i);
if (buffer.length() == 0) {
if (Character.isJavaIdentifierStart(ch))
if (Character.isJavaIdentifierStart(ch)) {
buffer.append(Character.toLowerCase(ch));
}
} else {
if (Character.isJavaIdentifierPart(ch) || ch == '.')
if (Character.isJavaIdentifierPart(ch) || ch == '.') {
buffer.append(ch);
}
}
}
return buffer.toString().toLowerCase(Locale.ENGLISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,25 @@ public boolean performFinish(IProject project, IPluginModelBase model, IProgress
String runtimeVersion = null;

for (IPluginImport ii : pb.getImports()) {
if (ii.getId().equals(ORG_ECLIPSE_UI))
if (ii.getId().equals(ORG_ECLIPSE_UI)) {
ui = ii;
}
if (ii.getId().equals(ORG_ECLIPSE_CORE_RUNTIME)) {
// This plugin appears twice : with and without version (due to ancestor)
if (ii.getVersion() == null)
if (ii.getVersion() == null) {
runtime = ii;
else
} else {
runtimeVersion = ii.getVersion();
}
}

}

// Remove these two bad imports...
try {
if (ui != null)
if (ui != null) {
pb.remove(ui);
}
if (runtime != null) {
// Remove the org.eclipse.core.runtime without any version
pb.remove(runtime);
Expand Down Expand Up @@ -124,8 +127,9 @@ private void openEditorForApplicationModel(IProject project) throws PartInitExce
final FileEditorInput input = new FileEditorInput(file);
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
if (page != null)
if (page != null) {
page.openEditor(input, MODEL_EDITOR_ID);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ private void createProductExtension() throws CoreException {

extension.add(element);

if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
protected boolean isOkToCreateFolder(File sourceFolder) {
// We copy the files in 'org.eclipse.pde.ui.templates/templates_3.5/E4Application/*/handlers' or 'parts' if content required
String fname = sourceFolder.getName();
if (fname.endsWith("handlers") || fname.endsWith("parts")) //$NON-NLS-1$//$NON-NLS-2$
if (fname.endsWith("handlers") || fname.endsWith("parts")) { //$NON-NLS-1$//$NON-NLS-2$
return getBooleanOption(KEY_CREATE_SAMPLE_CONTENT);
}
return super.isOkToCreateFolder(sourceFolder);
}

Expand All @@ -162,8 +164,9 @@ protected boolean isOkToCreateFile(File sourceFile) {
// If file is the lifeCycleClassname (with a $ at the end) we keep it only if life cycle must be created.
String fname = sourceFile.getName();

if (fname.equals(TEMPLATE_LIFECYCLE_FILENAME))
if (fname.equals(TEMPLATE_LIFECYCLE_FILENAME)) {
return getBooleanOption(KEY_CREATE_LIFE_CYCLE);
}

// There are 2 application models :
// the bin/Application.e4xmi containing the empty model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ private void createE4ModelExtension() throws CoreException {

extension.add(element);

if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ private void createE4ModelExtension() throws CoreException {

extension.add(element);

if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ private void createE4ModelExtension() throws CoreException {

extension.add(element);

if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
viewElement.setAttribute("category", cid); //$NON-NLS-1$
viewElement.setAttribute("inject", "true"); //$NON-NLS-1$ //$NON-NLS-2$
extension.add(viewElement);
if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}

if (addToPerspective.isSelected()) {
IPluginExtension perspectiveExtension = createExtension("org.eclipse.ui.perspectiveExtensions", true); //$NON-NLS-1$
Expand All @@ -161,8 +162,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
perspectiveElement.add(view);

perspectiveExtension.add(perspectiveElement);
if (!perspectiveExtension.isInTheModel())
if (!perspectiveExtension.isInTheModel()) {
plugin.add(perspectiveExtension);
}
}
}

Expand All @@ -174,8 +176,9 @@ private void createCategory(IPluginExtension extension, String id) throws CoreEx
IPluginAttribute att = element.getAttribute("id"); //$NON-NLS-1$
if (att != null) {
String cid = att.getValue();
if (cid != null && cid.equals(id))
if (cid != null && cid.equals(id)) {
return;
}
}
}
}
Expand All @@ -194,24 +197,27 @@ public String[] getNewFiles() {
@Override
public IPluginReference[] getDependencies(String schemaVersion) {
ArrayList<PluginReference> result = new ArrayList<>();
if (schemaVersion != null)
if (schemaVersion != null) {
result.add(new PluginReference("org.eclipse.core.runtime")); //$NON-NLS-1$
}
result.add(new PluginReference("org.eclipse.ui")); //$NON-NLS-1$
return result.toArray(new IPluginReference[result.size()]);
}

@Override
protected String getFormattedPackageName(String id) {
String packageName = super.getFormattedPackageName(id);
if (packageName.length() != 0)
if (packageName.length() != 0) {
return packageName + ".views"; //$NON-NLS-1$
}
return "views"; //$NON-NLS-1$
}

@Override
public Object getValue(String name) {
if (name.equals("useEnablement")) //$NON-NLS-1$
if (name.equals("useEnablement")) { //$NON-NLS-1$
return Boolean.valueOf(getTargetVersion() >= 3.3);
}
return super.getValue(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
+ "." + getStringOption(KEY_BUILDER_CLASS_NAME)); //$NON-NLS-1$
builder.add(run);

if (!extension1.isInTheModel())
if (!extension1.isInTheModel()) {
plugin.add(extension1);
}

// Nature
IPluginExtension extension2 = createExtension("org.eclipse.core.resources.natures", true); //$NON-NLS-1$
Expand All @@ -165,8 +166,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
+ "." + getStringOption(KEY_BUILDER_ID)); //$NON-NLS-1$
extension2.add(builder2);

if (!extension2.isInTheModel())
if (!extension2.isInTheModel()) {
plugin.add(extension2);
}

// Popup Action
if (actionOption.isSelected()) {
Expand All @@ -190,8 +192,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
command.setAttribute("name", PDETemplateMessages.BuilderTemplate_commandName + getStringOption(KEY_NATURE_NAME)); //$NON-NLS-1$
extension3.add(command);

if (!extension3.isInTheModel())
if (!extension3.isInTheModel()) {
plugin.add(extension3);
}

IPluginExtension extension4 = createExtension("org.eclipse.ui.menus", true); //$NON-NLS-1$
IPluginElement menuContribution = factory.createElement(extension4);
Expand Down Expand Up @@ -282,8 +285,9 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
+ "." + getStringOption(KEY_NATURE_ID)); //$NON-NLS-1$
not.add(test2);

if (!extension4.isInTheModel())
if (!extension4.isInTheModel()) {
plugin.add(extension4);
}
}

// Marker
Expand All @@ -302,27 +306,31 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
persistent.setAttribute("value", "true"); //$NON-NLS-1$ //$NON-NLS-2$
extension8.add(persistent);

if (!extension8.isInTheModel())
if (!extension8.isInTheModel()) {
plugin.add(extension8);
}
}

@Override
public IPluginReference[] getDependencies(String schemaVersion) {
ArrayList<PluginReference> result = new ArrayList<>();
result.add(new PluginReference("org.eclipse.core.resources")); //$NON-NLS-1$
if (schemaVersion != null)
if (schemaVersion != null) {
result.add(new PluginReference("org.eclipse.core.runtime")); //$NON-NLS-1$
if (actionOption.isSelected())
}
if (actionOption.isSelected()) {
result.add(new PluginReference("org.eclipse.ui")); //$NON-NLS-1$
}

return result.toArray(new IPluginReference[result.size()]);
}

@Override
protected String getFormattedPackageName(String id) {
String packageName = super.getFormattedPackageName(id);
if (packageName.length() != 0)
if (packageName.length() != 0) {
return packageName + ".builder"; //$NON-NLS-1$
}
return "builder"; //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ private void createAddToPerspective() throws CoreException {
perspectiveElement.add(view);

perspectiveExtension.add(perspectiveElement);
if (!perspectiveExtension.isInTheModel())
if (!perspectiveExtension.isInTheModel()) {
plugin.add(perspectiveExtension);
}
}

private void createViewer() throws CoreException {
IPluginExtension viewerExtension = createExtension("org.eclipse.ui.navigator.viewer", true); //$NON-NLS-1$
if (!viewerExtension.isInTheModel())
if (!viewerExtension.isInTheModel()) {
plugin.add(viewerExtension);
}

createActionBinding(viewerExtension);
createContentBinding(viewerExtension);
Expand Down Expand Up @@ -151,8 +153,9 @@ private void createView() throws CoreException {

viewElement.setAttribute("class", "org.eclipse.ui.navigator.CommonNavigator"); //$NON-NLS-1$ //$NON-NLS-2$
viewExtension.add(viewElement);
if (!viewExtension.isInTheModel())
if (!viewExtension.isInTheModel()) {
plugin.add(viewExtension);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,21 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
projectObjectElement.setName("objectClass"); //$NON-NLS-1$
projectObjectElement.setAttribute("name", "org.eclipse.core.resources.IProject"); //$NON-NLS-1$ //$NON-NLS-2$

if (readOnlyOption.isSelected())
if (readOnlyOption.isSelected()) {
orElement.add(folderObjectElement);
else if (projectOption.isSelected())
} else if (projectOption.isSelected()) {
orElement.add(projectObjectElement);
}
orElement.add(fileObjectElement);
andElement.add(resourceObjectElement);
andElement.add(orElement);
enablementElement.add(andElement);
decoratorElement.add(enablementElement);

extension.add(decoratorElement);
if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
Expand All @@ -252,8 +254,9 @@ protected String getFormattedPackageName(String id) {
// Package name addition to create a location for containing
// any classes required by the decorator.
String packageName = super.getFormattedPackageName(id);
if (packageName.length() != 0)
if (packageName.length() != 0) {
return packageName + ".decorators"; //$NON-NLS-1$
}
return "decorators"; //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
editorElement.setAttribute("contributorClass", //$NON-NLS-1$
"org.eclipse.ui.texteditor.BasicTextEditorActionContributor"); //$NON-NLS-1$
extension.add(editorElement);
if (!extension.isInTheModel())
if (!extension.isInTheModel()) {
plugin.add(extension);
}
}

@Override
protected String getFormattedPackageName(String id) {
String packageName = super.getFormattedPackageName(id);
if (packageName.length() != 0)
if (packageName.length() != 0) {
return packageName + ".editors"; //$NON-NLS-1$
}
return "editors"; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ public String[] getNewFiles() {
@Override
protected String getFormattedPackageName(String id) {
String packageName = super.getFormattedPackageName(id);
if (packageName.length() != 0)
if (packageName.length() != 0) {
return packageName + ".handlers"; //$NON-NLS-1$
}
return "handlers"; //$NON-NLS-1$
}
}
Loading
Loading