Move AnalyzerExhaust from frontend.java to frontend.

This commit is contained in:
Pavel V. Talanov
2012-04-04 16:11:40 +04:00
parent 973c6f8d85
commit 766b4dc975
13 changed files with 316 additions and 251 deletions
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.ShutDownTracker;
import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
@@ -30,7 +31,6 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.SlicedMap;
@@ -86,7 +86,7 @@ public class JetTestUtils {
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
if (slice == BindingContext.PROCESSED) return (V) Boolean.FALSE;
if (slice == BindingContext.PROCESSED) return (V)Boolean.FALSE;
return SlicedMap.DO_NOTHING.get(slice, key);
}
@@ -100,61 +100,61 @@ public class JetTestUtils {
@Override
public void report(@NotNull Diagnostic diagnostic) {
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic;
throw new IllegalStateException("Unresolved: " + unresolvedReferenceDiagnostic.getPsiElement().getText());
}
}
};
public static BindingTrace DUMMY_EXCEPTION_ON_ERROR_TRACE = new BindingTrace() {
@Override
public BindingContext getBindingContext() {
return new BindingContext() {
@Override
public Collection<Diagnostic> getDiagnostics() {
throw new UnsupportedOperationException();
}
@Override
public BindingContext getBindingContext() {
return new BindingContext() {
@Override
public Collection<Diagnostic> getDiagnostics() {
throw new UnsupportedOperationException();
}
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
return DUMMY_EXCEPTION_ON_ERROR_TRACE.get(slice, key);
}
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
return DUMMY_EXCEPTION_ON_ERROR_TRACE.get(slice, key);
}
@NotNull
@Override
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice);
}
};
}
@Override
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
}
@Override
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
}
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
return null;
}
@NotNull
@Override
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
assert slice.isCollective();
return Collections.emptySet();
}
@Override
public void report(@NotNull Diagnostic diagnostic) {
if (diagnostic.getSeverity() == Severity.ERROR) {
throw new IllegalStateException(diagnostic.getMessage());
}
@NotNull
@Override
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice);
}
};
}
@Override
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
}
@Override
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
}
@Override
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
return null;
}
@NotNull
@Override
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
assert slice.isCollective();
return Collections.emptySet();
}
@Override
public void report(@NotNull Diagnostic diagnostic) {
if (diagnostic.getSeverity() == Severity.ERROR) {
throw new IllegalStateException(diagnostic.getMessage());
}
}
};
public static AnalyzeExhaust analyzeFile(@NotNull JetFile namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(namespace, flowDataTraceFactory);
@@ -202,24 +202,25 @@ public class JetTestUtils {
public static void deleteOnShutdown(File file) {
if (filesToDelete.isEmpty()) {
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
@Override
public void run() {
@Override
public void run() {
ShutDownTracker.invokeAndWait(true, true, new Runnable() {
@Override
public void run() {
for (File victim : filesToDelete) {
FileUtil.delete(victim);
}
}
@Override
public void run() {
for (File victim : filesToDelete) {
FileUtil.delete(victim);
}
}
});
}
});
}
});
}
filesToDelete.add(file);
}
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
public interface TestFileFactory<F> {
F create(String fileName, String text);
}
@@ -254,7 +255,10 @@ public class JetTestUtils {
if (!nextFileExists) break;
}
assert processedChars == expectedText.length() : "Characters skipped from " + processedChars + " to " + (expectedText.length() - 1);
assert processedChars == expectedText.length() : "Characters skipped from " +
processedChars +
" to " +
(expectedText.length() - 1);
}
return testFileFiles;
}
@@ -19,11 +19,10 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.parsing.JetParsingTest;
@@ -38,12 +37,13 @@ import java.util.Collections;
*/
public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) throws IllegalAccessException {
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args)
throws IllegalAccessException {
boolean caught = false;
try {
foo.invoke(instance, args);
}
catch(InvocationTargetException ex) {
catch (InvocationTargetException ex) {
caught = exceptionClass.isInstance(ex.getTargetException());
}
assertTrue(caught);
@@ -61,16 +61,17 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
protected void loadText(final String text) {
myFile = (JetFile) createFile("a.jet", text);
myFile = (JetFile)createFile("a.jet", text);
}
@Override
protected String loadFile(final String name) {
try {
final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
myFile = (JetFile) createFile(name, content);
myFile = (JetFile)createFile(name, content);
return content;
} catch (IOException e) {
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@@ -88,10 +89,12 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String actual;
try {
actual = blackBox();
} catch (NoClassDefFoundError e) {
}
catch (NoClassDefFoundError e) {
System.out.println(generateToText());
throw e;
} catch (Throwable e) {
}
catch (Throwable e) {
System.out.println(generateToText());
throw new RuntimeException(e);
}
@@ -109,9 +112,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
Class<?> namespaceClass = loader.loadClass(fqName);
Method method = namespaceClass.getMethod("box");
return (String) method.invoke(null);
} finally {
loader.dispose();
return (String)method.invoke(null);
}
finally {
loader.dispose();
}
}
@@ -124,7 +128,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
final AnalyzeExhaust analyzeExhaust =
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(myFile, JetControlFlowDataTraceFactory.EMPTY);
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
return state;
@@ -144,9 +149,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile), true).replace("/", ".");
try {
return createClassLoader(state).loadClass(fqName);
} catch (ClassNotFoundException e) {
}
catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
}
catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
@@ -155,8 +162,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected Class loadClass(String fqName, @NotNull ClassFileFactory state) {
try {
return createClassLoader(state).loadClass(fqName);
} catch (ClassNotFoundException e) {
} catch (MalformedURLException e) {
}
catch (ClassNotFoundException e) {
}
catch (MalformedURLException e) {
}
fail("No classfile was generated for: " + fqName);
@@ -169,7 +178,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
ClassBuilderFactory classBuilderFactory = ClassBuilderFactories.binaries(false);
return generateCommon(classBuilderFactory).getFactory();
} catch (RuntimeException e) {
}
catch (RuntimeException e) {
System.out.println(generateToText());
throw e;
}
@@ -190,10 +200,12 @@ public abstract class CodegenTestCase extends JetLiteFixture {
r = method;
}
if (r == null)
if (r == null) {
throw new AssertionError();
}
return r;
} catch (Error e) {
}
catch (Error e) {
System.out.println(generateToText());
throw e;
}
@@ -221,11 +233,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected static void assertIsCurrentTime(long returnValue) {
long currentTime = System.currentTimeMillis();
long diff = Math.abs(returnValue - currentTime);
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", diff <= 1L);
assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)",
diff <= 1L);
}
protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) {
return loadClass(name, codegens);
}
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
@@ -31,13 +32,12 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.List;
import java.util.Map;
@@ -139,11 +139,13 @@ public abstract class ExpectedResolveData {
JetStandardLibrary lib = JetStandardLibrary.getInstance();
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
Predicates.<PsiFile>alwaysTrue(),
JetControlFlowDataTraceFactory.EMPTY,
CompilerSpecialMode.REGULAR);
BindingContext bindingContext = analyzeExhaust.getBindingContext();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic;
unresolvedReferences.add(unresolvedReferenceDiagnostic.getPsiElement());
}
}
@@ -174,35 +176,35 @@ public abstract class ExpectedResolveData {
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class);
if ("!".equals(name)) {
assertTrue(
"Must have been unresolved: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
unresolvedReferences.contains(referenceExpression));
"Must have been unresolved: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
unresolvedReferences.contains(referenceExpression));
continue;
}
if ("!!".equals(name)) {
assertTrue(
"Must have been resolved to multiple descriptors: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null);
"Must have been resolved to multiple descriptors: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, referenceExpression) != null);
continue;
}
else if ("!null".equals(name)) {
assertTrue(
"Must have been resolved to null: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(REFERENCE_TARGET, referenceExpression) == null
"Must have been resolved to null: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
bindingContext.get(REFERENCE_TARGET, referenceExpression) == null
);
continue;
}
else if ("!error".equals(name)) {
assertTrue(
"Must have been resolved to error: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression))
"Must have been resolved to error: " +
renderReferenceInContext(referenceExpression) +
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(REFERENCE_TARGET, referenceExpression)),
ErrorUtils.isError(bindingContext.get(REFERENCE_TARGET, referenceExpression))
);
continue;
}
@@ -250,30 +252,30 @@ public abstract class ExpectedResolveData {
if (expected instanceof JetParameter || actual instanceof JetParameter) {
DeclarationDescriptor expectedDescriptor;
if (name.startsWith("$")) {
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter) expected);
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter)expected);
}
else {
expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected);
if (expectedDescriptor == null) {
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement) expected);
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement)expected);
}
}
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor)actualDescriptor;
actualDescriptor = descriptor.getVariableDescriptor();
}
assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expectedDescriptor, actualDescriptor);
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expectedDescriptor, actualDescriptor);
}
else {
assertEquals(
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expected, actual);
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
expected, actual);
}
}
@@ -305,7 +307,8 @@ public abstract class ExpectedResolveData {
expectedTypeConstructor = classDescriptor.getTypeConstructor();
}
else if (declaration instanceof JetTypeParameter) {
TypeParameterDescriptor typeParameterDescriptor = bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter) declaration);
TypeParameterDescriptor typeParameterDescriptor =
bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter)declaration);
expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor();
}
else {
@@ -325,14 +328,13 @@ public abstract class ExpectedResolveData {
PsiElement parent = statement.getParent();
if (!(parent instanceof JetExpression)) break;
if (parent instanceof JetBlockExpression) break;
statement = (JetExpression) parent;
statement = (JetExpression)parent;
}
JetDeclaration declaration = PsiTreeUtil.getParentOfType(referenceExpression, JetDeclaration.class);
return referenceExpression.getText() + " at " + DiagnosticUtils.atLocation(referenceExpression) +
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
}
private static <T> T getAncestorOfType(Class<T> type, PsiElement element) {
@@ -340,7 +342,7 @@ public abstract class ExpectedResolveData {
element = element.getParent();
}
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
T result = (T) element;
T result = (T)element;
return result;
}
}
@@ -18,12 +18,12 @@ package org.jetbrains.jet.types;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.di.InjectorForTests;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
@@ -45,7 +45,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc.setUp();
}
public class JetDefaultModalityModifiersTestCase {
public class JetDefaultModalityModifiersTestCase {
private ModuleDescriptor root = new ModuleDescriptor("test_root");
private DescriptorResolver descriptorResolver;
private JetScope scope;
@@ -62,11 +62,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = file.getDeclarations();
JetDeclaration aClass = declarations.get(0);
assert aClass instanceof JetClass;
AnalyzeExhaust bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeForJVM.SINGLE_DECLARATION_PROVIDER);
DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
AnalyzeExhaust bindingContext =
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeForJVM.SINGLE_DECLARATION_PROVIDER);
DeclarationDescriptor classDescriptor =
bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING);
assert classDescriptor instanceof ClassifierDescriptor;
scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
scope.addClassifierDescriptor((ClassifierDescriptor)classDescriptor);
scope.changeLockLevel(WritableScope.LockLevel.READING);
return scope;
}
@@ -90,8 +92,9 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass);
List<JetDeclaration> declarations = aClass.getDeclarations();
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE);
JetNamedFunction function = (JetNamedFunction)declarations.get(0);
SimpleFunctionDescriptor functionDescriptor =
descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE);
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
}
@@ -101,20 +104,25 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass);
List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
JetProperty property = (JetProperty)declarations.get(0);
PropertyDescriptor propertyDescriptor =
descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
}
private void testPropertyAccessorModality(String classWithPropertyWithAccessor, ClassKind kind, Modality expectedPropertyAccessorModality, boolean isGetter) {
private void testPropertyAccessorModality(String classWithPropertyWithAccessor,
ClassKind kind,
Modality expectedPropertyAccessorModality,
boolean isGetter) {
JetClass aClass = JetPsiFactory.createClass(getProject(), classWithPropertyWithAccessor);
MutableClassDescriptor classDescriptor = createClassDescriptor(kind, aClass);
List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
JetProperty property = (JetProperty)declarations.get(0);
PropertyDescriptor propertyDescriptor =
descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
PropertyAccessorDescriptor propertyAccessor = isGetter
? propertyDescriptor.getGetter()
: propertyDescriptor.getSetter();
@@ -382,13 +390,15 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; open get }", Modality.OPEN);
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final get }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; override get() = 2 }", Modality.OPEN);
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final override get() = 2 }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final override get() = 2 }",
Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0 }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; get }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final get }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; override get() = 2 }", Modality.OPEN);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final override get() = 2 }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final override get() = 2 }",
Modality.FINAL);
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int get }", Modality.ABSTRACT);
@@ -401,10 +411,12 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int get }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int open get }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int abstract get }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int abstract get }",
Modality.ABSTRACT);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int override get() = 10 }", Modality.OPEN);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int open override get() = 10 }", Modality.OPEN);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int final override get() = 10 }", Modality.FINAL);
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int final override get() = 10 }",
Modality.FINAL);
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int }", Modality.ABSTRACT);
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int get }", Modality.ABSTRACT);