Java Code Examples for com.sun.tools.javac.util.Context#Factory

The following examples show how to use com.sun.tools.javac.util.Context#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentCollectingScannerFactory.java    From EasyMPermission with MIT License 5 votes vote down vote up
@SuppressWarnings("all")
public static void preRegister(final Context context) {
	if (context.get(scannerFactoryKey) == null) {
		// Careful! There is voodoo magic here!
		//
		// Context.Factory is parameterized. make() is for javac6 and below; make(Context) is for javac7 and up.
		// this anonymous inner class definition is intentionally 'raw' - the return type of both 'make' methods is 'T',
		// which means the compiler will only generate the correct "real" override method (with returntype Object, which is
		// the lower bound for T, as a synthetic accessor for the make with returntype ScannerFactory) for that make method which
		// is actually on the classpath (either make() for javac6-, or make(Context) for javac7+).
		//
		// We normally solve this issue via src/stubs, with BOTH make methods listed, but for some reason the presence of a stubbed out
		// Context (or even a complete copy, it doesn't matter) results in a really strange eclipse bug, where any mention of any kind
		// of com.sun.tools.javac.tree.TreeMaker in a source file disables ALL usage of 'go to declaration' and auto-complete in the entire
		// source file.
		//
		// Thus, in short:
		// * Do NOT parameterize the anonymous inner class literal.
		// * Leave the return types as 'j.l.Object'.
		// * Leave both make methods intact; deleting one has no effect on javac6- / javac7+, but breaks the other. Hard to test for.
		// * Do not stub com.sun.tools.javac.util.Context or any of its inner types, like Factory.
		@SuppressWarnings("all")
		class MyFactory implements Context.Factory {
			// This overrides the javac6- version of make.
			public Object make() {
				return new CommentCollectingScannerFactory(context);
			}
			
			// This overrides the javac7+ version.
			public Object make(Context c) {
				return new CommentCollectingScannerFactory(c);
			}
		}
		@SuppressWarnings("unchecked") Context.Factory<ScannerFactory> factory = new MyFactory();
		context.put(scannerFactoryKey, factory);
	}
}
 
Example 2
Source File: CommentCollectingScannerFactory.java    From EasyMPermission with MIT License 5 votes vote down vote up
@SuppressWarnings("all")
public static void preRegister(final Context context) {
	if (context.get(scannerFactoryKey) == null) {
		// Careful! There is voodoo magic here!
		//
		// Context.Factory is parameterized. make() is for javac6 and below; make(Context) is for javac7 and up.
		// this anonymous inner class definition is intentionally 'raw' - the return type of both 'make' methods is 'T',
		// which means the compiler will only generate the correct "real" override method (with returntype Object, which is
		// the lower bound for T, as a synthetic accessor for the make with returntype ScannerFactory) for that make method which
		// is actually on the classpath (either make() for javac6-, or make(Context) for javac7+).
		//
		// We normally solve this issue via src/stubs, with BOTH make methods listed, but for some reason the presence of a stubbed out
		// Context (or even a complete copy, it doesn't matter) results in a really strange eclipse bug, where any mention of any kind
		// of com.sun.tools.javac.tree.TreeMaker in a source file disables ALL usage of 'go to declaration' and auto-complete in the entire
		// source file.
		//
		// Thus, in short:
		// * Do NOT parameterize the anonymous inner class literal.
		// * Leave the return types as 'j.l.Object'.
		// * Leave both make methods intact; deleting one has no effect on javac6- / javac7+, but breaks the other. Hard to test for.
		// * Do not stub com.sun.tools.javac.util.Context or any of its inner types, like Factory.
		@SuppressWarnings("all")
		class MyFactory implements Context.Factory {
			// This overrides the javac6- version of make.
			public Object make() {
				return new CommentCollectingScannerFactory(context);
			}
			
			// This overrides the javac7+ version of make.
			public Object make(Context c) {
				return new CommentCollectingScannerFactory(c);
			}
		}
		
		@SuppressWarnings("unchecked") Context.Factory<Scanner.Factory> factory = new MyFactory();
		context.put(scannerFactoryKey, factory);
	}
}
 
Example 3
Source File: CommentCollectingScannerFactory.java    From EasyMPermission with MIT License 5 votes vote down vote up
@SuppressWarnings("all")
public static void preRegister(final Context context) {
	if (context.get(scannerFactoryKey) == null) {
		// Careful! There is voodoo magic here!
		//
		// Context.Factory is parameterized. make() is for javac6 and below; make(Context) is for javac7 and up.
		// this anonymous inner class definition is intentionally 'raw' - the return type of both 'make' methods is 'T',
		// which means the compiler will only generate the correct "real" override method (with returntype Object, which is
		// the lower bound for T, as a synthetic accessor for the make with returntype ScannerFactory) for that make method which
		// is actually on the classpath (either make() for javac6-, or make(Context) for javac7+).
		//
		// We normally solve this issue via src/stubs, with BOTH make methods listed, but for some reason the presence of a stubbed out
		// Context (or even a complete copy, it doesn't matter) results in a really strange eclipse bug, where any mention of any kind
		// of com.sun.tools.javac.tree.TreeMaker in a source file disables ALL usage of 'go to declaration' and auto-complete in the entire
		// source file.
		//
		// Thus, in short:
		// * Do NOT parameterize the anonymous inner class literal.
		// * Leave the return types as 'j.l.Object'.
		// * Leave both make methods intact; deleting one has no effect on javac6- / javac7+, but breaks the other. Hard to test for.
		// * Do not stub com.sun.tools.javac.util.Context or any of its inner types, like Factory.
		@SuppressWarnings("all")
		class MyFactory implements Context.Factory {
			// This overrides the javac6- version of make.
			public Object make() {
				return new CommentCollectingScannerFactory(context);
			}
			
			// This overrides the javac7+ version.
			public Object make(Context c) {
				return new CommentCollectingScannerFactory(c);
			}
		}
		@SuppressWarnings("unchecked") Context.Factory<ScannerFactory> factory = new MyFactory();
		context.put(scannerFactoryKey, factory);
	}
}