8167643: JShell: silently ignore access modifiers (as semantically irrelevant)

Reviewed-by: jlahoda
This commit is contained in:
Robert Field 2016-10-27 17:11:16 -07:00
parent 9d6f124910
commit 70d8f3c7b4
9 changed files with 75 additions and 80 deletions

View File

@ -794,7 +794,7 @@ startup.feedback = \
/set format verbose unrerr '{unresolved} is declared and these errors are corrected: {errors}' unresolved1-error2 \n\
/set format verbose unrerr '{unresolved} are declared and these errors are corrected: {errors}' unresolved2-error2 \n\
\n\
/set format verbose resolve '{until}{unrerr}' added,modified,replaced,used \n\
/set format verbose resolve '{until}{unrerr}' defined,notdefined-added,modified,replaced,used \n\
\n\
/set format verbose typeKind 'class' class \n\
/set format verbose typeKind 'interface' interface \n\

View File

@ -855,6 +855,8 @@ class Eval {
case PUBLIC:
case PROTECTED:
case PRIVATE:
// quietly ignore, user cannot see effects one way or the other
break;
case STATIC:
case FINAL:
list.add(mod);

View File

@ -247,14 +247,11 @@ public class ClassesTest extends KullaTesting {
}
public void classesIgnoredModifiers() {
assertDeclareWarn1("public interface A { }",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING));
assertEval("public interface A { }");
assertDeclareWarn1("static class B implements A { }",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING));
assertDeclareWarn1("final interface C extends A { }",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 5, 0, -1, -1, Diagnostic.Kind.WARNING));
assertDeclareWarn1("protected enum D implements C { }",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 9, 0, -1, -1, Diagnostic.Kind.WARNING));
assertActiveKeys();
}

View File

