diff options
147 files changed, 3642 insertions, 349 deletions
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java index 53ae29196c..846323b647 100644 --- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java +++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java @@ -83,7 +83,7 @@ import com.sun.mirror.util.Types; public class BaseProcessorEnv implements AnnotationProcessorEnvironment { static{ - final AST ast = AST.newAST(AST.JLS9); + final AST ast = AST.newAST(AST.JLS10); EMPTY_AST_UNIT = ast.newCompilationUnit(); } public static final CompilationUnit EMPTY_AST_UNIT; @@ -505,7 +505,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment } final BindingRequestor requestor = new BindingRequestor(); - final ASTParser parser = ASTParser.newParser(AST.JLS9); + final ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setResolveBindings(true); parser.setBindingsRecovery(true); parser.setProject(_javaProject); @@ -716,7 +716,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment if( astUnit != null ) return astUnit; else{ // Note: very expensive operation. we are re-compiling a file with binding information. - final ASTParser parser = ASTParser.newParser(AST.JLS9); + final ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setResolveBindings(true); parser.setBindingsRecovery(true); parser.setSource(unit); @@ -865,7 +865,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment String bogusKey = BindingKey.createTypeBindingKey("java.lang.Object"); //$NON-NLS-1$ String[] keys = new String[] {bogusKey}; - ASTParser p = ASTParser.newParser( AST.JLS9 ); + ASTParser p = ASTParser.newParser( AST.JLS10 ); p.setResolveBindings(true); p.setBindingsRecovery(true); p.setProject( javaProject ); @@ -895,7 +895,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment } CompilationUnitRequestor requestor = new CompilationUnitRequestor(); - ASTParser p = ASTParser.newParser( AST.JLS9 ); + ASTParser p = ASTParser.newParser( AST.JLS10 ); p.setResolveBindings(true); p.setBindingsRecovery(true); p.setProject( javaProject ); diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java index ba36acf4b3..167e252435 100644 --- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/ReadAnnotationTests2.java @@ -184,7 +184,7 @@ public class ReadAnnotationTests2 extends BuilderTests { } final BindingRequestor requestor = new BindingRequestor(); - final ASTParser parser = ASTParser.newParser(AST.JLS9); + final ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setResolveBindings(true); parser.setProject(javaProj); parser.setIgnoreMethodBodies(true); diff --git a/org.eclipse.jdt.compiler.apt.tests/.classpath b/org.eclipse.jdt.compiler.apt.tests/.classpath index 2dc14fa091..df856ce433 100644 --- a/org.eclipse.jdt.compiler.apt.tests/.classpath +++ b/org.eclipse.jdt.compiler.apt.tests/.classpath @@ -4,7 +4,7 @@ <classpathentry kind="src" output="binprocessors" path="processors"/> <classpathentry kind="src" output="binprocessors8" path="processors8"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="lib" path="java9/java9api.jar"/> + <classpathentry kind="lib" path="java10/java10api.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.jdt.compiler.apt.tests/build.properties b/org.eclipse.jdt.compiler.apt.tests/build.properties index 7df12f4db2..02efcb0107 100644 --- a/org.eclipse.jdt.compiler.apt.tests/build.properties +++ b/org.eclipse.jdt.compiler.apt.tests/build.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2006, 2017 BEA Systems Inc. and others +# Copyright (c) 2006, 2018 BEA Systems Inc. and others # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -20,9 +20,9 @@ bin.includes = about.html,\ test.xml,\ META-INF/,\ resources/,\ - java9/,\ + java10/,\ lib/,\ . src.includes = about.html compilerArg=-proc:none -jars.extra.classpath = java9/java9api.jar +jars.extra.classpath = java10/java10api.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar b/org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar Binary files differnew file mode 100644 index 0000000000..464b69134f --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/java10/java10api.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar b/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar Binary files differdeleted file mode 100644 index fd56ad100e..0000000000 --- a/org.eclipse.jdt.compiler.apt.tests/java9/java9api.jar +++ /dev/null diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar Binary files differindex 1e01a671f2..121c0dbeb0 100644 --- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar +++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java index b8aa884386..4eabf11976 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java @@ -160,6 +160,7 @@ public class ArgsConstructorProcessor extends BaseProcessor { return false; } + @SuppressWarnings("deprecation") private final TypeVisitor<Boolean, List<TypeMirror>> argsVisitor = new SimpleTypeVisitor6<Boolean, List<TypeMirror>>() { @Override public Boolean visitExecutable(ExecutableType t, diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/visitors/VisitorProc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/visitors/VisitorProc.java index fb387cacb2..591e3c80a6 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/visitors/VisitorProc.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/visitors/VisitorProc.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 BEA Systems, Inc. + * Copyright (c) 2007, 2018 BEA Systems, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -47,6 +47,7 @@ public class VisitorProc extends BaseProcessor * This visitor is invoked on the top-level types in resources/targets/model. * We expect to see each of the visitX() methods get hit as a result. */ + @SuppressWarnings("deprecation") private static class ElementVisitorTester extends ElementScanner6<Void, Void> { public enum Visited { TYPE, EXECUTABLE, VARIABLE, TYPEPARAM, PACKAGE, UNKNOWN } @@ -129,6 +130,7 @@ public class VisitorProc extends BaseProcessor /* * The specific values checked by this visitor correspond to values in targets.model.pc.TypedAnnos.java */ + @SuppressWarnings("deprecation") private static class AnnotationVisitorTester extends AbstractAnnotationValueVisitor6<Void, Void> { public enum Visited { ANNOTATION, ARRAY, BOOLEAN, BYTE, CHAR, DOUBLE, ENUMCONSTANT, FLOAT, INT, LONG, SHORT, STRING, TYPE } diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java index 886054b020..8310874eba 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation. + * Copyright (c) 2017, 2018 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -45,6 +45,7 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor; +import org.eclipse.jdt.compiler.apt.tests.processors.util.TestDirectiveVisitor; /** * A processor that explores the java 9 specific elements and validates the lambda and @@ -674,6 +675,76 @@ public class Java9ElementProcessor extends BaseProcessor { } } + public void testDirectiveVisitor() { + ModuleElement mod = _elementUtils.getModuleElement("mod.b"); + assertNotNull("mod.b module null", mod); + try { + TestDirectiveVisitor<Object, Object> t = new TestDirectiveVisitor<>(); + List<? extends Directive> directives = mod.getDirectives(); + for (Directive directive : directives) { + Object result = t.visit(directive); + assertSame("Objects should be same", result, directive); + } + + } catch (SecurityException e) { + e.printStackTrace(); + } + } + public void testTypesImpl() { + ModuleElement mod = _elementUtils.getModuleElement("mod.a"); + Set<? extends TypeElement> typeElements = _elementUtils.getAllTypeElements("abc.internal.A"); + assertNotNull("mod.b module null", mod); + assertNotNull("Type should not be null", typeElements); + assertEquals("Incorrect no of types", 1, typeElements.size()); + TypeElement tElement = null; + for (TypeElement typeElement : typeElements) { + tElement = typeElement; + } + assertNotNull("Package should not be null", tElement); + TypeMirror t = tElement.asType(); + boolean exception = false; + try { + _typeUtils.erasure(mod.asType()); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + exception = false; + try { + _typeUtils.capture(mod.asType()); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + exception = false; + try { + _typeUtils.directSupertypes(mod.asType()); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + exception = false; + try { + _typeUtils.isSubtype(mod.asType(), t); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + exception = false; + try { + _typeUtils.isAssignable(mod.asType(), t); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + exception = false; + try { + _typeUtils.contains(mod.asType(), t); + } catch(IllegalArgumentException iae) { + exception = true; + } + assertTrue("Exception not thrown", exception); + } private void validateModifiers(ExecutableElement method, Modifier[] expected) { Set<Modifier> modifiers = method.getModifiers(); List<Modifier> list = new ArrayList<>(modifiers); diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/util/TestDirectiveVisitor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/util/TestDirectiveVisitor.java new file mode 100644 index 0000000000..82e43ee440 --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/util/TestDirectiveVisitor.java @@ -0,0 +1,32 @@ +package org.eclipse.jdt.compiler.apt.tests.processors.util; + +import javax.lang.model.element.ModuleElement.*; + +public class TestDirectiveVisitor<R, P> implements DirectiveVisitor<Object, Object> { + + @Override + public Object visitExports(ExportsDirective arg0, Object arg1) { + return arg0; + } + + @Override + public Object visitOpens(OpensDirective arg0, Object arg1) { + return arg0; + } + + @Override + public Object visitProvides(ProvidesDirective arg0, Object arg1) { + return arg0; + } + + @Override + public Object visitRequires(RequiresDirective arg0, Object arg1) { + return arg0; + } + + @Override + public Object visitUses(UsesDirective arg0, Object arg1) { + return arg0; + } + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java index fb57fea7b3..6a048807a7 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation. + * Copyright (c) 2017, 2018 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -371,7 +371,14 @@ public class Java9ElementsTests extends TestCase { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); internalTestWithBinary(compiler, MODULE_PROC, "9", "testBug521723", null, "bug521723"); } - + public void testDirectiveVisitorJavac() throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + internalTest2(compiler, MODULE_PROC, "testDirectiveVisitor", null); + } + public void testTypesImpl() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + internalTest2(compiler, MODULE_PROC, "testTypesImpl", null); + } protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException { if (!canRunJava9()) { return; diff --git a/org.eclipse.jdt.compiler.apt/build.properties b/org.eclipse.jdt.compiler.apt/build.properties index cb4935b695..62b759607f 100644 --- a/org.eclipse.jdt.compiler.apt/build.properties +++ b/org.eclipse.jdt.compiler.apt/build.properties @@ -19,4 +19,4 @@ jars.compile.order = . output.. = bin/ source.. = src/ -jars.extra.classpath = lib/java9api.jar +jars.extra.classpath = lib/java10api.jar diff --git a/org.eclipse.jdt.compiler.apt/lib/java10api.jar b/org.eclipse.jdt.compiler.apt/lib/java10api.jar Binary files differnew file mode 100644 index 0000000000..464b69134f --- /dev/null +++ b/org.eclipse.jdt.compiler.apt/lib/java10api.jar diff --git a/org.eclipse.jdt.compiler.apt/lib/java9api.jar b/org.eclipse.jdt.compiler.apt/lib/java9api.jar Binary files differdeleted file mode 100644 index fd56ad100e..0000000000 --- a/org.eclipse.jdt.compiler.apt/lib/java9api.jar +++ /dev/null diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java index 1a9a941de9..bf98ea31a1 100644 --- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java +++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java @@ -221,7 +221,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement { @Override public <R, P> R accept(DirectiveVisitor<R, P> visitor, P param) { - return visitor.visit(this); + return visitor.visitExports(this, param); } @Override @@ -254,7 +254,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement { @Override public <R, P> R accept(DirectiveVisitor<R, P> visitor, P param) { - return visitor.visit(this); + return visitor.visitRequires(this, param); } @Override @@ -287,7 +287,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement { @Override public <R, P> R accept(DirectiveVisitor<R, P> visitor, P param) { - return visitor.visit(this); + return visitor.visitOpens(this, param); } @Override @@ -312,7 +312,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement { @Override public <R, P> R accept(DirectiveVisitor<R, P> visitor, P param) { - return visitor.visit(this); + return visitor.visitUses(this, param); } @Override @@ -338,7 +338,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement { @Override public <R, P> R accept(DirectiveVisitor<R, P> visitor, P param) { - return visitor.visit(this); + return visitor.visitProvides(this, param); } @Override diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypesImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypesImpl.java index 13f27dbde6..faccb366aa 100644 --- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypesImpl.java +++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/TypesImpl.java @@ -220,6 +220,21 @@ public class TypesImpl implements Types { return null; } + private void validateRealType(TypeMirror t) { + switch (t.getKind()) { + case EXECUTABLE: + case PACKAGE: + case MODULE: + throw new IllegalArgumentException( + "Executable, package and module are illegal argument for Types.contains(..)"); //$NON-NLS-1$ + default: + break; + } + } + private void validateRealTypes(TypeMirror t1, TypeMirror t2) { + validateRealType(t1); + validateRealType(t2); + } @Override public TypeElement boxedClass(PrimitiveType p) { @@ -231,37 +246,23 @@ public class TypesImpl implements Types { @Override public TypeMirror capture(TypeMirror t) { - throw new UnsupportedOperationException("NYI: TypesImpl.capture(...)"); //$NON-NLS-1$ + validateRealType(t); + TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) t; + if (typeMirrorImpl._binding instanceof ParameterizedTypeBinding) { + throw new UnsupportedOperationException("NYI: TypesImpl.capture(...)"); //$NON-NLS-1$ + } + return t; } @Override public boolean contains(TypeMirror t1, TypeMirror t2) { - switch(t1.getKind()) { - case EXECUTABLE : - case PACKAGE : - throw new IllegalArgumentException("Executable and package are illegal argument for Types.contains(..)"); //$NON-NLS-1$ - default: - break; - } - switch(t2.getKind()) { - case EXECUTABLE : - case PACKAGE : - throw new IllegalArgumentException("Executable and package are illegal argument for Types.contains(..)"); //$NON-NLS-1$ - default: - break; - } + validateRealTypes(t1, t2); throw new UnsupportedOperationException("NYI: TypesImpl.contains(" + t1 + ", " + t2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @Override public List<? extends TypeMirror> directSupertypes(TypeMirror t) { - switch(t.getKind()) { - case PACKAGE : - case EXECUTABLE : - throw new IllegalArgumentException("Invalid type mirror for directSupertypes"); //$NON-NLS-1$ - default: - break; - } + validateRealType(t); TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) t; Binding binding = typeMirrorImpl._binding; if (binding instanceof ReferenceBinding) { @@ -281,6 +282,7 @@ public class TypesImpl implements Types { @Override public TypeMirror erasure(TypeMirror t) { + validateRealType(t); TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) t; Binding binding = typeMirrorImpl._binding; if (binding instanceof ReferenceBinding) { @@ -455,8 +457,9 @@ public class TypesImpl implements Types { */ @Override public boolean isAssignable(TypeMirror t1, TypeMirror t2) { + validateRealTypes(t1, t2); if (!(t1 instanceof TypeMirrorImpl) || !(t2 instanceof TypeMirrorImpl)) { - return false; + return false; } Binding b1 = ((TypeMirrorImpl)t1).binding(); Binding b2 = ((TypeMirrorImpl)t2).binding(); @@ -474,6 +477,14 @@ public class TypesImpl implements Types { @Override public boolean isSameType(TypeMirror t1, TypeMirror t2) { + if (t1 instanceof NoTypeImpl) { + if (t2 instanceof NoTypeImpl) { + return ((NoTypeImpl) t1).getKind() == ((NoTypeImpl) t2).getKind(); + } + return false; + } else if (t2 instanceof NoTypeImpl) { + return false; + } if (t1.getKind() == TypeKind.WILDCARD || t2.getKind() == TypeKind.WILDCARD) { // Wildcard types are never equal, according to the spec of this method return false; @@ -514,6 +525,7 @@ public class TypesImpl implements Types { */ @Override public boolean isSubtype(TypeMirror t1, TypeMirror t2) { + validateRealTypes(t1, t2); if (t1 instanceof NoTypeImpl) { if (t2 instanceof NoTypeImpl) { return ((NoTypeImpl) t1).getKind() == ((NoTypeImpl) t2).getKind(); @@ -523,7 +535,7 @@ public class TypesImpl implements Types { return false; } if (!(t1 instanceof TypeMirrorImpl) || !(t2 instanceof TypeMirrorImpl)) { - return false; + throw new IllegalArgumentException(); } if (t1 == t2) { return true; @@ -535,7 +547,7 @@ public class TypesImpl implements Types { } if (!(b1 instanceof TypeBinding) || !(b2 instanceof TypeBinding)) { // package, method, import, etc. - return false; + throw new IllegalArgumentException(); } if (b1.kind() == Binding.BASE_TYPE || b2.kind() == Binding.BASE_TYPE) { if (b1.kind() != b2.kind()) { diff --git a/org.eclipse.jdt.compiler.tool.tests/.classpath b/org.eclipse.jdt.compiler.tool.tests/.classpath index 2ae2e50653..a3b97caae2 100644 --- a/org.eclipse.jdt.compiler.tool.tests/.classpath +++ b/org.eclipse.jdt.compiler.tool.tests/.classpath @@ -2,7 +2,7 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="lib" path="lib/java9api.jar"/> + <classpathentry kind="lib" path="lib/java10api.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.jdt.compiler.tool.tests/build.properties b/org.eclipse.jdt.compiler.tool.tests/build.properties index 38fab73cd8..8c8d905889 100644 --- a/org.eclipse.jdt.compiler.tool.tests/build.properties +++ b/org.eclipse.jdt.compiler.tool.tests/build.properties @@ -1,5 +1,9 @@ ############################################################################### +<<<<<<< HEAD # Copyright (c) 2000, 2017 IBM Corporation and others. +======= +# Copyright (c) 2000, 2018 IBM Corporation and others. +>>>>>>> origin/R4_7_maintenance # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -13,9 +17,9 @@ bin.includes = META-INF/,\ about.html,\ plugin.properties,\ test.xml,\ - lib/java9api.jar,\ + lib/java10api.jar,\ . src.includes = about.html source.. = src/ output.. = bin/ -jars.extra.classpath = lib/java9api.jar +jars.extra.classpath = lib/java10api.jar diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar Binary files differnew file mode 100644 index 0000000000..464b69134f --- /dev/null +++ b/org.eclipse.jdt.compiler.tool.tests/lib/java10api.jar diff --git a/org.eclipse.jdt.compiler.tool.tests/lib/java9api.jar b/org.eclipse.jdt.compiler.tool.tests/lib/java9api.jar Binary files differdeleted file mode 100644 index fd56ad100e..0000000000 --- a/org.eclipse.jdt.compiler.tool.tests/lib/java9api.jar +++ /dev/null diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.one/module-info.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.one/module-info.java new file mode 100644 index 0000000000..c73cd45d40 --- /dev/null +++ b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.one/module-info.java @@ -0,0 +1,2 @@ +module module.one { +} diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.two/module-info.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.two/module-info.java new file mode 100644 index 0000000000..5ef97b0912 --- /dev/null +++ b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/source/SimpleModules/module.two/module-info.java @@ -0,0 +1,2 @@ +module module.two { +}
\ No newline at end of file diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java index 364af2dccd..0fadc35aff 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java @@ -166,8 +166,10 @@ public class CompilerToolJava9Tests extends TestCase { for(int i = 0; i < 2; i++) { String cName = this.compilerNames[i]; JavaCompiler compiler = this.compilers[i]; + if (!(compiler instanceof EclipseCompiler)) + continue; StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); - Path path = Paths.get(modules_directory + File.separator + "SimpleModules"); + Path path = Paths.get(modules_directory + File.separator + "source" + File.separator + "SimpleModules"); manager.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(path)); try { JavaFileManager.Location location = manager.getLocationForModule(StandardLocation.MODULE_PATH, "module.two"); @@ -183,8 +185,10 @@ public class CompilerToolJava9Tests extends TestCase { for(int i = 0; i < 2; i++) { String cName = this.compilerNames[i]; JavaCompiler compiler = this.compilers[i]; + if (!(compiler instanceof EclipseCompiler)) + continue; StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); - Path path = Paths.get(modules_directory + File.separator + "SimpleModules" + File.separator + "module.one"); + Path path = Paths.get(modules_directory + File.separator + "source" + File.separator + "SimpleModules"); manager.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(path)); try { JavaFileManager.Location location = manager.getLocationForModule(StandardLocation.MODULE_PATH, "module.one"); diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java index e5ea3bf24c..4bb9cb023f 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java @@ -465,7 +465,7 @@ static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { } assertNotNull("No reader", reader); // This needs fix. This test case by design will produce different output every compiler version. - assertEquals("Wrong value", ClassFileConstants.JDK9, reader.getVersion()); + assertEquals("Wrong value", ClassFileConstants.JDK10, reader.getVersion()); // check that the .class file exist for X assertTrue("delete failed", inputFile.delete()); } diff --git a/org.eclipse.jdt.compiler.tool/.classpath b/org.eclipse.jdt.compiler.tool/.classpath index 2ae2e50653..a3b97caae2 100644 --- a/org.eclipse.jdt.compiler.tool/.classpath +++ b/org.eclipse.jdt.compiler.tool/.classpath @@ -2,7 +2,7 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="lib" path="lib/java9api.jar"/> + <classpathentry kind="lib" path="lib/java10api.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.jdt.compiler.tool/build.properties b/org.eclipse.jdt.compiler.tool/build.properties index 5158a97629..fbdbd84368 100644 --- a/org.eclipse.jdt.compiler.tool/build.properties +++ b/org.eclipse.jdt.compiler.tool/build.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2017 IBM Corporation and others. +# Copyright (c) 2000, 2018 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -15,6 +15,6 @@ bin.includes = META-INF/,\ .,\ about.html,\ compiler_tool_fragment.properties,\ - lib/java9api.jar + lib/java10api.jar src.includes = about.html -jars.extra.classpath = lib/java9api.jar
\ No newline at end of file +jars.extra.classpath = lib/java10api.jar
\ No newline at end of file diff --git a/org.eclipse.jdt.compiler.tool/lib/java10api.jar b/org.eclipse.jdt.compiler.tool/lib/java10api.jar Binary files differnew file mode 100644 index 0000000000..464b69134f --- /dev/null +++ b/org.eclipse.jdt.compiler.tool/lib/java10api.jar diff --git a/org.eclipse.jdt.compiler.tool/lib/java9api.jar b/org.eclipse.jdt.compiler.tool/lib/java9api.jar Binary files differdeleted file mode 100644 index fd56ad100e..0000000000 --- a/org.eclipse.jdt.compiler.tool/lib/java9api.jar +++ /dev/null diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java index beb7ac3eba..db2e952a58 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java @@ -115,9 +115,9 @@ public class EclipseCompiler implements JavaCompiler { eclipseCompiler2.fileManager = this.getStandardFileManager(someDiagnosticListener, null, null); } - eclipseCompiler2.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); - eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); - eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + eclipseCompiler2.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); ArrayList<String> allOptions = new ArrayList<>(); if (options != null) { diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java index 3c01679ac1..32f35b3098 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java @@ -1351,9 +1351,9 @@ public class EclipseFileManager implements StandardJavaFileManager { Map<String, String> options = new HashMap<>(); // FIXME: Find a way to get the options from the EclipseCompiler and pass it to the parser. // FIXME: need to be the latest and not hardcoded value - options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); - options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); - options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); CompilerOptions compilerOptions = new CompilerOptions(options); ProblemReporter problemReporter = new ProblemReporter( diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java index 9daf6b44df..0d7d5fe969 100644 --- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java +++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java @@ -135,7 +135,13 @@ public void test002() throws JavaModelException { "@TestAnnotation package testcase;" //$NON-NLS-1$ ); incrementalBuild(projectPath); - expectingNoProblems(); + String javaVersion = System.getProperty("java.version"); + if (javaVersion != null && JavaCore.compareJavaVersions(javaVersion, "9") >= 0) { + expectingProblemsFor(new Path("/Project/src/testcase/Main.java"), + "Problem : The method getPackage(String) from the type Package is deprecated [ resource : </Project/src/testcase/Main.java> range : <125,147> category : <110> severity : <1>]"); + } else { + expectingNoProblems(); + } executeClass(projectPath, "testcase.Main", "@testcase.TestAnnotation()@testcase.TestAnnotation()", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } public void test003() throws JavaModelException { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest10.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest10.java new file mode 100644 index 0000000000..04b6998bbd --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest10.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - contributions for: + * Bug 531046: [10] ICodeAssist#codeSelect support for 'var' + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.core.JavaModelException; + +import junit.framework.Test; + +public class SelectionParserTest10 extends AbstractSelectionTest { + static { + // TESTS_NUMBERS = new int[] { 1 }; + // TESTS_NAMES = new String[] { "test001" }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(SelectionParserTest10.class, F_10); + } + + public SelectionParserTest10(String testName) { + super(testName); + } + + public void test001() throws JavaModelException { + String string = "public class X {\n" + + " public static void main(String[] args) {\n" + + " var s_s = args[0];\n" + + " }\n" + + "}\n"; + + String selection = "s_s"; + String expectedSelection = "<SelectionOnLocalName:var s_s = args[0]>;"; + + String completionIdentifier = "s_s"; + String expectedUnitDisplayString = "public class X {\n" + + " public X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " <SelectionOnLocalName:var s_s = args[0]>;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "s_s"; + String testName = "X.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString, + completionIdentifier, expectedReplacedSource, testName); + } + + public void test002() throws JavaModelException { + String string = "public class X {\n" + + " public static void main(String[] args) {\n" + + " var s_s = args[0];\n" + + " }\n" + + "}\n"; + + String selection = "var"; + String expectedSelection = "<SelectOnType:var>"; + + String completionIdentifier = "var"; + String expectedUnitDisplayString = "public class X {\n" + + " public X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " <SelectOnType:var> s_s = args[0];\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "var"; + String testName = "X.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString, + completionIdentifier, expectedReplacedSource, testName); + } +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java index d67c64bb8a..b95f46e47d 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,16 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - Contributions for + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.parser; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.core.tests.compiler.regression.JEP286ReservedWordTest; import org.eclipse.jdt.core.tests.junit.extension.TestCase; import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -136,6 +140,26 @@ public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) { TestCase.RUN_ONLY_ID = null; all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK9, tests_9)); } + if ((possibleComplianceLevels & AbstractCompilerTest.F_10) != 0) { + ArrayList tests_10 = (ArrayList)testClasses.clone(); + tests_10.addAll(TEST_CLASSES_1_5); + tests_10.add(ParserTest1_7.class); + tests_10.add(LambdaExpressionSyntaxTest.class); + tests_10.add(ReferenceExpressionSyntaxTest.class); + tests_10.add(TypeAnnotationSyntaxTest.class); + tests_10.add(CompletionParserTest18.class); + tests_10.add(SelectionParserTest18.class); + tests_10.add(SelectionParserTest9.class); + tests_10.add(ModuleDeclarationSyntaxTest.class); + tests_10.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK9, tests_10)); + } return all; } public static Test suite() { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 03b3e57b8f..604875066a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -247,6 +247,8 @@ static class JavacCompiler { this.version = JavaCore.VERSION_1_8; } else if(rawVersion.startsWith("9")) { this.version = JavaCore.VERSION_9; + } else if(rawVersion.startsWith("10")) { + this.version = JavaCore.VERSION_10; } else { throw new RuntimeException("unknown javac version: " + rawVersion); } @@ -351,6 +353,9 @@ static class JavacCompiler { return 0100; } } + if (version == JavaCore.VERSION_10) { + return 0000; // We are still in EA + } throw new RuntimeException("unknown raw javac version: " + rawVersion); } // returns 0L if everything went fine; else the lower word contains the @@ -1102,6 +1107,8 @@ protected static class JavacTestOptions { buffer.append("\" -1.8 " + processAnnot); } else if (this.complianceLevel == ClassFileConstants.JDK9) { buffer.append("\" -9 " + processAnnot); + } else if (this.complianceLevel == ClassFileConstants.JDK10) { + buffer.append("\" -10 " + processAnnot); } buffer .append(" -preserveAllLocals -proceedOnError -nowarn -g -classpath \"") diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java index 1df5c5718b..b6258bf59a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java @@ -10314,7 +10314,7 @@ public void testBug365437b() { "----------\n"; INameEnvironment save = this.javaClassLib; try { - if (isJRE9) { + if (isJRE9Plus) { List<String> limitModules = Arrays.asList("java.se", "java.xml.ws.annotation"); this.javaClassLib = new CustomFileSystem(limitModules); } @@ -10864,7 +10864,7 @@ public void _testBug386356_1() { public void testBug386356_2() { INameEnvironment save = this.javaClassLib; try { - if (isJRE9) { + if (isJRE9Plus) { List<String> limitModules = Arrays.asList("java.se", "java.xml.bind"); this.javaClassLib = new CustomFileSystem(limitModules); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index ed850ab645..bdaf044fa9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -12580,7 +12580,7 @@ public void test385780_warn_option() { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=405225 public void test405225_extdirs() { - if (AbstractCompilerTest.isJRE9) + if (AbstractCompilerTest.isJRE9Plus) return; this.runConformTest( new String[] { @@ -13085,7 +13085,7 @@ public void testReleaseOption() throws Exception { } public void testBug531579() throws Exception { - if (!isJRE9) return; + if (!isJRE9Plus) return; // these types replace inaccessible types from JRE/javax.xml.bind: runConformTest(new String[] { "src/javax/xml/bind/JAXBContext.java", diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index 76cc4ee9f9..8563f7414b 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -43,6 +43,7 @@ * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration * bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable * bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -1150,6 +1151,20 @@ public void test011_problem_categories() { expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionModule", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionPackage", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("VarIsNotAllowedHere", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarIsReserved", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarIsReservedInFuture", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArray", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArrayInitalizers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalCannotBeLambda", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalCannotBeMethodReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalInitializedToNull", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalInitializedToVoid", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalMultipleDeclarators", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalReferencesItself", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArray", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalWithoutInitizalier", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("VarargsElementTypeNotVisible", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("VarargsElementTypeNotVisibleForConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("VarargsConflict", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -2070,6 +2085,19 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("IllegalArrayOfUnionType", SKIP); expectedProblemAttributes.put("IllegalArrayTypeInIntersectionCast", SKIP); expectedProblemAttributes.put("ProblemNotAnalysed", SKIP); + expectedProblemAttributes.put("VarIsNotAllowedHere", SKIP); + expectedProblemAttributes.put("VarIsReserved", SKIP); + expectedProblemAttributes.put("VarIsReservedInFuture", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeArray", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeArrayInitalizers", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeLambda", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeMethodReference", SKIP); + expectedProblemAttributes.put("VarLocalInitializedToNull", SKIP); + expectedProblemAttributes.put("VarLocalInitializedToVoid", SKIP); + expectedProblemAttributes.put("VarLocalMultipleDeclarators", SKIP); + expectedProblemAttributes.put("VarLocalReferencesItself", SKIP); + expectedProblemAttributes.put("VarLocalTooManyBrackets", SKIP); + expectedProblemAttributes.put("VarLocalWithoutInitizalier", SKIP); Map constantNamesIndex = new HashMap(); Field[] fields = JavaCore.class.getFields(); for (int i = 0, length = fields.length; i < length; i++) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java index 551a059714..23ec58c797 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java @@ -40281,7 +40281,7 @@ public void test1151() throws Exception { "}\n" }, //"java.lang.ref.Reference<X<java.lang.String>.Other<java.lang.Thread>.Deeply>##java.lang.ref.Reference<X<java.lang.String>.Other<java.lang.Thread>.Deeply$Inside<java.lang.Number>>" - (isJRE9 + (isJRE9Plus ? "java.lang.ref.Reference<X<java.lang.String>$Other<java.lang.Thread>$Deeply>" : "java.lang.ref.Reference<X<java.lang.String>.Other<java.lang.Thread>.Deeply>") ); @@ -40397,7 +40397,7 @@ public void test1153() { "}\n" }, "java.lang.ref.Reference<p.X$Rather$Deeply>##java.lang.ref.Reference<p.X$Rather>##java.lang.ref.Reference<p.X$Rather$Deeply$Inside>##"+ - (isJRE9 + (isJRE9Plus ? "java.lang.ref.Reference<p.X<java.lang.String>$Other<java.lang.Thread>$Deeply>" : "java.lang.ref.Reference<p.X<java.lang.String>.Other<java.lang.Thread>.Deeply>"), null, @@ -40479,7 +40479,7 @@ public void test1155() throws Exception { " }\n" + "}\n" }, - (isJRE9 + (isJRE9Plus ? "java.lang.ref.Reference<X<java.lang.String>$Other<java.lang.Thread>$Deeply>" : "java.lang.ref.Reference<X<java.lang.String>.Other<java.lang.Thread>.Deeply>") ); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java new file mode 100644 index 0000000000..354723e13a --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2018 Jesper Steen Møller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * Jesper Steen Møller - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; + +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class JEP286ReservedWordTest extends AbstractRegressionTest { + +public static Class testClass() { + return JEP286ReservedWordTest.class; +} +public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public JEP286ReservedWordTest(String testName){ + super(testName); +} + +public void test0001_class_var_warning() throws IOException { + String classVar = + " public class var { public int a; };\n"; + + String classX = + "public class X {\n" + + classVar + + " +\n" + + "}\n"; + String errorTail = + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " +\n" + + " ^\n" + + "Syntax error on token \"+\", delete this token\n" + + "----------\n"; + + if (this.complianceLevel == ClassFileConstants.JDK10) { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + classVar + + " ^^^\n" + + "'var' is not a valid type name\n" + + errorTail); + } else { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + classVar + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + + errorTail); + } +} +public void test0002_interface_var_warning() throws IOException { + String interfaceVar = + " interface var { };\n"; + + String classX = + "public class X {\n" + + interfaceVar + + " +\n" + + "}\n"; + String errorTail = + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " +\n" + + " ^\n" + + "Syntax error on token \"+\", delete this token\n" + + "----------\n"; + + if (this.complianceLevel == ClassFileConstants.JDK10) { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + interfaceVar + + " ^^^\n" + + "'var' is not a valid type name\n" + + errorTail); + } else { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + interfaceVar + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + + errorTail); + } +} +public void testBug530920() throws IOException { + String classX = "public class X<var extends Number> { }\n"; + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + this.complianceLevel == ClassFileConstants.JDK10 ? + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<var extends Number> { }\n" + + " ^^^\n" + + "'var' is not allowed here\n" + : + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X<var extends Number> { }\n" + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + ); +} +public void testBug530920a() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " <var extends Number> var getNumber() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + this.complianceLevel == ClassFileConstants.JDK10 ? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " <var extends Number> var getNumber() {\n" + + " ^^^\n" + + "'var' is not allowed here\n" + : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " <var extends Number> var getNumber() {\n" + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + ); +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java new file mode 100644 index 0000000000..20e5a14883 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java @@ -0,0 +1,792 @@ +/******************************************************************************* + * Copyright (c) 2018 Jesper Steen Møller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * Jesper Steen Møller - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.junit.Assert; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JEP286Test extends AbstractRegressionTest { + +public static Class testClass() { + return JEP286Test.class; +} +public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_10); +} + +public JEP286Test(String testName){ + super(testName); +} +static { +// TESTS_NAMES = new String[] { "test0018_project_variable_types" }; +} +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + return options; +} +private static final Map<String, String> simpleTypeNames = new HashMap<>(); +static { + simpleTypeNames.put("String", "java.lang.String"); + simpleTypeNames.put("Object", "java.lang.Object"); + simpleTypeNames.put("Bar", "X.Bar"); + + simpleTypeNames.put("AnonymousObjectSubclass", "new java.lang.Object(){}"); + simpleTypeNames.put("AnonymousRunnableSubclass", "new java.lang.Runnable(){}"); + simpleTypeNames.put("CollectionOfExtString", "Collection<? extends java.lang.String>"); + simpleTypeNames.put("CollectionOfSuperString", "Collection<? super java.lang.String>"); + simpleTypeNames.put("CollectionAny", "Collection<?>"); + simpleTypeNames.put("ComparableAny", "Comparable<?>"); + simpleTypeNames.put("CollectionExt_ComparableAny", "Collection<? extends Comparable<?>>"); + simpleTypeNames.put("CollectionSuperComparableAny", "Collection<? super Comparable<?>>"); + simpleTypeNames.put("IntLongFloat", "java.lang.Number&Comparable<?>"); + simpleTypeNames.put("ListTestAndSerializable", "List<? extends Z & java.io.Serializable>"); + simpleTypeNames.put("TestAndSerializable", "Z & java.io.Serializable"); +} + +static void assertInferredType(LocalDeclaration varDecl) { + String varName = new String(varDecl.name); + int underscoreIndex = varName.indexOf('_'); + Assert.assertNotEquals(-1, underscoreIndex); + String typeNamePart = varName.substring(underscoreIndex+1); + typeNamePart = typeNamePart.replaceAll("ARRAY", "[]"); // So that we assume that x_intARRAY is of type int[] + String expectedTypeName = simpleTypeNames.getOrDefault(typeNamePart, typeNamePart); + String actualTypeName = varDecl.binding.type.debugName(); + // System.out.println("For " + varName + ", we expect " + expectedTypeName + ", the type was: " + // + actualTypeName + " - " + (expectedTypeName.equals(actualTypeName) ? "❤️" : "🤡")); + Assert.assertEquals("Type of variable " + varName, expectedTypeName, actualTypeName); +} + +// This visitor visits the 'testXxx' method in the visited classes, checking for expected types of local variables (using the debug name) +private final static class InferredTypeVerifier extends ASTVisitor { + public int localsChecked = 0; + public InferredTypeVerifier() { } + + @Override + public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { + return false; // Don't check Foo itself + } + + @Override + public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + if (! new String(methodDeclaration.selector).startsWith("test")) return false; + return super.visit(methodDeclaration, scope); + } + + @Override + public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) { + assertInferredType(localDeclaration); + this.localsChecked++; + return super.visit(localDeclaration, scope); + } + } + +public void test0001_local_variable_inference() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " var x = \"SUCCESS\";\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test0002_inferred_for() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int sum = 0;\n" + + " for(var n = 1; n <= 2; ++n) {\n" + + " sum += n;\n" + + " }\n" + + " System.out.println(\"SUCCESS \" + sum);\n" + + " }\n" + + "}\n" + }, + "SUCCESS 3"); +} +public void test0003_inferred_enhanced_for() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int sum = 0;\n" + + " for(var n : java.util.List.of(1, 2)) {\n" + + " sum += n;\n" + + " }\n" + + " System.out.println(\"SUCCESS \" + sum);\n" + + " }\n" + + "}\n" + }, + "SUCCESS 3"); +} +public void test0004_try_with_resources() throws IOException { + try(java.io.Writer w = new java.io.StringWriter()) { + w.write("SUCCESS!\n"); + System.out.println(w.toString()); + } + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " try(var w = new java.io.StringWriter()) {\n" + + " w.write(\"SUCCESS\\n\");" + + " System.out.println(w.toString());\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test0005_no_initializer() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " var a;\n" + + " for(var b;;);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a;\n" + + " ^\n" + + "Cannot use 'var' on variable without initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for(var b;;);\n" + + " ^\n" + + "Cannot use 'var' on variable without initializer\n" + + "----------\n"); +} +public void test0006_multiple_declarators() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " var a = 1, b = 2;\n" + + " for(var c = 1, d = 20; c<d; c++);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = 1, b = 2;\n" + + " ^\n" + + "'var' is not allowed in a compound declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for(var c = 1, d = 20; c<d; c++);\n" + + " ^\n" + + "'var' is not allowed in a compound declaration\n" + + "----------\n"); +} +public void test0007_var_in_wrong_place() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private var someField = 0;\n" + + " public var method() {\n" + + " return null;\n" + + " }\n" + + " public void main(var arg) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private var someField = 0;\n" + + " ^^^\n" + + "'var' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public var method() {\n" + + " ^^^\n" + + "'var' is not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void main(var arg) {\n" + + " ^^^\n" + + "'var' is not allowed here\n" + + "----------\n"); +} +public void test0008_null_initializer() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String[] arg) {\n" + + " var notMuch = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var notMuch = null;\n" + + " ^^^^^^^\n" + + "Cannot infer type for local variable initialized to 'null'\n" + + "----------\n"); +} +public void test0008_void_initializer() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "\n" + + " public void baz() {\n" + + " var nothingHere = foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " var nothingHere = foo();\n" + + " ^^^^^^^^^^^\n" + + "Variable initializer is 'void' -- cannot infer variable type\n" + + "----------\n"); +} +public void test0009_var_as_type_name() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public enum var { V, A, R };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public enum var { V, A, R };\n" + + " ^^^\n" + + "'var' is not a valid type name\n" + + "----------\n"); +} +public void test0010_array_initializer() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var myArray = { 1, 2, 3 };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var myArray = { 1, 2, 3 };\n" + + " ^^^^^^^\n" + + "Array initializer needs an explicit target-type\n" + + "----------\n"); +} +public void test0011_array_type() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var myArray[] = new int[42];\n" + + " var[] moreArray = new int[1337];\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var myArray[] = new int[42];\n" + + " ^^^^^^^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " var[] moreArray = new int[1337];\n" + + " ^^^^^^^^^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n"); +} +public void test0012_self_reference() throws IOException { + + // BTW: This will give a VerifyError: int a = ((java.util.concurrent.Callable<Integer>)(() -> true ? 1 : a)).call(); + // The cases are tested. a is a simple case, with plain usage in the same scope. b is used in a nested scope. + // c and d are shadowed by the nested definitions. + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = 42 + a;\n" + + " var b = ((java.util.concurrent.Callable<Integer>)(() -> true ? 1 : b)).call();\n" + + " var c = new java.util.concurrent.Callable<Integer>() {\n" + + " public Integer call() {\n" + + " int c = 42; return c;\n" + + " }\n" + + " }.call();" + + " var d = new java.util.concurrent.Callable<Integer>() {\n" + + " int d = 42;\n" + + " public Integer call() {\n" + + " return d;\n" + + " }\n" + + " }.call();" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = 42 + a;\n" + + " ^\n" + + "Declaration using 'var' may not contain references to itself\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " var b = ((java.util.concurrent.Callable<Integer>)(() -> true ? 1 : b)).call();\n" + + " ^\n" + + "Declaration using 'var' may not contain references to itself\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " int c = 42; return c;\n" + + " ^\n" + + "The local variable c is hiding another local variable defined in an enclosing scope\n" + + "----------\n"+ + "3. WARNING in X.java (at line 10)\n" + + " int d = 42;\n" + + " ^\n" + + "The field new Callable<Integer>(){}.d is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +public void test0013_lambda() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = (int i) -> 42;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = (int i) -> 42;\n" + + " ^\n" + + "Lambda expression needs an explicit target-type\n" + + "----------\n"); +} +public void test0014_method_reference() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = X::main;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = X::main;\n" + + " ^\n" + + "Method reference needs an explicit target-type\n" + + "----------\n"); +} +public void test0015_complain_over_first_poly_encountered() throws Exception { + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = args.length > 1 ? X::main : (int i) -> 42;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = args.length > 1 ? X::main : (int i) -> 42;\n" + + " ^\n" + + "Method reference needs an explicit target-type\n" + + "----------\n"); +} +public void test0016_dont_capture_deep_poly_expressions() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " var z = ((java.util.concurrent.Callable<String>)(() -> \"SUCCESS\"));\n" + + " var x = args.length > 1 ? \"FAILURE\" : z.call();\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//static <T extends List<? super E>, E extends List<? super Integer>> void doSomething(T[] e) { +// e[0] = null; +//} + +public void test0017_simple_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void test() {\n" + + " var i_String = \"\";\n" + + " for (var i2_String = \"\" ; ; ) { break; }\n" + + " for (var i2_String : iterableOfString()) { break; }\n" + + " for (var i2_String : arrayOfString()) { break; }\n" + + " try (var i2_Bar = new Bar()) { } finally { }\n" + + " try (var i2_Bar = new Bar(); var i3_Bar = new Bar()) { } finally { }\n" + + " }\n" + + "\n" + + " Iterable<String> iterableOfString() { return null; }\n" + + " String[] arrayOfString() { return null; }\n" + + "\n" + + " static class Bar implements AutoCloseable {\n" + + " @Override\n" + + " public void close() { }\n" + + " }\n" + + "}\n" + + "\n" + }, + typeVerifier); + Assert.assertEquals(7, typeVerifier.localsChecked); +} +public void test0018_primitive_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "Y.java", + "class Y {\n" + + " boolean[] booleanArray = { true };\n" + + " byte[] byteArray = { 1 };\n" + + " char[] charArray = { 'c' };\n" + + " short[] shortArray = { 42 };\n" + + " int[] intArray = { 42 };\n" + + " long[] longArray = { 42L };\n" + + " float[] floatArray = { 0.1f };\n" + + " double[] doubleArray = { 0.2d };\n" + + "\n" + + " void testBuiltins() {\n" + + " var z_boolean = false;\n" + + " var b_byte = (byte)0xff;\n" + + " var c_char = 'c';\n" + + " var s_short = (short)42;\n" + + " var i_int = 42;\n" + + " var l_long = 42L;\n" + + " var f_float = 0.25f;\n" + + " var d_double = 0.35d;\n" + + " }\n" + + "\n" + + " void testBuiltinsForEach() {\n" + + " for (var z_boolean : booleanArray) { System.out.print(\".\"); }\n" + + " for (var b_byte : byteArray) { System.out.print(\".\"); }\n" + + " for (var c_char : charArray) { System.out.print(\".\"); }\n" + + " for (var s_short : shortArray) { System.out.print(\".\"); }\n" + + " for (var i_int : intArray) { System.out.print(\".\"); }\n" + + " for (var l_long : longArray) { System.out.print(\".\"); }\n" + + " for (var f_float : floatArray) { System.out.print(\".\"); }\n" + + " for (var d_double : doubleArray) { System.out.print(\".\"); }\n" + + " }\n" + + " void testBuiltinsArray() {\n" + + " var z_booleanARRAY = booleanArray;\n" + + " var b_byteARRAY = byteArray;\n" + + " var c_charARRAY = charArray;\n" + + " var s_shortARRAY = shortArray;\n" + + " var i_intARRAY = intArray;\n" + + " var l_longARRAY = longArray;\n" + + " var f_floatARRAY = floatArray;\n" + + " var d_doubleARRAY = doubleArray;\n" + + " }\n" + + "\n" + + "}\n" + }, + typeVerifier); + Assert.assertEquals(24, typeVerifier.localsChecked); +} +public void test0018_project_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "Z.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.io.Serializable;\n" + + "\n" + + "class Z {\n" + + "\n" + + " void testExtends() {\n" + + " var l1_CollectionOfExtString = extendsString();\n" + + " for (var l2_CollectionOfExtString = extendsString() ; ; ) { break; }\n" + + " for (var l3_CollectionOfExtString : extendsStringArr()) { break; }\n" + + " for (var l4_CollectionOfExtString : extendsCollectionIterable()) { break; }\n" + + " for (var l5_String : extendsString()) { break; }\n" + + " }\n" + + "\n" + + " void testExtendsFbound() { \n" + + " var l1_CollectionExt_ComparableAny = extendsTBound();\n" + + " for (var l2_CollectionExt_ComparableAny = extendsTBound() ; ; ) { break; }\n" + + " for (var l3_CollectionExt_ComparableAny : extendsTBoundArray()) { break; }\n" + + " for (var l3_CollectionExt_ComparableAny : extendsTBoundIter()) { break; }\n" + + " for (var l4_ComparableAny : extendsTBound()) { break; }\n" + + " }\n" + + "\n" + + " void testSuperTBound() {\n" + + " var s_CollectionAny = superTBound();\n" + + " for (var s2_CollectionAny = superTBound() ; ; ) { break; }\n" + + " for (var s2_CollectionAny : superTBoundArray()) { break; }\n" + + " for (var s2_CollectionAny : superTBoundIter()) { break; }\n" + + " for (var s2_Object : superTBound()) { break; }\n" + + " }\n" + + "\n" + + " void testCollectSuper() {\n" + + " var s_CollectionOfSuperString = superString();\n" + + " for (var s2_CollectionOfSuperString = superString() ; ; ) { break; }\n" + + " for (var s2_CollectionOfSuperString : superStringArray()) { break; }\n" + + " for (var s2_CollectionOfSuperString : superCollectionIterable()) { break; }\n" + + " for (var s2_Object : superString()) { break; }\n" + + " }\n" + + "\n" + + " void testUnbound() {\n" + + " var s_CollectionAny = unboundedString();\n" + + " for (var s2_CollectionAny = unboundedString() ; ; ) { break; }\n" + + " for (var s2_CollectionAny : unboundedStringArray()) { break; }\n" + + " for (var s2_CollectionAny : unboundedCollectionIterable()) { break; }\n" + + " for (var s2_Object : unboundedString()) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfAnAnonymousClass() {\n" + + " var o_AnonymousObjectSubclass = new Object() { };\n" + + " for (var s2_AnonymousObjectSubclass = new Object() { } ; ; ) { break; }\n" + + " for (var s2_AnonymousObjectSubclass : arrayOf(new Object() { })) { break; }\n" + + " for (var s2_AnonymousObjectSubclass : listOf(new Object() { })) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfAnAnonymousInterface() {\n" + + " var r_AnonymousRunnableSubclass = new Runnable() { public void run() { } };\n" + + " for (var s2_AnonymousRunnableSubclass = new Runnable() { public void run() { } } ; ; ) { break; }\n" + + " for (var s2_AnonymousRunnableSubclass : arrayOf(new Runnable() { public void run() { } })) { break; }\n" + + " for (var s2_AnonymousRunnableSubclass : listOf(new Runnable() { public void run() { } })) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfIntersectionType() {\n" + + " var c_IntLongFloat = choose(1, 1L);\n" + + " for (var s2_IntLongFloat = choose(1, 1L) ; ;) { break; }\n" + + " for (var s2_IntLongFloat : arrayOf(choose(1, 1L))) { break; }\n" + + " for (var s2_IntLongFloat : listOf(choose(1, 1L))) { break; }\n" + + " }\n" + + "\n" + + " public void testProjections() {\n" + + " var inter_ListTestAndSerializable = getIntersections();\n" + + " var r_TestAndSerializable = inter_ListTestAndSerializable.get(0);\n" + + " }\n" + + "\n" + + " Collection<? extends String> extendsString() { return null; }\n" + + " Collection<? super String> superString() { return null; }\n" + + " Collection<?> unboundedString() { return null; }\n" + + "\n" + + " Collection<? extends String>[] extendsStringArr() { return null; }\n" + + " Collection<? super String>[] superStringArray() { return null; }\n" + + " Collection<?>[] unboundedStringArray() { return null; }\n" + + "\n" + + " Iterable<? extends Collection<? extends String>> extendsCollectionIterable() { return null; }\n" + + " Iterable<? extends Collection<? super String>> superCollectionIterable() { return null; }\n" + + " Iterable<? extends Collection<?>> unboundedCollectionIterable() { return null; }\n" + + "\n" + + " <TBound extends Comparable<TBound>> Collection<? extends TBound> extendsTBound() { return null; }\n" + + " <TBound extends Comparable<TBound>> Collection<? super TBound> superTBound() { return null; }\n" + + "\n" + + " <TBound extends Comparable<TBound>> Collection<? extends TBound>[] extendsTBoundArray() { return null; }\n" + + " <TBound extends Comparable<TBound>> Collection<? super TBound>[] superTBoundArray() { return null; }\n" + + "\n" + + " <TBound extends Comparable<TBound>> Iterable<? extends Collection<? extends TBound>> extendsTBoundIter() { return null; }\n" + + " <TBound extends Comparable<TBound>> Iterable<? extends Collection<? super TBound>> superTBoundIter() { return null; }\n" + + "\n" + + " <TBound> Collection<TBound> listOf(TBound b) { return null; }\n" + + " <TBound> TBound[] arrayOf(TBound b) { return null; }\n" + + "\n" + + " <TBound> TBound choose(TBound b1, TBound b2) { return b1; }\n" + + " <T extends Z & Serializable> List<? extends T> getIntersections() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + typeVerifier); + Assert.assertEquals(39, typeVerifier.localsChecked); +} +public void testBug531832() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " for (var[] v : args) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (var[] v : args) { }\n" + + " ^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n"); +} +public void testBug530879() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() { }\n" + + " public static void main(String [] args) {\n" + + " for (var v : foo()) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (var v : foo()) { }\n" + + " ^\n" + + "Variable initializer is 'void' -- cannot infer variable type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for (var v : foo()) { }\n" + + " ^^^^^\n" + + "Can only iterate over an array or an instance of java.lang.Iterable\n" + + "----------\n"); +} +public void testBug530879a() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " for (var v : null) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (var v : null) { }\n" + + " ^\n" + + "Cannot infer type for local variable initialized to 'null'\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " for (var v : null) { }\n" + + " ^^^^\n" + + "Can only iterate over an array or an instance of java.lang.Iterable\n" + + "----------\n"); +} +public void testBug532349() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y<? super Boolean> y = new Y<>();\n" + + " var v = y;\n" + + " Y<? super Boolean> tmp = v;\n" + + " }\n" + + "}\n" + + "class Y<T extends Boolean> {\n" + + "}" + }); +} +public void testBug532349a() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " List<Y<? super Boolean>> l = new ArrayList<>();\n" + + " var dlv = l;\n" + + " for (var iv : dlv) {\n" + + " Y<? super Boolean> id = iv;\n" + + " }" + + " }\n" + + "}\n" + + "class Y<T extends Boolean> {}" + }); +} +public void testBug532349b() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y<? super Boolean> y = new Y<>();\n" + + " try (var v = y) {\n" + + " Y<? super Boolean> tmp = v;\n" + + " } catch (Exception e) { }\n" + + " }\n" + + "}\n" + + "class Y<T extends Boolean> implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws Exception {}\n" + + "}" + }); +} +public void testBug532351() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y<? super Number> y = new Y<Number>(); // Javac reports, ECJ accepts\n" + + " var v = y;\n" + + " Y<? super Number> tmp = v;\n" + + " }\n" + + " class Y<T extends Number> {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y<? super Number> y = new Y<Number>(); // Javac reports, ECJ accepts\n" + + " ^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).\n" + + "----------\n"); +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java index 8d68be3428..48de8fc616 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java @@ -35,7 +35,9 @@ public JSR335ClassFileTest(String name) { // No need for a tearDown() protected void setUp() throws Exception { super.setUp(); - this.versionString = (this.complianceLevel < ClassFileConstants.JDK9) ? "version 1.8 : 52.0" : "version 9 : 53.0"; + this.versionString = (this.complianceLevel < ClassFileConstants.JDK9) + ? "version 1.8 : 52.0" + : (this.complianceLevel < ClassFileConstants.JDK10 ? "version 9 : 53.0" : "version 10 : 54.0"); } /* diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java index 10c7d45c53..0859892887 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java @@ -5052,7 +5052,7 @@ public void test447119d() { "[- java.util.List<java.lang.String> noop(java.util.List<java.lang.String>)]", null, true, - (isJRE9 + (isJRE9Plus ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } : new String [] { "-Ddummy" }) // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. ); @@ -5220,7 +5220,7 @@ public void test449063() { null, customOptions, null, - (isJRE9 + (isJRE9Plus ? "Test$Tuple<java.lang.Integer, java.lang.String>\n" + "Test$Tuple<java.lang.String, java.lang.Double>" : "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + @@ -5296,7 +5296,7 @@ public void test449063a() { null, customOptions, null, - (isJRE9 + (isJRE9Plus ? "Test$Tuple<java.lang.Integer, java.lang.String>\n" + "Test$Tuple<java.lang.String, java.lang.Double>" : "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + @@ -5511,7 +5511,7 @@ public void test449063e() { " }\n" + "}" }, - (isJRE9 + (isJRE9Plus ? "Test$Tuple<java.lang.Integer, java.lang.String>\n" + "Test$Tuple<java.lang.String, java.lang.Double>" : "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java index 694795410a..e4a4a6a6e4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java @@ -4,9 +4,11 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Jesper Steen Moeller - initial API and implementation + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -33,7 +35,9 @@ public class MethodParametersAttributeTest extends AbstractRegressionTest { // No need for a tearDown() protected void setUp() throws Exception { super.setUp(); - this.versionString = (this.complianceLevel < ClassFileConstants.JDK9) ? "version 1.8 : 52.0" : "version 9 : 53.0"; + this.versionString = (this.complianceLevel < ClassFileConstants.JDK9) + ? "version 1.8 : 52.0" + : (this.complianceLevel < ClassFileConstants.JDK10 ? "version 9 : 53.0" : "version 10 : 54.0"); } @SuppressWarnings("rawtypes") public static Class testClass() { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java index 355798a180..cff7d2b767 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java @@ -10024,77 +10024,6 @@ public void testBug458332() { "450\n" + "250"); } -public void testBug521808() { - runNegativeTest( - new String[] { - "Z.java", - "interface FI1 {\n" + - " Object m(Integer... s);\n" + - "}\n" + - "interface FI2<T> {\n" + - " Object m(T... arg);\n" + - "}\n" + - "public class Z {\n" + - " static Object m(FI1 fi, Number v1, Number v2) {\n" + - " return fi.m(v1.intValue(), v2.intValue());\n" + - " }\n" + - " static <V extends Integer> Object m(FI2<V> fi, V v1, V v2) {\n" + - " return null;// fi.m(v1, v2);\n" + - " }\n" + - " public static void main(String argv[]) {\n" + - " Object obj = m((FI1) (Integer... is) -> is[0] + is[1], 3, 4);\n" + - " obj = m((FI2<Integer>) (Integer... is) -> is[0] + is[1], 3, 4);\n" + - " obj = m((Integer... is) -> is[0] + is[1], 3, 4); // ECJ compiles, Javac won't\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. WARNING in Z.java (at line 5)\n" + - " Object m(T... arg);\n" + - " ^^^\n" + - "Type safety: Potential heap pollution via varargs parameter arg\n" + - "----------\n" + - "2. WARNING in Z.java (at line 11)\n" + - " static <V extends Integer> Object m(FI2<V> fi, V v1, V v2) {\n" + - " ^^^^^^^\n" + - "The type parameter V should not be bounded by the final type Integer. Final types cannot be further extended\n" + - "----------\n" + - "3. ERROR in Z.java (at line 17)\n" + - " obj = m((Integer... is) -> is[0] + is[1], 3, 4); // ECJ compiles, Javac won\'t\n" + - " ^\n" + - "The method m(FI1, Number, Number) is ambiguous for the type Z\n" + - "----------\n"); -} -public void testBug525303() { - runNegativeTest( - new String[] { - "X.java", - "interface FI<A1 extends C<A2>, A2 extends A3, A3> {\n" + - " String m(A1 a, A2 b);\n" + - "}\n" + - "class C<T>{}\n" + - "public class X {\n" + - " static String method(C<Integer> c, Integer i) {\n" + - " return \"\";\n" + - " }\n" + - " public static void main(String argv[]) {\n" + - " FI<?, ?, ?> i = (C<Integer> a, Integer b) -> String.valueOf(a) + String.valueOf(b); // no error here\n" + - " FI<?, ?, ?> i2 = X::method; // error here\n" + - " }\n" + - "}" - }, - "----------\n" + - "1. ERROR in X.java (at line 10)\n" + - " FI<?, ?, ?> i = (C<Integer> a, Integer b) -> String.valueOf(a) + String.valueOf(b); // no error here\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " FI<?, ?, ?> i2 = X::method; // error here\n" + - " ^^^^^^^^^\n" + - "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + - "----------\n"); -} public static Class testClass() { return NegativeLambdaExpressionsTest.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java index 4c5ebfe3fe..48d2f60fa3 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java @@ -23,6 +23,7 @@ import java.util.Map; import junit.framework.Test; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -17429,4 +17430,46 @@ public void testBug518839_BTB() { "----------\n" ); } +public void testBug531040() { + if (this.complianceLevel < ClassFileConstants.JDK10) + return; + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test {\n" + + " void test() {\n" + + " var list1 = new ArrayList<@NonNull String>();\n" + + " list1.add(null);\n" + + " @NonNull String val = \"\";\n" + + " var list2 = getList(val);\n" + + " list2.add(null);\n" + + " }\n" + + " <T> List<T> getList(T... in) {\n" + + " return Arrays.asList(in);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in Test.java (at line 8)\n" + + " list1.add(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Test.java (at line 11)\n" + + " list2.add(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in Test.java (at line 13)\n" + + " <T> List<T> getList(T... in) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter in\n" + + "----------\n" + ); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java index c76e6bc9ed..e608cf8f80 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java @@ -1574,7 +1574,7 @@ public class SerializableLambdaTest extends AbstractRegressionTest { "Looking for Testbed.foo\n" + "true", null,true, - (isJRE9 + (isJRE9Plus ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } : new String [] { "-Ddummy" }) ); @@ -1662,7 +1662,7 @@ public class SerializableLambdaTest extends AbstractRegressionTest { "Looking for Testbed$MethodRefImpl.<init>\n" + "true", null,true, - (isJRE9 + (isJRE9Plus ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } : new String [] { "-Ddummy" }) ); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java index d71134c659..fd2f95e98a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -163,6 +163,10 @@ public static Test suite() { since_9.add(AutomaticModuleNamingTest.class); since_9.add(UnnamedModuleTest.class); since_9.add(NullAnnotationTests9.class); + + // add 10 specific test here (check duplicates) + ArrayList since_10 = new ArrayList(); + since_10.add(JEP286Test.class); // Build final test suite TestSuite all = new TestSuite(TestAll.class.getName()); @@ -235,6 +239,19 @@ public static Test suite() { TestCase.RUN_ONLY_ID = null; all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK9, tests_9)); } + + if ((possibleComplianceLevels & AbstractCompilerTest.F_10) != 0) { + ArrayList tests_10 = (ArrayList)standardTests.clone(); + tests_10.addAll(since_1_4); + tests_10.addAll(since_1_5); + tests_10.addAll(since_1_6); + tests_10.addAll(since_1_7); + tests_10.addAll(since_1_8); + tests_10.addAll(since_9); + tests_10.addAll(since_10); + TestCase.resetForgottenFilters(tests_10); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK10, tests_10)); + } all.addTest(new TestSuite(Jsr14Test.class)); return all; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java index 38617dc994..267ab84a41 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2017 IBM Corporation and others. + * Copyright (c) 2010, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -43,6 +43,7 @@ import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.ModuleDeclaration; import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; @@ -54,7 +55,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { super(name); } - private static final int AST_JLS_LATEST = AST.JLS9; + private static final int AST_JLS_LATEST = AST.JLS10; public ASTNode runConversion( int astLevel, @@ -638,6 +639,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { assertTrue("should have parsed a CUD", ast instanceof CompilationUnit); } + @Deprecated public void testBug465048() { String source = "class A {\n" + @@ -670,6 +672,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { /** * Verifies that ASTParser doesn't throw an IllegalArgumentException when given * this valid input. + * @deprecated */ public void testBug480545() { String input = "class Test2 { void f(Test2... xs) {} }"; @@ -680,6 +683,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { parser.setCompilerOptions(options); assertNotNull(parser.createAST(null)); } + @Deprecated public void testBug493336_001() { String input = "public class X implements á¼³ {\n" + " public static final class if {\n"+ @@ -701,6 +705,7 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { parser.setCompilerOptions(options1); assertNotNull(parser.createAST(null)); } + @Deprecated public void testBug526996_001() { File rootDir = new File(System.getProperty("java.io.tmpdir")); String contents = @@ -1600,4 +1605,31 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { fileY.delete(); } } + public void testBug530299_001() { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var x = new X();\n" + + " for (var i = 0; i < 10; ++i) {}\n" + + " }\n" + + "}"; + ASTParser parser = ASTParser.newParser(AST.JLS10); + parser.setSource(contents.toCharArray()); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(null, new String[] {null}, null, true); + parser.setResolveBindings(true); + ASTNode node = parser.createAST(null); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit cu = (CompilationUnit) node; + assertTrue("Problems in compilation", cu.getProblems().length == 0); + TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0); + MethodDeclaration[] methods = typeDeclaration.getMethods(); + MethodDeclaration methodDeclaration = methods[0]; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + Type type = vStmt.getType(); + assertNotNull(type); + assertTrue("not a var", type.isVar()); + } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java index fbab9ba3be..5c4d47d673 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java @@ -1,12 +1,18 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation + * Jesper S Moller <jesper@selskabet.org> - Contributions for + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.core.tests.junit.extension; @@ -35,6 +41,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.compiler.batch.Main; import org.eclipse.jdt.internal.core.nd.indexer.Indexer; @@ -817,7 +824,7 @@ protected boolean isFirst() { } protected void setUp() throws Exception { - Indexer.getInstance().enableAutomaticIndexing(false); + if (JavaCore.getPlugin() != null) Indexer.getInstance().enableAutomaticIndexing(false); super.setUp(); // Store test class and its name when changing @@ -906,7 +913,7 @@ public void stopMeasuring() { protected void tearDown() throws Exception { super.tearDown(); - Indexer.getInstance().enableAutomaticIndexing(true); + if (JavaCore.getPlugin() != null) Indexer.getInstance().enableAutomaticIndexing(true); // Memory storage if specified if (STORE_MEMORY != null && MEM_LOG_FILE != null) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java index 484c911236..363e6cd1bd 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java @@ -15,6 +15,7 @@ package org.eclipse.jdt.core.tests.runtime; import java.io.*; import java.util.*; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.tests.util.Util; /** @@ -71,7 +72,7 @@ public static LocalVMLauncher getLauncher() { return new MacVMLauncher(); } String javaVersion = System.getProperty("java.version"); - boolean isJrt = javaVersion != null && javaVersion.length() > 0 && javaVersion.charAt(0) == '9'; + boolean isJrt = javaVersion != null && javaVersion.length() > 0 && JavaCore.compareJavaVersions(javaVersion, "9") >= 0; File file = new File(Util.getJREDirectory() + (isJrt ? "/lib/jrt-fs.jar" : "/lib/rt.jar")); if (file.exists()) { return new StandardVMLauncher(); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java index ea9289e239..a450a2234a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -38,6 +38,7 @@ public class AbstractCompilerTest extends TestCase { public static final int F_1_7 = 0x10; public static final int F_1_8 = 0x20; public static final int F_9 = 0x40; + public static final int F_10 = 0x80; public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac")); private static final int UNINITIALIZED = -1; @@ -46,7 +47,7 @@ public class AbstractCompilerTest extends TestCase { protected long complianceLevel; protected boolean enableAPT = false; - protected static boolean isJRE9 = false; // Stop gap, so tests need not be run at 9, but some tests can be adjusted for JRE 9 + protected static boolean isJRE9Plus = false; // Stop gap, so tests need not be run at 9, but some tests can be adjusted for JRE 9 /** * Build a test suite made of test suites for all possible running VM compliances . @@ -84,6 +85,9 @@ public class AbstractCompilerTest extends TestCase { if ((complianceLevels & AbstractCompilerTest.F_9) != 0) { suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK9)); } + if ((complianceLevels & AbstractCompilerTest.F_10) != 0) { + suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK10)); + } } /** @@ -120,6 +124,9 @@ public class AbstractCompilerTest extends TestCase { if ((complianceLevels & AbstractCompilerTest.F_9) != 0) { suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK9)); } + if ((complianceLevels & AbstractCompilerTest.F_10) != 0) { + suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK10)); + } return suite; } @@ -251,6 +258,14 @@ public class AbstractCompilerTest extends TestCase { suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK9)); } } + int level10 = complianceLevels & AbstractCompilerTest.F_10; + if (level10 != 0) { + if (level10 < minimalCompliance) { + System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK10)+"!"); + } else { + suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK10)); + } + } return suite; } @@ -267,7 +282,9 @@ public class AbstractCompilerTest extends TestCase { long highestLevel = highestComplianceLevels(); if (highestLevel < uniqueCompliance) { String complianceString; - if (highestLevel == ClassFileConstants.JDK9) + if (highestLevel == ClassFileConstants.JDK10) + complianceString = "10"; + else if (highestLevel == ClassFileConstants.JDK9) complianceString = "9"; else if (highestLevel == ClassFileConstants.JDK1_8) complianceString = "1.8"; @@ -299,6 +316,9 @@ public class AbstractCompilerTest extends TestCase { */ public static long highestComplianceLevels() { int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); + if ((complianceLevels & AbstractCompilerTest.F_10) != 0) { + return ClassFileConstants.JDK10; + } if ((complianceLevels & AbstractCompilerTest.F_9) != 0) { return ClassFileConstants.JDK9; } @@ -326,7 +346,7 @@ public class AbstractCompilerTest extends TestCase { public static int getPossibleComplianceLevels() { if (possibleComplianceLevels == UNINITIALIZED) { String specVersion = System.getProperty("java.specification.version"); - isJRE9 = CompilerOptions.VERSION_9.equals(specVersion); + isJRE9Plus = CompilerOptions.VERSION_9.equals(specVersion) || CompilerOptions.VERSION_10.equals(specVersion); String compliance = System.getProperty("compliance"); if (compliance != null) { if (CompilerOptions.VERSION_1_3.equals(compliance)) { @@ -343,6 +363,8 @@ public class AbstractCompilerTest extends TestCase { possibleComplianceLevels = F_1_8; } else if (CompilerOptions.VERSION_9.equals(compliance)) { possibleComplianceLevels = F_9; + } else if (CompilerOptions.VERSION_10.equals(compliance)) { + possibleComplianceLevels = F_10; } else { System.out.println("Invalid compliance specified (" + compliance + ")"); System.out.print("Use one of "); @@ -352,7 +374,9 @@ public class AbstractCompilerTest extends TestCase { System.out.print(CompilerOptions.VERSION_1_6 + ", "); System.out.print(CompilerOptions.VERSION_1_7 + ", "); System.out.print(CompilerOptions.VERSION_1_8 + ", "); - System.out.println(CompilerOptions.VERSION_9); + System.out.print(CompilerOptions.VERSION_1_8 + ", "); + System.out.print(CompilerOptions.VERSION_9 + ", "); + System.out.println(CompilerOptions.VERSION_10); System.out.println("Defaulting to all possible compliances"); } } @@ -386,6 +410,10 @@ public class AbstractCompilerTest extends TestCase { if (canRun9) { possibleComplianceLevels |= F_9; } + boolean canRun10 = canRun9 && !CompilerOptions.VERSION_9.equals(specVersion); + if (canRun10) { + possibleComplianceLevels |= F_10; + } } else if ("1.0".equals(specVersion) || CompilerOptions.VERSION_1_1.equals(specVersion) || CompilerOptions.VERSION_1_2.equals(specVersion) @@ -402,6 +430,9 @@ public class AbstractCompilerTest extends TestCase { possibleComplianceLevels |= F_1_8; if (!CompilerOptions.VERSION_1_8.equals(specVersion)) { possibleComplianceLevels |= F_9; + if (!CompilerOptions.VERSION_10.equals(specVersion)) { + possibleComplianceLevels |= F_10; + } } } } @@ -506,7 +537,7 @@ public class AbstractCompilerTest extends TestCase { } public String decorateAnnotationValueLiteral(String val) { - if (!isJRE9) { + if (!isJRE9Plus) { return val; } StringBuilder builder = new StringBuilder(val); @@ -550,6 +581,10 @@ public class AbstractCompilerTest extends TestCase { options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (this.complianceLevel == ClassFileConstants.JDK10) { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); } return options; } diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar Binary files differnew file mode 100644 index 0000000000..df361f565f --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10.jar diff --git a/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip Binary files differnew file mode 100644 index 0000000000..23ce774f5e --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/JCL/converterJclMin10src.zip diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin10.jar b/org.eclipse.jdt.core.tests.model/JCL/jclMin10.jar Binary files differnew file mode 100644 index 0000000000..6f2af93c90 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin10.jar diff --git a/org.eclipse.jdt.core.tests.model/JCL/jclMin10src.zip b/org.eclipse.jdt.core.tests.model/JCL/jclMin10src.zip Binary files differnew file mode 100644 index 0000000000..37447f944f --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/JCL/jclMin10src.zip diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava10Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava10Tests.java new file mode 100644 index 0000000000..1b34f6dc46 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava10Tests.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.eclipse.jdt.core.tests.dom.ASTConverter10Test; +import org.eclipse.jdt.core.tests.dom.ConverterTestSetup; +import org.eclipse.jdt.core.tests.model.CompletionTests10; +import org.eclipse.jdt.core.tests.model.JavaSearchBugs10Tests; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class RunAllJava10Tests extends TestCase { + + public RunAllJava10Tests(String name) { + super(name); + } + public static Class[] getAllTestClasses() { + return new Class[] { + JavaSearchBugs10Tests.class, + CompletionTests10.class, + }; + } + + public static Class[] getConverterTestClasses() { + return new Class[] { + ASTConverter10Test.class, + }; + } + + public static Class[] getCompilerClasses() { + return new Class[] { + org.eclipse.jdt.core.tests.eval.TestAll.class, + org.eclipse.jdt.core.tests.compiler.regression.TestAll.class, + }; + } + + public static Test suite() { + TestSuite ts = new TestSuite(RunAllJava10Tests.class.getName()); + + Class[] testClasses = getAllTestClasses(); + addTestsToSuite(ts, testClasses); + testClasses = getConverterTestClasses(); + addTestsToSuite(ts, testClasses); + + AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_10); + addTestsToSuite(ts, getCompilerClasses()); + // ComplianceDiagnoseTest is already added to the test suite through getTestSuite + ts.addTest(org.eclipse.jdt.core.tests.compiler.parser.TestAll.getTestSuite(false)); + return ts; + } + public static void addTestsToSuite(TestSuite suite, Class[] testClasses) { + + for (int i = 0; i < testClasses.length; i++) { + Class testClass = testClasses[i]; + // call the suite() method and add the resulting suite to the suite + try { + Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$ + Test test = (Test)suiteMethod.invoke(null, new Object[0]); + suite.addTest(test); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + } + protected void tearDown() throws Exception { + ConverterTestSetup.PROJECT_SETUP = false; + super.tearDown(); + } +} diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java new file mode 100644 index 0000000000..6150d12b8e --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter10Test.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.dom; + +import junit.framework.Test; + +import org.eclipse.jdt.core.dom.*; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.JavaModelException; + +public class ASTConverter10Test extends ConverterTestSetup { + + ICompilationUnit workingCopy; +// private static final String jcl9lib = "CONVERTER_JCL9_LIB"; + + + public void setUpSuite() throws Exception { + super.setUpSuite(); + this.ast = AST.newAST(AST_INTERNAL_JLS10); + } + + public ASTConverter10Test(String name) { + super(name); + } + + static { +// TESTS_NUMBERS = new int[] { 19 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] {"testBug532421_002"}; + } + public static Test suite() { + String javaVersion = System.getProperty("java.version"); + if (javaVersion.length() > 3) { + javaVersion = javaVersion.substring(0, 3); + } + long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion); + if (jdkLevel >= ClassFileConstants.JDK9) { + isJRE9 = true; + } + return buildModelTestSuite(ASTConverter10Test.class); + } + + protected void tearDown() throws Exception { + super.tearDown(); + if (this.workingCopy != null) { + this.workingCopy.discardWorkingCopy(); + this.workingCopy = null; + } + } + + public void testBug527558_001() throws JavaModelException { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var x = new X();\n" + + " for (var i = 0; i < 10; ++i) {}\n" + + " }\n" + + "}"; + this.workingCopy = getWorkingCopy("/Converter10/src/X.java", true/*resolve*/); + ASTNode node = buildAST(contents, this.workingCopy); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + node = getASTNode((CompilationUnit)node, 0, 0); + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + checkSourceRange(vStmt, "var x = new X();", contents); + Type type = vStmt.getType(); + assertNotNull(type); + assertTrue("not a var", type.isVar()); + IBinding binding = type.resolveBinding(); + assertTrue("null binding", binding != null); + } + public void testBug527558_002() throws JavaModelException { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var i = y -> 1;\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int foo(int i);\n" + + "}\n"; + this.workingCopy = getWorkingCopy("/Converter10/src/X.java", true/*resolve*/); + ASTNode node = buildAST(contents, this.workingCopy, false); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + node = getASTNode((CompilationUnit)node, 0, 0); + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + checkSourceRange(vStmt, "var i = y -> 1;", contents); + Type type = vStmt.getType(); + assertTrue("not a var", type.isVar()); + IBinding binding = type.resolveBinding(); + assertTrue("null binding", binding != null); + } + public void testBug532421_001() throws JavaModelException { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var arr1 = new String[10];\n" + + " }\n" + + "}"; + this.workingCopy = getWorkingCopy("/Converter10/src/X.java", true/*resolve*/); + ASTNode node = buildAST(contents, this.workingCopy, false); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + node = getASTNode((CompilationUnit)node, 0, 0); + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + checkSourceRange(vStmt, "var arr1 = new String[10];", contents); + Type type = vStmt.getType(); + assertTrue("not a var", type.isVar()); + IBinding binding = type.resolveBinding(); + assertTrue("null binding", binding != null); + assertTrue("binding incorrect", binding.getName().equals("String[]")); + } + public void testBug532421_002() throws JavaModelException { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var list = new Y<String>();\n" + + " }\n" + + "}\n" + + "class Y<T> {}"; + this.workingCopy = getWorkingCopy("/Converter10/src/X.java", true/*resolve*/); + ASTNode node = buildAST(contents, this.workingCopy, false); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + node = getASTNode((CompilationUnit)node, 0, 0); + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + checkSourceRange(vStmt, "var list = new Y<String>();", contents); + Type type = vStmt.getType(); + assertTrue("not a var", type.isVar()); + IBinding binding = type.resolveBinding(); + assertTrue("null binding", binding != null); + assertTrue("binding incorrect", binding.getName().equals("Y<String>")); + } +// Add new tests here +} diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java index 5a09d6e42d..baa8f6bbf6 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java index cc37982814..6ec2491c2c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java @@ -44,7 +44,13 @@ public class ASTConverter9Test extends ConverterTestSetup { public void setUpSuite() throws Exception { super.setUpSuite(); - this.ast = AST.newAST(AST_INTERNAL_JLS9); + this.ast = AST.newAST(getAST9()); + } + /** + * @deprecated + */ + static int getAST9() { + return AST.JLS9; } public ASTConverter9Test(String name) { @@ -165,7 +171,7 @@ public class ASTConverter9Test extends ConverterTestSetup { this.workingCopies[0] = getWorkingCopy( "/Converter9/src/module-info.java", content); - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); ModuleDeclaration moduleDecl = unit.getModule(); assertFalse(moduleDecl.isOpen()); @@ -260,7 +266,7 @@ public class ASTConverter9Test extends ConverterTestSetup { "}\n"; createFile("/Bug514417/src/pack1/X.java", content); ICompilationUnit sourceUnit = getCompilationUnit("Bug514417" , "src", "pack1", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit = runConversion(AST_INTERNAL_JLS9, sourceUnit, true); + ASTNode unit = runConversion(this.ast.apiLevel(), sourceUnit, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit.getNodeType()); List imps = ((CompilationUnit) unit).imports(); assertEquals("import missing", 1, imps.size()); @@ -300,7 +306,7 @@ public class ASTConverter9Test extends ConverterTestSetup { this.workingCopies[0] = getWorkingCopy( "/Converter9/src/module-info.java", content); - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); ModuleDeclaration moduleDecl = unit.getModule(); assertTrue(moduleDecl.isOpen()); @@ -426,7 +432,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project3.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -441,7 +447,7 @@ public class ASTConverter9Test extends ConverterTestSetup { // indirectly fetch the binary version of "first" via "third": ICompilationUnit sourceUnit3 = getCompilationUnit("third" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit3 = runConversion(AST_INTERNAL_JLS9, sourceUnit3, true); + ASTNode unit3 = runConversion(this.ast.apiLevel(), sourceUnit3, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit3.getNodeType()); ModuleDeclaration moduleDecl3 = ((CompilationUnit) unit3).getModule(); IModuleBinding firstModAsBinary = moduleDecl3.resolveBinding().getRequiredModules()[1]; // skip java.base @@ -532,7 +538,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -588,7 +594,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -654,7 +660,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -706,7 +712,7 @@ public class ASTConverter9Test extends ConverterTestSetup { + "}"; this.workingCopies[0] = getWorkingCopy("/Converter9/src/module-info.java", content); - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); ModuleDeclaration moduleDecl = unit.getModule(); checkSourceRange(moduleDecl, content, content); } @@ -718,7 +724,7 @@ public class ASTConverter9Test extends ConverterTestSetup { + "}"; this.workingCopies[0] = getWorkingCopy("/Converter9/src/p/I1.java", content); - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) unit.types().get(0); MethodDeclaration method = (MethodDeclaration) typeDeclaration.bodyDeclarations().get(0); assertTrue("Method Malformed", (method.getFlags() & ASTNode.MALFORMED) == 0); @@ -738,7 +744,7 @@ public class ASTConverter9Test extends ConverterTestSetup { IJavaElement[] elements = new IJavaElement[] { firstModule, }; - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(this.ast.apiLevel()); parser.setProject(project1); IBinding[] bindings = parser.createBindings(elements, null); assertBindingsEqual( @@ -784,7 +790,7 @@ public class ASTConverter9Test extends ConverterTestSetup { IJavaElement[] elements = new IJavaElement[] { firstModule, }; - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(this.ast.apiLevel()); parser.setProject(project2); IBinding[] bindings = parser.createBindings(elements, null); assertBindingsEqual( @@ -806,7 +812,7 @@ public class ASTConverter9Test extends ConverterTestSetup { this.workingCopies[0] = getWorkingCopy("/Converter9/src/module-info.java", content); try { - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); ModuleDeclaration moduleDecl = unit.getModule(); assertFalse(moduleDecl.isOpen()); } catch (ClassCastException e) { @@ -819,7 +825,7 @@ public class ASTConverter9Test extends ConverterTestSetup { this.workingCopies[0] = getWorkingCopy("/Converter9/src/module-info.java", content); try { - CompilationUnit unit = (CompilationUnit) runConversion(AST_INTERNAL_JLS9, this.workingCopies[0], false/*no bindings*/); + CompilationUnit unit = (CompilationUnit) runConversion(this.ast.apiLevel(), this.workingCopies[0], false/*no bindings*/); ModuleDeclaration moduleDecl = unit.getModule(); assertTrue(moduleDecl.isOpen()); } catch (ClassCastException e) { @@ -846,7 +852,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack1", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode((CompilationUnit) unit1, 0); ITypeBinding typeBinding = typedeclaration.resolveBinding(); @@ -879,7 +885,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack1", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode((CompilationUnit) unit1, 0); TypeParameter typeParameter = (TypeParameter) typedeclaration.typeParameters().get(0); @@ -912,7 +918,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack1", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode((CompilationUnit) unit1, 0); typedeclaration = typedeclaration.getTypes()[0]; @@ -943,7 +949,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode((CompilationUnit) unit1, 0); ITypeBinding typeBinding = typedeclaration.resolveBinding(); @@ -969,7 +975,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode((CompilationUnit) unit1, 0); ITypeBinding typeBinding = typedeclaration.resolveBinding(); @@ -1003,7 +1009,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack1", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); PackageDeclaration packageDeclaration = ((CompilationUnit) unit1).getPackage(); IPackageBinding packageBinding = packageDeclaration.resolveBinding(); @@ -1036,7 +1042,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); CompilationUnit cu = (CompilationUnit) unit1; ImportDeclaration importDeclaration = (ImportDeclaration) cu.imports().get(0); @@ -1098,7 +1104,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -1165,7 +1171,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -1239,7 +1245,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); ModuleDeclaration moduleDecl1 = ((CompilationUnit) unit1).getModule(); checkSourceRange(moduleDecl1, fileContent, fileContent); @@ -1286,7 +1292,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("ConverterTests9" , "src", "pack", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); CompilationUnit cu = (CompilationUnit) unit1; ImportDeclaration importDeclaration = (ImportDeclaration) cu.imports().get(0); @@ -1331,7 +1337,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project1.open(null); ICompilationUnit sourceUnit1 = getCompilationUnit("First" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit1 = runConversion(AST_INTERNAL_JLS9, sourceUnit1, true); + ASTNode unit1 = runConversion(this.ast.apiLevel(), sourceUnit1, true); assertEquals("Node type", ASTNode.COMPILATION_UNIT, unit1.getNodeType()); CompilationUnit cu = (CompilationUnit) unit1; ModuleDeclaration moduleDeclaration = cu.getModule(); @@ -1349,7 +1355,7 @@ public class ASTConverter9Test extends ConverterTestSetup { project2.open(null); ICompilationUnit sourceUnit2 = getCompilationUnit("Second" , "src", "", "module-info.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - ASTNode unit2 = runConversion(AST_INTERNAL_JLS9, sourceUnit2, true); + ASTNode unit2 = runConversion(this.ast.apiLevel(), sourceUnit2, true); assertEquals("Node type", ASTNode.COMPILATION_UNIT, unit2.getNodeType()); CompilationUnit cu2 = (CompilationUnit) unit2; ModuleDeclaration moduleDeclaration2 = cu2.getModule(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java index 55ebfed024..b8e1159d14 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -40,6 +40,7 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase /** * Internal synonym for constant AST.JSL9 * to alleviate deprecation warnings once AST.JLS9 is deprecated in future. + * @deprecated */ protected static final int AST_INTERNAL_JLS9 = AST.JLS9; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java index 7192aea4fc..74100a9d53 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2016 IBM Corporation and others. + * Copyright (c) 2004, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -485,11 +485,14 @@ public class AbstractASTTests extends ModifyingResourceTests implements DefaultM return new ASTNode[] {unit}; return nodes; } + @SuppressWarnings("deprecation") protected ASTNode[] buildASTs(String newContents, ICompilationUnit cu, boolean reportErrors, boolean enableStatementRecovery, boolean bindingRecovery) throws JavaModelException { String option = cu.getJavaProject().getOption(JavaCore.COMPILER_COMPLIANCE, true); long jdkLevel = CompilerOptions.versionToJdkLevel(option); int JLSLevel = AST_INTERNAL_JLS3; - if (jdkLevel >= ClassFileConstants.JDK9) { + if (jdkLevel >= ClassFileConstants.JDK10) { + JLSLevel = AST_INTERNAL_JLS10; + } else if (jdkLevel >= ClassFileConstants.JDK9) { JLSLevel = AST_INTERNAL_JLS9; } else if (jdkLevel >= ClassFileConstants.JDK1_8) { JLSLevel = AST_INTERNAL_JLS8; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java index 9da38a030e..e6d8500270 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -100,6 +100,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests { this.deleteProject("Converter17"); //$NON-NLS-1$ this.deleteProject("Converter18"); //$NON-NLS-1$ this.deleteProject("Converter9"); //$NON-NLS-1$ + this.deleteProject("Converter10"); //$NON-NLS-1$ PROJECT_SETUP = false; } else { TEST_SUITES.remove(getClass()); @@ -110,6 +111,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests { this.deleteProject("Converter17"); //$NON-NLS-1$ this.deleteProject("Converter18"); //$NON-NLS-1$ this.deleteProject("Converter9"); //$NON-NLS-1$ + this.deleteProject("Converter10"); //$NON-NLS-1$ PROJECT_SETUP = false; } } @@ -155,6 +157,14 @@ public abstract class ConverterTestSetup extends AbstractASTTests { new IPath[] {getConverterJCLPath("9"), getConverterJCLSourcePath("9"), getConverterJCLRootSourcePath()}, null); } + } else if ("10".equals(compliance)) { + if (JavaCore.getClasspathVariable("CONVERTER_JCL10_LIB") == null) { + setupExternalJCL("converterJclMin10"); + JavaCore.setClasspathVariables( + new String[] {"CONVERTER_JCL10_LIB", "CONVERTER_JCL10_SRC", "CONVERTER_JCL10_SRCROOT"}, + new IPath[] {getConverterJCLPath("10"), getConverterJCLSourcePath("10"), getConverterJCLRootSourcePath()}, + null); + } } else if (JavaCore.getClasspathVariable("CONVERTER_JCL_LIB") == null) { setupExternalJCL("converterJclMin"); JavaCore.setClasspathVariables( @@ -177,6 +187,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests { setUpJavaProject("Converter17", "1.7"); //$NON-NLS-1$ //$NON-NLS-2$ setUpJavaProject("Converter18", "1.8"); //$NON-NLS-1$ //$NON-NLS-2$ setUpJavaProject("Converter9", "9"); //$NON-NLS-1$ //$NON-NLS-2$ + setUpJavaProject("Converter10", "10"); //$NON-NLS-1$ //$NON-NLS-2$ waitUntilIndexesReady(); // needed to find secondary types PROJECT_SETUP = true; } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java index 89a3410927..8b179d937d 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/TypeAnnotationsConverterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,7 +23,7 @@ public class TypeAnnotationsConverterTest extends ConverterTestSetup { public void setUpSuite() throws Exception { super.setUpSuite(); - this.ast = AST.newAST(AST_INTERNAL_JLS9); + this.ast = AST.newAST(AST_INTERNAL_JLS10); } public TypeAnnotationsConverterTest(String name) { diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index 0d596050d5..a5ad49c20b 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -107,8 +107,14 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { /** * Internal synonym for constant AST.JSL9 * to alleviate deprecation warnings once AST.JLS9 is deprecated in future. + * @deprecated */ protected static final int AST_INTERNAL_JLS9 = AST.JLS9; + /** + * Internal synonym for constant AST.JSL10 + * to alleviate deprecation warnings once AST.JLS10 is deprecated in future. + */ + protected static final int AST_INTERNAL_JLS10 = AST.JLS10; public static class BasicProblemRequestor implements IProblemRequestor { public void acceptProblem(IProblem problem) {} @@ -1387,21 +1393,13 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { return createJava9ProjectWithJREAttributes(name, new String[]{"src"}, null, compliance); } protected IJavaProject createJava9Project(String name, String[] srcFolders) throws CoreException { - return createJava9ProjectWithJREAttributes(name, srcFolders, null); + return createJava9ProjectWithJREAttributes(name, srcFolders, null, "9"); + } + protected IJavaProject createJava10Project(String name, String[] srcFolders) throws CoreException { + return createJava9ProjectWithJREAttributes(name, srcFolders, null, "10"); } protected IJavaProject createJava9ProjectWithJREAttributes(String name, String[] srcFolders, IClasspathAttribute[] attributes) throws CoreException { - String javaHome = System.getProperty("java.home") + File.separator; - Path bootModPath = new Path(javaHome +"/lib/jrt-fs.jar"); - Path sourceAttachment = new Path(javaHome +"/lib/src.zip"); - IClasspathEntry jrtEntry = JavaCore.newLibraryEntry(bootModPath, sourceAttachment, null, null, attributes, false); - IJavaProject project = this.createJavaProject(name, srcFolders, new String[0], - new String[0], "bin", "9"); - IClasspathEntry[] old = project.getRawClasspath(); - IClasspathEntry[] newPath = new IClasspathEntry[old.length +1]; - System.arraycopy(old, 0, newPath, 0, old.length); - newPath[old.length] = jrtEntry; - project.setRawClasspath(newPath, null); - return project; + return createJava9ProjectWithJREAttributes(name, srcFolders, attributes, "9"); } protected IJavaProject createJava9ProjectWithJREAttributes(String name, String[] srcFolders, IClasspathAttribute[] attributes, String compliance) throws CoreException { String javaHome = System.getProperty("java.home") + File.separator; @@ -1947,6 +1945,12 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); javaProject.setOptions(options); + } else if ("10".equals(compliance)) { + Map options = new HashMap(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + javaProject.setOptions(options); } result[0] = javaProject; } @@ -3039,7 +3043,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { newJclLibString = "JCL18_FULL"; newJclSrcString = "JCL18_SRC"; // Use the same source } else { - if (compliance.length() < 3) { + if (compliance.equals("10")) { + newJclLibString = "JCL10_LIB"; + newJclSrcString = "JCL10_SRC"; + } else if (compliance.length() < 3) { newJclLibString = "JCL19_LIB"; newJclSrcString = "JCL19_SRC"; } else if (compliance.charAt(2) > '7') { @@ -3088,9 +3095,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { IPath jcl5Lib = new Path("JCL15_LIB"); IPath jcl8Lib = new Path("JCL18_LIB"); IPath jcl9Lib = new Path("JCL19_LIB"); + IPath jcl10Lib = new Path("JCL10_LIB"); IPath jclFull = new Path("JCL18_FULL"); - return path.equals(jclLib) || path.equals(jcl5Lib) || path.equals(jcl8Lib) || path.equals(jcl9Lib) || path.equals(jclFull); + return path.equals(jclLib) || path.equals(jcl5Lib) || path.equals(jcl8Lib) || path.equals(jcl9Lib) || path.equals(jcl10Lib) || path.equals(jclFull); } public void setUpJCLClasspathVariables(String compliance) throws JavaModelException, IOException { setUpJCLClasspathVariables(compliance, false); @@ -3137,6 +3145,14 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { new IPath[] {getExternalJCLPath("9"), getExternalJCLSourcePath("9"), getExternalJCLRootSourcePath()}, null); } + } else if ("10".equals(compliance)) { + if (JavaCore.getClasspathVariable("JCL10_LIB") == null) { + setupExternalJCL("jclMin10"); + JavaCore.setClasspathVariables( + new String[] {"JCL10_LIB", "JCL10_SRC", "JCL_SRCROOT"}, + new IPath[] {getExternalJCLPath("9"), getExternalJCLSourcePath("9"), getExternalJCLRootSourcePath()}, + null); + } } else { if (JavaCore.getClasspathVariable("JCL_LIB") == null) { setupExternalJCL("jclMin"); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java index 82e1053222..9d2b3cb189 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2596,7 +2596,7 @@ public void testBug495598_001() throws CoreException { "public class X {}\n"); ICompilationUnit cuD = getCompilationUnit("/P/src/X.java"); - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setProject(this.testProject); parser.setSource(cuD); parser.setResolveBindings(true); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests10.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests10.java new file mode 100644 index 0000000000..8ff3ac113e --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests10.java @@ -0,0 +1,354 @@ +/******************************************************************************* + * Copyright (c) 2018 Jesper Steen Møller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * Jesper Steen Møller - initial API and implementation + * bug 529556 - [18.3] Add content assist support for 'var' as a type + *******************************************************************************/ +package org.eclipse.jdt.core.tests.model; + +import java.util.stream.Stream; + +import org.eclipse.jdt.core.JavaModelException; + +import junit.framework.Test; + +public class CompletionTests10 extends AbstractJavaModelCompletionTests { + static { +// TESTS_NAMES = new String[]{"test0001_block_scope"}; + } +public CompletionTests10(String name) { + super(name); +} +public void setUpSuite() throws Exception { + if (COMPLETION_PROJECT == null) { + COMPLETION_PROJECT = setUpJavaProject("Completion", "10"); + } else { + setUpProjectCompliance(COMPLETION_PROJECT, "10"); + } + super.setUpSuite(); +} +public static Test suite() { + return buildModelTestSuite(CompletionTests10.class); +} +public void test0001_block_scope() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0001/Test.java", + "package test0001;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0001a_block_scope_switch() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0001/Test.java", + "package test0001;\n" + + "\n" + + "public class Test {\n" + + " void x(int a) {\n" + + " switch(a) {\n" + + " case 1: va\n" + + " }\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0002_block_scope_final() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0002/Test.java", + "package test0002;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " final va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0003_inside_for() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0003/Test.java", + "package test0003;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " for(va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0004_inside_for_final() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0004/Test.java", + "package test0004;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " for(final va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0005_inside_try() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0005/Test.java", + "package test0005;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " try(va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} +public void test0006_inside_try_final() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0006/Test.java", + "package test0006;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " try(final va\n" + + " }\n" + + "}", + "va"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertResults( + "var[KEYWORD]{var, null, null, var, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", + result.proposals); +} + +public void test0007_not_inside_expression() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0007/Test.java", + "package test0007;\n" + + "\n" + + "public class Test {\n" + + " void x() {\n" + + " int a = 2 + \n" + + " }\n" + + "}", + "+ "); + + assertResults( + "expectedTypesSignatures={S,I,J,F,D,C,B,Ljava.lang.String;}\n" + + "expectedTypesKeys={S,I,J,F,D,C,B,Ljava/lang/String;}", + result.context); + + assertProposalCount("var[KEYWORD]", 0, 14, result); +} + +public void test0008_not_in_class_scope() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0008/Test.java", + "package test0008;\n" + + "\n" + + "public class Test { \n" + + + "}", + "{"); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + + assertProposalCount("var[KEYWORD]", 0, 21, result); +} + public void test0009_in_formal_param_lists() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0009/Test.java", + "package test0009;\n" + + "\n" + + "public class Test {\n" + + " void x( ) {\n" + + " }\n" + + "}", + "x("); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null", + result.context); + assertProposalCount("var[KEYWORD]", 0, 15, result); + } + +public void testbug_529556_missing_type_info_on_vars() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/test0001/Test.java", + "package test0001;\n" + + "\n" + + "public class Test {\n" + + " private class Dummy {\n" + + " public void a_method() {/n"+ + " }\n" + + " void x() {\n" + + " var x = new Dummy();\n" + + " x.a\n" + + " }\n" + + "}", + "x.a"); + assertResults( + "a_method[METHOD_REF]{a_method(), Ltest0001.Test$Dummy;, ()V, a_method, null, " + (R_DEFAULT + 30) + "}", + result.proposals); +} +public void testBug532476a() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var i_jk = 0;\n" + + " System.out.println(i_);/n"+ + " }\n" + + "}", + "i_"); + assertResults( + "i_jk[LOCAL_VARIABLE_REF]{i_jk, null, I, i_jk, null, " + (R_DEFAULT + 22) + "}", + result.proposals); +} +public void testBug532476b() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (var i_jkl : args) {\n" + + " System.out.println(i_);/n"+ + " }\n" + + " }\n" + + "}", + "i_"); + assertResults( + "i_jkl[LOCAL_VARIABLE_REF]{i_jkl, null, Ljava.lang.Object;, i_jkl, null, " + (R_DEFAULT + 22) + "}", + result.proposals); +} +public void testBug532476c() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (var i_jkl = 0; i_ " + + " }\n" + + "}", + "i_"); + assertResults( + "i_jkl[LOCAL_VARIABLE_REF]{i_jkl, null, I, i_jkl, null, " + (R_DEFAULT + 22) + "}", + result.proposals); +} +public void testBug532476d() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (var i_jkl = 0; ; i_ " + + " }\n" + + "}", + "i_"); + assertResults( + "i_jkl[LOCAL_VARIABLE_REF]{i_jkl, null, I, i_jkl, null, " + (R_DEFAULT + 22) + "}", + result.proposals); +} +public void testBug532476e() throws JavaModelException { + CompletionResult result = complete( + "/Completion/src3/p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (var i_jkl : args) {\n" + + " System.out.println(i_jkl.fin);/n"+ + " }\n" + + " }\n" + + "}", + "i_jkl.fin"); + assertResults( + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, " + (R_DEFAULT + 30) + "}", + result.proposals); +} +private void assertProposalCount(String proposal, int expectedCount, int expectedOtherCount, CompletionResult result) { + String[] proposals = result.proposals.split("\n"); + long proposalsCount = Stream.of(proposals).filter(s -> s.startsWith(proposal)).count(); + assertEquals( + "Unexpected occurrences of " + proposal + " - result was " + result.proposals, + expectedCount, proposalsCount); + + long otherProposalsCount = proposals.length - proposalsCount; + assertEquals( + "Unexpected occurrences that were not " + proposal + " - result was " + result.proposals, + expectedOtherCount, otherProposalsCount); +} + +} diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java index 5508af8281..7841a36750 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java @@ -359,6 +359,7 @@ public void test522604_0001() throws Exception { } } + public void test486988_0010() throws Exception { IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9"); IJavaProject project2 = createJavaProject("Completion9_2", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9"); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations9Test.java index 736f8963d6..6ac2a92d5d 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations9Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations9Test.java @@ -47,7 +47,7 @@ public class ExternalAnnotations9Test extends ExternalAnnotations18Test { static { // TESTS_NAMES = new String[] {"testBug522401"}; } - + public static Test suite() { return buildModelTestSuite(ExternalAnnotations9Test.class, BYTECODE_DECLARATION_ORDER); } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java index f523f5e9ed..3c63fac4f5 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaConventionTests.java @@ -96,6 +96,7 @@ public class JavaConventionTests extends AbstractJavaModelTests { CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_8, CompilerOptions.VERSION_9, + CompilerOptions.VERSION_10, }; /* diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java index c57bbbac31..e4b81e3ca1 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java @@ -2633,7 +2633,7 @@ public void testBug351697() throws Exception { proj.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); try { - ASTParser parser= ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser= ASTParser.newParser(AST_INTERNAL_JLS10); parser.setSource(unit); parser.setResolveBindings(true); ASTNode node = parser.createAST(null); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs10Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs10Tests.java new file mode 100644 index 0000000000..6652b41e71 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs10Tests.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.model; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.WorkingCopyOwner; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.ReferenceMatch; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.core.search.SearchMatch; +import org.eclipse.jdt.core.search.TypeReferenceMatch; +import junit.framework.Test; + +public class JavaSearchBugs10Tests extends AbstractJavaSearchTests { + + static { +// org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true; +// TESTS_NUMBERS = new int[] { 19 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] {"testBug529434_001"}; +} + +public JavaSearchBugs10Tests(String name) { + super(name); + this.endChar = ""; +} +public static Test suite() { + return buildModelTestSuite(JavaSearchBugs10Tests.class, BYTECODE_DECLARATION_ORDER); +} +class TestCollector extends JavaSearchResultCollector { + public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { + super.acceptSearchMatch(searchMatch); + } +} +class ReferenceCollector extends JavaSearchResultCollector { + protected void writeLine() throws CoreException { + super.writeLine(); + ReferenceMatch refMatch = (ReferenceMatch) this.match; + IJavaElement localElement = refMatch.getLocalElement(); + if (localElement != null) { + this.line.append("+["); + if (localElement.getElementType() == IJavaElement.ANNOTATION) { + this.line.append('@'); + this.line.append(localElement.getElementName()); + this.line.append(" on "); + this.line.append(localElement.getParent().getElementName()); + } else { + this.line.append(localElement.getElementName()); + } + this.line.append(']'); + } + } + +} +class TypeReferenceCollector extends ReferenceCollector { + protected void writeLine() throws CoreException { + super.writeLine(); + TypeReferenceMatch typeRefMatch = (TypeReferenceMatch) this.match; + IJavaElement[] others = typeRefMatch.getOtherElements(); + int length = others==null ? 0 : others.length; + if (length > 0) { + this.line.append("+["); + for (int i=0; i<length; i++) { + IJavaElement other = others[i]; + if (i>0) this.line.append(','); + if (other.getElementType() == IJavaElement.ANNOTATION) { + this.line.append('@'); + this.line.append(other.getElementName()); + this.line.append(" on "); + this.line.append(other.getParent().getElementName()); + } else { + this.line.append(other.getElementName()); + } + } + this.line.append(']'); + } + } +} + +IJavaSearchScope getJavaSearchScope() { + return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")}); +} +IJavaSearchScope getJavaSearchScopeBugs(String packageName, boolean addSubpackages) throws JavaModelException { + if (packageName == null) return getJavaSearchScope(); + return getJavaSearchPackageScope("JavaSearchBugs", packageName, addSubpackages); +} +public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException { + if (this.wcOwner == null) { + this.wcOwner = new WorkingCopyOwner() {}; + } + return getWorkingCopy(path, source, this.wcOwner); +} +@Override +public void setUpSuite() throws Exception { + super.setUpSuite(); + JAVA_PROJECT = setUpJavaProject("JavaSearchBugs", "10"); +} +public void tearDownSuite() throws Exception { + deleteProject("JavaSearchBugs"); + super.tearDownSuite(); +} +protected void setUp () throws Exception { + super.setUp(); + this.resultCollector = new TestCollector(); + this.resultCollector.showAccuracy(true); +} + +public void testBug529434_001() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", + "class B {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " var B = new B();\n" + + " }\n" + + "}\n" + ); + search("B", CONSTRUCTOR, REFERENCES, EXACT_RULE); + assertSearchResults("src/X.java void X.main(String[]) [new B()] EXACT_MATCH"); +} +// Add more tests here +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index ee4d3595af..847747e7a2 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -709,9 +709,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests { Hashtable<String, String> javaCoreOptions = JavaCore.getOptions(); try { IJavaProject project = setUpJavaProject("ConvertToModule", "9"); - if (!project.getOption("org.eclipse.jdt.core.compiler.compliance", true).equals("9")) { - return; - } + assertEquals(project.getOption("org.eclipse.jdt.core.compiler.compliance", true), "9"); project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); IPackageFragmentRoot theRoot = null; @@ -4886,6 +4884,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests { JavaCore.setOptions(javaCoreOptions); } } + @Deprecated public void testBug519935() throws CoreException, IOException { if (!isJRE9) return; Hashtable<String, String> javaCoreOptions = JavaCore.getOptions(); @@ -4954,6 +4953,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests { JavaCore.setOptions(javaCoreOptions); } } + @Deprecated public void testBug520310() throws CoreException, IOException { if (!isJRE9) return; try { diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java index 6c76ce18b9..9e73be422e 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java @@ -293,7 +293,7 @@ public class NullAnnotationModelTests extends ReconcilerTests { "Buildpath problem: the type invalid, which is configured as a null annotation type, cannot be resolved\n" + "----------\n"); - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setProject(p); parser.setResolveBindings(true); parser.setSource(unit); @@ -356,7 +356,7 @@ public class NullAnnotationModelTests extends ReconcilerTests { assertEquals("Should have no markers", 0, markers.length); // Challenge CompilationUnitResolver: - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setProject(p); parser.setResolveBindings(true); parser.setSource(unit); @@ -427,7 +427,7 @@ public class NullAnnotationModelTests extends ReconcilerTests { assertEquals("Unexpected marker path", "/P/p1/C1.java", markers[0].getResource().getFullPath().toString()); // Challenge CompilationUnitResolver: - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setProject(p); parser.setResolveBindings(true); parser.setSource(unit); @@ -480,7 +480,7 @@ public class NullAnnotationModelTests extends ReconcilerTests { final ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); assertNoProblem(c1SourceString.toCharArray(), unit); - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setProject(p); parser.setResolveBindings(true); parser.setSource(unit); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java index 573dae8e1a..418bb24276 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -76,7 +76,7 @@ public class ReconcilerTests extends ModifyingResourceTests { } } - /*package*/ static final int JLS_LATEST = AST.JLS9; + /*package*/ static final int JLS_LATEST = AST.JLS10; static class ReconcileParticipant extends CompilationParticipant { IJavaElementDelta delta; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java index b06899c52c..f16c12b3b2 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java @@ -1,13 +1,15 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * * * Contributors: * IBM Corporation - initial API and implementation * Gábor Kövesdán - Contribution for Bug 350000 - [content assist] Include non-prefix matches in auto-complete suggestions + * Jesper Steen Møller - Contributions for bug 529552 - [18.3] Add 'var' in completions *******************************************************************************/ package org.eclipse.jdt.core.tests.model; @@ -34,6 +36,7 @@ public class RunCompletionModelTests extends junit.framework.TestCase { COMPLETION_SUITES.add(CompletionTests_1_5.class); COMPLETION_SUITES.add(CompletionTests18.class); COMPLETION_SUITES.add(CompletionTests9.class); + COMPLETION_SUITES.add(CompletionTests10.class); COMPLETION_SUITES.add(CompletionContextTests.class); COMPLETION_SUITES.add(CompletionContextTests_1_5.class); COMPLETION_SUITES.add(CompletionWithMissingTypesTests.class); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java index 8b12c726da..e2539e7699 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunJavaSearchTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -62,6 +62,7 @@ public class RunJavaSearchTests extends junit.framework.TestCase { allClasses.add(JavaSearchBugsTests2.class); allClasses.add(JavaSearchBugs8Tests.class); allClasses.add(JavaSearchBugs9Tests.class); + allClasses.add(JavaSearchBugs10Tests.class); allClasses.add(JavaSearchMultipleProjectsTests.class); allClasses.add(SearchTests.class); allClasses.add(JavaSearchScopeTests.class); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java index 0919999255..f73a622c9c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java @@ -1211,9 +1211,136 @@ public void test528818a() throws CoreException, IOException { assertNotNull("Type should not be null", type); String[][] resolveType = type.resolveType("java.lang.Object"); assertNotNull("Type should not be null", resolveType); - } finally { deleteProject("P"); } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=479963 +public void test531046a() throws CoreException, IOException { + if (!isJRE9) return; + try { + createJava10Project("P", new String[] {"src"}); + String source = "package p;\n" + + "public class X {\n" + + " public static void main(java.lang.String[] args) {\n" + + " var s1 = args[0];\n" + + " System.out.println(s1);\n" + + " }\n" + + "}\n"; + createFolder("/P/src/p"); + createFile("/P/src/p/X.java", source); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + String select = "s1"; + IJavaElement[] elements = unit.codeSelect(source.indexOf(select), select.length()); + ILocalVariable variable = (ILocalVariable) elements[0]; + elements = unit.findElements(variable); + assertNotNull("Should not be null", elements); + assertEquals("incorrect type", "Ljava.lang.String;", variable.getTypeSignature()); + } finally { + deleteProject("P"); + } +} +public void test531046b() throws CoreException, IOException { + if (!isJRE9) return; + try { + createJava10Project("P", new String[] {"src"}); + String source = "package p;\n" + + "public class X {\n" + + " public static void main(java.lang.String[] args) {\n" + + " var s1 = args[0];\n" + + " System.out.println(s1);\n" + + " }\n" + + "}\n"; + createFolder("/P/src/p"); + createFile("/P/src/p/X.java", source); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + String select = "s1"; + IJavaElement[] elements = unit.codeSelect(source.lastIndexOf(select), select.length()); + ILocalVariable variable = (ILocalVariable) elements[0]; + elements = unit.findElements(variable); + assertNotNull("Should not be null", elements); + assertEquals("incorrect type", "Ljava.lang.String;", variable.getTypeSignature()); + } finally { + deleteProject("P"); + } +} +public void test531046c() throws CoreException, IOException { + if (!isJRE9) return; + try { + createJava10Project("P", new String[] {"src"}); + String source = "package p;\n" + + "public class X {\n" + + " public static void main(java.lang.String[] args) {\n" + + " var s1 = args;\n" + + " System.out.println(s1);\n" + + " }\n" + + "}\n"; + createFolder("/P/src/p"); + createFile("/P/src/p/X.java", source); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + String select = "s1"; + IJavaElement[] elements = unit.codeSelect(source.lastIndexOf(select), select.length()); + ILocalVariable variable = (ILocalVariable) elements[0]; + elements = unit.findElements(variable); + assertNotNull("Should not be null", elements); + assertEquals("incorrect type", "[Ljava.lang.String;", variable.getTypeSignature()); + } finally { + deleteProject("P"); + } +} +public void test531046d() throws CoreException, IOException { + if (!isJRE9) return; + try { + createJava10Project("P", new String[] {"src"}); + String source = "package p;\n" + + "public class X {\n" + + " public static void main(java.lang.String[] args) {\n" + + " var s1 = new java.util.HashMap<String, Object>();\n" + + " }\n" + + "}\n"; + createFolder("/P/src/p"); + createFile("/P/src/p/X.java", source); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + String select = "s1"; + IJavaElement[] elements = unit.codeSelect(source.lastIndexOf(select), select.length()); + ILocalVariable variable = (ILocalVariable) elements[0]; + elements = unit.findElements(variable); + assertNotNull("Should not be null", elements); + assertEquals("incorrect type", "Ljava.util.HashMap<Ljava.lang.String;Ljava.lang.Object;>;", variable.getTypeSignature()); + } finally { + deleteProject("P"); + } +} +public void test531046e() throws CoreException, IOException { + if (!isJRE9) return; + try { + createJava10Project("P", new String[] {"src"}); + String source = "package p;\n" + + "public class X {\n" + + " public static void main(java.lang.String[] args) {\n" + + " var s1 = new java.util.HashMap<String, Object>();\n" + + " }\n" + + "}\n"; + createFolder("/P/src/p"); + createFile("/P/src/p/X.java", source); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + String select = "var"; + IJavaElement[] elements = unit.codeSelect(source.lastIndexOf(select), select.length()); + assertEquals("should not be empty", 1, elements.length); + IType type = (IType) elements[0]; + assertEquals("incorrect type", "java.util.HashMap<java.lang.String,java.lang.Object>", type.getFullyQualifiedParameterizedName()); + } finally { + deleteProject("P"); + } +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java index f7a005aecc..93ba63190e 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -62,7 +62,12 @@ public class ASTRewritingTest extends AbstractJavaModelTests { /** @deprecated using deprecated code */ private final static int JLS8_INTERNAL = AST.JLS8; - private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, AST.JLS9 }; + /** @deprecated using deprecated code */ + private final static int JLS9_INTERNAL = AST.JLS9; + + private final static int JLS10_INTERNAL = AST.JLS10; + + private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL }; private static final String ONLY_AST_STRING = "_only"; private static final String SINCE_AST_STRING = "_since"; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java index 7877192e48..5b740675a3 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -4956,7 +4956,7 @@ public class ImportRewriteTest extends AbstractJavaModelTests { "}\n"; ICompilationUnit cu = pack1.createCompilationUnit("X.java", contents, false, null); - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setSource(cu); parser.setResolveBindings(true); parser.setStatementsRecovery(true); @@ -4981,7 +4981,7 @@ public class ImportRewriteTest extends AbstractJavaModelTests { "}\n"; ICompilationUnit cu = pack1.createCompilationUnit("X.java", contents, false, null); - ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS9); + ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS10); parser.setSource(cu); parser.setResolveBindings(true); parser.setStatementsRecovery(true); diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter10/.classpath b/org.eclipse.jdt.core.tests.model/workspace/Converter10/.classpath new file mode 100644 index 0000000000..3522bc0c3f --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Converter10/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="var" path="CONVERTER_JCL18_LIB" sourcepath="CONVERTER_JCL18_SRC" rootpath="CONVERTER_JCL_SRCROOT"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter10/.project b/org.eclipse.jdt.core.tests.model/workspace/Converter10/.project new file mode 100644 index 0000000000..474aee115d --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Converter10/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Converter10</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter10/src/X.java b/org.eclipse.jdt.core.tests.model/workspace/Converter10/src/X.java new file mode 100644 index 0000000000..5a1a8880f1 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Converter10/src/X.java @@ -0,0 +1,4 @@ +public class X { + public void foo(X this) { + } +} diff --git a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java index f1a7950c63..095863df6d 100644 --- a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java +++ b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/SecondaryTypesPerformanceTest.java @@ -81,7 +81,7 @@ public class SecondaryTypesPerformanceTest extends PerformanceTestCase { classpathList.add(testScratchArea); for (int i = 0; i<10; ++i) { - ASTParser parser = ASTParser.newParser(AST.JLS9); + ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setResolveBindings(true); parser.setStatementsRecovery(true); parser.setBindingsRecovery(true); diff --git a/org.eclipse.jdt.core/.settings/.api_filters b/org.eclipse.jdt.core/.settings/.api_filters index 5b320e9377..28f4232e07 100644 --- a/org.eclipse.jdt.core/.settings/.api_filters +++ b/org.eclipse.jdt.core/.settings/.api_filters @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <component id="org.eclipse.jdt.core" version="2"> <resource path="META-INF/MANIFEST.MF"> - <filter comment="keep the same version as 4.7.1 for now" id="924844039"> + <filter id="924844039"> <message_arguments> - <message_argument value="3.13.0"/> - <message_argument value="3.13.0"/> + <message_argument value="3.13.102"/> + <message_argument value="3.13.101"/> </message_arguments> </filter> <filter comment="API was backported to 4.7.1a" id="926941240"> @@ -14,34 +14,123 @@ </message_arguments> </filter> </resource> - <resource path="compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java" type="org.eclipse.jdt.core.compiler.CategorizedProblem"> - <filter comment="future additions have always been announced in the API" id="336658481"> + <resource path="compiler/org/eclipse/jdt/core/compiler/IProblem.java" type="org.eclipse.jdt.core.compiler.IProblem"> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarIsNotAllowedHere"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarIsReserved"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarIsReservedInFuture"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalCannotBeArray"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalCannotBeArrayInitalizers"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalCannotBeLambda"/> + </message_arguments> + </filter> + <filter id="1209008130"> <message_arguments> - <message_argument value="org.eclipse.jdt.core.compiler.CategorizedProblem"/> - <message_argument value="CAT_MODULE"/> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalCannotBeMethodReference"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalInitializedToNull"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalInitializedToVoid"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalMultipleDeclarators"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalReferencesItself"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VarLocalWithoutInitizalier"/> </message_arguments> </filter> </resource> - <resource path="compiler/org/eclipse/jdt/core/compiler/IProblem.java" type="org.eclipse.jdt.core.compiler.IProblem"> - <filter comment="must react to added constant CAT_MODULE" id="388194388"> + <resource path="dom/org/eclipse/jdt/core/dom/AST.java" type="org.eclipse.jdt.core.dom.AST"> + <filter id="1141899266"> <message_arguments> - <message_argument value="org.eclipse.jdt.core.compiler.IProblem"/> - <message_argument value="IgnoreCategoriesMask"/> - <message_argument value="16777215"/> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="JLS10"/> </message_arguments> </filter> </resource> - <resource path="dom/org/eclipse/jdt/core/dom/CompilationUnit.java" type="org.eclipse.jdt.core.dom.CompilationUnit"> - <filter comment="has never been subclassable" id="336744520"> + <resource path="dom/org/eclipse/jdt/core/dom/Type.java" type="org.eclipse.jdt.core.dom.Type"> + <filter id="1141899266"> <message_arguments> - <message_argument value="org.eclipse.jdt.core.dom.CompilationUnit"/> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="isVar()"/> </message_arguments> </filter> </resource> - <resource path="dom/org/eclipse/jdt/core/dom/TryStatement.java" type="org.eclipse.jdt.core.dom.TryStatement"> - <filter comment="has never been subclassable" id="336744520"> + <resource path="model/org/eclipse/jdt/core/JavaCore.java" type="org.eclipse.jdt.core.JavaCore"> + <filter id="1141899266"> + <message_arguments> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="VERSION_10"/> + </message_arguments> + </filter> + <filter id="1141899266"> <message_arguments> - <message_argument value="org.eclipse.jdt.core.dom.TryStatement"/> + <message_argument value="3.14"/> + <message_argument value="3.13"/> + <message_argument value="getAllVersions()"/> </message_arguments> </filter> </resource> diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java index 095c943bff..0c0524327b 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -112,7 +112,7 @@ public class ClasspathJep247 extends ClasspathLocation { HashMap<String, ?> env = new HashMap<>(); this.fs = FileSystems.newFileSystem(uri, env); } - this.releasePath = this.fs.getPath(""); //$NON-NLS-1$ + this.releasePath = this.fs.getPath("/"); //$NON-NLS-1$ if (!Files.exists(this.fs.getPath(this.release))) { throw new IllegalArgumentException("release " + this.release + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$ } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index 8c385c1ca0..2016d311c2 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -1739,6 +1739,8 @@ private boolean checkVMVersion(long minimalSupportedVersion) { return ClassFileConstants.JDK1_8 >= minimalSupportedVersion; case ClassFileConstants.MAJOR_VERSION_9: // 9 return ClassFileConstants.JDK9 >= minimalSupportedVersion; + case ClassFileConstants.MAJOR_VERSION_10: // 9 + return ClassFileConstants.JDK10 >= minimalSupportedVersion; } // unknown version return false; @@ -2164,6 +2166,16 @@ public void configure(String[] argv) { mode = DEFAULT; continue; } + if (currentArg.equals("-10") || currentArg.equals("-10.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (didSpecifyCompliance) { + throw new IllegalArgumentException( + this.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$ + } + didSpecifyCompliance = true; + this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + mode = DEFAULT; + continue; + } if (currentArg.equals("-d")) { //$NON-NLS-1$ if (this.destinationPath != null) { StringBuffer errorMessage = new StringBuffer(); @@ -2702,6 +2714,8 @@ public void configure(String[] argv) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); } else if (currentArg.equals("1.9") || currentArg.equals("9") || currentArg.equals("9.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (currentArg.equals("10") || currentArg.equals("10.0")) { //$NON-NLS-1$//$NON-NLS-2$ + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); } else if (currentArg.equals("jsr14")) { //$NON-NLS-1$ this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14); @@ -2787,6 +2801,8 @@ public void configure(String[] argv) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); } else if (currentArg.equals("1.9") || currentArg.equals("9") || currentArg.equals("9.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + } else if (currentArg.equals("10") || currentArg.equals("10.0")) { //$NON-NLS-1$//$NON-NLS-2$ + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); } else { throw new IllegalArgumentException(this.bind("configure.source", currentArg)); //$NON-NLS-1$ } @@ -5347,7 +5363,30 @@ protected void validateOptions(boolean didSpecifyCompliance) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); } + } else if (CompilerOptions.VERSION_10.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } else if (CompilerOptions.VERSION_1_8.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } else if (CompilerOptions.VERSION_9.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (CompilerOptions.VERSION_10.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + } } + } else if (this.didSpecifySource) { Object version = this.options.get(CompilerOptions.OPTION_Source); // default is source 1.3 target 1.2 and compliance 1.4 @@ -5369,6 +5408,9 @@ protected void validateOptions(boolean didSpecifyCompliance) { } else if (CompilerOptions.VERSION_9.equals(version)) { if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (CompilerOptions.VERSION_10.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); } } @@ -5377,7 +5419,11 @@ protected void validateOptions(boolean didSpecifyCompliance) { final String compliance = this.options.get(CompilerOptions.OPTION_Compliance); this.complianceLevel = CompilerOptions.versionToJdkLevel(compliance); } - if (sourceVersion.equals(CompilerOptions.VERSION_9) + if (sourceVersion.equals(CompilerOptions.VERSION_10) + && this.complianceLevel < ClassFileConstants.JDK10) { + // compliance must be 10 if source is 10 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_10)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_9) && this.complianceLevel < ClassFileConstants.JDK9) { // compliance must be 9 if source is 9 throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_9)); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java index f34cb4618e..b02403efc8 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java @@ -12407,7 +12407,7 @@ public final class CompletionEngine continue next; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328674 - if (local.declaration.initialization != null) { + if (local.declaration.initialization != null && !local.declaration.type.isTypeNameVar(null)) { // proposal being asked inside field's initialization. Don't propose this field. continue next; } diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java index f38be41fab..85aab61d1e 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - contributions for: + * Bug 531046: [10] ICodeAssist#codeSelect support for 'var' *******************************************************************************/ package org.eclipse.jdt.internal.codeassist; @@ -56,9 +58,11 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.ast.PackageVisibilityStatement; +import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -1422,6 +1426,13 @@ public final class SelectionEngine extends Engine implements ISearchRequestor { return true; } @Override + public boolean visit( + LocalDeclaration localDeclaration, BlockScope scope) { + if (localDeclaration.type instanceof SingleTypeReference && ((SingleTypeReference)localDeclaration.type).token == assistIdentifier) + throw new SelectionNodeFound(localDeclaration.binding.type); + return true; // do nothing by default, keep traversing + } + @Override public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { if (fieldDeclaration.name == assistIdentifier){ throw new SelectionNodeFound(fieldDeclaration.binding); diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java index c694a53994..6174f59b53 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java @@ -9,6 +9,9 @@ * IBM Corporation - initial API and implementation * Stephan Herrmann - Contribution for * bug 401035 - [1.8] A few tests have started failing recently + * Jesper Steen Møller - Contributions for + * bug 529552 - [18.3] Add 'var' in completions + * Bug 529556 - [18.3] Add content assist support for 'var' as a type *******************************************************************************/ package org.eclipse.jdt.internal.codeassist.complete; @@ -2788,7 +2791,11 @@ protected void consumeExitVariableWithInitialization() { AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; if (this.cursorLocation + 1 < variable.initialization.sourceStart || this.cursorLocation > variable.initialization.sourceEnd) { - variable.initialization = null; + if (!variable.type.isTypeNameVar(null)) { + if (! (variable instanceof LocalDeclaration && ((LocalDeclaration)variable).isTypeNameVar(this.compilationUnit.scope))) { + variable.initialization = null; + } + } } else if (this.assistNode != null && this.assistNode == variable.initialization) { this.assistNodeParent = variable; } @@ -4825,6 +4832,9 @@ public NameReference createSingleAssistNameReference(char[] assistName, long pos keywords[count++]= Keywords.FINAL; keywords[count++]= Keywords.CLASS; + if (this.options.complianceLevel >= ClassFileConstants.JDK10) { + keywords[count++]= Keywords.VAR; + } if(this.previousKind == K_BLOCK_DELIMITER) { switch (this.previousInfo) { @@ -4845,6 +4855,10 @@ public NameReference createSingleAssistNameReference(char[] assistName, long pos if(isInsideBreakable()) { keywords[count++]= Keywords.BREAK; } + } else if (kind == K_BETWEEN_FOR_AND_RIGHT_PAREN) { + if (this.options.complianceLevel >= ClassFileConstants.JDK10) { + keywords[count++]= Keywords.VAR; + } } else if(kind != K_BETWEEN_CASE_AND_COLON && kind != K_BETWEEN_DEFAULT_AND_COLON) { keywords[count++]= Keywords.TRUE; keywords[count++]= Keywords.FALSE; @@ -4872,6 +4886,9 @@ public NameReference createSingleAssistNameReference(char[] assistName, long pos keywords[count++]= Keywords.FINAL; keywords[count++]= Keywords.CLASS; + if (this.options.complianceLevel >= ClassFileConstants.JDK10) { + keywords[count++]= Keywords.VAR; + } if(isInsideLoop()) { keywords[count++]= Keywords.CONTINUE; } diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java index e905601b49..5622b84551 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Keywords.java @@ -1,17 +1,19 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller - Contributions for + * bug 529552 - [18.3] Add 'var' in completions *******************************************************************************/ package org.eclipse.jdt.internal.codeassist.impl; public interface Keywords { - int COUNT = 49; + int COUNT = 50; char[] ABSTRACT = "abstract".toCharArray(); //$NON-NLS-1$ char[] ASSERT = "assert".toCharArray(); //$NON-NLS-1$ @@ -63,4 +65,5 @@ public interface Keywords { char[] TRUE = "true".toCharArray(); //$NON-NLS-1$ char[] FALSE = "false".toCharArray(); //$NON-NLS-1$ char[] NULL = "null".toCharArray(); //$NON-NLS-1$ + char[] VAR = "var".toCharArray(); //$NON-NLS-1$ // Admittedly not a full blown keyword, just "reserved" } diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java index 1254f6a056..0daa0709d6 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java @@ -1,12 +1,14 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Møller <jesper@selskabet.org> - contributions for: + * Bug 531046: [10] ICodeAssist#codeSelect support for 'var' *******************************************************************************/ package org.eclipse.jdt.internal.codeassist.select; @@ -603,7 +605,7 @@ protected void consumeEnterVariable() { AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; if (variable.type == this.assistNode){ - if (!this.diet){ + if (!this.diet && ! variable.type.isTypeNameVar(null)) { this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } @@ -617,11 +619,14 @@ protected void consumeExitVariableWithInitialization() { // does not keep the initialization if selection is not inside AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; - int start = variable.initialization.sourceStart; - int end = variable.initialization.sourceEnd; - if ((this.selectionStart < start) && (this.selectionEnd < start) || - (this.selectionStart > end) && (this.selectionEnd > end)) { + int start = variable.declarationSourceStart; + int end = variable.declarationSourceEnd; + // Keep the initialization intact, because that's the only way we are going to know the type + if (!variable.type.isTypeNameVar(null)) { + if ((this.selectionStart < start) && (this.selectionEnd < start) || + (this.selectionStart > end) && (this.selectionEnd > end)) { variable.initialization = null; + } } triggerRecoveryUponLambdaClosure(variable, false); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 7eaa38d246..aae1f7c9f0 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -214,7 +214,18 @@ * RepeatableAnnotationIsDocumented * RepeatableAnnotationIsInherited * RepeatableAnnotationWithRepeatingContainerAnnotation -*******************************************************************************/ + * VarLocalMultipleDeclarators + * VarLocalCannotBeArray + * VarLocalReferencesItself + * VarLocalWithoutInitizalier + * VarLocalInitializedToNull + * VarLocalCannotBeArrayInitalizers + * VarLocalCannotBeLambda + * VarLocalCannotBeMethodReference + * VarIsReserved + * VarIsReservedInFuture + * VarIsNotAllowedHere +******************************************************************************/ package org.eclipse.jdt.core.compiler; import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; @@ -2033,4 +2044,31 @@ void setSourceStart(int sourceStart); int UnlikelyCollectionMethodArgumentType = 1200; /** @since 3.13 */ int UnlikelyEqualsArgumentType = 1201; + + /* Local-Variable Type Inference */ + /** @since 3.14 */ + int VarLocalMultipleDeclarators = Syntax + 1500; // ''var'' is not allowed in a compound declaration + /** @since 3.14 */ + int VarLocalCannotBeArray = Syntax + 1501; // ''var'' is not allowed as an element type of an array + /** @since 3.14 */ + int VarLocalReferencesItself = Syntax + 1502; // Declaration using ''var'' may not contin references to itself + /** @since 3.14 */ + int VarLocalWithoutInitizalier = Syntax + 1503; // Cannot use ''var'' on variable without initializer + /** @since 3.14 */ + int VarLocalInitializedToNull = TypeRelated + 1504; // Variable initialized to ''null'' needs an explicit target-type + /** @since 3.14 */ + int VarLocalInitializedToVoid = TypeRelated + 1505; // Variable initializer is ''void'' -- cannot infer variable type + /** @since 3.14 */ + int VarLocalCannotBeArrayInitalizers = TypeRelated + 1506; // Array initializer needs an explicit target-type + /** @since 3.14 */ + int VarLocalCannotBeLambda = TypeRelated + 1507; // Lambda expression needs an explicit target-type + /** @since 3.14 */ + int VarLocalCannotBeMethodReference = TypeRelated + 1508; // Method reference needs an explicit target-type + /** @since 3.14 */ + int VarIsReserved = Syntax + 1509; // ''var'' is not a valid type name + /** @since 3.14 */ + int VarIsReservedInFuture = Syntax + 1510; // ''var'' should not be used as an type name, since it is a reserved word from source level 10 on + /** @since 3.14 */ + int VarIsNotAllowedHere = Syntax + 1511; // ''var'' is not allowed here + } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java index 891c318cef..e3edb55ee8 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -107,7 +107,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds { public final static int Bit20 = 0x80000; // contains syntax errors (method declaration, type declaration, field declarations, initializer), typeref: <> name ref: lambda capture) public final static int Bit21 = 0x100000; public final static int Bit22 = 0x200000; // parenthesis count (expression) | used (import reference) shadows outer local (local declarations) - public final static int Bit23 = 0x400000; // parenthesis count (expression) + public final static int Bit23 = 0x400000; // parenthesis count (expression) | second or later declarator in declaration (local declarations) public final static int Bit24 = 0x800000; // parenthesis count (expression) public final static int Bit25 = 0x1000000; // parenthesis count (expression) public final static int Bit26 = 0x2000000; // parenthesis count (expression) @@ -177,6 +177,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds { public static final int IsLocalDeclarationReachable = Bit31; public static final int IsForeachElementVariable = Bit5; public static final int ShadowsOuterLocal = Bit22; + public static final int IsAdditionalDeclarator = Bit23; // for name refs or local decls public static final int FirstAssignmentToLocal = Bit4; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java index b723033649..c0e2c3e039 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann - Contribution for @@ -19,6 +19,7 @@ * Bug 415790 - [compiler][resource]Incorrect potential resource leak warning in for loop with close in try/catch * Jesper S Moller - Contribution for * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError) + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -417,6 +418,46 @@ public class ForeachStatement extends Statement { return output; } + private TypeBinding getCollectionElementType(TypeBinding collectionType) { + if (collectionType == null) return null; + + boolean isTargetJsr14 = this.scope.compilerOptions().targetJDK == ClassFileConstants.JDK1_4; + if (collectionType.isCapture()) { + TypeBinding upperBound = ((CaptureBinding)collectionType).firstBound; + if (upperBound != null && upperBound.isArrayType()) + collectionType = upperBound; // partially anticipating the fix for https://bugs.openjdk.java.net/browse/JDK-8013843 + } + if (collectionType.isArrayType()) { // for(E e : E[]) + return ((ArrayBinding) collectionType).elementsType(); + } else if (collectionType instanceof ReferenceBinding) { + ReferenceBinding iterableType = ((ReferenceBinding)collectionType).findSuperTypeOriginatingFrom(T_JavaLangIterable, false /*Iterable is not a class*/); + if (iterableType == null && isTargetJsr14) { + iterableType = ((ReferenceBinding)collectionType).findSuperTypeOriginatingFrom(T_JavaUtilCollection, false /*Iterable is not a class*/); + } + if (iterableType == null) return null; + + TypeBinding[] arguments = null; + switch (iterableType.kind()) { + case Binding.RAW_TYPE : // for(Object o : Iterable) + return this.scope.getJavaLangObject(); + + case Binding.GENERIC_TYPE : // for (T t : Iterable<T>) - in case used inside Iterable itself + arguments = iterableType.typeVariables(); + break; + + case Binding.PARAMETERIZED_TYPE : // for(E e : Iterable<E>) + arguments = ((ParameterizedTypeBinding)iterableType).arguments; + break; + + default: + return null; + } + // generic or parameterized case + if (arguments.length != 1) return null; // per construction can only be one + return arguments[0]; + } + return null; + } @Override public void resolve(BlockScope upperScope) { // use the scope that will hold the init declarations @@ -425,6 +466,22 @@ public class ForeachStatement extends Statement { TypeBinding elementType = this.elementVariable.type.resolvedType; TypeBinding collectionType = this.collection == null ? null : this.collection.resolveType(upperScope); + // Patch the resolved type + if (this.elementVariable.isTypeNameVar(upperScope)) { + elementType = getCollectionElementType(collectionType); + if (this.elementVariable.type.dimensions() > 0 || this.elementVariable.type.extraDimensions() > 0) { + upperScope.problemReporter().varLocalCannotBeArray(this.elementVariable); + } + if (TypeBinding.equalsEquals(TypeBinding.NULL, collectionType)) { + upperScope.problemReporter().varLocalInitializedToNull(this.elementVariable); + elementType = collectionType; + } else if (TypeBinding.equalsEquals(TypeBinding.VOID, collectionType)) { + upperScope.problemReporter().varLocalInitializedToVoid(this.elementVariable); + elementType = collectionType; + } + elementType = this.elementVariable.patchType(elementType); + } + TypeBinding expectedCollectionType = null; if (elementType != null && collectionType != null) { boolean isTargetJsr14 = this.scope.compilerOptions().targetJDK == ClassFileConstants.JDK1_4; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java index 085fc8688a..5c0ff3f67b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for @@ -28,6 +28,8 @@ * Bug 453483 - [compiler][null][loop] Improve null analysis for loops * Jesper S Moller - Contributions for * Bug 378674 - "The method can be declared as static" is wrong + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * Bug 529556 - [18.3] Add content assist support for 'var' as a type * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for * Bug 409250 - [1.8][compiler] Various loose ends in 308 code generation * Bug 426616 - [1.8][compiler] Type Annotations, multiple problems @@ -35,8 +37,11 @@ package org.eclipse.jdt.internal.compiler.ast; import static org.eclipse.jdt.internal.compiler.ast.ExpressionContext.ASSIGNMENT_CONTEXT; +import static org.eclipse.jdt.internal.compiler.ast.ExpressionContext.VANILLA_CONTEXT; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.impl.*; @@ -196,14 +201,75 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl public boolean isReceiver() { return false; } + public TypeBinding patchType(TypeBinding newType) { + // Perform upwards projection on type wrt mentioned type variables + TypeBinding[] mentionedTypeVariables= findCapturedTypeVariables(newType); + if (mentionedTypeVariables != null && mentionedTypeVariables.length > 0) { + newType = newType.upwardsProjection(this.binding.declaringScope, mentionedTypeVariables); + } + this.type.resolvedType = newType; + if (this.binding != null) { + this.binding.type = newType; + this.binding.markInitialized(); + } + return this.type.resolvedType; + } + + private TypeVariableBinding[] findCapturedTypeVariables(TypeBinding typeBinding) { + final Set<TypeVariableBinding> mentioned = new HashSet<>(); + TypeBindingVisitor.visit(new TypeBindingVisitor() { + @Override + public boolean visit(TypeVariableBinding typeVariable) { + if (typeVariable.isCapture()) + mentioned.add(typeVariable); + return super.visit(typeVariable); + } + }, typeBinding); + if (mentioned.isEmpty()) return null; + return mentioned.toArray(new TypeVariableBinding[mentioned.size()]); + } + + private static Expression findPolyExpression(Expression e) { + // This is simpler than using an ASTVisitor, since we only care about a very few select cases. + if (e instanceof FunctionalExpression) { + return e; + } + if (e instanceof ConditionalExpression) { + ConditionalExpression ce = (ConditionalExpression)e; + Expression candidate = findPolyExpression(ce.valueIfTrue); + if (candidate == null) { + candidate = findPolyExpression(ce.valueIfFalse); + } + if (candidate != null) return candidate; + } + return null; + } + @Override public void resolve(BlockScope scope) { // prescan NNBD handleNonNullByDefault(scope, this.annotations, this); - // create a binding and add it to the scope - TypeBinding variableType = this.type.resolveType(scope, true /* check bounds*/); + TypeBinding variableType = null; + boolean variableTypeInferenceError = false; + boolean isTypeNameVar = isTypeNameVar(scope); + if (isTypeNameVar) { + if ((this.bits & ASTNode.IsForeachElementVariable) == 0) { + // infer a type from the initializer + if (this.initialization != null) { + variableType = checkInferredLocalVariableInitializer(scope); + variableTypeInferenceError = variableType != null; + } else { + // That's always an error + scope.problemReporter().varLocalWithoutInitizalier(this); + variableType = scope.getJavaLangObject(); + variableTypeInferenceError = true; + } + } + } else { + variableType = this.type.resolveType(scope, true /* check bounds*/); + } this.bits |= (this.type.bits & ASTNode.HasTypeAnnotations); checkModifiers(); @@ -233,15 +299,53 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl if ((this.modifiers & ClassFileConstants.AccFinal)!= 0 && this.initialization == null) { this.modifiers |= ExtraCompilerModifiers.AccBlankFinal; } - this.binding = new LocalVariableBinding(this, variableType, this.modifiers, false /*isArgument*/); + if (isTypeNameVar) { + // Create binding for the initializer's type + // In order to resolve self-referential initializers, we must declare the variable with a placeholder type (j.l.Object), and then patch it later + this.binding = new LocalVariableBinding(this, variableType != null ? variableType : scope.getJavaLangObject(), this.modifiers, false) { + private boolean isInitialized = false; + + @Override + public void markReferenced() { + if (! this.isInitialized) { + scope.problemReporter().varLocalReferencesItself(LocalDeclaration.this); + this.type = null; + this.isInitialized = true; // Quell additional type errors + } + } + @Override + public void markInitialized() { + this.isInitialized = true; + } + }; + } else { + // create a binding from the specified type + this.binding = new LocalVariableBinding(this, variableType, this.modifiers, false /*isArgument*/); + } scope.addLocalVariable(this.binding); this.binding.setConstant(Constant.NotAConstant); // allow to recursivelly target the binding.... // the correct constant is harmed if correctly computed at the end of this method if (variableType == null) { - if (this.initialization != null) + if (this.initialization != null) { this.initialization.resolveType(scope); // want to report all possible errors + if (isTypeNameVar && this.initialization.resolvedType != null) { + if (TypeBinding.equalsEquals(TypeBinding.NULL, this.initialization.resolvedType)) { + scope.problemReporter().varLocalInitializedToNull(this); + variableTypeInferenceError = true; + } else if (TypeBinding.equalsEquals(TypeBinding.VOID, this.initialization.resolvedType)) { + scope.problemReporter().varLocalInitializedToVoid(this); + variableTypeInferenceError = true; + } + variableType = patchType(this.initialization.resolvedType); + } else { + variableTypeInferenceError = true; + } + } + } + this.binding.markInitialized(); + if (variableTypeInferenceError) { return; } @@ -254,9 +358,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl this.initialization.computeConversion(scope, variableType, initializationType); } } else { - this.initialization.setExpressionContext(ASSIGNMENT_CONTEXT); + this.initialization.setExpressionContext(isTypeNameVar ? VANILLA_CONTEXT : ASSIGNMENT_CONTEXT); this.initialization.setExpectedType(variableType); - TypeBinding initializationType = this.initialization.resolveType(scope); + TypeBinding initializationType = this.initialization.resolvedType != null ? this.initialization.resolvedType : this.initialization.resolveType(scope); if (initializationType != null) { if (TypeBinding.notEquals(variableType, initializationType)) // must call before computeConversion() and typeMismatchError() scope.compilationUnitScope().recordTypeConversion(variableType, initializationType); @@ -303,6 +407,37 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl this.binding.tagBits &= ~TagBits.AnnotationNullMASK; } + /* + * Checks the initializer for simple errors, and reports an error as needed. If error is found, + * returns a reasonable match for further type checking. + */ + private TypeBinding checkInferredLocalVariableInitializer(BlockScope scope) { + TypeBinding errorType = null; + if (this.initialization instanceof ArrayInitializer) { + scope.problemReporter().varLocalCannotBeArrayInitalizers(this); + errorType = scope.createArrayType(scope.getJavaLangObject(), 1); // Treat as array of anything + } else { + // Catch-22: isPolyExpression() is not reliable BEFORE resolveType, so we need to peek to suppress the errors + Expression polyExpression = findPolyExpression(this.initialization); + if (polyExpression instanceof ReferenceExpression) { + scope.problemReporter().varLocalCannotBeMethodReference(this); + errorType = TypeBinding.NULL; + } else if (polyExpression != null) { // Should be instanceof LambdaExpression, but this is safer + scope.problemReporter().varLocalCannotBeLambda(this); + errorType = TypeBinding.NULL; + } + } + if (this.type.dimensions() > 0 || this.type.extraDimensions() > 0) { + scope.problemReporter().varLocalCannotBeArray(this); + errorType = scope.createArrayType(scope.getJavaLangObject(), 1); // This is just to quell some warnings + } + if ((this.bits & ASTNode.IsAdditionalDeclarator) != 0) { + scope.problemReporter().varLocalMultipleDeclarators(this); + errorType = this.initialization.resolveType(scope); + } + return errorType; + } + @Override public void traverse(ASTVisitor visitor, BlockScope scope) { @@ -335,4 +470,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl return this.name == RecoveryScanner.FAKE_IDENTIFIER && (this.type instanceof SingleTypeReference || (this.type instanceof QualifiedTypeReference && !(this.type instanceof ArrayQualifiedTypeReference))) && this.initialization == null && !this.type.isBaseTypeReference(); } + + public boolean isTypeNameVar(Scope scope) { + return this.type != null && this.type.isTypeNameVar(scope); + } + } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java index a063267a12..36302c1023 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for @@ -19,6 +19,7 @@ * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment * bug 378674 - "The method can be declared as static" is wrong * bug 404657 - [1.8][compiler] Analysis for effectively final variables fails to consider loops + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -1017,6 +1018,7 @@ public TypeBinding resolveType(BlockScope scope) { if (this.binding instanceof LocalVariableBinding) { this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.LOCAL; + ((LocalVariableBinding) this.binding).markReferenced(); if (!variable.isFinal() && (this.bits & ASTNode.IsCapturedOuterLocal) != 0) { if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) // for 8, defer till effective finality could be ascertained. scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding)variable, this); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java index 523118a5be..a5a0eabf52 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann - Contributions for @@ -1029,6 +1029,13 @@ public void resolve() { return; } try { + if (CharOperation.equals(this.name, TypeConstants.VAR)) { + if (this.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK10) { + this.scope.problemReporter().varIsReservedTypeNameInFuture(this); + } else { + this.scope.problemReporter().varIsReservedTypeName(this); + } + } // resolve annotations and check @Deprecated annotation long annotationTagBits = sourceType.getAnnotationTagBits(); if ((annotationTagBits & TagBits.AnnotationDeprecated) == 0 diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java index b33629a8e0..da008c489e 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,8 +17,10 @@ package org.eclipse.jdt.internal.compiler.ast; import java.util.List; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.ast.TypeReference.AnnotationCollector; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; @@ -29,6 +31,7 @@ import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.Scope; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; @SuppressWarnings("rawtypes") @@ -107,6 +110,13 @@ public class TypeParameter extends AbstractVariableDeclaration { if (this.annotations != null || scope.environment().usesNullTypeAnnotations()) { resolveAnnotations(scope); } + if (CharOperation.equals(this.name, TypeConstants.VAR)) { + if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK10) { + scope.problemReporter().varIsReservedTypeNameInFuture(this); + } else { + scope.problemReporter().varIsNotAllowedHere(this); + } + } } @Override diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java index f61f0a5673..8d49dcfa9e 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,14 +28,20 @@ * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator * Bug 415399 - [1.8][compiler] Type annotations on constructor results dropped by the code generator + * Jesper S Møller <jesper@selskabet.org> - Contributions for + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * bug 529556 - [18.3] Add content assist support for 'var' as a type + * *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching.CheckMode; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.AnnotationContext; import org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants; import org.eclipse.jdt.internal.compiler.flow.FlowContext; @@ -56,6 +62,7 @@ import org.eclipse.jdt.internal.compiler.lookup.Scope; import org.eclipse.jdt.internal.compiler.lookup.Substitution; import org.eclipse.jdt.internal.compiler.lookup.TagBits; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -505,7 +512,11 @@ protected TypeBinding internalResolveType(Scope scope, int location) { if (type == null) { return null; // detected cycle while resolving hierarchy } else if ((hasError = !type.isValidBinding()) == true) { - reportInvalidType(scope); + if (this.isTypeNameVar(scope)) { + reportVarIsNotAllowedHere(scope); + } else { + reportInvalidType(scope); + } switch (type.problemId()) { case ProblemReasons.NotFound : case ProblemReasons.NotVisible : @@ -569,6 +580,10 @@ protected void reportInvalidType(Scope scope) { scope.problemReporter().invalidType(this, this.resolvedType); } +protected void reportVarIsNotAllowedHere(Scope scope) { + scope.problemReporter().varIsNotAllowedHere(this); +} + public TypeBinding resolveSuperType(ClassScope scope) { // assumes the implementation of resolveType(ClassScope) will call back to detect cycles TypeBinding superType = resolveType(scope); @@ -752,4 +767,17 @@ public TypeReference[] getTypeReferences() { public boolean isBaseTypeReference() { return false; } +/** + * Checks to see if the declaration uses 'var' as type name + * @param scope Relevant scope, for error reporting + * @return true, if source level is Java 10 or above and the type name is just 'var', false otherwise + */ +public boolean isTypeNameVar(Scope scope) { + CompilerOptions compilerOptions = scope != null ? scope.compilerOptions() : null; + if (compilerOptions != null && compilerOptions.sourceLevel < ClassFileConstants.JDK10) { + return false; + } + char[][] typeName = this.getTypeName(); + return typeName.length == 1 && CharOperation.equals(typeName[0], TypeConstants.VAR); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java index 895405e003..a67ec237ad 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java @@ -121,6 +121,7 @@ public interface ClassFileConstants { int MAJOR_VERSION_1_7 = 51; int MAJOR_VERSION_1_8 = 52; int MAJOR_VERSION_9 = 53; + int MAJOR_VERSION_10 = 54; int MINOR_VERSION_0 = 0; int MINOR_VERSION_1 = 1; @@ -139,6 +140,7 @@ public interface ClassFileConstants { long JDK1_7 = ((long)ClassFileConstants.MAJOR_VERSION_1_7 << 16) + ClassFileConstants.MINOR_VERSION_0; long JDK1_8 = ((long)ClassFileConstants.MAJOR_VERSION_1_8 << 16) + ClassFileConstants.MINOR_VERSION_0; long JDK9 = ((long)ClassFileConstants.MAJOR_VERSION_9 << 16) + ClassFileConstants.MINOR_VERSION_0; + long JDK10 = ((long)ClassFileConstants.MAJOR_VERSION_10 << 16) + ClassFileConstants.MINOR_VERSION_0; /* * cldc1.1 is 45.3, but we modify it to be different from JDK1_1. diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 38a564340c..d2ad9173df 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -217,6 +217,7 @@ public class CompilerOptions { public static final String VERSION_1_7 = "1.7"; //$NON-NLS-1$ public static final String VERSION_1_8 = "1.8"; //$NON-NLS-1$ public static final String VERSION_9 = "9"; //$NON-NLS-1$ + public static final String VERSION_10 = "10"; //$NON-NLS-1$ public static final String ERROR = "error"; //$NON-NLS-1$ public static final String WARNING = "warning"; //$NON-NLS-1$ public static final String INFO = "info"; //$NON-NLS-1$ @@ -787,6 +788,11 @@ public class CompilerOptions { if (jdkLevel == ClassFileConstants.JDK9) return VERSION_9; break; + case ClassFileConstants.MAJOR_VERSION_10 : + // JDK10 uses same major version ad JDK9 + if (jdkLevel == ClassFileConstants.JDK10) + return VERSION_10; + break; } return Util.EMPTY_STRING; // unknown version } @@ -837,6 +843,10 @@ public class CompilerOptions { switch (version.charAt(0)) { case '9': return ClassFileConstants.JDK9; + case '1': + if (version.length() > 1 && version.charAt(1) == '0') { + return ClassFileConstants.JDK10; // Level for JDK 10 + } // No default - let it go through the remaining checks. } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java index 7cc939fd01..8cf91b44ca 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2014 IBM Corporation and others. + * Copyright (c) 2013, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java index 20f22ce102..b98e77cf27 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,8 @@ * Bug 438458 - [1.8][null] clean up handling of null type annotations wrt type variables * Bug 440759 - [1.8][null] @NonNullByDefault should never affect wildcards and uses of a type variable * Bug 441693 - [1.8][null] Bogus warning for type argument annotated with @NonNull + * Jesper S Møller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -221,6 +223,19 @@ public TypeBinding erasure() { return this.environment.createArrayType(erasedType, this.dimensions); return this; } + +@Override +public ArrayBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + TypeBinding leafType = this.leafComponentType.upwardsProjection(scope, mentionedTypeVariables); + return scope.environment().createArrayType(leafType, this.dimensions, this.typeAnnotations); +} + +@Override +public ArrayBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + TypeBinding leafType = this.leafComponentType.downwardsProjection(scope, mentionedTypeVariables); + return scope.environment().createArrayType(leafType, this.dimensions, this.typeAnnotations); +} + public LookupEnvironment environment() { return this.environment; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java index 514aae58cd..07b8d00c08 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,8 @@ * Bug 456497 - [1.8][null] during inference nullness from target type is lost against weaker hint from applicability analysis * Bug 456924 - StackOverflowError during compilation * Bug 462790 - [null] NPE in Expression.computeConversion() + * Jesper S Møller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -461,6 +463,23 @@ public class CaptureBinding extends TypeVariableBinding { return this.wildcard; } + @Override + public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + ReferenceBinding result = null; + if (enterRecursiveProjectionFunction()) { + for (int i = 0; i < mentionedTypeVariables.length; ++i) { + if (TypeBinding.equalsEquals(this, mentionedTypeVariables[i])) { + if (this.lowerBound != null) { + result = (ReferenceBinding) this.lowerBound.downwardsProjection(scope, mentionedTypeVariables); + } + break; + } + } + exitRecursiveProjectionFunction(); + } + return result; + } + /* * CaptureBinding needs even more propagation, because we are creating a naked type * (during CaptureBinding(WildcardBinding,ReferenceBinding,int,int,ASTNode,int) diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java index 47bab7d49f..cf962ac8ab 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java index ccfe671e86..47ede96297 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,8 @@ * Bug 428019 - [1.8][compiler] Type inference failure with nested generic invocation. * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for * Bug 405104 - [1.8][compiler][codegen] Implement support for serializeable lambdas + * Jesper S Møller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -291,6 +293,24 @@ public class IntersectionTypeBinding18 extends ReferenceBinding { // abstraction } @Override + public ReferenceBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + ReferenceBinding[] projectedTypes = new ReferenceBinding[this.intersectingTypes.length]; + for (int i = 0; i < this.intersectingTypes.length; ++i) { + projectedTypes[i] = this.intersectingTypes[i].upwardsProjection(scope, mentionedTypeVariables); + } + return (ReferenceBinding) scope.environment().createIntersectionType18(projectedTypes); + } + + @Override + public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + ReferenceBinding[] projectedTypes = new ReferenceBinding[this.intersectingTypes.length]; + for (int i = 0; i < this.intersectingTypes.length; ++i) { + projectedTypes[i] = this.intersectingTypes[i].downwardsProjection(scope, mentionedTypeVariables); + } + return (ReferenceBinding) scope.environment().createIntersectionType18(projectedTypes); + } + + @Override public boolean mentionsAny(TypeBinding[] parameters, int idx) { if (super.mentionsAny(parameters, idx)) return true; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java index c6ae98216d..9d7fbb6e38 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for @@ -14,6 +14,9 @@ * bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations * bug 331649 - [compiler][null] consider null annotations for fields * Bug 466308 - [hovering] Javadoc header for parameter is wrong with annotation-based null analysis + * Jesper S Møller <jesper@selskabet.org> - Contributions for + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -314,4 +317,12 @@ public class LocalVariableBinding extends VariableBinding { } return null; } + + public void markInitialized() { + // Signals that the type is correctly set now - This is for extension in subclasses + } + public void markReferenced() { + // Signal that the name is used - This is for extension in subclasses + } + } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java index 073598c82f..d06f04654d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -39,6 +39,8 @@ * Bug 435805 - [1.8][compiler][null] Java 8 compiler does not recognize declaration style null annotations * Bug 456508 - Unexpected RHS PolyTypeBinding for: <code-snippet> * Bug 390064 - [compiler][resource] Resource leak warning missing when extending parameterized class + * Jesper S Møller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -460,6 +462,114 @@ public class ParameterizedTypeBinding extends ReferenceBinding implements Substi public TypeBinding erasure() { return this.type.erasure(); // erasure } + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#upwardsProjection(org.eclipse.jdt.internal.compiler.lookup.Scope, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[]) + */ + @Override + public ReferenceBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + TypeBinding[] typeVariables = this.arguments; + if (typeVariables == null) return this; // How would that be possible? + + TypeBinding[] a_i_primes = new TypeBinding[typeVariables.length]; + for (int i = 0, length = typeVariables.length; i < length; i++) { + TypeBinding a_i = typeVariables[i]; + + // If Ai does not mention any restricted type variable, then Ai' = Ai. + int typeVariableKind = a_i.kind(); + if (! a_i.mentionsAny(mentionedTypeVariables, -1)) { + a_i_primes[i] = a_i; + } else if (typeVariableKind != Binding.WILDCARD_TYPE) { + // If Ai is a type that mentions a restricted type variable, then Ai' is a wildcard. + // Let U be the upward projection of Ai. There are three cases: + TypeBinding u = a_i.upwardsProjection(scope, mentionedTypeVariables); + TypeVariableBinding[] g_vars = this.type.typeVariables(); + if (g_vars == null || g_vars.length == 0) return this; // Careful - could be a MissingTypeBinding here + TypeBinding b_i = g_vars[i].upperBound(); + + // If U is not Object, + // and if either + // * the declared bound of the ith parameter of G, Bi, mentions a type parameter of G, or + // * Bi is not a subtype of U, + // then Ai' is an upper-bounded wildcard, ? extends U. + if (u.id != TypeIds.T_JavaLangObject + && (b_i.mentionsAny(typeVariables, -1) || b_i.findSuperTypeOriginatingFrom(u) == null)) { + a_i_primes[i] = this.environment().createWildcard(null, i, u, null, Wildcard.EXTENDS); + } else { + TypeBinding l = a_i.downwardsProjection(scope, mentionedTypeVariables); + // Otherwise, if the downward projection of Ai is L, + // then Ai' is a lower-bounded wildcard, ? super L. + if (l != null) { + a_i_primes[i] = this.environment().createWildcard(null, i, l, null, Wildcard.SUPER); + } else { + // Otherwise, the downward projection of Ai is undefined and Ai' is an unbounded wildcard, ?. + a_i_primes[i] = this.environment().createWildcard(null, i, null, null, Wildcard.UNBOUND); + } + } + } else { + WildcardBinding wildcard = (WildcardBinding)a_i; + if (wildcard.boundKind() == Wildcard.EXTENDS) { + // If Ai is an upper-bounded wildcard that mentions a restricted type variable, + // then let U be the upward projection of the wildcard bound. + TypeBinding u = wildcard.bound().upwardsProjection(scope, mentionedTypeVariables); + // Ai' is a wildcard ? extends U. + a_i_primes[i] = this.environment().createWildcard(null, 0, u, null, Wildcard.EXTENDS); + } else if (wildcard.boundKind() == Wildcard.SUPER) { + // If Ai is a lower-bounded wildcard that mentions a restricted type variable, + TypeBinding l = wildcard.bound().downwardsProjection(scope, mentionedTypeVariables); + if (l != null) { + // then if the downward projection of the wildcard bound is L, then Ai' is a wildcard ? super L; + a_i_primes[i] = this.environment().createWildcard(null, 0, l, null, Wildcard.SUPER); + } else { + // if the downward projection of the wildcard bound is undefined, then Ai' is an unbounded wildcard, ?. + a_i_primes[i] = this.environment().createWildcard(null, 0, null, null, Wildcard.UNBOUND); + } + } + } + } + return this.environment.createParameterizedType(this.type, a_i_primes, this.enclosingType); + } + @Override + public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + TypeBinding[] typeVariables = this.arguments; + if (typeVariables == null) return this; // How would that be possible? + + TypeBinding[] a_i_primes = new TypeBinding[typeVariables.length]; + for (int i = 0, length = typeVariables.length; i < length; i++) { + TypeBinding a_i = typeVariables[i]; + + // If Ai does not mention any restricted type variable, then Ai' = Ai. + int typeVariableKind = a_i.kind(); + if (! a_i.mentionsAny(mentionedTypeVariables, -1)) { + a_i_primes[i] = a_i; + } else if (typeVariableKind != Binding.WILDCARD_TYPE) { + return null; + } else { + WildcardBinding wildcard = (WildcardBinding)a_i; + if (wildcard.boundKind() == Wildcard.EXTENDS) { + // Ai is an upper-bounded wildcard that mentions a restricted type variable, + TypeBinding u = wildcard.bound().downwardsProjection(scope, mentionedTypeVariables); + // then if the downward projection of the wildcard bound is U, then Ai' is a wildcard ? extends U; + if (u != null) { + // Ai' is a wildcard ? extends U. + a_i_primes[i] = this.environment().createWildcard(null, 0, u, null, Wildcard.EXTENDS); + } else { + // if the downward projection of the wildcard bound is undefined, then Ai' is undefined. + return null; + } + } else if (wildcard.boundKind() == Wildcard.SUPER) { + // If Ai is a lower-bounded wildcard that mentions a restricted type variable, + // then let L be the upward projection of the wildcard bound. + TypeBinding l = wildcard.bound().upwardsProjection(scope, mentionedTypeVariables); + // Ai' is a wildcard ? super L. + a_i_primes[i] = this.environment().createWildcard(null, 0, l, null, Wildcard.SUPER); + } else { + return null; + } + } + } + return this.environment.createParameterizedType(this.type, a_i_primes, this.enclosingType); + } + /** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#fieldCount() */ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java index 719c63e839..7e182e5a2c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index f6dea08ac6..b3519617c3 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -39,6 +39,7 @@ * Jesper S Moller - Contributions for * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression * bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type * Ulrich Grave <ulrich.grave@gmx.de> - Contributions for * bug 386692 - Missing "unused" warning on "autowired" fields *******************************************************************************/ @@ -1365,6 +1366,7 @@ private boolean isCompatibleWith0(TypeBinding otherType, /*@Nullable*/ Scope cap case Binding.TYPE : case Binding.PARAMETERIZED_TYPE : case Binding.RAW_TYPE : + case Binding.INTERSECTION_TYPE18 : switch (kind()) { case Binding.GENERIC_TYPE : case Binding.PARAMETERIZED_TYPE : @@ -1860,6 +1862,28 @@ public char[] sourceName() { return this.sourceName; } +/** + * Perform an upwards type projection as per JLS 4.10.5 + * @param scope Relevant scope for evaluating type projection + * @param mentionedTypeVariables Filter for mentioned type variabled + * @returns Upwards type projection of 'this', or null if downwards projection is undefined +*/ +@Override +public ReferenceBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + return this; +} + +/** + * Perform a downwards type projection as per JLS 4.10.5 + * @param scope Relevant scope for evaluating type projection + * @param mentionedTypeVariables Filter for mentioned type variabled + * @returns Downwards type projection of 'this', or null if downwards projection is undefined +*/ +@Override +public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + return this; +} + void storeAnnotationHolder(Binding binding, AnnotationHolder holder) { if (holder == null) { SimpleLookupTable store = storedAnnotations(false, false); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java index 759d0e5fff..347995bad6 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephen Herrmann <stephan@cs.tu-berlin.de> - Contributions for @@ -30,6 +30,8 @@ * Bug 446434 - [1.8][null] Enable interned captures also when analysing null type annotations * Jesper S Moller <jesper@selskabet.org> - Contributions for * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -273,6 +275,26 @@ public TypeBinding erasure() { } /** + * Perform an upwards type projection as per JLS 4.10.5 + * @param scope Relevant scope for evaluating type projection + * @param mentionedTypeVariables Filter for mentioned type variabled + * @returns Upwards type projection of 'this', or null if downwards projection is undefined +*/ +public TypeBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + return this; +} + +/** + * Perform a downwards type projection as per JLS 4.10.5 + * @param scope Relevant scope for evaluating type projection + * @param mentionedTypeVariables Filter for mentioned type variabled + * @returns Downwards type projection of 'this', or null if downwards projection is undefined +*/ +public TypeBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + return this; +} + +/** * Find supertype which originates from a given well-known type, or null if not found * (using id avoids triggering the load of well-known type: 73740) * NOTE: only works for erasures of well-known types, as random other types may share @@ -1661,7 +1683,7 @@ public SyntheticArgumentBinding[] syntheticOuterLocalVariables() { } /** * Call this before descending into type details to prevent infinite recursion. - * @return true if a recursion has already been started. + * @return true if a recursion was not already started. */ public boolean enterRecursiveFunction() { return true; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java index 618a41568e..a08d7f3114 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java @@ -21,6 +21,7 @@ * Jesper S Moller - Contributions for * Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335 * Bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for * Bug 405104 - [1.8][compiler][codegen] Implement support for serializeable lambdas * Ulrich Grave <ulrich.grave@gmx.de> - Contributions for @@ -104,6 +105,9 @@ public interface TypeConstants { char[] LAMBDA_TYPE = "<lambda>".toCharArray(); //$NON-NLS-1$ char[] UPPER_MODULE = "MODULE".toCharArray(); //$NON-NLS-1$ + // JEP 286 + char[] VAR = "var".toCharArray(); //$NON-NLS-1$ + // jsr308 char[] TYPE_USE_TARGET = "TYPE_USE".toCharArray(); //$NON-NLS-1$ char[] TYPE_PARAMETER_TARGET = "TYPE_PARAMETER".toCharArray(); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java index cc1180e83a..f0b8e1ace5 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2015 IBM Corporation and others. + * Copyright (c) 2013, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java index 566244e577..2eab055688 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for @@ -34,6 +34,8 @@ * Bug 456487 - [1.8][null] @Nullable type variant of @NonNull-constrained type parameter causes grief * Bug 462790 - [null] NPE in Expression.computeConversion() * Bug 456532 - [1.8][null] ReferenceBinding.appendNullAnnotation() includes phantom annotations in error messages + * Jesper S Møller <jesper@selskabet.org> - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -597,7 +599,20 @@ public class TypeVariableBinding extends ReferenceBinding { public void exitRecursiveFunction() { this.inRecursiveFunction = false; } + + // to prevent infinite recursion when inspecting recursive generics: + boolean inRecursiveProjectionFunction = false; + public boolean enterRecursiveProjectionFunction() { + if (this.inRecursiveProjectionFunction) + return false; + this.inRecursiveProjectionFunction = true; + return true; + } + public void exitRecursiveProjectionFunction() { + this.inRecursiveProjectionFunction = false; + } + @Override public boolean isProperType(boolean admitCapture18) { // handle recursive calls: @@ -1117,4 +1132,44 @@ public class TypeVariableBinding extends ReferenceBinding { && this.environment.globalOptions.pessimisticNullAnalysisForFreeTypeVariablesEnabled && (this.tagBits & TagBits.AnnotationNullMASK) == 0; } + + @Override + public ReferenceBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + if (enterRecursiveProjectionFunction()) { + try { + for (int i = 0; i < mentionedTypeVariables.length; ++i) { + if (TypeBinding.equalsEquals(this, mentionedTypeVariables[i])) { + TypeBinding upperBound = this.upperBound(); + ReferenceBinding projectedUpper = ((ReferenceBinding)upperBound).upwardsProjection(scope, mentionedTypeVariables); + TypeBinding additionalBounds[] = this.additionalBounds(); + if (additionalBounds == null || additionalBounds.length == 0) { + // Return upwards projection of upper bound + return projectedUpper; + } else { + // If the type variable has more than one upper bound, + // we'll need to make an intersection type of projections of all bounds + int totalBounds = 1 + additionalBounds.length; + ReferenceBinding[] projectedTypes = new ReferenceBinding[totalBounds]; + projectedTypes[0] = projectedUpper; + for (int j = 0; j < additionalBounds.length; ++j) { + projectedTypes[j+1] = (ReferenceBinding)additionalBounds[j].upwardsProjection(scope, mentionedTypeVariables); + } + return (ReferenceBinding) scope.environment().createIntersectionType18(projectedTypes); + } + } + } + return this; + } finally { + exitRecursiveProjectionFunction(); + } + } else { + return scope.getJavaLangObject(); + } + } + + @Override + public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { + return null; + } + } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java index ef628fae02..8c796b3f68 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java @@ -150,6 +150,8 @@ public interface JavadocTagConstants { // since 1.8 {}, // since 9 + {}, + // since 10 {} }; public static final char[][][] INLINE_TAGS = { @@ -172,6 +174,8 @@ public interface JavadocTagConstants { // since 1.8 {}, // since 9 + {}, + // since 10 {} }; public final static int INLINE_TAGS_LENGTH = INLINE_TAGS.length; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java index 93bad9e08e..fd47b4901a 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,7 +19,8 @@ * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression * bug 399695 - [1.8][compiler] [1.8][compiler] migrate parser to other syntax for default methods * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration - * bug 393192 - Incomplete type hierarchy with > 10 annotations + * bug 393192 - Incomplete type hierarchy with > 10 annotations + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type * Andy Clement - Contributions for * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) * Bug 409250 - [1.8][compiler] Various loose ends in 308 code generation @@ -3510,6 +3511,7 @@ protected void consumeEnterVariable() { final int annotationsLength = annotations.length; System.arraycopy(annotations, 0, declaration.annotations = new Annotation[annotationsLength], 0, annotationsLength); } + declaration.bits |= ASTNode.IsAdditionalDeclarator; } declaration.type = extendedDimensions == 0 ? type : augmentTypeWithAdditionalDimensions(type, extendedDimensions, annotationsOnExtendedDimensions, false); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index 6fbe04433f..aeed19c409 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Benjamin Muskalla - Contribution for bug 239066 @@ -69,6 +69,7 @@ * bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains * Bug 429384 - [1.8][null] implement conformance rules for null-annotated lower / upper type bounds * Bug 416182 - [1.8][compiler][null] Contradictory null annotations not rejected + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type * Ulrich Grave <ulrich.grave@gmx.de> - Contributions for * bug 386692 - Missing "unused" warning on "autowired" fields ********************************************************************************/ @@ -9386,6 +9387,103 @@ public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) { varDecl.sourceStart, varDecl.sourceEnd); } +public void varLocalMultipleDeclarators(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalMultipleDeclarators, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalCannotBeArray(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalCannotBeArray, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalReferencesItself(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalReferencesItself, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalWithoutInitizalier(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalWithoutInitizalier, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalInitializedToNull(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalInitializedToNull, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalInitializedToVoid(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalInitializedToVoid, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalCannotBeArrayInitalizers(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalCannotBeArrayInitalizers, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalCannotBeLambda(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalCannotBeLambda, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varLocalCannotBeMethodReference(AbstractVariableDeclaration varDecl) { + this.handle( + IProblem.VarLocalCannotBeMethodReference, + NoArgument, + NoArgument, + varDecl.sourceStart, + varDecl.sourceEnd); +} +public void varIsReservedTypeName(TypeDeclaration decl) { + this.handle( + IProblem.VarIsReserved, + NoArgument, + NoArgument, + decl.sourceStart, + decl.sourceEnd); +} +public void varIsReservedTypeNameInFuture(ASTNode decl) { + this.handle( + IProblem.VarIsReservedInFuture, + NoArgument, + NoArgument, + ProblemSeverities.Warning, + decl.sourceStart, + decl.sourceEnd); +} +public void varIsNotAllowedHere(ASTNode astNode) { + this.handle( + IProblem.VarIsNotAllowedHere, + NoArgument, + NoArgument, + astNode.sourceStart, + astNode.sourceEnd); +} public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) { this.handle( IProblem.CannotAllocateVoidArray, diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index 283791280a..5e3fe1f7bf 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -4,6 +4,7 @@ # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html +# # # Contributors: # IBM Corporation - initial API and implementation @@ -48,6 +49,7 @@ # Bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable # Bug 412151 - [1.8][compiler] Check repeating annotation's collection type # Bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains +# Bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type ############################################################################### 0 = {0} 1 = super cannot be used in java.lang.Object @@ -946,6 +948,20 @@ 1460 = Must declare a named package because this compilation unit is associated to the named module ''{0}'' 1461 = Name of automatic module ''{0}'' is unstable, it is derived from the module''s file name. +# Local-Variable Type Inference +1500 = ''var'' is not allowed in a compound declaration +1501 = ''var'' is not allowed as an element type of an array +1502 = Declaration using ''var'' may not contain references to itself +1503 = Cannot use ''var'' on variable without initializer +1504 = Cannot infer type for local variable initialized to ''null'' +1505 = Variable initializer is ''void'' -- cannot infer variable type +1506 = Array initializer needs an explicit target-type +1507 = Lambda expression needs an explicit target-type +1508 = Method reference needs an explicit target-type +1509 = ''var'' is not a valid type name +1510 = ''var'' should not be used as an type name, since it is a reserved word from source level 10 on +1511 = ''var'' is not allowed here + ### ELABORATIONS ## Access restrictions 78592 = The type ''{1}'' is not API (restriction on classpath entry ''{0}'') diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java index 3d646e94b2..4b5b232998 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -113,7 +113,7 @@ public final class AST { * </p> * * @since 3.0 - * @deprecated Clients should use the {@link #JLS9} AST API instead. + * @deprecated Clients should use the {@link #JLS10} AST API instead. */ public static final int JLS2 = 2; @@ -137,7 +137,7 @@ public final class AST { * </p> * * @since 3.1 - * @deprecated Clients should use the {@link #JLS9} AST API instead. + * @deprecated Clients should use the {@link #JLS10} AST API instead. */ public static final int JLS3 = 3; @@ -161,7 +161,7 @@ public final class AST { * </p> * * @since 3.7.1 - * @deprecated Clients should use the {@link #JLS9} AST API instead. + * @deprecated Clients should use the {@link #JLS10} AST API instead. */ public static final int JLS4 = 4; @@ -185,7 +185,7 @@ public final class AST { * </p> * * @since 3.10 - * @deprecated Clients should use the {@link #JLS9} AST API instead. + * @deprecated Clients should use the {@link #JLS10} AST API instead. */ public static final int JLS8 = 8; @@ -209,6 +209,7 @@ public final class AST { * </p> * * @since 3.14 + * @deprecated Clients should use the {@link #JLS10} AST API instead. */ public static final int JLS9 = 9; @@ -218,6 +219,29 @@ public final class AST { * @since 3.14 */ /*package*/ static final int JLS9_INTERNAL = JLS9; + + /** + * Constant for indicating the AST API that handles JLS10. + * <p> + * This API is capable of handling all constructs in the + * Java language as described in the Java Language + * Specification, Java SE 10 Edition (JLS10). + * JLS10 is a superset of all earlier versions of the + * Java language, and the JLS10 API can be used to manipulate + * programs written in all versions of the Java language + * up to and including Java SE 10 (aka JDK 10). + * </p> + * + * @since 3.14 + */ + public static final int JLS10 = 10; + + /** + * Internal synonym for {@link #JLS10}. Use to alleviate + * deprecation warnings once JLS10 is deprecated + * @since 3.14 + */ + /*package*/ static final int JLS10_INTERNAL = JLS10; /* * Must not collide with a value for ICompilationUnit constants @@ -309,7 +333,7 @@ public final class AST { * Creates a new Java abstract syntax tree * (AST) following the specified set of API rules. * <p> - * Clients should use this method specifying {@link #JLS9} as the + * Clients should use this method specifying {@link #JLS10} as the * AST level in all cases, even when dealing with source of earlier JDK versions like 1.3 or 1.4. * </p> * @@ -745,7 +769,7 @@ public final class AST { null/*taskPriorities*/, true/*taskCaseSensitive*/); break; - case JLS9 : + case JLS9_INTERNAL : this.apiLevel = level; // initialize a scanner this.scanner = new Scanner( @@ -758,6 +782,19 @@ public final class AST { null/*taskPriorities*/, true/*taskCaseSensitive*/); break; + case JLS10_INTERNAL : + this.apiLevel = level; + // initialize a scanner + this.scanner = new Scanner( + true /*comment*/, + true /*whitespace*/, + false /*nls*/, + ClassFileConstants.JDK10 /*sourceLevel*/, + ClassFileConstants.JDK10 /*complianceLevel*/, + null/*taskTag*/, + null/*taskPriorities*/, + true/*taskCaseSensitive*/); + break; default: throw new IllegalArgumentException("Unsupported JLS level"); //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java index 6ce62ce0c0..ca88cf8f00 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -3642,12 +3642,16 @@ class ASTConverter { final VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration); final VariableDeclarationStatement variableDeclarationStatement = new VariableDeclarationStatement(this.ast); variableDeclarationStatement.fragments().add(variableDeclarationFragment); - if (this.resolveBindings) { - recordNodes(variableDeclarationFragment, localDeclaration); - } variableDeclarationStatement.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd - localDeclaration.declarationSourceStart + 1); Type type = convertType(localDeclaration.type); setTypeForVariableDeclarationStatement(variableDeclarationStatement, type, variableDeclarationFragment.getExtraDimensions()); + if (this.resolveBindings) { + recordNodes(variableDeclarationFragment, localDeclaration); + if (this.ast.apiLevel() >= AST.JLS10_INTERNAL && type.isVar()) { + Name varName = ((SimpleType) type).getName(); + recordNodes(varName, localDeclaration); + } + } if (localDeclaration.modifiersSourceStart != -1) { setModifiers(variableDeclarationStatement, localDeclaration); } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java index 13d068af7c..2592caefd4 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2039,6 +2039,21 @@ public abstract class ASTNode { } } /** + * Checks that this AST operation is not used when + * building JLS2, JLS3, JLS4, JLS8 or JLS9 level ASTs. + * <p> + * Use this method to prevent access to new properties that have been added in JLS10 + * </p> + * + * @exception UnsupportedOperationException if this operation is used below JLS10 + * @since 3.14 + */ + final void unsupportedBelow10() { + if (this.ast.apiLevel < AST.JLS10_INTERNAL) { + throw new UnsupportedOperationException("Operation only supported in ASTs with level JLS10 and above"); //$NON-NLS-1$ + } + } + /** * Checks that this AST operation is only used when * building JLS2 level ASTs. * <p> diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java index b4a118b67f..7ba7f9e66c 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2017 IBM Corporation and others. + * Copyright (c) 2004, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -229,6 +229,7 @@ public class ASTParser { case AST.JLS4_INTERNAL: case AST.JLS8_INTERNAL: case AST.JLS9_INTERNAL: + case AST.JLS10_INTERNAL: break; default: throw new IllegalArgumentException(); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java index 69539fb2e2..24ee1fbe4f 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -318,7 +318,7 @@ class DefaultBindingResolver extends BindingResolver { @Override synchronized IPackageBinding getPackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding) { - if (packageBinding == null) { + if (packageBinding == null || packageBinding instanceof ProblemPackageBinding) { return null; } IPackageBinding binding = (IPackageBinding) this.bindingTables.compilerBindingsToASTBindings.get(packageBinding); @@ -1660,6 +1660,9 @@ class DefaultBindingResolver extends BindingResolver { // retrieve the old ast node org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(type); org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = null; + if (type.getAST().apiLevel() >= AST.JLS10_INTERNAL && type.isVar()) { + return resolveTypeBindingForName(((SimpleType) type).getName()); + } if (node != null) { if (node instanceof Receiver) { node = ((Receiver) node).type; diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java index de1ac21021..5ba3d464b3 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -231,6 +231,19 @@ public class SimpleType extends AnnotatableType { postReplaceChild(oldChild, typeName, NAME_PROPERTY); } + /** + * @since 3.14 + */ + @Override + public boolean isVar() { + unsupportedBelow10(); + if (this.typeName == null) getName(); + String qName = this.typeName.getFullyQualifiedName(); + return qName != null && qName.equals("var"); //$NON-NLS-1$ + } + /* (omit javadoc for this method) + * Method declared on ASTNode. + */ @Override int memSize() { // treat Code as free diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Type.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Type.java index 494b2be168..13f328b08c 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Type.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Type.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -178,6 +178,20 @@ public abstract class Type extends ASTNode { } /** + * Returns whether this type is a var. The convenience method checks + * whether the type is so named. + * + * @return <code>true</code> if this is a var, and + * <code>false</code> otherwise + * @exception UnsupportedOperationException if this operation is used in + * an AST of level less than JLS10 + * @since 3.14 + */ + public boolean isVar() { + return false; + } + + /** * Returns whether this type is an intersection type * ({@link IntersectionType}). * diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index aa5bd71541..913834d348 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1312,7 +1312,7 @@ public final class ImportRewrite { CompilationUnit usedAstRoot= this.astRoot; if (usedAstRoot == null) { - ASTParser parser= ASTParser.newParser(AST.JLS9); + ASTParser parser= ASTParser.newParser(AST.JLS10); parser.setSource(this.compilationUnit); parser.setFocalPosition(0); // reduced AST parser.setResolveBindings(false); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java index a84b090cb8..b585097113 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -71,6 +71,12 @@ public class NaiveASTFlattener extends ASTVisitor { */ private static final int JLS8 = AST.JLS8; + /** + * Internal synonym for {@link AST#JLS9}. Use to alleviate + * deprecation warnings. + * @deprecated + * @since 3.14 + */ private static final int JLS9 = AST.JLS9; /** @@ -1137,6 +1143,10 @@ public class NaiveASTFlattener extends ASTVisitor { } @Override + /* + * @see ASTVisitor#visit(ModuleModifier) + * @since 3.14 + */ public boolean visit(ModuleModifier node) { this.buffer.append(node.getKeyword().toString()); return false; diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java index c79d113e34..885ed4bf1c 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java @@ -127,6 +127,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { /** @deprecated using deprecated code */ private static final int JLS8_INTERNAL = AST.JLS8; + /** @deprecated using deprecated code */ private static final int JLS9_INTERNAL = AST.JLS9; diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java index 1145943ca2..003255859d 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -84,6 +84,7 @@ public class ASTRewriteFlattener extends ASTVisitor { /** @deprecated using deprecated code */ private static final int JLS8_INTERNAL = AST.JLS8; + /** @deprecated using deprecated code */ private static final int JLS9_INTERNAL = AST.JLS9; @@ -1337,6 +1338,10 @@ public class ASTRewriteFlattener extends ASTVisitor { } @Override + /* + * @see ASTVisitor#visit(ModuleModifier) + * @since 3.14 + */ public boolean visit(ModuleModifier node) { this.result.append(getAttribute(node, ModuleModifier.KEYWORD_PROPERTY).toString()); return false; diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java index 538711fb4c..822e192a71 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -329,6 +329,7 @@ public class DefaultCodeFormatter extends CodeFormatter { } private ASTParser createParser(int kind) { + @SuppressWarnings("deprecation") ASTParser parser = ASTParser.newParser(AST.JLS9); if (kind == K_MODULE_INFO) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java index 5c78b3fcd9..131346684d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IModuleDescription.java @@ -28,6 +28,7 @@ public interface IModuleDescription extends IMember, IAnnotatable { /** * Answer the names of all modules directly required from this module. + * * @return a non-null array of module names * @since 3.14 */ diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java index 32eaa31c7e..3dcd7faee9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java @@ -337,7 +337,7 @@ public final class JavaCore extends Plugin { * <p><code>"cldc1.1"</code> requires the source version to be <code>"1.3"</code> and the compliance version to be <code>"1.4"</code> or lower.</p> * <dl> * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.codegen.targetPlatform"</code></dd> - * <dt>Possible values:</dt><dd><code>{ "1.1", "cldc1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9" }</code></dd> + * <dt>Possible values:</dt><dd><code>{ "1.1", "cldc1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9", "10" }</code></dd> * <dt>Default:</dt><dd><code>"1.2"</code></dd> * </dl> * @category CompilerOptionID @@ -2057,7 +2057,7 @@ public final class JavaCore extends Plugin { * set to the same version as the source level.</p> * <dl> * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.source"</code></dd> - * <dt>Possible values:</dt><dd><code>{ "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9" }</code></dd> + * <dt>Possible values:</dt><dd><code>{ "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "10" }</code></dd> * <dt>Default:</dt><dd><code>"1.3"</code></dd> * </dl> * @since 2.0 @@ -2075,7 +2075,7 @@ public final class JavaCore extends Plugin { * should match the compliance setting.</p> * <dl> * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.compliance"</code></dd> - * <dt>Possible values:</dt><dd><code>{ "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9" }</code></dd> + * <dt>Possible values:</dt><dd><code>{ "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9", "10" }</code></dd> * <dt>Default:</dt><dd><code>"1.4"</code></dd> * </dl> * @since 2.0 @@ -2998,6 +2998,12 @@ public final class JavaCore extends Plugin { public static final String VERSION_9 = "9"; //$NON-NLS-1$ /** * Configurable option value: {@value}. + * @since 3.14 + * @category OptionValue + */ + public static final String VERSION_10 = "10"; //$NON-NLS-1$ + /** + * Configurable option value: {@value}. * @since 3.4 * @category OptionValue */ @@ -3011,7 +3017,7 @@ public final class JavaCore extends Plugin { */ public static List<String> getAllVersions() { return Arrays.asList(VERSION_CLDC_1_1, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, - VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9); + VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_9, VERSION_10); } /** @@ -5973,6 +5979,14 @@ public final class JavaCore extends Plugin { options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED); options.put(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED); break; + case ClassFileConstants.MAJOR_VERSION_10: + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); + options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED); + break; } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/provisional/JavaModelAccess.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/provisional/JavaModelAccess.java index acde5f712c..be2596e4b2 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/provisional/JavaModelAccess.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/provisional/JavaModelAccess.java @@ -10,8 +10,11 @@ *******************************************************************************/ package org.eclipse.jdt.core.provisional; +import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IModuleDescription; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.JavaProject; +import org.eclipse.jdt.internal.core.PackageFragmentRoot; /** * Provisional API for use by JDT/UI or JDT/Debug, which may possibly be removed in a future version. @@ -28,4 +31,31 @@ public class JavaModelAccess { public static String[] getRequiredModules(IModuleDescription module) throws JavaModelException { return module.getRequiredModuleNames(); } + + /** + * Returns the <code>IModuleDescription</code> that the given java element contains + * when regarded as an automatic module. The element must be an <code>IPackageFragmentRoot</code> + * or an <code>IJavaProject</code>. + * + * <p>The returned module descriptor has a name (<code>getElementName()</code>) following + * the specification of <code>java.lang.module.ModuleFinder.of(Path...)</code>, but it + * contains no other useful information.</p> + * + * @return the <code>IModuleDescription</code> representing this java element as an automatic module, + * never <code>null</code>. + * @throws JavaModelException + * @throws IllegalArgumentException if the provided element is neither <code>IPackageFragmentRoot</code> + * nor <code>IJavaProject</code> + * @since 3.14 + */ + public static IModuleDescription getAutomaticModuleDescription(IJavaElement element) throws JavaModelException, IllegalArgumentException { + switch (element.getElementType()) { + case IJavaElement.JAVA_PROJECT: + return ((JavaProject) element).getAutomaticModuleDescription(); + case IJavaElement.PACKAGE_FRAGMENT_ROOT: + return ((PackageFragmentRoot) element).getAutomaticModuleDescription(); + default: + throw new IllegalArgumentException("Illegal kind of java element: "+element.getElementType()); //$NON-NLS-1$ + } + } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java index c1f5ec1c3b..179f25239d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -53,6 +53,7 @@ public final class CompilationUnitSorter { case AST.JLS4 : case AST.JLS8 : case AST.JLS9 : + case AST.JLS10 : break; default : throw new IllegalArgumentException(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java index d972c74122..e2a4f509ca 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java index 0a39be6b80..e46056d22a 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -87,7 +87,7 @@ public class CopyResourceElementsOperation extends MultiOperation implements Suf initializeASTParser(); } private void initializeASTParser() { - this.parser = ASTParser.newParser(AST.JLS9); + this.parser = ASTParser.newParser(AST.JLS10); } /** * Returns the children of <code>source</code> which are affected by this operation. diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java index 0537f470c9..8fee3aaabf 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -264,7 +264,7 @@ public abstract class CreateElementInCUOperation extends JavaModelOperation { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit - ASTParser parser = ASTParser.newParser(AST.JLS9); + ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java index b698ec3f8c..04ee6c4676 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -80,7 +80,7 @@ protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { if (this.createdNode == null) { this.source = removeIndentAndNewLines(this.source, cu); - ASTParser parser = ASTParser.newParser(AST.JLS9); + ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setSource(this.source.toCharArray()); parser.setProject(getCompilationUnit().getJavaProject()); parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); @@ -167,7 +167,7 @@ protected String generateSyntaxIncorrectAST() { buff.append(lineSeparator + " public class A {" + lineSeparator); //$NON-NLS-1$ buff.append(this.source); buff.append(lineSeparator).append('}'); - ASTParser parser = ASTParser.newParser(AST.JLS9); + ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setSource(buff.toString().toCharArray()); CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null); TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().iterator().next(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java index ac8882949d..775ebfeb67 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,7 +81,7 @@ public class DeleteElementsOperation extends MultiOperation { } private void initASTParser() { - this.parser = ASTParser.newParser(AST.JLS9); + this.parser = ASTParser.newParser(AST.JLS10); } /** diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java index 060dcc9cbc..33136eb339 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java index 30508bd9c8..827f7da5dd 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -427,7 +427,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public static class CompilationParticipants { - private final static int MAX_SOURCE_LEVEL = 9; // 1.1 to 1.8 and 9 + private final static int MAX_SOURCE_LEVEL = 10 ; // 1.1 to 1.8 and 9, 10 /* * The registered compilation participants (a table from int (source level) to Object[]) @@ -579,6 +579,8 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return 7; case ClassFileConstants.MAJOR_VERSION_9: return 8; + case ClassFileConstants.MAJOR_VERSION_10: + return 9; default: // all other cases including ClassFileConstants.MAJOR_VERSION_1_1 return 0; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java index df40d5ff84..1b950d2e76 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java index aa86b9c691..c252d2a27b 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -466,6 +466,12 @@ public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.in } LocalVariable localVar = null; if(parent != null) { + String typeSig = null; + if (local.type == null || local.type.isTypeNameVar(binding.declaringScope)) { + typeSig = Signature.createTypeSignature(binding.type.signableName(), true);// : Util.typeSignature(local.type) + } else { + typeSig = Util.typeSignature(local.type); + } localVar = new LocalVariable( (JavaElement)parent, new String(local.name), @@ -473,7 +479,7 @@ public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.in local.declarationSourceEnd, local.sourceStart, local.sourceEnd, - local.type == null ? Signature.createTypeSignature(binding.type.signableName(), true) : Util.typeSignature(local.type), + typeSig, local.annotations, local.modifiers, local.getKind() == AbstractVariableDeclaration.PARAMETER); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index 8498de94fc..a0f8c57cd7 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -517,6 +517,11 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam NameEnvironmentAnswer answer = classpathLocation.findClass(binaryFileName, qPackageName, moduleName, qBinaryFileName, false, this.modulePathEntries != null ? this.modulePathEntries::containsKey : null); if (answer != null) { + char[] answerMod = answer.moduleName(); + if (answerMod != null && this.modulePathEntries != null) { + if (!this.modulePathEntries.containsKey(String.valueOf(answerMod))) + continue; // assumed to be filtered out by --limit-modules + } if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Disassembler.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Disassembler.java index 2f2e7637f3..a2e3492c71 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Disassembler.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Disassembler.java @@ -1002,6 +1002,8 @@ public class Disassembler extends ClassFileBytesDisassembler { versionNumber = JavaCore.VERSION_1_8; } else if (minorVersion == 0 && majorVersion == 53) { versionNumber = JavaCore.VERSION_9; + } else if (minorVersion == 0 && majorVersion == 54) { + versionNumber = JavaCore.VERSION_10; } buffer.append( Messages.bind(Messages.classfileformat_versiondetails, diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties index 4556e19f92..90ba58db1a 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties @@ -234,6 +234,7 @@ convention_module_dotName = A module name cannot start or end with a dot convention_module_nameWithBlanks = A module name must not start or end with a blank convention_module_consecutiveDotsName = A module name must not contain consecutive dots convention_module_uppercaseName = By convention, module names usually start with a lowercase letter +convention_module_terminalDigits = A module name should avoid terminal digits convention_module_javaName = 'java' is reserved for system modules ### DOM |