Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 2ab0c79

Browse files
committed
Convert code to Java 7
Switched the processor and the API project to use 1.7 Java level. Code has been converted to utilize the new language features. The functional test project is still at 1.6 because we use API 19 > which cannot use Java 7. Newer Android deps are not on Central due to known reasons.
1 parent f588006 commit 2ab0c79

56 files changed

Lines changed: 481 additions & 499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AndroidAnnotations/androidannotations-api/.settings/org.eclipse.jdt.core.prefs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3-
org.eclipse.jdt.core.compiler.compliance=1.6
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
3+
org.eclipse.jdt.core.compiler.compliance=1.7
44
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5-
org.eclipse.jdt.core.compiler.source=1.6
5+
org.eclipse.jdt.core.compiler.source=1.7
66
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
77
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
88
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

‎AndroidAnnotations/androidannotations-api/pom.xml‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434

3535
<build>
3636
<plugins>
37-
<plugin>
38-
<groupId>org.apache.maven.plugins</groupId>
39-
<artifactId>maven-compiler-plugin</artifactId>
40-
<configuration>
41-
<source>1.6</source>
42-
<target>1.6</target>
43-
</configuration>
44-
</plugin>
4537
<plugin>
4638
<groupId>org.apache.maven.plugins</groupId>
4739
<artifactId>maven-resources-plugin</artifactId>

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/BackgroundExecutor.java‎

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
import java.util.concurrent.TimeUnit;
2727
import java.util.concurrent.atomic.AtomicBoolean;
2828

29-
import android.os.Looper;
30-
import android.util.Log;
3129
import org.androidannotations.annotations.SupposeBackground;
3230
import org.androidannotations.annotations.SupposeUiThread;
3331

