/* * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * From JEP 277, JDK-8085614 * * use site | API declaration site * context | not dep. ord. dep. term. dep. * +---------------------------------- * not dep. | N W W * | * ord. dep. | N N (2) W (4) * | * term. dep. | N N (3) W (5)
*/
publicclass Removal extends TestRunner { publicstaticvoid main(String... args) throws Exception {
Removal r = new Removal();
r.runTests(m -> new Object[] { Paths.get(m.getName()) });
r.report();
}
privatefinal ToolBox tb = new ToolBox(); privatefinal Path libSrc = Paths.get("lib").resolve("src"); privatefinal Path libClasses = Paths.get("lib").resolve("classes"); int testCount = 0;
/** * Options that may be used during compilation.
*/ enum Options { DEFAULT(),
XLINT_DEPRECATED("-Xlint:deprecation"),
XLINT_NO_REMOVAL("-Xlint:-removal");
/** * The kind of deprecation.
*/ enum DeprKind {
NONE("", null),
DEPRECATED("@Deprecated ", "compiler.warn.has.been.deprecated"),
REMOVAL("@Deprecated(forRemoval=true) ", "compiler.warn.has.been.deprecated.for.removal");
DeprKind(String anno, String warn) { this.anno = anno; this.warn = warn;
} final String anno; final String warn;
}
final String[] lib = { "package lib; public class Class {\n"
+ " public static void method() { }\n"
+ " @Deprecated public static void depMethod() { }\n"
+ " @Deprecated(forRemoval=true) public static void remMethod() { }\n"
+ " public static int field;\n"
+ " @Deprecated public static int depField;\n"
+ " @Deprecated(forRemoval=true) public static int remField;\n"
+ "}", "package lib; @Deprecated public class DepClass { }", "package lib; @Deprecated(forRemoval=true) public class RemClass { }"
};
/** * The kind of declaration to be referenced at the use site.
*/ enum RefKind { CLASS("lib.%s c;", "Class", "DepClass", "RemClass"),
METHOD("{ lib.Class.%s(); }", "method", "depMethod", "remMethod"),
FIELD("int i = lib.Class.%s;", "field", "depField", "remField");
privatefinal Map<DeprKind, String> fragments = new EnumMap<>(DeprKind.class);
}
/** * Get source code for a reference to a possibly-deprecated item declared in a library. * @param refKind the kind of element (class, method, field) being referenced * @param declDeprKind the kind of deprecation on the declaration of the item being referenced * @param useDeprKind the kind of deprecation enclosing the use site * @return
*/ static String getSource(RefKind refKind, DeprKind declDeprKind, DeprKind useDeprKind) { return"package p; "
+ useDeprKind.anno
+ "class Class { "
+ refKind.getFragment(declDeprKind)
+ " }";
}
privatestaticfinal String NO_OUTPUT = null;
public Removal() throws IOException { super(System.err);
initLib();
}
/* * Additional special case: * there should not be any warnings for any reference in a type-import statement.
*/
@Test publicvoid test_UseImports(Path base) throws IOException {
String source = "import lib.Class;\n"
+ "import lib.DepClass;\n"
+ "import lib.RemClass;\n"
+ "class C { }"; for (Options o : Options.values()) {
test(base, source, o, NO_OUTPUT);
}
}
/** * Compile source code with given options, and check for expected output. * The compilation is done twice, first against the library in source form, * and then again, against the compiled library. * @param base base working directory * @param source the source code to be compiled * @param options the options for the compilation * @param expectText the expected output, or NO_OUTPUT, if none expected. * @throws IOException if an error occurs during the compilation
*/ privatevoid test(Path base, String source, Options options, String expectText) throws IOException {
test(base.resolve("lib-source"), libSrc, source, options, expectText);
test(base.resolve("lib-classes"), libClasses, source, options, expectText);
}
/** * Compile source code with given options against a given version of the library, * and check for expected output. * @param base base working directory * @param lib the directory containing the library, in either source or compiled form * @param source the source code to be compiled * @param options the options for the compilation * @param expectText the expected output, or NO_OUTPUT, if none expected. * @throws IOException if an error occurs during the compilation
*/ privatevoid test(Path base, Path lib, String source, Options options, String expectText) throws IOException {
Expect expect = (expectText != null && expectText.contains("compiler.warn.")) ? Expect.FAIL : Expect.SUCCESS;
test(base, lib, source, options.opts, expect, expectText);
}
/** * Compile source code with given options against a given version of the library, * and check for expected exit code and expected output. * @param base base working directory * @param lib the directory containing the library, in either source or compiled form * @param source the source code to be compiled * @param options the options for the compilation * @param expect the expected outcome of the compilation * @param expectText the expected output, or NO_OUTPUT, if none expected. * @throws IOException if an error occurs during the compilation
*/ privatevoid test(Path base, Path lib, String source, List<String> options,
Expect expect, String expectText) throws IOException {
testCount++;
String log = new JavacTask(tb)
.outdir(classes)
.classpath(lib) // use classpath for libSrc or libClasses
.files(tb.findJavaFiles(src))
.options(allOptions.toArray(new String[0]))
.run(expect)
.writeAll()
.getOutput(OutputKind.DIRECT);
if (expectText == null) { if (!log.trim().isEmpty())
error("Unexpected text found: >>>" + log + "<<<");
} else { if (!log.contains(expectText))
error("expected text not found: >>>" + expectText + "<<<");
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.