@ -62,12 +62,9 @@ public class ErrorTranslationTest extends ReplToolTesting {
public void testWarnings() {
List<ReplTest> list = new ArrayList<>();
ExpectedDiagnostic[] diagnostics = new ExpectedDiagnostic[]{
newExpectedDiagnostic(0, 6, 0, -1, -1, Diagnostic.Kind.WARNING),
newExpectedDiagnostic(0, 9, 0, -1, -1, Diagnostic.Kind.WARNING),
newExpectedDiagnostic(0, 7, 0, -1, -1, Diagnostic.Kind.WARNING),
newExpectedDiagnostic(0, 6, 0, -1, -1, Diagnostic.Kind.WARNING),
newExpectedDiagnostic(0, 5, 0, -1, -1, Diagnostic.Kind.WARNING)};
String[] mods = {"public", "protected", "private", "static", "final"};
String[] mods = {"static", "final"};
for (int i = 0; i < mods.length; ++i) {
for (String code : new String[] {"class A {}", "void f() {}", "int a;"}) {
final int finalI = i;

View File

@ -58,12 +58,12 @@ public class IgnoreTest extends KullaTesting {
}
public void testVarModifier() {
VarSnippet x1 = (VarSnippet) assertDeclareWarn1("public int x1;", "jdk.eval.warn.illegal.modifiers");
assertVariableDeclSnippet(x1, "x1", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
VarSnippet x2 = (VarSnippet) assertDeclareWarn1("protected int x2;", "jdk.eval.warn.illegal.modifiers");
assertVariableDeclSnippet(x2, "x2", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
VarSnippet x3 = (VarSnippet) assertDeclareWarn1("private int x3;", "jdk.eval.warn.illegal.modifiers");
assertVariableDeclSnippet(x3, "x3", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
VarSnippet x1 = varKey(assertEval("public int x1;"));
assertVariableDeclSnippet(x1, "x1", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 0);
VarSnippet x2 = varKey(assertEval("protected int x2;"));
assertVariableDeclSnippet(x2, "x2", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 0);
VarSnippet x3 = varKey(assertEval("private int x3;"));
assertVariableDeclSnippet(x3, "x3", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 0);
VarSnippet x4 = (VarSnippet) assertDeclareWarn1("static int x4;", "jdk.eval.warn.illegal.modifiers");
assertVariableDeclSnippet(x4, "x4", "int", VALID, VAR_DECLARATION_SUBKIND, 0, 1);
VarSnippet x5 = (VarSnippet) assertDeclareWarn1("final int x5;", "jdk.eval.warn.illegal.modifiers");
@ -71,12 +71,6 @@ public class IgnoreTest extends KullaTesting {
}
public void testMethodModifier() {
MethodSnippet m1 = (MethodSnippet) assertDeclareWarn1("public void m1() {}", "jdk.eval.warn.illegal.modifiers");
assertMethodDeclSnippet(m1, "m1", "()void", VALID, 0, 1);
MethodSnippet m2 = (MethodSnippet) assertDeclareWarn1("protected void m2() {}", "jdk.eval.warn.illegal.modifiers");
assertMethodDeclSnippet(m2, "m2", "()void", VALID, 0, 1);
MethodSnippet m3 = (MethodSnippet) assertDeclareWarn1("private void m3() {}", "jdk.eval.warn.illegal.modifiers");
assertMethodDeclSnippet(m3, "m3", "()void", VALID, 0, 1);
MethodSnippet m4 = (MethodSnippet) assertDeclareWarn1("static void m4() {}", "jdk.eval.warn.illegal.modifiers");
assertMethodDeclSnippet(m4, "m4", "()void", VALID, 0, 1);
MethodSnippet m5 = (MethodSnippet) assertDeclareWarn1("final void m5() {}", "jdk.eval.warn.illegal.modifiers");
@ -84,12 +78,6 @@ public class IgnoreTest extends KullaTesting {
}
public void testClassModifier() {
TypeDeclSnippet c1 = (TypeDeclSnippet) assertDeclareWarn1("public class C1 {}", "jdk.eval.warn.illegal.modifiers");
assertTypeDeclSnippet(c1, "C1", VALID, CLASS_SUBKIND, 0, 1);
TypeDeclSnippet c2 = (TypeDeclSnippet) assertDeclareWarn1("protected class C2 {}", "jdk.eval.warn.illegal.modifiers");
assertTypeDeclSnippet(c2, "C2", VALID, CLASS_SUBKIND, 0, 1);
TypeDeclSnippet c3 = (TypeDeclSnippet) assertDeclareWarn1("private class C3 {}", "jdk.eval.warn.illegal.modifiers");
assertTypeDeclSnippet(c3, "C3", VALID, CLASS_SUBKIND, 0, 1);
TypeDeclSnippet c4 = (TypeDeclSnippet) assertDeclareWarn1("static class C4 {}", "jdk.eval.warn.illegal.modifiers");
assertTypeDeclSnippet(c4, "C4", VALID, CLASS_SUBKIND, 0, 1);
TypeDeclSnippet c5 = (TypeDeclSnippet) assertDeclareWarn1("final class C5 {}", "jdk.eval.warn.illegal.modifiers");

View File

@ -957,43 +957,33 @@ public class KullaTesting {
}
public enum ClassType {
CLASS("CLASS_SUBKIND") {
@Override
public String toString() {
return "class";
}
},
ENUM("ENUM_SUBKIND") {
@Override
public String toString() {
return "enum";
}
},
INTERFACE("INTERFACE_SUBKIND") {
@Override
public String toString() {
return "interface";
}
},
ANNOTATION("ANNOTATION_TYPE_SUBKIND") {
@Override
public String toString() {
return "@interface";
}
};
CLASS("CLASS_SUBKIND", "class", "class"),
ENUM("ENUM_SUBKIND", "enum", "enum"),
INTERFACE("INTERFACE_SUBKIND", "interface", "interface"),
ANNOTATION("ANNOTATION_TYPE_SUBKIND", "@interface", "annotation interface");
private final String classType;
private final String name;
private final String displayed;
ClassType(String classType) {
ClassType(String classType, String name, String displayed) {
this.classType = classType;
this.name = name;
this.displayed = displayed;
}
public String getClassType() {
return classType;
}
public String getDisplayed() {
return displayed;
}
@Override
public abstract String toString();
public String toString() {
return name;
}
}
public static MemberInfo variable(String type, String name) {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8080357
* @bug 8080357 8167643
* @summary Tests for EvaluationState.methods
* @build KullaTesting TestingInputStream ExpectedDiagnostic
* @run testng MethodsTest
@ -230,34 +230,33 @@ public class MethodsTest extends KullaTesting {
assertActiveKeys();
}
public void methodsAccessModifierIgnored() {
Snippet f = methodKey(assertEval("public String f() {return null;}",
added(VALID)));
assertNumberOfActiveMethods(1);
assertActiveKeys();
f = methodKey(assertEval("protected String f() {return null;}",
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
assertNumberOfActiveMethods(1);
assertActiveKeys();
assertEval("private String f() {return null;}",
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertNumberOfActiveMethods(1);
assertActiveKeys();
}
public void methodsWarn() {
Snippet f = assertDeclareWarn1("public String f() {return null;}",
Snippet f = assertDeclareWarn1("static String f() {return null;}",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING),
added(VALID));
assertNumberOfActiveMethods(1);
assertActiveKeys();
f = assertDeclareWarn1("protected String f() {return null;}",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 9, 0, -1, -1, Diagnostic.Kind.WARNING),
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertNumberOfActiveMethods(1);
assertActiveKeys();
f = assertDeclareWarn1("private String f() {return null;}",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 7, 0, -1, -1, Diagnostic.Kind.WARNING),
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertNumberOfActiveMethods(1);
assertActiveKeys();
f = assertDeclareWarn1("static String f() {return null;}",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING),
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertNumberOfActiveMethods(1);
assertActiveKeys();
assertDeclareWarn1("final String f() {return null;}",
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 5, 0, -1, -1, Diagnostic.Kind.WARNING),
ste(MAIN_SNIPPET, VALID, VALID, false, null),

View File

@ -22,7 +22,7 @@
*/
/*
* @test
* @test 8167643
* @summary Tests for modifiers
* @build KullaTesting TestingInputStream ExpectedDiagnostic
* @run testng ModifiersTest
@ -43,7 +43,7 @@ public class ModifiersTest extends KullaTesting {
public Object[][] getTestCases() {
List<Object[]> testCases = new ArrayList<>();
String[] ignoredModifiers = new String[] {
"public", "protected", "private", "static", "final"
"static", "final"
};
for (String ignoredModifier : ignoredModifiers) {
for (ClassType classType : ClassType.values()) {
@ -62,6 +62,28 @@ public class ModifiersTest extends KullaTesting {
assertActiveKeys();
}
@DataProvider(name = "silentlyIgnoredModifiers")
public Object[][] getSilentTestCases() {
List<Object[]> testCases = new ArrayList<>();
String[] ignoredModifiers = new String[] {
"public", "protected", "private"
};
for (String ignoredModifier : ignoredModifiers) {
for (ClassType classType : ClassType.values()) {
testCases.add(new Object[] { ignoredModifier, classType });
}
}
return testCases.toArray(new Object[testCases.size()][]);
}
@Test(dataProvider = "silentlyIgnoredModifiers")
public void silentlyIgnoredModifiers(String modifier, ClassType classType) {
assertEval(String.format("%s %s A {}", modifier, classType));
assertNumberOfActiveClasses(1);
assertClasses(clazz(classType, "A"));
assertActiveKeys();
}
public void accessToStaticFieldsOfClass() {
assertEval("class A {" +
"int x = 14;" +

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643
* @summary Tests for Basic tests for REPL tool
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -520,7 +520,7 @@ public class ToolBasicTest extends ReplToolTesting {
a -> assertCommand(a, "int a", ""),
a -> assertCommand(a, "void f() {}", ""),
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")),
a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:"))
a -> assertCommandCheckOutput(a, "static void f() {}", assertStartsWith("| Warning:"))
);
}
}