Skip to content

Commit 4135560

Browse files
committed
Clean up.
1 parent 7a22d51 commit 4135560

File tree

49 files changed

+1145
-1148
lines changed

Some content is hidden

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

49 files changed

+1145
-1148
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/CannotDetermineStreamOrderingException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ public CannotDetermineStreamOrderingException(String message, Class<?> sourceTyp
1313
super(message);
1414
}
1515

16-
public CannotDetermineStreamOrderingException(Throwable cause, Class<?> sourceType) {
17-
super(cause);
16+
public CannotDetermineStreamOrderingException(String message, Throwable cause, boolean enableSuppression,
17+
boolean writableStackTrace, Class<?> sourceType) {
18+
super(message, cause, enableSuppression, writableStackTrace);
1819
}
1920

2021
public CannotDetermineStreamOrderingException(String message, Throwable cause, Class<?> sourceType) {
2122
super(message, cause);
2223
}
2324

24-
public CannotDetermineStreamOrderingException(String message, Throwable cause, boolean enableSuppression,
25-
boolean writableStackTrace, Class<?> sourceType) {
26-
super(message, cause, enableSuppression, writableStackTrace);
25+
public CannotDetermineStreamOrderingException(Throwable cause, Class<?> sourceType) {
26+
super(cause);
2727
}
2828

2929
public Class<?> getSourceType() {

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/CannotExtractSpliteratorException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ public CannotExtractSpliteratorException(String message, Class<? extends Object>
1313
this.fromType = fromType;
1414
}
1515

16-
public CannotExtractSpliteratorException(Throwable cause) {
17-
super(cause);
16+
public CannotExtractSpliteratorException(String message, Throwable cause, boolean enableSuppression,
17+
boolean writableStackTrace) {
18+
super(message, cause, enableSuppression, writableStackTrace);
1819
}
1920

2021
public CannotExtractSpliteratorException(String message, Throwable cause, Class<? extends Object> fromType) {
2122
super(message, cause);
2223
this.fromType = fromType;
2324
}
2425

25-
public CannotExtractSpliteratorException(String message, Throwable cause, boolean enableSuppression,
26-
boolean writableStackTrace) {
27-
super(message, cause, enableSuppression, writableStackTrace);
26+
public CannotExtractSpliteratorException(Throwable cause) {
27+
super(cause);
2828
}
2929

3030
public Class<? extends Object> getFromType() {

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/InstanceKeyNotFoundException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ public InstanceKeyNotFoundException(String message) {
1111
super(message);
1212
}
1313

14-
public InstanceKeyNotFoundException(Throwable cause) {
15-
super(cause);
16-
}
17-
1814
public InstanceKeyNotFoundException(String message, Throwable cause) {
1915
super(message, cause);
2016
}
@@ -24,4 +20,8 @@ public InstanceKeyNotFoundException(String message, Throwable cause, boolean ena
2420
super(message, cause, enableSuppression, writableStackTrace);
2521
}
2622

23+
public InstanceKeyNotFoundException(Throwable cause) {
24+
super(cause);
25+
}
26+
2727
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/NoEnclosingMethodNodeFoundException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ public NoEnclosingMethodNodeFoundException(String message) {
1616
super(message);
1717
}
1818

19-
public NoEnclosingMethodNodeFoundException(Throwable cause) {
20-
super(cause);
21-
}
22-
2319
public NoEnclosingMethodNodeFoundException(String message, Throwable cause) {
2420
super(message, cause);
2521
}
@@ -29,6 +25,10 @@ public NoEnclosingMethodNodeFoundException(String message, Throwable cause, bool
2925
super(message, cause, enableSuppression, writableStackTrace);
3026
}
3127

28+
public NoEnclosingMethodNodeFoundException(Throwable cause) {
29+
super(cause);
30+
}
31+
3232
public MethodReference getMethodReference() {
3333
return this.methodReference;
3434
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package edu.cuny.hunter.streamrefactoring.core.analysis;
22

33
public class NoEntryPointException extends Exception {
4-
5-
public NoEntryPointException(String string) {
6-
super(string);
7-
}
4+
5+
/**
6+
*
7+
*/
8+
private static final long serialVersionUID = 3216982694001353012L;
9+
10+
public NoEntryPointException(String string) {
11+
super(string);
12+
}
813
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/NoniterableException.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
public class NoniterableException extends Exception {
44

5+
/**
6+
*
7+
*/
8+
private static final long serialVersionUID = 6340319816698688446L;
9+
510
public NoniterableException() {
611
super();
712
}
@@ -10,10 +15,6 @@ public NoniterableException(String message) {
1015
super(message);
1116
}
1217

13-
public NoniterableException(Throwable cause) {
14-
super(cause);
15-
}
16-
1718
public NoniterableException(String message, Throwable cause) {
1819
super(message, cause);
1920
}
@@ -22,4 +23,8 @@ public NoniterableException(String message, Throwable cause, boolean enableSuppr
2223
boolean writableStackTrace) {
2324
super(message, cause, enableSuppression, writableStackTrace);
2425
}
26+
27+
public NoniterableException(Throwable cause) {
28+
super(cause);
29+
}
2530
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/OrderingInference.java

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,102 @@
2323

2424
class OrderingInference {
2525

26-
private Objenesis objenesis = new ObjenesisStd();
26+
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
2727

2828
private IClassHierarchy classHierarchy;
2929

30-
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
30+
private Objenesis objenesis = new ObjenesisStd();
3131

3232
public OrderingInference(IClassHierarchy classHierarchy) {
3333
this.classHierarchy = classHierarchy;
3434
}
3535

36-
Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes, IMethod calledMethod)
37-
throws InconsistentPossibleOrderingException, NoniterableException, NoninstantiableException,
38-
CannotExtractSpliteratorException {
39-
return inferOrdering(possibleTypes, calledMethod.getElementName());
36+
private Object createInstance(Class<?> clazz) throws NoninstantiableException {
37+
try {
38+
return clazz.newInstance();
39+
} catch (InstantiationException | IllegalAccessException e) {
40+
ObjectInstantiator<?> instantiator = objenesis.getInstantiatorOf(clazz);
41+
try {
42+
return instantiator.newInstance();
43+
} catch (InstantiationError e2) {
44+
throw new NoninstantiableException(clazz + " cannot be instantiated: " + e2.getCause(), e2, clazz);
45+
}
46+
}
4047
}
4148

42-
private Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes, String calledMethodName)
43-
throws InconsistentPossibleOrderingException, NoniterableException, NoninstantiableException,
44-
CannotExtractSpliteratorException {
45-
Ordering ret = null;
49+
private String findStreamCreationMethod(Collection<TypeAbstraction> types) {
50+
// find the first one.
51+
for (TypeAbstraction typeAbstraction : types) {
52+
String methodName = findStreamCreationMethod(typeAbstraction);
4653

47-
for (TypeAbstraction typeAbstraction : possibleTypes) {
48-
if (typeAbstraction != TypeAbstraction.TOP) {
49-
Ordering ordering = inferOrdering(typeAbstraction, calledMethodName);
54+
if (methodName != null)
55+
return methodName;
56+
}
57+
// not found.
58+
return null;
59+
}
5060

51-
if (ret == null)
52-
ret = ordering;
53-
else if (ret != ordering) {
54-
throw new InconsistentPossibleOrderingException(
55-
"Types have inconsistent orderings: " + possibleTypes);
56-
}
57-
}
61+
private String findStreamCreationMethod(IClass type) {
62+
Collection<com.ibm.wala.classLoader.IMethod> allMethods = type.getAllMethods();
63+
for (com.ibm.wala.classLoader.IMethod method : allMethods) {
64+
TypeReference typeToCheck = Util.getEvaluationType(method);
65+
66+
// find the first one that returns a stream.
67+
if (Util.implementsBaseStream(typeToCheck, this.getClassHierarchy()))
68+
return method.getName().toString();
5869
}
5970

60-
return ret;
71+
return null;
72+
}
73+
74+
private String findStreamCreationMethod(TypeAbstraction typeAbstraction) {
75+
IClass type = typeAbstraction.getType();
76+
return findStreamCreationMethod(type);
77+
}
78+
79+
protected IClassHierarchy getClassHierarchy() {
80+
return classHierarchy;
81+
}
82+
83+
private Spliterator<?> getSpliterator(Object instance, String calledMethodName)
84+
throws CannotExtractSpliteratorException {
85+
Objects.requireNonNull(instance);
86+
Objects.requireNonNull(calledMethodName);
87+
88+
Spliterator<?> spliterator = null;
89+
90+
if (instance instanceof Iterable) {
91+
try {
92+
spliterator = ((Iterable<?>) instance).spliterator();
93+
} catch (NullPointerException e) {
94+
LOGGER.log(Level.WARNING, "Possible trouble creating instance (most likely private type).", e);
95+
return null;
96+
}
97+
} else {
98+
// try to call the stream() method to get the spliterator.
99+
BaseStream<?, ?> baseStream = null;
100+
try {
101+
Method streamCreationMethod = instance.getClass().getMethod(calledMethodName);
102+
Object stream = streamCreationMethod.invoke(instance);
103+
104+
if (stream instanceof BaseStream) {
105+
baseStream = (BaseStream<?, ?>) stream;
106+
spliterator = baseStream.spliterator();
107+
} else
108+
throw new CannotExtractSpliteratorException(
109+
"Returned object of type: " + stream.getClass() + " doesn't implement BaseStream.",
110+
stream.getClass());
111+
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
112+
| InvocationTargetException e) {
113+
throw new CannotExtractSpliteratorException(
114+
"Cannot extract the spliterator from object of type: " + instance.getClass(), e,
115+
instance.getClass());
116+
} finally {
117+
if (baseStream != null)
118+
baseStream.close();
119+
}
120+
}
121+
return spliterator;
61122
}
62123

63124
Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes) throws InconsistentPossibleOrderingException,
@@ -76,34 +137,31 @@ Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes) throws Inconsi
76137
}
77138
}
78139

79-
private String findStreamCreationMethod(Collection<TypeAbstraction> types) {
80-
// find the first one.
81-
for (TypeAbstraction typeAbstraction : types) {
82-
String methodName = findStreamCreationMethod(typeAbstraction);
83-
84-
if (methodName != null)
85-
return methodName;
86-
}
87-
// not found.
88-
return null;
140+
Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes, IMethod calledMethod)
141+
throws InconsistentPossibleOrderingException, NoniterableException, NoninstantiableException,
142+
CannotExtractSpliteratorException {
143+
return inferOrdering(possibleTypes, calledMethod.getElementName());
89144
}
90145

91-
private String findStreamCreationMethod(TypeAbstraction typeAbstraction) {
92-
IClass type = typeAbstraction.getType();
93-
return findStreamCreationMethod(type);
94-
}
146+
private Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes, String calledMethodName)
147+
throws InconsistentPossibleOrderingException, NoniterableException, NoninstantiableException,
148+
CannotExtractSpliteratorException {
149+
Ordering ret = null;
95150

96-
private String findStreamCreationMethod(IClass type) {
97-
Collection<com.ibm.wala.classLoader.IMethod> allMethods = type.getAllMethods();
98-
for (com.ibm.wala.classLoader.IMethod method : allMethods) {
99-
TypeReference typeToCheck = Util.getEvaluationType(method);
151+
for (TypeAbstraction typeAbstraction : possibleTypes) {
152+
if (typeAbstraction != TypeAbstraction.TOP) {
153+
Ordering ordering = inferOrdering(typeAbstraction, calledMethodName);
100154

101-
// find the first one that returns a stream.
102-
if (Util.implementsBaseStream(typeToCheck, this.getClassHierarchy()))
103-
return method.getName().toString();
155+
if (ret == null)
156+
ret = ordering;
157+
else if (ret != ordering) {
158+
throw new InconsistentPossibleOrderingException(
159+
"Types have inconsistent orderings: " + possibleTypes);
160+
}
161+
}
104162
}
105163

106-
return null;
164+
return ret;
107165
}
108166

109167
// TODO: Cache this?
@@ -150,60 +208,6 @@ private Ordering inferOrdering(String className, String calledMethodName)
150208
}
151209
}
152210

153-
private Object createInstance(Class<?> clazz) throws NoninstantiableException {
154-
try {
155-
return clazz.newInstance();
156-
} catch (InstantiationException | IllegalAccessException e) {
157-
ObjectInstantiator<?> instantiator = objenesis.getInstantiatorOf(clazz);
158-
try {
159-
return instantiator.newInstance();
160-
} catch (InstantiationError e2) {
161-
throw new NoninstantiableException(clazz + " cannot be instantiated: " + e2.getCause(), e2, clazz);
162-
}
163-
}
164-
}
165-
166-
private Spliterator<?> getSpliterator(Object instance, String calledMethodName)
167-
throws CannotExtractSpliteratorException {
168-
Objects.requireNonNull(instance);
169-
Objects.requireNonNull(calledMethodName);
170-
171-
Spliterator<?> spliterator = null;
172-
173-
if (instance instanceof Iterable) {
174-
try {
175-
spliterator = ((Iterable<?>) instance).spliterator();
176-
} catch (NullPointerException e) {
177-
LOGGER.log(Level.WARNING, "Possible trouble creating instance (most likely private type).", e);
178-
return null;
179-
}
180-
} else {
181-
// try to call the stream() method to get the spliterator.
182-
BaseStream<?, ?> baseStream = null;
183-
try {
184-
Method streamCreationMethod = instance.getClass().getMethod(calledMethodName);
185-
Object stream = streamCreationMethod.invoke(instance);
186-
187-
if (stream instanceof BaseStream) {
188-
baseStream = (BaseStream<?, ?>) stream;
189-
spliterator = baseStream.spliterator();
190-
} else
191-
throw new CannotExtractSpliteratorException(
192-
"Returned object of type: " + stream.getClass() + " doesn't implement BaseStream.",
193-
stream.getClass());
194-
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
195-
| InvocationTargetException e) {
196-
throw new CannotExtractSpliteratorException(
197-
"Cannot extract the spliterator from object of type: " + instance.getClass(), e,
198-
instance.getClass());
199-
} finally {
200-
if (baseStream != null)
201-
baseStream.close();
202-
}
203-
}
204-
return spliterator;
205-
}
206-
207211
private Ordering inferOrdering(TypeAbstraction type, String calledMethodName)
208212
throws NoniterableException, NoninstantiableException, CannotExtractSpliteratorException {
209213
TypeReference typeReference = type.getTypeReference();
@@ -215,8 +219,4 @@ private Ordering inferOrdering(TypeAbstraction type, String calledMethodName)
215219
String binaryName = Util.getBinaryName(typeReference);
216220
return inferOrdering(binaryName, calledMethodName);
217221
}
218-
219-
protected IClassHierarchy getClassHierarchy() {
220-
return classHierarchy;
221-
}
222222
}

0 commit comments

Comments
 (0)