1 /* |
1 /* |
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * |
3 * |
4 * Redistribution and use in source and binary forms, with or without |
4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions |
5 * modification, are permitted provided that the following conditions |
6 * are met: |
6 * are met: |
7 * |
7 * |
37 import javax.lang.model.util.*; |
37 import javax.lang.model.util.*; |
38 import java.lang.reflect.*; |
38 import java.lang.reflect.*; |
39 import java.io.Writer; |
39 import java.io.Writer; |
40 import java.util.*; |
40 import java.util.*; |
41 |
41 |
42 import static javax.lang.model.SourceVersion.RELEASE_8; |
42 import static javax.lang.model.SourceVersion.RELEASE_9; |
43 import static java.util.Objects.*; |
43 import static java.util.Objects.*; |
44 |
44 |
45 /** |
45 /** |
46 * This class provides a proof-of-concept implementation of the {@code |
46 * This class provides a proof-of-concept implementation of the {@code |
47 * javax.lang.model.*} API backed by core reflection. That is, rather |
47 * javax.lang.model.*} API backed by core reflection. That is, rather |
485 } |
485 } |
486 |
486 |
487 /** |
487 /** |
488 * Base class for concrete visitors of elements backed by core reflection. |
488 * Base class for concrete visitors of elements backed by core reflection. |
489 */ |
489 */ |
490 public static abstract class AbstractReflectionElementVisitor8<R, P> |
490 public static abstract class AbstractReflectionElementVisitor9<R, P> |
491 extends AbstractElementVisitor8<R, P> |
491 extends AbstractElementVisitor9<R, P> |
492 implements ReflectionElementVisitor<R, P> { |
492 implements ReflectionElementVisitor<R, P> { |
493 protected AbstractReflectionElementVisitor8() { |
493 protected AbstractReflectionElementVisitor9() { |
494 super(); |
494 super(); |
495 } |
495 } |
496 } |
496 } |
497 |
497 |
498 /** |
498 /** |
499 * Base class for simple visitors of elements that are backed by core reflection. |
499 * Base class for simple visitors of elements that are backed by core reflection. |
500 */ |
500 */ |
501 @SupportedSourceVersion(value=RELEASE_8) |
501 @SupportedSourceVersion(value=RELEASE_9) |
502 public static abstract class SimpleReflectionElementVisitor8<R, P> |
502 public static abstract class SimpleReflectionElementVisitor9<R, P> |
503 extends SimpleElementVisitor8<R, P> |
503 extends SimpleElementVisitor9<R, P> |
504 implements ReflectionElementVisitor<R, P> { |
504 implements ReflectionElementVisitor<R, P> { |
505 |
505 |
506 protected SimpleReflectionElementVisitor8(){ |
506 protected SimpleReflectionElementVisitor9(){ |
507 super(); |
507 super(); |
508 } |
508 } |
509 |
509 |
510 protected SimpleReflectionElementVisitor8(R defaultValue) { |
510 protected SimpleReflectionElementVisitor9(R defaultValue) { |
511 super(defaultValue); |
511 super(defaultValue); |
512 } |
512 } |
513 |
513 |
514 // Create manual "bridge methods" for now. |
514 // Create manual "bridge methods" for now. |
515 |
515 |
2525 Class<?> printProcClass = |
2525 Class<?> printProcClass = |
2526 ClassLoader.getSystemClassLoader().loadClass("com.sun.tools.javac.processing.PrintingProcessor$PrintingElementVisitor"); |
2526 ClassLoader.getSystemClassLoader().loadClass("com.sun.tools.javac.processing.PrintingProcessor$PrintingElementVisitor"); |
2527 Constructor<?> printProcCtor = printProcClass.getConstructor(Writer.class, Elements.class); |
2527 Constructor<?> printProcCtor = printProcClass.getConstructor(Writer.class, Elements.class); |
2528 return (ElementVisitor) printProcCtor.newInstance(w, getElements()); |
2528 return (ElementVisitor) printProcCtor.newInstance(w, getElements()); |
2529 } catch (ReflectiveOperationException | SecurityException e) { |
2529 } catch (ReflectiveOperationException | SecurityException e) { |
2530 return new ElementScanner8<Writer, Void>(w){ |
2530 return new ElementScanner9<Writer, Void>(w){ |
2531 @Override |
2531 @Override |
2532 public Writer scan(Element e, Void v) { |
2532 public Writer scan(Element e, Void v) { |
2533 try { |
2533 try { |
2534 DEFAULT_VALUE.append(e.toString()); |
2534 DEFAULT_VALUE.append(e.toString()); |
2535 DEFAULT_VALUE.append("\n"); |
2535 DEFAULT_VALUE.append("\n"); |