32+
import android.os.Looper;
33+
import android.util.Log;
34+
3435
public class BackgroundExecutor {
3536

3637
private static final String TAG = "BackgroundExecutor";
@@ -39,8 +40,8 @@ public class BackgroundExecutor {
3940
private static Executor executor = DEFAULT_EXECUTOR;
4041

4142
/**
42-
* The default invocation handler for wrong thread execution.
43-
* It just throws {@link IllegalStateException} with explanation what is going wrong.
43+
* The default invocation handler for wrong thread execution. It just throws
44+
* {@link IllegalStateException} with explanation what is going wrong.
4445
*
4546
* @see #setWrongThreadListener(BackgroundExecutor.WrongThreadListener)
4647
* @see SupposeBackground
@@ -71,8 +72,8 @@ public void onWrongBgSerial(String currentSerial, String... expectedSerials) {
7172

7273
private static WrongThreadListener wrongThreadListener = DEFAULT_WRONG_THREAD_LISTENER;
7374

74-
private static final List<Task> tasks = new ArrayList<Task>();
75-
private static final ThreadLocal<String> currentSerial = new ThreadLocal<String>();
75+
private static final List<Task> tasks = new ArrayList<>();
76+
private static final ThreadLocal<String> currentSerial = new ThreadLocal<>();
7677

7778
/**
7879
* Execute a runnable after the given delay.
@@ -224,10 +225,11 @@ public static void setExecutor(Executor executor) {
224225
}
225226

226227
/**
227-
* Changes the default {@link WrongThreadListener}.
228-
* To restore the default one use {@link #DEFAULT_WRONG_THREAD_LISTENER}.
228+
* Changes the default {@link WrongThreadListener}. To restore the default
229+
* one use {@link #DEFAULT_WRONG_THREAD_LISTENER}.
229230
*
230-
* @param listener the new {@link WrongThreadListener}
231+
* @param listener
232+
* the new {@link WrongThreadListener}
231233
*/
232234
public static void setWrongThreadListener(WrongThreadListener listener) {
233235
wrongThreadListener = listener;
@@ -269,7 +271,8 @@ public static synchronized void cancelAll(String id, boolean mayInterruptIfRunni
269271

270272
/**
271273
* Checks if the current thread is UI thread and notifies
272-
* {@link BackgroundExecutor.WrongThreadListener#onUiExpected()} if it doesn't.
274+
* {@link BackgroundExecutor.WrongThreadListener#onUiExpected()} if it
275+
* doesn't.
273276
*/
274277
public static void checkUiThread() {
275278
if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
@@ -278,17 +281,21 @@ public static void checkUiThread() {
278281
}
279282

280283
/**
281-
* Checks if the current thread is a background thread and, optionally, restricts it
282-
* with passed serials. If no serials passed and current thread is the UI thread, then
283-
* {@link WrongThreadListener#onBgExpected(String...)} will be called.
284-
* If the current thread is not UI and serials list is empty, then this method just returns.
285-
* Otherwise, if the method was called not during {@link Task} execution or the task has no
286-
* serial, then the {@link WrongThreadListener#onWrongBgSerial(String, String...)} will be called
287-
* with null for the first parameter. If task has a serial but passed serials don't contain that,
288-
* then {@link WrongThreadListener#onWrongBgSerial(String, String...)} will be called with
289-
* the task's serial for the first parameter.
284+
* Checks if the current thread is a background thread and, optionally,
285+
* restricts it with passed serials. If no serials passed and current thread
286+
* is the UI thread, then
287+
* {@link WrongThreadListener#onBgExpected(String...)} will be called. If
288+
* the current thread is not UI and serials list is empty, then this method
289+
* just returns. Otherwise, if the method was called not during {@link Task}
290+
* execution or the task has no serial, then the
291+
* {@link WrongThreadListener#onWrongBgSerial(String, String...)} will be
292+
* called with null for the first parameter. If task has a serial but passed
293+
* serials don't contain that, then
294+
* {@link WrongThreadListener#onWrongBgSerial(String, String...)} will be
295+
* called with the task's serial for the first parameter.
290296
*
291-
* @param serials (optional) list of allowed serials
297+
* @param serials
298+
* (optional) list of allowed serials
292299
*/
293300
public static void checkBgThread(String... serials) {
294301
if (serials.length == 0) {
@@ -314,9 +321,10 @@ public static void checkBgThread(String... serials) {
314321
* Indicates whether a task with the specified <code>serial</code> has been
315322
* submitted to the executor.
316323
*
317-
* @param serial the serial queue
324+
* @param serial
325+
* the serial queue
318326
* @return <code>true</code> if such a task has been submitted,
319-
* <code>false</code> otherwise
327+
* <code>false</code> otherwise
320328
*/
321329
private static boolean hasSerialRunning(String serial) {
322330
for (Task task : tasks) {
@@ -426,7 +434,8 @@ private void postExecute() {
426434
}
427435

428436
/**
429-
* A callback interface to be notified when a method invocation is expected from another thread.
437+
* A callback interface to be notified when a method invocation is expected
438+
* from another thread.
430439
*
431440
* @see #setWrongThreadListener(WrongThreadListener)
432441
* @see #checkUiThread()
@@ -437,8 +446,8 @@ private void postExecute() {
437446
public static interface WrongThreadListener {
438447

439448
/**
440-
* Will be called, if the method is supposed to be called from the UI-thread, but was called from a background
441-
* thread.
449+
* Will be called, if the method is supposed to be called from the
450+
* UI-thread, but was called from a background thread.
442451
*
443452
* @see SupposeUiThread
444453
* @see #setWrongThreadListener(WrongThreadListener)
@@ -447,23 +456,28 @@ public static interface WrongThreadListener {
447456
void onUiExpected();
448457

449458
/**
450-
* Will be called, if the method is supposed to be called from a background thread, but was called from the
451-
* UI-thread.
459+
* Will be called, if the method is supposed to be called from a
460+
* background thread, but was called from the UI-thread.
452461
*
453-
* @param expectedSerials a list of allowed serials. If any background thread is allowed the list will be empty.
462+
* @param expectedSerials
463+
* a list of allowed serials. If any background thread is
464+
* allowed the list will be empty.
454465
* @see SupposeBackground
455466
* @see #setWrongThreadListener(WrongThreadListener)
456467
* @see #DEFAULT_WRONG_THREAD_LISTENER
457468
*/
458469
void onBgExpected(String... expectedSerials);
459470

460471
/**
461-
* Will be called, if the method is supposed to be called from a background thread with one of
462-
* {@code expectedSerials}, but was called from a {@code currentSerial}. {@code currentSerial} will be null,
463-
* if it is called from a background thread without a serial.
472+
* Will be called, if the method is supposed to be called from a
473+
* background thread with one of {@code expectedSerials}, but was called
474+
* from a {@code currentSerial}. {@code currentSerial} will be null, if
475+
* it is called from a background thread without a serial.
464476
*
465-
* @param currentSerial the serial of caller thread or null if there is no serial
466-
* @param expectedSerials a list of allowed serials
477+
* @param currentSerial
478+
* the serial of caller thread or null if there is no serial
479+
* @param expectedSerials
480+
* a list of allowed serials
467481
* @see SupposeBackground
468482
* @see #setWrongThreadListener(WrongThreadListener)
469483
* @see #DEFAULT_WRONG_THREAD_LISTENER

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/ViewServer.java‎

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
*/
1616
package org.androidannotations.api;
1717

18-
import android.app.Activity;
19-
import android.content.Context;
20-
import android.content.pm.ApplicationInfo;
21-
import android.os.Build;
22-
import android.text.TextUtils;
23-
import android.util.Log;
24-
import android.view.View;
25-
import android.view.ViewDebug;
26-
27-
import java.io.*;
18+
import java.io.BufferedReader;
19+
import java.io.BufferedWriter;
20+
import java.io.IOException;
21+
import java.io.InputStreamReader;
22+
import java.io.OutputStream;
23+
import java.io.OutputStreamWriter;
2824
import java.lang.reflect.Method;
2925
import java.net.InetAddress;
3026
import java.net.ServerSocket;
@@ -37,6 +33,15 @@
3733
import java.util.concurrent.Executors;
3834
import java.util.concurrent.locks.ReentrantReadWriteLock;
3935

36+
import android.app.Activity;
37+
import android.content.Context;
38+
import android.content.pm.ApplicationInfo;
39+
import android.os.Build;
40+
import android.text.TextUtils;
41+
import android.util.Log;
42+
import android.view.View;
43+
import android.view.ViewDebug;
44+
4045
/**
4146
* <p>
4247
* This class can be used to enable the use of HierarchyViewer inside an
@@ -137,9 +142,9 @@ public class ViewServer implements Runnable {
137142
private Thread mThread;
138143
private ExecutorService mThreadPool;
139144

140-
private final List<WindowListener> mListeners = new CopyOnWriteArrayList<ViewServer.WindowListener>();
145+
private final List<WindowListener> mListeners = new CopyOnWriteArrayList<>();
141146

142-
private final HashMap<View, String> mWindows = new HashMap<View, String>();
147+
private final HashMap<View, String> mWindows = new HashMap<>();
143148
private final ReentrantReadWriteLock mWindowsLock = new ReentrantReadWriteLock();
144149

145150
private View mFocusedWindow;
@@ -209,8 +214,7 @@ private ViewServer(int port) {
209214
* If the server cannot be created.
210215
*
211216
* @see #stop()
212-
* @see #isRunning()
213-
* see WindowManagerService#startViewServer(int)
217+
* @see #isRunning() see WindowManagerService#startViewServer(int)
214218
*/
215219
public boolean start() throws IOException {
216220
if (mThread != null) {
@@ -231,8 +235,7 @@ public boolean start() throws IOException {
231235
* the server wasn't started.
232236
*
233237
* @see #start()
234-
* @see #isRunning()
235-
* see WindowManagerService#stopViewServer()
238+
* @see #isRunning() see WindowManagerService#stopViewServer()
236239
*/
237240
public boolean stop() {
238241
if (mThread != null) {
@@ -280,8 +283,7 @@ public boolean stop() {
280283
* @return True if the server is running, false otherwise.
281284
*
282285
* @see #start()
283-
* @see #stop()
284-
* see WindowManagerService#isViewServerRunning()
286+
* @see #stop() see WindowManagerService#isViewServerRunning()
285287
*/
286288
public boolean isRunning() {
287289
return mThread != null && mThread.isAlive();
@@ -322,8 +324,10 @@ public void removeWindow(Activity activity) {
322324
/**
323325
* Invoke this method to register a new view hierarchy.
324326
*
325-
* @param view A view that belongs to the view hierarchy/window to register
326-
* @param name The name of the view hierarchy/window to register
327+
* @param view
328+
* A view that belongs to the view hierarchy/window to register
329+
* @param name
330+
* The name of the view hierarchy/window to register
327331
*
328332
* @see #removeWindow(View)
329333
*/

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/roboguice/RoboGuiceHelper.java‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,8 @@ public static void callInjectViews(Object activity) {
3030
Method injectViewsMethod = viewMembersInjectorClass.getDeclaredMethod("injectViews", Object.class);
3131
injectViewsMethod.setAccessible(true);
3232
injectViewsMethod.invoke(null, activity);
33-
} catch (ClassNotFoundException e) {
34-
propagateRuntimeException(e);
35-
} catch (NoSuchMethodException e) {
36-
propagateRuntimeException(e);
37-
} catch (SecurityException e) {
38-
propagateRuntimeException(e);
39-
} catch (IllegalAccessException e) {
40-
propagateRuntimeException(e);
41-
} catch (IllegalArgumentException e) {
42-
propagateRuntimeException(e);
43-
} catch (InvocationTargetException e) {
44-
propagateRuntimeException(e);
33+
} catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | SecurityException | NoSuchMethodException e) {
34+
throw new RuntimeException("Could not invoke RoboGuice method!", e);
4535
}
4636
}
47-
48-
private static void propagateRuntimeException(Throwable t) {
49-
throw new RuntimeException("Could not invoke RoboGuice method!", t);
50-
}
5137
}

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/EditorHelper.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ public final void apply() {
4040
}
4141

4242
protected IntPrefEditorField<T> intField(String key) {
43-
return new IntPrefEditorField<T>(cast(), key);
43+
return new IntPrefEditorField<>(cast(), key);
4444
}
4545

4646
protected StringPrefEditorField<T> stringField(String key) {
47-
return new StringPrefEditorField<T>(cast(), key);
47+
return new StringPrefEditorField<>(cast(), key);
4848
}
4949

5050
protected StringSetPrefEditorField<T> stringSetField(String key) {
51-
return new StringSetPrefEditorField<T>(cast(), key);
51+
return new StringSetPrefEditorField<>(cast(), key);
5252
}
5353

5454
protected BooleanPrefEditorField<T> booleanField(String key) {
55-
return new BooleanPrefEditorField<T>(cast(), key);
55+
return new BooleanPrefEditorField<>(cast(), key);
5656
}
5757

5858
protected FloatPrefEditorField<T> floatField(String key) {
59-
return new FloatPrefEditorField<T>(cast(), key);
59+
return new FloatPrefEditorField<>(cast(), key);
6060
}
6161

6262
protected LongPrefEditorField<T> longField(String key) {
63-
return new LongPrefEditorField<T>(cast(), key);
63+
return new LongPrefEditorField<>(cast(), key);
6464
}
6565

6666
@SuppressWarnings("unchecked")

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/SetXmlSerializer.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,15 @@ public static String serialize(Set<String> set) {
6060
serializer.endTag(NAMESPACE, SET_TAG) //
6161
.endDocument();
6262

63-
} catch (IllegalArgumentException e) {
64-
65-
} catch (IllegalStateException e) {
66-
67-
} catch (IOException e) {
63+
} catch (IllegalArgumentException | IOException | IllegalStateException e) {
6864

6965
}
7066

7167
return writer.toString();
7268
}
7369

7470
public static Set<String> deserialize(String data) {
75-
Set<String> stringSet = new TreeSet<String>();
71+
Set<String> stringSet = new TreeSet<>();
7672
XmlPullParser parser = Xml.newPullParser();
7773

7874
try {

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/SharedPreferencesCompat.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ public static <T> T invoke(Method method, Object obj, Object... args) throws NoS
7777

7878
try {
7979
return (T) method.invoke(obj, args);
80-
} catch (IllegalAccessException e) {
81-
// fall through
82-
} catch (IllegalArgumentException e) {
83-
// fall through
84-
} catch (InvocationTargetException e) {
80+
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
8581
// fall through
8682
}
8783

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/view/OnViewChangedNotifier.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void registerOnViewChangedListener(OnViewChangedListener listener)
3434
}
3535
}
3636

37-
private final Set<OnViewChangedListener> listeners = new LinkedHashSet<OnViewChangedListener>();
37+
private final Set<OnViewChangedListener> listeners = new LinkedHashSet<>();
3838

3939
public void notifyViewChanged(HasViews hasViews) {
4040
for (OnViewChangedListener listener : listeners) {

0 commit comments

Comments
 (0)