|
48 | 48 | import java.util.Map; |
49 | 49 | import java.util.Set; |
50 | 50 | import java.util.TreeSet; |
| 51 | +import java.util.concurrent.atomic.AtomicReference; |
51 | 52 |
|
52 | 53 | import org.autorefactor.util.IllegalArgumentException; |
53 | 54 | import org.autorefactor.util.IllegalStateException; |
@@ -367,6 +368,37 @@ public static boolean is(Statement statement, Class<? extends Statement> stmtCla |
367 | 368 | return as(statement, stmtClass) != null; |
368 | 369 | } |
369 | 370 |
|
| 371 | + /** |
| 372 | + * Casts the provided expression to an object of the provided type if type |
| 373 | + * matches. |
| 374 | + * |
| 375 | + * @param <T> the required expression type |
| 376 | + * @param expression the expression to cast |
| 377 | + * @return the provided expression as an object of the provided type if type |
| 378 | + * matches, null otherwise |
| 379 | + */ |
| 380 | + public static <T extends Expression> T as(Expression expression) { |
| 381 | + Class<T> theClass= getParameterizedClass(); |
| 382 | + |
| 383 | + if (theClass == null) { |
| 384 | + return null; |
| 385 | + } |
| 386 | + |
| 387 | + return as(expression, theClass); |
| 388 | + } |
| 389 | + |
| 390 | + private static <T extends Expression> Class<T> getParameterizedClass() { |
| 391 | + AtomicReference<T> ar= new AtomicReference<>(); |
| 392 | + String className = ar.getClass().getCanonicalName(); |
| 393 | + String elementClassName = className.replaceFirst("\\Ajava\\.util\\.concurrent\\.atomic\\.AtomicReference\\<(.*)\\>\\z", "\\1"); |
| 394 | + throw new NullPointerException("className " + className + " elementClassName " + elementClassName); |
| 395 | +// try { |
| 396 | +// return (Class<T>) Class.forName(elementClassName); |
| 397 | +// } catch (ClassNotFoundException e) { |
| 398 | +// return null; |
| 399 | +// } |
| 400 | + } |
| 401 | + |
370 | 402 | /** |
371 | 403 | * Casts the provided expression to an object of the provided type if type |
372 | 404 | * matches. |
@@ -1516,7 +1548,7 @@ public static boolean isHardCoded(final Expression expression) { |
1516 | 1548 | * @return Integer literal. |
1517 | 1549 | */ |
1518 | 1550 | public static Long integerLiteral(Expression input) { |
1519 | | - NumberLiteral contant= as(input, NumberLiteral.class); |
| 1551 | + NumberLiteral contant= as(input); |
1520 | 1552 | PrefixExpression negativeContant= as(input, PrefixExpression.class); |
1521 | 1553 |
|
1522 | 1554 | if (negativeContant != null && hasOperator(negativeContant, PrefixExpression.Operator.MINUS)) { |
|
0 commit comments