Skip to content

Commit

Permalink
improvments based on Sonar report
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolayek committed Sep 3, 2020
1 parent 0fe1b25 commit 25f4d78
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
* The activator class controls the plug-in life cycle. Generated class allowing
* the UI contributions
*/
public class Activator extends AbstractUIPlugin {

// The plug-in ID
Expand All @@ -30,25 +26,13 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package com.hybris.hyeclipse.commons.utils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -54,7 +56,7 @@ public static IWorkbenchWindow getActiveWorkbenchWindow() {
* @return active editor file
*/
public static IFile getActiveEditorFile() {
return (IFile) getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
return getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
}

/**
Expand All @@ -70,7 +72,7 @@ public static IFile getSelectedFile(final ISelection selection) {
if (selection instanceof IStructuredSelection) {
final IStructuredSelection ssel = (IStructuredSelection) selection;
final Object obj = ssel.getFirstElement();
file = (IFile) Platform.getAdapterManager().getAdapter(obj, IFile.class);
file = Platform.getAdapterManager().getAdapter(obj, IFile.class);
} else if (selection instanceof TextSelection) {
file = getActiveEditorFile();
}
Expand Down Expand Up @@ -112,7 +114,7 @@ public static Optional<TextSelection> getCurrentTextSelection() {
final IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();

if ( editorPart != null && editorPart instanceof ITextEditor) {
if (editorPart instanceof ITextEditor) {
final ITextEditor editor = (ITextEditor) editorPart;
final ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
Expand All @@ -129,7 +131,7 @@ public static Optional<TextSelection> getCurrentTextSelection() {
* @return selected text in file, if none is selected empty string will be returned
*/
public static String getCurrentSelectedText() {
return getCurrentTextSelection().map(TextSelection::getText).orElse(CharactersConstants.EMPTY_STRING);
return getCurrentTextSelection().map(TextSelection::getText).orElse(StringUtils.EMPTY);
}

/**
Expand All @@ -142,7 +144,7 @@ public static String getCurrentSelectedText() {
public static String getContentOfFiles(final Set<IFile> files) {
final StringBuilder filesContent = new StringBuilder();

files.forEach(file -> filesContent.append(getContentOfFile(file)).append(CharactersConstants.NEW_LINE));
files.forEach(file -> filesContent.append(getContentOfFile(file)).append(StringUtils.LF));

return filesContent.toString();
}
Expand All @@ -156,10 +158,10 @@ public static String getContentOfFiles(final Set<IFile> files) {
*/
public static String getContentOfFile(final IFile file) {
try {
return IOUtils.toString(file.getContents(), CharactersConstants.UTF_8_ENCODING);
return IOUtils.toString(file.getContents(), StandardCharsets.UTF_8);
} catch (CoreException | IOException e) {
ConsoleUtils.printError(e.getMessage());
}
return CharactersConstants.EMPTY_STRING;
return StringUtils.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Base64;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void saveObjectToStoreAsDefault(final IPreferenceStore store, fina
public static <T extends Serializable> Optional<T> readObjectFromStore(final IPreferenceStore store, final String preferenceKey) {
Optional<T> result = Optional.empty();
final String storedPreference = store.getString(preferenceKey);
final byte bytes[] = Base64.getDecoder().decode(storedPreference);
final byte[] bytes = Base64.getDecoder().decode(storedPreference);

try( final ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) ) {
result = Optional.of( (T) objectInputStream.readObject());
Expand Down Expand Up @@ -104,6 +105,6 @@ public static String serializeObjectToString(final Serializable object) {
ConsoleUtils.printError(exception.getMessage());
}

return CharactersConstants.EMPTY_STRING;
return StringUtils.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,13 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class CopyrightFix implements ICleanUpFix {

private final static CopyrightManager copyrightManager = new CopyrightManager();
private static final CopyrightManager copyrightManager = new CopyrightManager();
private final CompilationUnitChange change;

protected CopyrightFix(final CompilationUnitChange change) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public Composite createContents(final Composite parent) {

@Override
public void controlMoved(final ControlEvent e) {
// intentionally empty
}

@Override
Expand Down Expand Up @@ -245,17 +246,9 @@ public Point computeSize(final Composite composite, final int wHint, final int h
}

final Rectangle area = fContainer.getClientArea();
if (area.width > x) {
fContainer.setExpandHorizontal(true);
} else {
fContainer.setExpandHorizontal(false);
}

if (area.height > y) {
fContainer.setExpandVertical(true);
} else {
fContainer.setExpandVertical(false);
}

fContainer.setExpandHorizontal(area.width > x);
fContainer.setExpandVertical(area.height > y);

if (wHint != SWT.DEFAULT) {
x = wHint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
public class CopyrightPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
private static final int FIELD_WIDTH = 5;

private static interface LABELS {
private final class LABELS {
static final String COPYRIGHT_CONTENTS = "Copyright contents: ";
static final String COPYRIGHT_FIRST_LINE = "First line: ";
static final String COPYRIGHT_LINE_PREFIX = "Line prefix: ";
static final String COPYRIGHT_LAST_LINE = "Last line: ";
static final String COPYRIGHT_PREFERENCES = "Copyright preferences";
}

private StringFieldEditor copyrightContent;
private StringFieldEditor firstLine;
private StringFieldEditor linePrefix;
private StringFieldEditor lastLine;

public CopyrightPreferencePage() {
super(GRID);
}
Expand All @@ -60,13 +55,13 @@ public void init(final IWorkbench arg0) {
*/
@Override
protected void createFieldEditors() {
copyrightContent = new MultiLineStringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_CONTENT,
StringFieldEditor copyrightContent = new MultiLineStringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_CONTENT,
LABELS.COPYRIGHT_CONTENTS, getFieldEditorParent());
firstLine = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_FIRST_LINE,
StringFieldEditor firstLine = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_FIRST_LINE,
LABELS.COPYRIGHT_FIRST_LINE, FIELD_WIDTH, getFieldEditorParent());
linePrefix = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_LINE_PREFIX,
StringFieldEditor linePrefix = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_LINE_PREFIX,
LABELS.COPYRIGHT_LINE_PREFIX, FIELD_WIDTH, getFieldEditorParent());
lastLine = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_LAST_LINE, LABELS.COPYRIGHT_LAST_LINE,
StringFieldEditor lastLine = new StringFieldEditor(CopyrightPreferenceConstants.COPYRIGHT_LAST_LINE, LABELS.COPYRIGHT_LAST_LINE,
FIELD_WIDTH, getFieldEditorParent());
addField(copyrightContent);
addField(firstLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
Expand Down Expand Up @@ -115,12 +113,7 @@ public void focusLost(final FocusEvent e) {
default:
Assert.isTrue(false, UNKNOWN_VALIDATE_STRATEGY);
}
textFieldML.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(final DisposeEvent event) {
textFieldML = null;
}
});
textFieldML.addDisposeListener(e -> textFieldML = null);
if (textLimitML > 0) {
textFieldML.setTextLimit(textLimitML);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
* @generated
*/
public abstract class AbstractPojoImpl extends MinimalEObjectImpl.Container implements AbstractPojo {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static final String copyright = "Copyright by SAP";

/**
* The default value of the '{@link #getClass_() <em>Class</em>}' attribute.
Expand All @@ -68,7 +62,7 @@ public abstract class AbstractPojoImpl extends MinimalEObjectImpl.Container impl
* @generated
* @ordered
*/
protected String class_ = CLASS_EDEFAULT;
protected String clazz = CLASS_EDEFAULT;

/**
* The default value of the '{@link #getTemplate() <em>Template</em>}' attribute.
Expand Down Expand Up @@ -115,7 +109,7 @@ protected EClass eStaticClass() {
* @generated
*/
public String getClass_() {
return class_;
return clazz;
}

/**
Expand All @@ -124,10 +118,10 @@ public String getClass_() {
* @generated
*/
public void setClass(String newClass) {
String oldClass = class_;
class_ = newClass;
String oldClass = clazz;
clazz = newClass;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, BeansPackage.ABSTRACT_POJO__CLASS, oldClass, class_));
eNotify(new ENotificationImpl(this, Notification.SET, BeansPackage.ABSTRACT_POJO__CLASS, oldClass, clazz));
}

/**
Expand Down Expand Up @@ -163,6 +157,8 @@ public Object eGet(int featureID, boolean resolve, boolean coreType) {
return getClass_();
case BeansPackage.ABSTRACT_POJO__TEMPLATE:
return getTemplate();
default:
break;
}
return super.eGet(featureID, resolve, coreType);
}
Expand All @@ -181,6 +177,8 @@ public void eSet(int featureID, Object newValue) {
case BeansPackage.ABSTRACT_POJO__TEMPLATE:
setTemplate((String)newValue);
return;
default:
break;
}
super.eSet(featureID, newValue);
}
Expand All @@ -199,6 +197,8 @@ public void eUnset(int featureID) {
case BeansPackage.ABSTRACT_POJO__TEMPLATE:
setTemplate(TEMPLATE_EDEFAULT);
return;
default:
break;
}
super.eUnset(featureID);
}
Expand All @@ -212,9 +212,11 @@ public void eUnset(int featureID) {
public boolean eIsSet(int featureID) {
switch (featureID) {
case BeansPackage.ABSTRACT_POJO__CLASS:
return CLASS_EDEFAULT == null ? class_ != null : !CLASS_EDEFAULT.equals(class_);
return clazz != null;
case BeansPackage.ABSTRACT_POJO__TEMPLATE:
return TEMPLATE_EDEFAULT == null ? template != null : !TEMPLATE_EDEFAULT.equals(template);
return template != null;
default:
break;
}
return super.eIsSet(featureID);
}
Expand All @@ -228,9 +230,9 @@ public boolean eIsSet(int featureID) {
public String toString() {
if (eIsProxy()) return super.toString();

StringBuffer result = new StringBuffer(super.toString());
StringBuilder result = new StringBuilder(super.toString());
result.append(" (class: ");
result.append(class_);
result.append(clazz);
result.append(", template: ");
result.append(template);
result.append(')');
Expand Down

0 comments on commit 25f4d78

Please sign in to comment.