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