This commit is contained in:
Lana Steuck 2015-02-12 16:38:39 -08:00
commit 86ab634dc1
9 changed files with 258 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015, 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
@ -236,7 +236,8 @@ public class DeferredAttr extends JCTree.Visitor {
DeferredStuckPolicy deferredStuckPolicy;
if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
deferredStuckPolicy = dummyStuckPolicy;
} else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) {
} else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE ||
resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) {
deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this);
} else {
deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2015, 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
@ -56,7 +56,7 @@ public class JavacMessages implements Messages {
private Map<Locale, SoftReference<List<ResourceBundle>>> bundleCache;
private List<String> bundleNames;
private List<ResourceBundleHelper> bundleHelpers;
private Locale currentLocale;
private List<ResourceBundle> currentBundles;
@ -91,7 +91,7 @@ public class JavacMessages implements Messages {
* @param bundleName the name to identify the resource bundle of localized messages.
*/
public JavacMessages(String bundleName, Locale locale) throws MissingResourceException {
bundleNames = List.nil();
bundleHelpers = List.nil();
bundleCache = new HashMap<>();
add(bundleName);
setCurrentLocale(locale);
@ -101,8 +101,13 @@ public class JavacMessages implements Messages {
this(defaultBundleName);
}
@Override
public void add(String bundleName) throws MissingResourceException {
bundleNames = bundleNames.prepend(bundleName);
add(locale -> ResourceBundle.getBundle(bundleName, locale));
}
public void add(ResourceBundleHelper ma) {
bundleHelpers = bundleHelpers.prepend(ma);
if (!bundleCache.isEmpty())
bundleCache.clear();
currentBundles = null;
@ -115,12 +120,13 @@ public class JavacMessages implements Messages {
List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
if (bundleList == null) {
bundleList = List.nil();
for (String bundleName : bundleNames) {
for (ResourceBundleHelper helper : bundleHelpers) {
try {
ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
ResourceBundle rb = helper.getResourceBundle(locale);
bundleList = bundleList.prepend(rb);
} catch (MissingResourceException e) {
throw new InternalError("Cannot find javac resource bundle for locale " + locale);
throw new InternalError("Cannot find requested resource bundle for locale " +
locale, e);
}
}
bundleCache.put(locale, new SoftReference<>(bundleList));
@ -134,6 +140,7 @@ public class JavacMessages implements Messages {
return getLocalizedString(currentLocale, key, args);
}
@Override
public String getLocalizedString(Locale l, String key, Object... args) {
if (l == null)
l = getCurrentLocale();
@ -146,8 +153,7 @@ public class JavacMessages implements Messages {
* easy access to simple localized strings.
*/
private static final String defaultBundleName =
"com.sun.tools.javac.resources.compiler";
private static final String defaultBundleName = "com.sun.tools.javac.resources.compiler";
private static ResourceBundle defaultBundle;
private static JavacMessages defaultMessages;
@ -198,4 +204,17 @@ public class JavacMessages implements Messages {
}
return MessageFormat.format(msg, args);
}
/**
* This provides a way for the JavacMessager to retrieve a
* ResourceBundle from another module such as jdk.javadoc.
*/
public interface ResourceBundleHelper {
/**
* Gets the ResourceBundle.
* @param locale the requested bundle's locale
* @return ResourceBundle
*/
ResourceBundle getResourceBundle(Locale locale);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -27,6 +27,7 @@ package com.sun.tools.javadoc;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.ResourceBundle;
import com.sun.javadoc.*;
import com.sun.tools.javac.util.Context;
@ -126,9 +127,11 @@ public class Messager extends Log implements DocErrorReporter {
PrintWriter noticeWriter) {
super(context, errWriter, warnWriter, noticeWriter);
messages = JavacMessages.instance(context);
messages.add("com.sun.tools.javadoc.resources.javadoc");
messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc",
locale));
javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
this.programName = programName;
}
public void setLocale(Locale locale) {

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8016081 8016178
* @bug 8016081 8016178 8069545
* @summary structural most specific and stuckness
* @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java
*/

View File

@ -1,2 +1,3 @@
T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int)
1 error
T8016177g.java:34:14: compiler.err.cant.apply.symbol: kindname.method, print, java.lang.String, Test.Person, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: Test.Person, java.lang.String,java.lang.Object))
T8016177g.java:35:20: compiler.err.cant.apply.symbol: kindname.method, abs, int, java.lang.Double, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , R, int))
2 errors

View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* @test
* @bug 8068399
* @summary structural most specific and stuckness
*/
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class T8068399 {
public static class Spectrum {
public double[] getEnergy() {
return new double[0];
}
}
protected Spectrum spectrum;
public static class Ref<T> {
T value;
public Ref() {
}
public Ref(T value) {
this.value = value;
}
public boolean isNull() {
return value == null;
}
public T get() {
return value;
}
public void set(T value) {
this.value = value;
}
}
public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) {
Ref<Double> max = new Ref<>();
Ref<T> index = new Ref<>();
stream.forEach(v -> {
Double value = function.apply(v);
if (max.isNull() || value > max.get()) {
max.set(value);
index.set(v);
}
});
return index.get();
}
public static int interpolate(int x, int x0, int x1, int y0, int y1) {
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
public static double interpolate(double x, double x0, double x1, double y0, double y1) {
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
protected int getXByFrequency(double frequency) {
return (int) Math.round(interpolate(frequency,
getMinSpectrumCoord(),
getMaxSpectrumCoord(),
0, getWidth()));
}
private int getWidth() {
return 0;
}
private double getMaxSpectrumCoord() {
return 0;
}
private double getMinSpectrumCoord() {
return 0;
}
void foo() {
int maxBpmIndex = 0;
int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(),
i -> Math.abs(spectrum.getEnergy()[i])));
}
public static void main(String [] args) {
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* @test
* @bug 8068430
* @summary structural most specific and stuckness
*/
import java.util.HashMap;
import java.util.Map;
public class T8068430 {
public static void main(String[] args) {
Map<Integer, String> mp = new HashMap<>();
mp.put(1, "a");
mp.put(2, "b");
mp.put(3, "c");
mp.put(4, "d");
System.out.println(mp.entrySet().stream().reduce(0,
(i, e) -> i + e.getKey(),
(i1, i2) -> i1 + i2));
}
}

View File

@ -0,0 +1,50 @@
/*
* @test /nodynamiccopyright/
* @bug 8071432
* @summary structural most specific and stuckness
* @compile/fail/ref=T8071432.out -XDrawDiagnostics T8071432.java
*/
import java.util.Arrays;
import java.util.Collection;
class T8071432 {
static class Point {
private double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double distance(Point p) {
return Math.sqrt((this.x - p.x) * (this.x - p.x) +
(this.y - p.y) * (this.y - p.y));
}
public double distance() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
public String toString() {
return "(" + x + ":" + y + ")";
}
}
public static void main(String[] args) {
Collection<Point> c = Arrays.asList(new Point(1.0, 0.1));
System.out.println("------- 1 ---------------");
System.out.println(c.stream().reduce(0.0,
(s, p) -> s += p.distance(), (d1, d2) -> 0));
}
}

View File

@ -0,0 +1,3 @@
T8071432.java:47:45: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double)))
T8071432.java:47:27: compiler.err.cant.apply.symbol: kindname.method, println, java.lang.Object, <any>, kindname.class, java.io.PrintStream, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double))))
2 errors