Commit cf7b024b authored by Yusuke Iwaki's avatar Yusuke Iwaki

respect ShortVariable, ShortMethodName rules for PMD

parent 9bb20414
...@@ -10,12 +10,12 @@ import chat.rocket.android.activity.ServerConfigActivity; ...@@ -10,12 +10,12 @@ import chat.rocket.android.activity.ServerConfigActivity;
*/ */
public class LaunchUtil { public class LaunchUtil {
/** /**
* launc ServerConfigActivity with proper flags. * launch ServerConfigActivity with proper flags.
*/ */
public static void showServerConfigActivity(Context context, String id) { public static void showServerConfigActivity(Context context, String serverCondigId) {
Intent intent = new Intent(context, ServerConfigActivity.class); Intent intent = new Intent(context, ServerConfigActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("id", id); intent.putExtra("id", serverCondigId);
context.startActivity(intent); context.startActivity(intent);
} }
} }
...@@ -12,21 +12,24 @@ abstract class AbstractFragmentActivity extends AppCompatActivity { ...@@ -12,21 +12,24 @@ abstract class AbstractFragmentActivity extends AppCompatActivity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
Fragment f = getSupportFragmentManager().findFragmentById(getLayoutContainerForFragment()); Fragment fragment =
if (f instanceof OnBackPressListener && ((OnBackPressListener) f).onBackPressed()) { getSupportFragmentManager().findFragmentById(getLayoutContainerForFragment());
if (fragment instanceof OnBackPressListener
&& ((OnBackPressListener) fragment).onBackPressed()) {
//consumed. do nothing. //consumed. do nothing.
} else super.onBackPressed(); } else super.onBackPressed();
} }
protected void showFragment(Fragment f) { protected void showFragment(Fragment fragment) {
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), f) .replace(getLayoutContainerForFragment(), fragment)
.commit(); .commit();
} }
protected void showFragmentWithBackStack(Fragment f) { protected void showFragmentWithBackStack(Fragment fragment) {
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), f) .replace(getLayoutContainerForFragment(), fragment)
.addToBackStack(null) .addToBackStack(null)
.commit(); .commit();
} }
......
...@@ -161,22 +161,22 @@ public class ServerConfigActivity extends AbstractFragmentActivity { ...@@ -161,22 +161,22 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
} }
@Override @Override
protected void showFragment(Fragment f) { protected void showFragment(Fragment fragment) {
injectIdArgTo(f); injectIdArgTo(fragment);
super.showFragment(f); super.showFragment(fragment);
} }
@Override @Override
protected void showFragmentWithBackStack(Fragment f) { protected void showFragmentWithBackStack(Fragment fragment) {
injectIdArgTo(f); injectIdArgTo(fragment);
super.showFragmentWithBackStack(f); super.showFragmentWithBackStack(fragment);
} }
private void injectIdArgTo(Fragment f) { private void injectIdArgTo(Fragment fragment) {
Bundle args = f.getArguments(); Bundle args = fragment.getArguments();
if (args == null) args = new Bundle(); if (args == null) args = new Bundle();
args.putString("id", mServerConfigId); args.putString("id", mServerConfigId);
f.setArguments(args); fragment.setArguments(args);
} }
@Override @Override
......
...@@ -41,7 +41,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -41,7 +41,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
@Override @Override
protected void onSetupView() { protected void onSetupView() {
mRootView.findViewById(R.id.btn_connect).setOnClickListener(v -> handleConnect()); mRootView.findViewById(R.id.btn_connect).setOnClickListener(view -> handleConnect());
mObserver.sub(); mObserver.sub();
} }
...@@ -83,8 +83,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -83,8 +83,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
private void showError(String errString) { private void showError(String errString) {
mShowError.removeMessages(0); mShowError.removeMessages(0);
Message m = Message.obtain(mShowError, 0, errString); Message msg = Message.obtain(mShowError, 0, errString);
mShowError.sendMessageDelayed(m, 160); mShowError.sendMessageDelayed(msg, 160);
} }
private void onRenderServerConfig(ServerConfig config) { private void onRenderServerConfig(ServerConfig config) {
......
...@@ -18,6 +18,7 @@ public class TextUtils { ...@@ -18,6 +18,7 @@ public class TextUtils {
/** /**
* Returns str if it is not empty; otherwise defaultValue is returned. * Returns str if it is not empty; otherwise defaultValue is returned.
*/ */
@SuppressWarnings("PMD.ShortMethodName")
public static CharSequence or(CharSequence str, CharSequence defaultValue) { public static CharSequence or(CharSequence str, CharSequence defaultValue) {
if (isEmpty(str)) return defaultValue; if (isEmpty(str)) return defaultValue;
return str; return str;
......
...@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey; ...@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey;
/** /**
* subscription model for "meteor_accounts_loginServiceConfiguration" * subscription model for "meteor_accounts_loginServiceConfiguration"
*/ */
@SuppressWarnings("PMD.ShortVariable")
public class MeteorLoginServiceConfiguration extends RealmObject { public class MeteorLoginServiceConfiguration extends RealmObject {
@PrimaryKey @PrimaryKey
private String id; private String id;
......
...@@ -15,6 +15,7 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts; ...@@ -15,6 +15,7 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
/** /**
* Server configuration * Server configuration
*/ */
@SuppressWarnings("PMD.ShortVariable")
public class ServerConfig extends RealmObject { public class ServerConfig extends RealmObject {
@PrimaryKey @PrimaryKey
private String id; private String id;
...@@ -99,12 +100,12 @@ public class ServerConfig extends RealmObject { ...@@ -99,12 +100,12 @@ public class ServerConfig extends RealmObject {
} }
@DebugLog @DebugLog
public static void logError(String id, Exception e) { public static void logError(String id, Exception exception) {
RealmHelperBolts RealmHelperBolts
.executeTransaction(realm -> .executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject() realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", id) .put("id", id)
.put("connectionError", e.getMessage()))) .put("connectionError", exception.getMessage())))
.continueWith(new LogcatIfError()); .continueWith(new LogcatIfError());
} }
} }
...@@ -66,22 +66,22 @@ public class RocketChatService extends Service { ...@@ -66,22 +66,22 @@ public class RocketChatService extends Service {
} }
private void syncWebSocketThreadsWith(List<ServerConfig> configList) { private void syncWebSocketThreadsWith(List<ServerConfig> configList) {
final Iterator<Map.Entry<String, RocketChatWebSocketThread>> it = final Iterator<Map.Entry<String, RocketChatWebSocketThread>> iterator =
mWebSocketThreads.entrySet().iterator(); mWebSocketThreads.entrySet().iterator();
while (it.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, RocketChatWebSocketThread> e = it.next(); Map.Entry<String, RocketChatWebSocketThread> entry = iterator.next();
String id = e.getKey(); String serverConfigId = entry.getKey();
boolean found = false; boolean found = false;
for (ServerConfig config: configList) { for (ServerConfig config: configList) {
if (id.equals(config.getId())) { if (serverConfigId.equals(config.getId())) {
found = true; found = true;
break; break;
} }
} }
if (!found) { if (!found) {
RocketChatWebSocketThread.terminate(e.getValue()); RocketChatWebSocketThread.terminate(entry.getValue());
it.remove(); iterator.remove();
} }
} }
...@@ -95,13 +95,13 @@ public class RocketChatService extends Service { ...@@ -95,13 +95,13 @@ public class RocketChatService extends Service {
} }
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) { private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String id = config.getId(); final String serverConfigId = config.getId();
if (mWebSocketThreads.containsKey(id)) { if (mWebSocketThreads.containsKey(serverConfigId)) {
return Task.forResult(mWebSocketThreads.get(id)); return Task.forResult(mWebSocketThreads.get(serverConfigId));
} else { } else {
return RocketChatWebSocketThread.getStarted(getApplicationContext(), config) return RocketChatWebSocketThread.getStarted(getApplicationContext(), config)
.onSuccessTask(task -> { .onSuccessTask(task -> {
mWebSocketThreads.put(id, task.getResult()); mWebSocketThreads.put(serverConfigId, task.getResult());
return task; return task;
}); });
} }
......
...@@ -29,9 +29,9 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -29,9 +29,9 @@ public class RocketChatWebSocketThread extends HandlerThread {
private boolean mSocketExists; private boolean mSocketExists;
private boolean mListenersRegistered; private boolean mListenersRegistered;
private RocketChatWebSocketThread(Context appContext, String id) { private RocketChatWebSocketThread(Context appContext, String serverConfigId) {
super("RC_thread_" + id); super("RC_thread_" + serverConfigId);
mServerConfigId = id; mServerConfigId = serverConfigId;
mAppContext = appContext; mAppContext = appContext;
} }
...@@ -48,8 +48,8 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -48,8 +48,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
try { try {
super.onLooperPrepared(); super.onLooperPrepared();
task.setResult(this); task.setResult(this);
} catch (Exception e) { } catch (Exception exception) {
task.setError(e); task.setError(exception);
} }
} }
}.start(); }.start();
...@@ -60,8 +60,8 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -60,8 +60,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
* terminate the thread * terminate the thread
*/ */
@DebugLog @DebugLog
public static void terminate(RocketChatWebSocketThread t) { public static void terminate(RocketChatWebSocketThread thread) {
t.quit(); thread.quit();
} }
private Task<Void> ensureConnection() { private Task<Void> ensureConnection() {
...@@ -178,12 +178,12 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -178,12 +178,12 @@ public class RocketChatWebSocketThread extends HandlerThread {
Object obj = ctor.newInstance(mAppContext, mWebSocketAPI); Object obj = ctor.newInstance(mAppContext, mWebSocketAPI);
if (obj instanceof Registerable) { if (obj instanceof Registerable) {
Registerable l = (Registerable) obj; Registerable registerable = (Registerable) obj;
l.register(); registerable.register();
mListeners.add(l); mListeners.add(registerable);
} }
} catch (Exception e) { } catch (Exception exception) {
Timber.w(e, "Failed to register listeners!!"); Timber.w(exception, "Failed to register listeners!!");
} }
} }
} }
...@@ -192,18 +192,18 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -192,18 +192,18 @@ public class RocketChatWebSocketThread extends HandlerThread {
private void keepaliveListeners() { private void keepaliveListeners() {
if (!mSocketExists || !mListenersRegistered) return; if (!mSocketExists || !mListenersRegistered) return;
for (Registerable l : mListeners) l.keepalive(); for (Registerable registerable : mListeners) registerable.keepalive();
} }
//@DebugLog //@DebugLog
private void unregisterListeners() { private void unregisterListeners() {
if (!mSocketExists || !mListenersRegistered) return; if (!mSocketExists || !mListenersRegistered) return;
Iterator<Registerable> it = mListeners.iterator(); Iterator<Registerable> iterator = mListeners.iterator();
while (it.hasNext()) { while (iterator.hasNext()) {
Registerable l = it.next(); Registerable registerable = iterator.next();
l.unregister(); registerable.unregister();
it.remove(); iterator.remove();
} }
if (mWebSocketAPI != null) { if (mWebSocketAPI != null) {
mWebSocketAPI.close(); mWebSocketAPI.close();
......
...@@ -103,9 +103,9 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable { ...@@ -103,9 +103,9 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
} }
private void mergeJSON(JSONObject target, JSONObject src) throws JSONException { private void mergeJSON(JSONObject target, JSONObject src) throws JSONException {
Iterator<String> it = src.keys(); Iterator<String> iterator = src.keys();
while (it.hasNext()) { while (iterator.hasNext()) {
String key = it.next(); String key = iterator.next();
target.put(key, src.get(key)); target.put(key, src.get(key));
} }
} }
......
...@@ -33,8 +33,8 @@ abstract class AbstractCustomFontTextView extends AppCompatTextView { ...@@ -33,8 +33,8 @@ abstract class AbstractCustomFontTextView extends AppCompatTextView {
private void init() { private void init() {
String font = getFont(); String font = getFont();
if (font != null) { if (font != null) {
Typeface tf = TypefaceHelper.getTypeface(getContext(), font); Typeface typeface = TypefaceHelper.getTypeface(getContext(), font);
if (tf != null) setTypeface(tf); if (typeface != null) setTypeface(typeface);
} }
} }
} }
...@@ -18,16 +18,16 @@ public class TypefaceHelper { ...@@ -18,16 +18,16 @@ public class TypefaceHelper {
/** /**
* read font in assets directory. * read font in assets directory.
*/ */
public static Typeface getTypeface(Context c, String assetPath) { public static Typeface getTypeface(Context context, String assetPath) {
synchronized (CACHE) { synchronized (CACHE) {
if (!CACHE.containsKey(assetPath)) { if (!CACHE.containsKey(assetPath)) {
try { try {
Typeface t = Typeface.createFromAsset(c.getAssets(), Typeface typeface = Typeface.createFromAsset(context.getAssets(),
assetPath); assetPath);
CACHE.put(assetPath, t); CACHE.put(assetPath, typeface);
} catch (Exception e) { } catch (Exception exception) {
Log.e(TAG, "Could not get typeface '" + assetPath Log.e(TAG, "Could not get typeface '" + assetPath
+ "' because " + e.getMessage()); + "' because " + exception.getMessage());
return null; return null;
} }
} }
......
...@@ -48,12 +48,12 @@ public class WaitingView extends LinearLayout { ...@@ -48,12 +48,12 @@ public class WaitingView extends LinearLayout {
int count = 3; int count = 3;
if (attrs != null) { if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes( TypedArray array = context.getTheme().obtainStyledAttributes(
attrs, attrs,
R.styleable.WaitingView, 0, 0); R.styleable.WaitingView, 0, 0);
size = a.getDimensionPixelSize(R.styleable.WaitingView_dotSize, size); size = array.getDimensionPixelSize(R.styleable.WaitingView_dotSize, size);
count = a.getInteger(R.styleable.WaitingView_dotCount, count); count = array.getInteger(R.styleable.WaitingView_dotCount, count);
a.recycle(); array.recycle();
} }
mDots = new ArrayList<>(); mDots = new ArrayList<>();
...@@ -74,13 +74,14 @@ public class WaitingView extends LinearLayout { ...@@ -74,13 +74,14 @@ public class WaitingView extends LinearLayout {
} }
private void addDot(Context context, int size) { private void addDot(Context context, int size) {
FrameLayout f = new FrameLayout(context); FrameLayout frameLayout = new FrameLayout(context);
f.setLayoutParams(new LinearLayoutCompat.LayoutParams(size * 3 / 2, size * 3 / 2)); frameLayout.setLayoutParams(
new LinearLayoutCompat.LayoutParams(size * 3 / 2, size * 3 / 2));
ImageView dot = new ImageView(context); ImageView dot = new ImageView(context);
dot.setImageResource(R.drawable.white_circle); dot.setImageResource(R.drawable.white_circle);
dot.setLayoutParams(new FrameLayout.LayoutParams(size, size, Gravity.CENTER)); dot.setLayoutParams(new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
f.addView(dot); frameLayout.addView(dot);
addView(f); addView(frameLayout);
mDots.add(dot); mDots.add(dot);
} }
......
...@@ -62,8 +62,8 @@ public class RocketChatWebSocketAPI { ...@@ -62,8 +62,8 @@ public class RocketChatWebSocketAPI {
/** /**
* Unsubscribe with DDP client. * Unsubscribe with DDP client.
*/ */
public Task<DDPSubscription.NoSub> unsubscribe(final String id) { public Task<DDPSubscription.NoSub> unsubscribe(final String subscriptionId) {
return mDDPClient.unsub(id); return mDDPClient.unsub(subscriptionId);
} }
/** /**
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
<rule ref="rulesets/java/naming.xml"> <rule ref="rulesets/java/naming.xml">
<!--<exclude name="AbstractNaming" />--> <!--<exclude name="AbstractNaming" />-->
<exclude name="LongVariable" /> <exclude name="LongVariable" />
<exclude name="ShortMethodName" /> <!--exclude name="ShortMethodName" /-->
<exclude name="ShortVariable" /> <!--exclude name="ShortVariable" /-->
<!--<exclude name="ShortClassName" />--> <!--<exclude name="ShortClassName" />-->
<!--<exclude name="VariableNamingConventions" />--> <!--<exclude name="VariableNamingConventions" />-->
</rule> </rule>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment