Add test for check access flags in class file (refactor WriteAccessFlagTest)
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
public class Foo() {
|
||||
public class publicFinalInnerClass() {
|
||||
}
|
||||
}
|
||||
|
||||
// ACC_ABSTRACT : false
|
||||
// ACC_ANNOTATION : false
|
||||
// ACC_FINAL : true
|
||||
// ACC_INTERFACE : false
|
||||
// ACC_PUBLIC : true
|
||||
// ACC_STATIC : false
|
||||
// ACC_SUPER : true
|
||||
@@ -1,12 +0,0 @@
|
||||
public class Foo() {
|
||||
public trait publicInnerInterface {
|
||||
}
|
||||
}
|
||||
|
||||
// ACC_ABSTRACT : true
|
||||
// ACC_ANNOTATION : false
|
||||
// ACC_FINAL : false
|
||||
// ACC_INTERFACE : true
|
||||
// ACC_PUBLIC : true
|
||||
// ACC_STATIC : false
|
||||
// ACC_SUPER : false
|
||||
@@ -1,10 +0,0 @@
|
||||
public class publicFinalClass() {
|
||||
}
|
||||
|
||||
// ACC_ABSTRACT : false
|
||||
// ACC_ANNOTATION : false
|
||||
// ACC_FINAL : true
|
||||
// ACC_INTERFACE : false
|
||||
// ACC_PUBLIC : true
|
||||
// ACC_STATIC : false
|
||||
// ACC_SUPER : true
|
||||
@@ -1,10 +0,0 @@
|
||||
public trait publicInterface {
|
||||
}
|
||||
|
||||
// ACC_ABSTRACT : true
|
||||
// ACC_ANNOTATION : false
|
||||
// ACC_FINAL : false
|
||||
// ACC_INTERFACE : true
|
||||
// ACC_PUBLIC : true
|
||||
// ACC_STATIC : false
|
||||
// ACC_SUPER : false
|
||||
@@ -0,0 +1,6 @@
|
||||
public class MyClass() {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyClass
|
||||
// FLAGS: ACC_FINAL, ACC_PUBLIC, ACC_SUPER
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Foo() {
|
||||
public class MyClass() {
|
||||
}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: Foo$MyClass
|
||||
// FLAGS: ACC_FINAL, ACC_PUBLIC, ACC_SUPER
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Foo() {
|
||||
public trait MyTrait {
|
||||
}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: Foo$MyTrait
|
||||
// FLAGS: ACC_ABSTRACT, ACC_INTERFACE, ACC_PUBLIC
|
||||
@@ -0,0 +1,6 @@
|
||||
public trait MyTrait {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyTrait
|
||||
// FLAGS: ACC_ABSTRACT, ACC_INTERFACE, ACC_PUBLIC
|
||||
@@ -0,0 +1,6 @@
|
||||
Deprecated class MyClass() {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyClass
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL, ACC_SUPER
|
||||
@@ -0,0 +1,9 @@
|
||||
class MyClass {
|
||||
Deprecated class object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyClass$ClassObject$
|
||||
// FLAGS: ACC_PUBLIC, ACC_FINAL, ACC_DEPRECATED, ACC_SUPER
|
||||
@@ -0,0 +1,7 @@
|
||||
Deprecated enum class MyEnum {
|
||||
FIRST
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyEnum
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_ENUM
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyClass() {
|
||||
Deprecated public class MyInnerClass() {}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyClass$MyInnerClass
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL, ACC_SUPER
|
||||
@@ -0,0 +1,6 @@
|
||||
Deprecated public trait MyTrait {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
// TESTED_OBJECTS: MyTrait
|
||||
// FLAGS: ACC_ABSTRACT, ACC_DEPRECATED, ACC_INTERFACE, ACC_PUBLIC
|
||||
@@ -0,0 +1,8 @@
|
||||
class MyClass() {
|
||||
val test = ""
|
||||
[Deprecated] get
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, getTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,8 @@
|
||||
class MyClass() {
|
||||
var test = ""
|
||||
[Deprecated] set
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, setTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyClass() { }
|
||||
|
||||
Deprecated fun MyClass.test() {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL, ACC_STATIC
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyClass() {
|
||||
Deprecated fun test() {}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,9 @@
|
||||
class MyClass() {
|
||||
class object {
|
||||
Deprecated fun test() {}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass$ClassObject$, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,9 @@
|
||||
class MyClass() {
|
||||
val test: Int
|
||||
[Deprecated] get(): Int { return 0 }
|
||||
}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, getTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,8 @@
|
||||
class MyClass() {
|
||||
Deprecated val test = ""
|
||||
}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, getTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,5 @@
|
||||
class MyClass(Deprecated val test: Int) {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, getTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,9 @@
|
||||
class MyClass() {
|
||||
var test = 1
|
||||
[Deprecated] set(i: Int) { test = i }
|
||||
}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, setTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,8 @@
|
||||
class MyClass() {
|
||||
Deprecated var test = ""
|
||||
}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, setTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,6 @@
|
||||
class MyClass(Deprecated var test: Int) {}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, setTest
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL
|
||||
@@ -0,0 +1,5 @@
|
||||
Deprecated fun test() {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PUBLIC, ACC_FINAL, ACC_STATIC
|
||||
@@ -0,0 +1,8 @@
|
||||
class MyClass() {
|
||||
Deprecated public val test: Int = 0
|
||||
}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: property
|
||||
// TESTED_OBJECTS: MyClass, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_PRIVATE, ACC_FINAL
|
||||
@@ -0,0 +1,5 @@
|
||||
Deprecated val test: Int = 0
|
||||
|
||||
// TESTED_OBJECT_KIND: property
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
// FLAGS: ACC_DEPRECATED, ACC_FINAL, ACC_STATIC
|
||||
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.asm4.ClassReader;
|
||||
import org.jetbrains.asm4.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Test correctness of written access flags in class file
|
||||
*
|
||||
* @author Natalia.Ukhorskaya
|
||||
*/
|
||||
public class WriteAccessFlagsTest extends TestCaseWithTmpdir {
|
||||
|
||||
private final File ktFile;
|
||||
private JetCoreEnvironment jetCoreEnvironment;
|
||||
|
||||
public WriteAccessFlagsTest(File ktFile) {
|
||||
this.ktFile = ktFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return ktFile.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable);
|
||||
|
||||
String text = FileUtil.loadFile(ktFile);
|
||||
|
||||
JetFile psiFile = JetTestUtils.createFile(ktFile.getName(), text, jetCoreEnvironment.getProject());
|
||||
assert psiFile != null;
|
||||
|
||||
final ClassFileFactory factory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
|
||||
|
||||
String modifiedTestName = this.getName().replace(".kt", ".class");
|
||||
boolean isClassFound = false;
|
||||
for (String filename : factory.files()) {
|
||||
if (filename.equals(modifiedTestName)) {
|
||||
isClassFound = true;
|
||||
ClassReader cr = new ClassReader(factory.asBytes(filename));
|
||||
final Expectation expectation = parseExpectations();
|
||||
int expectedAccess = 0;
|
||||
if (expectation.isAbstract) {
|
||||
expectedAccess |= Opcodes.ACC_ABSTRACT;
|
||||
}
|
||||
if (expectation.isAnnotation) {
|
||||
expectedAccess |= Opcodes.ACC_ANNOTATION;
|
||||
}
|
||||
if (expectation.isFinal) {
|
||||
expectedAccess |= Opcodes.ACC_FINAL;
|
||||
}
|
||||
if (expectation.isPublic) {
|
||||
expectedAccess |= Opcodes.ACC_PUBLIC;
|
||||
}
|
||||
if (expectation.isInterface) {
|
||||
expectedAccess |= Opcodes.ACC_INTERFACE;
|
||||
}
|
||||
if (expectation.isStatic) {
|
||||
expectedAccess |= Opcodes.ACC_STATIC;
|
||||
}
|
||||
if (expectation.isSuper) {
|
||||
expectedAccess |= Opcodes.ACC_SUPER;
|
||||
}
|
||||
|
||||
assertEquals("Wrong access flag", expectedAccess, cr.getAccess());
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClassFound) {
|
||||
throw new AssertionError("file name should be the same as class name. File name is " + modifiedTestName);
|
||||
}
|
||||
|
||||
Disposer.dispose(myTestRootDisposable);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/writeAccessFlags", true,
|
||||
new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath,
|
||||
@NotNull String name,
|
||||
@NotNull File file) {
|
||||
return new WriteAccessFlagsTest(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class Expectation {
|
||||
private final boolean isAbstract;
|
||||
private final boolean isAnnotation;
|
||||
private final boolean isFinal;
|
||||
private final boolean isInterface;
|
||||
private final boolean isPublic;
|
||||
private final boolean isStatic;
|
||||
private final boolean isSuper;
|
||||
|
||||
private Expectation(@NotNull String isAbstract,
|
||||
@NotNull String isAnnotation,
|
||||
@NotNull String isFinal,
|
||||
@NotNull String isInterface,
|
||||
@NotNull String isPublic,
|
||||
@NotNull String isStatic,
|
||||
@NotNull String isSuper) {
|
||||
this.isAbstract = isAbstract.equals("true");
|
||||
this.isAnnotation = isAnnotation.equals("true");
|
||||
this.isFinal = isFinal.equals("true");
|
||||
this.isPublic = isPublic.equals("true");
|
||||
this.isInterface = isInterface.equals("true");
|
||||
this.isStatic = isStatic.equals("true");
|
||||
this.isSuper = isSuper.equals("true");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final Pattern isAbstract = Pattern.compile("^// ACC_ABSTRACT : *(.*)");
|
||||
private static final Pattern isAnnotation = Pattern.compile("^// ACC_ANNOTATION : *(.*)");
|
||||
private static final Pattern isFinal = Pattern.compile("^// ACC_FINAL : *(.*)");
|
||||
private static final Pattern isInterface = Pattern.compile("^// ACC_INTERFACE : *(.*)");
|
||||
private static final Pattern isPublic = Pattern.compile("^// ACC_PUBLIC : *(.*)");
|
||||
private static final Pattern isStatic = Pattern.compile("^// ACC_STATIC : *(.*)");
|
||||
private static final Pattern isSuper = Pattern.compile("^// ACC_SUPER : *(.*)");
|
||||
|
||||
private Expectation parseExpectations() throws IOException {
|
||||
List<String> lines = Files.readLines(ktFile, Charset.forName("utf-8"));
|
||||
for (int i = 0; i < lines.size() - 6; ++i) {
|
||||
Matcher abstractMatcher = isAbstract.matcher(lines.get(i));
|
||||
if (abstractMatcher.matches()) {
|
||||
Matcher annotationMatcher = isAnnotation.matcher(lines.get(i + 1));
|
||||
Matcher finalMatcher = isFinal.matcher(lines.get(i + 2));
|
||||
Matcher interfaceMatcher = isInterface.matcher(lines.get(i + 3));
|
||||
Matcher publicMatcher = isPublic.matcher(lines.get(i + 4));
|
||||
Matcher staticMatcher = isStatic.matcher(lines.get(i + 5));
|
||||
Matcher superMatcher = isSuper.matcher(lines.get(i + 6));
|
||||
|
||||
if (!interfaceMatcher.matches()
|
||||
|| !annotationMatcher.matches()
|
||||
|| !finalMatcher.matches()
|
||||
|| !interfaceMatcher.matches()
|
||||
|| !publicMatcher.matches()
|
||||
|| !staticMatcher.matches()
|
||||
|| !superMatcher.matches()) {
|
||||
throw new AssertionError("Incorrect test instructions format");
|
||||
}
|
||||
|
||||
return new Expectation(abstractMatcher.group(1),
|
||||
annotationMatcher.group(1),
|
||||
finalMatcher.group(1),
|
||||
interfaceMatcher.group(1),
|
||||
publicMatcher.group(1),
|
||||
staticMatcher.group(1),
|
||||
superMatcher.group(1));
|
||||
}
|
||||
}
|
||||
throw new AssertionError("test instructions not found in " + ktFile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.flags;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.asm4.*;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.test.generator.SimpleTestClassModel;
|
||||
import org.jetbrains.jet.test.generator.TestGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.InTextDirectivesUtils.findListWithPrefix;
|
||||
|
||||
/*
|
||||
* Test correctness of written flags in class file
|
||||
*
|
||||
* TESTED_OBJECT_KIND - maybe class, function or property
|
||||
* TESTED_OBJECTS - className, [function/property name]
|
||||
* FLAGS - only flags which must be true
|
||||
*/
|
||||
public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
|
||||
private JetCoreEnvironment jetCoreEnvironment;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
protected void doTest(String path) throws IOException {
|
||||
File ktFile = new File(path);
|
||||
assertTrue("Cannot find a file " + ktFile.getAbsolutePath(), ktFile.exists());
|
||||
|
||||
String fileText = FileUtil.loadFile(ktFile);
|
||||
|
||||
JetFile psiFile = JetTestUtils.createFile(ktFile.getName(), fileText, jetCoreEnvironment.getProject());
|
||||
assertTrue("Cannot create JetFile from text", psiFile != null);
|
||||
|
||||
final ClassFileFactory factory = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
|
||||
|
||||
TestedObject testedObject = parseExpectedTestedObject(fileText);
|
||||
|
||||
boolean isClassFound = false;
|
||||
for (String filename : factory.files()) {
|
||||
if (filename.equals(testedObject.containingClass + ".class")) {
|
||||
isClassFound = true;
|
||||
ClassReader cr = new ClassReader(factory.asBytes(filename));
|
||||
TestClassVisitor classVisitor;
|
||||
classVisitor = getClassVisitor(testedObject.kind, testedObject.name);
|
||||
cr.accept(classVisitor, ClassReader.SKIP_CODE);
|
||||
int expectedAccess = getExpectedFlags(fileText);
|
||||
assertEquals("Wrong access flag", expectedAccess, classVisitor.getAccess());
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClassFound) {
|
||||
throw new AssertionError("Couldn't find a class file with name " + testedObject.containingClass);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String aPackage = "org.jetbrains.jet.codegen.flags";
|
||||
Class<AbstractWriteFlagsTest> thisClass = AbstractWriteFlagsTest.class;
|
||||
new TestGenerator(
|
||||
"compiler/tests/",
|
||||
aPackage,
|
||||
"WriteFlagsTestGenerated",
|
||||
thisClass,
|
||||
Arrays.asList(
|
||||
new SimpleTestClassModel(new File("compiler/testData/writeFlags"), true, "kt", "doTest")
|
||||
),
|
||||
thisClass
|
||||
).generateAndSave();
|
||||
}
|
||||
|
||||
private static TestedObject parseExpectedTestedObject(String fileText) {
|
||||
TestedObject result = new TestedObject();
|
||||
List<String> testedObjects = findListWithPrefix("// TESTED_OBJECTS: ", fileText);
|
||||
assertTrue("Cannot find TESTED_OBJECTS instruction", !testedObjects.isEmpty());
|
||||
result.containingClass = testedObjects.get(0);
|
||||
if (testedObjects.size() == 1) {
|
||||
result.name = testedObjects.get(0);
|
||||
}
|
||||
else if (testedObjects.size() == 2) {
|
||||
result.name = testedObjects.get(1);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"TESTED_OBJECTS instruction must contains one (for class) or two (for function and property) values");
|
||||
}
|
||||
|
||||
List<String> testedObjectKinds = findListWithPrefix("// TESTED_OBJECT_KIND: ", fileText);
|
||||
assertTrue("TESTED_OBJECT_KIND instruction must contains exactly one value. Actual value is " + testedObjectKinds.size(),
|
||||
testedObjectKinds.size() == 1);
|
||||
result.kind = testedObjectKinds.get(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class TestedObject {
|
||||
public String name;
|
||||
public String containingClass = "";
|
||||
public String kind;
|
||||
}
|
||||
|
||||
private static TestClassVisitor getClassVisitor(String visitorKind, String testedObjectName) {
|
||||
if (visitorKind.equals("class")) {
|
||||
return new ClassFlagsVisitor();
|
||||
}
|
||||
else if (visitorKind.equals("function")) {
|
||||
return new FunctionFlagsVisitor(testedObjectName);
|
||||
}
|
||||
else if (visitorKind.equals("property")) {
|
||||
return new PropertyFlagsVisitor(testedObjectName);
|
||||
}
|
||||
throw new IllegalArgumentException("Value of TESTED_OBJECT_KIND is incorrect: " + visitorKind);
|
||||
}
|
||||
|
||||
protected static abstract class TestClassVisitor extends ClassVisitor {
|
||||
public TestClassVisitor() {
|
||||
super(Opcodes.ASM4);
|
||||
}
|
||||
|
||||
abstract public int getAccess();
|
||||
}
|
||||
|
||||
private static int getExpectedFlags(String text) {
|
||||
int expectedAccess = 0;
|
||||
Class klass = Opcodes.class;
|
||||
List<String> flags = findListWithPrefix("// FLAGS: ", text);
|
||||
for (String flag : flags) {
|
||||
try {
|
||||
Field field = klass.getDeclaredField(flag);
|
||||
expectedAccess |= field.getInt(klass);
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
throw new IllegalArgumentException("Cannot find " + flag + " field in Opcodes class", e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Cannot find " + flag + " field in Opcodes class", e);
|
||||
}
|
||||
}
|
||||
return expectedAccess;
|
||||
}
|
||||
|
||||
private static class ClassFlagsVisitor extends TestClassVisitor {
|
||||
private int access = 0;
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
this.access = access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccess() {
|
||||
return access;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FunctionFlagsVisitor extends TestClassVisitor {
|
||||
private int access = 0;
|
||||
private final String funName;
|
||||
|
||||
public FunctionFlagsVisitor(String name) {
|
||||
funName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
if (name.equals(funName)) {
|
||||
this.access = access;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccess() {
|
||||
return access;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PropertyFlagsVisitor extends TestClassVisitor {
|
||||
private int access = 0;
|
||||
private final String propertyName;
|
||||
|
||||
public PropertyFlagsVisitor(String name) {
|
||||
propertyName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
|
||||
if (name.equals(propertyName)) {
|
||||
this.access = access;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccess() {
|
||||
return access;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.flags;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest}. DO NOT MODIFY MANUALLY */
|
||||
@TestMetadata("compiler/testData/writeFlags")
|
||||
@InnerTestClasses({WriteFlagsTestGenerated.Class.class, WriteFlagsTestGenerated.Function.class, WriteFlagsTestGenerated.Property.class})
|
||||
public class WriteFlagsTestGenerated extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInWriteFlags() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/class")
|
||||
@InnerTestClasses({Class.AccessFlags.class, Class.DeprecatedFlag.class})
|
||||
public static class Class extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInClass() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/class"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/class/accessFlags")
|
||||
public static class AccessFlags extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInAccessFlags() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/class/accessFlags"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("publicFinalClass.kt")
|
||||
public void testPublicFinalClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/accessFlags/publicFinalClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("publicFinalInnerClass.kt")
|
||||
public void testPublicFinalInnerClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/accessFlags/publicFinalInnerClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("publicInnerInterface.kt")
|
||||
public void testPublicInnerInterface() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/accessFlags/publicInnerInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("publicInterface.kt")
|
||||
public void testPublicInterface() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/accessFlags/publicInterface.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/class/deprecatedFlag")
|
||||
public static class DeprecatedFlag extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInDeprecatedFlag() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/class/deprecatedFlag"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("class.kt")
|
||||
public void testClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/deprecatedFlag/class.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classObject.kt")
|
||||
public void testClassObject() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/deprecatedFlag/classObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumClass.kt")
|
||||
public void testEnumClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/deprecatedFlag/enumClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/deprecatedFlag/innerClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("trait.kt")
|
||||
public void testTrait() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/class/deprecatedFlag/trait.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Class");
|
||||
suite.addTestSuite(Class.class);
|
||||
suite.addTestSuite(AccessFlags.class);
|
||||
suite.addTestSuite(DeprecatedFlag.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/function")
|
||||
@InnerTestClasses({Function.DeprecatedFlag.class})
|
||||
public static class Function extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInFunction() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/function"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/function/deprecatedFlag")
|
||||
public static class DeprecatedFlag extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInDeprecatedFlag() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/function/deprecatedFlag"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("emptyGetter.kt")
|
||||
public void testEmptyGetter() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/emptyGetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptySetter.kt")
|
||||
public void testEmptySetter() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/emptySetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extentionFun.kt")
|
||||
public void testExtentionFun() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/extentionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("funInClass.kt")
|
||||
public void testFunInClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/funInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("funInClassObject.kt")
|
||||
public void testFunInClassObject() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/funInClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("getterAnnotationOnProperty.kt")
|
||||
public void testGetterAnnotationOnProperty() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/getterAnnotationOnProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("getterForPropertyInConstructor.kt")
|
||||
public void testGetterForPropertyInConstructor() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/getterForPropertyInConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/setter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterAnnotationOnProperty.kt")
|
||||
public void testSetterAnnotationOnProperty() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/setterAnnotationOnProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterForPropertyInConstructor.kt")
|
||||
public void testSetterForPropertyInConstructor() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/setterForPropertyInConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelFun.kt")
|
||||
public void testTopLevelFun() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/function/deprecatedFlag/topLevelFun.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Function");
|
||||
suite.addTestSuite(Function.class);
|
||||
suite.addTestSuite(DeprecatedFlag.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/property")
|
||||
@InnerTestClasses({Property.DeprecatedFlag.class})
|
||||
public static class Property extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInProperty() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/property"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeFlags/property/deprecatedFlag")
|
||||
public static class DeprecatedFlag extends AbstractWriteFlagsTest {
|
||||
public void testAllFilesPresentInDeprecatedFlag() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest", new File("compiler/testData/writeFlags/property/deprecatedFlag"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyInClass.kt")
|
||||
public void testPropertyInClass() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/property/deprecatedFlag/propertyInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelProperty.kt")
|
||||
public void testTopLevelProperty() throws Exception {
|
||||
doTest("compiler/testData/writeFlags/property/deprecatedFlag/topLevelProperty.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Property");
|
||||
suite.addTestSuite(Property.class);
|
||||
suite.addTestSuite(DeprecatedFlag.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("WriteFlagsTestGenerated");
|
||||
suite.addTestSuite(WriteFlagsTestGenerated.class);
|
||||
suite.addTest(Class.innerSuite());
|
||||
suite.addTest(Function.innerSuite());
|
||||
suite.addTest(Property.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user