1 /* 2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.javac.main; 27 28 import java.nio.file.Path; 29 30 import com.sun.tools.javac.util.Log; 31 import com.sun.tools.javac.util.Log.PrefixKind; 32 33 /** 34 * Helper object to be used by {@link Option#process}, providing access to 35 * the compilation environment. 36 * 37 * <p><b>This is NOT part of any supported API. 38 * If you write code that depends on this, you do so at your own 39 * risk. This code and its internal interfaces are subject to change 40 * or deletion without notice.</b></p> 41 */ 42 43 public abstract class OptionHelper { 44 45 /** Get the current value of an option. */ 46 public abstract String get(Option option); 47 48 /** Set the value of an option. */ 49 public abstract void put(String name, String value); 50 51 /** Remove any prior value for an option. */ 52 public abstract void remove(String name); 53 54 /** Handle a file manager option. */ 55 public abstract boolean handleFileManagerOption(Option option, String value); 56 57 /** Get access to the Log for the compilation. */ 58 public abstract Log getLog(); 59 60 /** Get the name of the tool, such as "javac", to be used in info like -help. */ 61 public abstract String getOwnName(); 62 63 /** Report an error. */ 64 abstract void error(String key, Object... args); 65 66 /** Record a file to be compiled. */ 67 abstract void addFile(Path p); 68 69 /** Record the name of a class for annotation processing. */ 70 abstract void addClassName(String s); 71 72 /** An implementation of OptionHelper that mostly throws exceptions. */ 73 public static class GrumpyHelper extends OptionHelper { 74 private final Log log; 75 76 public GrumpyHelper(Log log) { 77 this.log = log; 78 } 79 80 @Override 81 public Log getLog() { 82 return log; 83 } 84 85 @Override 86 public String getOwnName() { 87 throw new IllegalStateException(); 88 } 89 90 @Override 91 public String get(Option option) { 92 throw new IllegalArgumentException(); 93 } 94 95 @Override 96 public void put(String name, String value) { 97 throw new IllegalArgumentException(); 98 } 99 100 @Override 101 public void remove(String name) { 102 throw new IllegalArgumentException(); 103 } 104 105 @Override 106 public boolean handleFileManagerOption(Option option, String value) { 107 throw new IllegalArgumentException(); 108 } 109 110 @Override 111 void error(String key, Object... args) { 112 throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args)); 113 } 114 115 @Override 116 public void addFile(Path p) { 117 throw new IllegalArgumentException(p.toString()); 118 } 119 120 @Override 121 public void addClassName(String s) { 122 throw new IllegalArgumentException(s); 123 } 124 } 125 126 }