Merge branch 'master' of ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* @author max
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
@@ -16,9 +17,7 @@ import org.objectweb.asm.commons.Method;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
@@ -152,6 +151,9 @@ public class ClosureCodegen extends FunctionOrClosureCodegen {
|
||||
final Method bridge = erasedInvokeSignature(funDescriptor);
|
||||
final Method delegate = invokeSignature(funDescriptor);
|
||||
|
||||
if(bridge.getDescriptor().equals(delegate.getDescriptor()))
|
||||
return;
|
||||
|
||||
final MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "invoke", bridge.getDescriptor(), state.getTypeMapper().genericSignature(funDescriptor), new String[0]);
|
||||
mv.visitCode();
|
||||
|
||||
@@ -212,7 +214,8 @@ public class ClosureCodegen extends FunctionOrClosureCodegen {
|
||||
ExpressionCodegen expressionCodegen = new ExpressionCodegen(mv, null, Type.VOID_TYPE, context, state);
|
||||
|
||||
iv.load(0, Type.getObjectType(funClass));
|
||||
expressionCodegen.generateTypeInfo(new ProjectionErasingJetType(returnType));
|
||||
// expressionCodegen.generateTypeInfo(new ProjectionErasingJetType(returnType));
|
||||
iv.aconst(null); // @todo
|
||||
iv.invokespecial(funClass, "<init>", "(Ljet/typeinfo/TypeInfo;)V");
|
||||
|
||||
i = 1;
|
||||
|
||||
@@ -313,10 +313,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
myContinueTargets.pop();
|
||||
}
|
||||
|
||||
private DeclarationDescriptor contextType() {
|
||||
return context.getContextClass();
|
||||
}
|
||||
|
||||
private OwnerKind contextKind() {
|
||||
return context.getContextKind();
|
||||
}
|
||||
@@ -874,7 +870,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
String owner;
|
||||
|
||||
boolean isInterface;
|
||||
boolean isInsideClass = containingDeclaration == contextType();
|
||||
boolean isInsideClass = containingDeclaration == context.getContextClass();
|
||||
if (isInsideClass || isStatic) {
|
||||
owner = typeMapper.getOwner(functionDescriptor, contextKind());
|
||||
isInterface = false;
|
||||
@@ -904,7 +900,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||
boolean isStatic = containingDeclaration instanceof NamespaceDescriptorImpl;
|
||||
propertyDescriptor = propertyDescriptor.getOriginal();
|
||||
boolean isInsideClass = !forceInterface && containingDeclaration == contextType();
|
||||
boolean isInsideClass = !forceInterface && containingDeclaration == context.getContextClass();
|
||||
Method getter;
|
||||
Method setter;
|
||||
if (forceField) {
|
||||
@@ -1024,10 +1020,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return funDescriptor;
|
||||
}
|
||||
|
||||
public void invokeMethodWithArguments(CallableMethod callableMethod, JetCallElement expression) {
|
||||
invokeMethodWithArguments(callableMethod, expression, StackValue.none());
|
||||
}
|
||||
|
||||
public void invokeMethodWithArguments(CallableMethod callableMethod, JetCallElement expression, StackValue receiver) {
|
||||
final Type calleeType = callableMethod.getGenerateCalleeType();
|
||||
if (calleeType != null && expression instanceof JetCallExpression) {
|
||||
@@ -1053,7 +1045,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
else {
|
||||
if (callableMethod.isNeedsReceiver()) {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
if (receiver == StackValue.none()) {
|
||||
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
}
|
||||
else
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1812,7 +1808,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) constructorDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
invokeMethodWithArguments(method, expression);
|
||||
invokeMethodWithArguments(method, expression, StackValue.none());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1849,7 +1845,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
v.anew(type);
|
||||
v.dup();
|
||||
final CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructor);
|
||||
invokeMethodWithArguments(callableMethod, expression);
|
||||
invokeMethodWithArguments(callableMethod, expression, StackValue.none());
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1867,20 +1863,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
throw new CompilationException("primitive array constructor requires one argument");
|
||||
}
|
||||
}
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
|
||||
if(isArray) {
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/typeinfo/TypeInfo", "newArray", "(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;");
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
v.invokevirtual("jet/typeinfo/TypeInfo", "newArray", "(I)[Ljava/lang/Object;");
|
||||
}
|
||||
else {
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
v.newarray(JetTypeMapper.boxType(typeMapper.mapType(arrayType.getArguments().get(0).getType())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
v.newarray(type.getElementType());
|
||||
}
|
||||
|
||||
@@ -2311,12 +2309,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return;
|
||||
}
|
||||
DeclarationDescriptor containingDeclaration = typeParameterDescriptor.getContainingDeclaration();
|
||||
if (contextType() instanceof ClassDescriptor) {
|
||||
ClassDescriptor descriptor = (ClassDescriptor) contextType();
|
||||
if (context.getContextClass() instanceof ClassDescriptor) {
|
||||
ClassDescriptor descriptor = (ClassDescriptor) context.getContextClass();
|
||||
JetType defaultType = ((ClassDescriptor)containingDeclaration).getDefaultType();
|
||||
Type ownerType = typeMapper.mapType(defaultType);
|
||||
ownerType = JetTypeMapper.boxType(ownerType);
|
||||
if (containingDeclaration == contextType()) {
|
||||
if (containingDeclaration == context.getContextClass()) {
|
||||
if(!CodegenUtil.isInterface(descriptor)) {
|
||||
if (CodegenUtil.hasTypeInfoField(defaultType)) {
|
||||
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
|
||||
@@ -461,7 +461,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
CallableMethod method = state.getTypeMapper().mapToCallableMethod(constructorDescriptor, kind);
|
||||
codegen.invokeMethodWithArguments(method, constructorCall);
|
||||
codegen.invokeMethodWithArguments(method, constructorCall, StackValue.none());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -513,7 +513,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
final JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier;
|
||||
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) state.getBindingContext().get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
||||
CallableMethod method = state.getTypeMapper().mapToCallableMethod(constructorDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
codegen.invokeMethodWithArguments(method, superCall);
|
||||
codegen.invokeMethodWithArguments(method, superCall, StackValue.none());
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier);
|
||||
|
||||
@@ -75,6 +75,7 @@ public class IntrinsicMethods {
|
||||
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("toString"), 0, new ToString());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("equals"), 1, new Equals());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("plus"), 1, new StringPlus());
|
||||
|
||||
// declareIntrinsicFunction("Any", "equals", 1, new Equals());
|
||||
//
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.jetbrains.jet.codegen.intrinsics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class StringPlus implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||
codegen.gen(arguments.get(0)).put(JetTypeMapper.JL_STRING_TYPE, v);
|
||||
codegen.gen(arguments.get(1)).put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
v.invokestatic("jet/runtime/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
||||
return StackValue.onStack(JetTypeMapper.JL_STRING_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.jet.cli;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -10,6 +12,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.sampullara.cli.Args;
|
||||
import com.sampullara.cli.Argument;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
@@ -17,13 +20,11 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -61,17 +62,13 @@ public class KotlinCompiler {
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
JavaCoreEnvironment environment = new JavaCoreEnvironment(root);
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(root);
|
||||
|
||||
File rtJar = initJdk();
|
||||
if (rtJar == null) return;
|
||||
|
||||
environment.addToClasspath(rtJar);
|
||||
|
||||
environment.registerFileType(JetFileType.INSTANCE, "kt");
|
||||
environment.registerFileType(JetFileType.INSTANCE, "jet");
|
||||
environment.registerParserDefinition(new JetParserDefinition());
|
||||
|
||||
VirtualFile vFile = environment.getLocalFileSystem().findFileByPath(arguments.src);
|
||||
if (vFile == null) {
|
||||
System.out.print("File/directory not found: " + arguments.src);
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ public class JavaDescriptorResolver {
|
||||
private DeclarationDescriptor resolveParentDescriptor(PsiClass psiClass) {
|
||||
PsiClass containingClass = psiClass.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
return resolveClass(psiClass);
|
||||
return resolveClass(containingClass);
|
||||
}
|
||||
|
||||
PsiJavaFile containingFile = (PsiJavaFile) psiClass.getContainingFile();
|
||||
|
||||
@@ -40,6 +40,8 @@ fun Any?.equals(other : Any?) : Boolean// = this === other
|
||||
// Returns "null" for null
|
||||
fun Any?.toString() : String// = this === other
|
||||
|
||||
fun String?.plus(other: Any?) : String
|
||||
|
||||
trait Iterator<out T> {
|
||||
fun next() : T
|
||||
val hasNext : Boolean
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
public JetCoreEnvironment(Disposable parentDisposable) {
|
||||
super(parentDisposable);
|
||||
registerFileType(JetFileType.INSTANCE, "kt");
|
||||
registerFileType(JetFileType.INSTANCE, "kts");
|
||||
registerFileType(JetFileType.INSTANCE, "ktm");
|
||||
registerFileType(JetFileType.INSTANCE, "jet");
|
||||
registerParserDefinition(new JetParserDefinition());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun Any.with(operation : fun Any.() : Any) = operation().toString()
|
||||
|
||||
val f = { (a : Int) :Unit => }
|
||||
|
||||
fun box () : String {
|
||||
return if(20.with {
|
||||
this
|
||||
} == "20")
|
||||
"OK"
|
||||
else
|
||||
"fail"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JetLightProjectDescriptor extends DefaultLightProjectDescriptor {
|
||||
public static JetLightProjectDescriptor INSTANCE = new JetLightProjectDescriptor();
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,21 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.lang.impl.PsiBuilderFactoryImpl;
|
||||
import com.intellij.mock.*;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.fileTypes.FileTypeFactory;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.options.SchemesManagerFactory;
|
||||
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiCachedValuesFactory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.MockSchemesManagerFactory;
|
||||
import com.intellij.testFramework.PlatformLiteFixture;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.util.CachedValuesManagerImpl;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusFactory;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
import org.picocontainer.PicoContainer;
|
||||
import org.picocontainer.PicoInitializationException;
|
||||
import org.picocontainer.PicoIntrospectionException;
|
||||
import org.picocontainer.defaults.AbstractComponentAdapter;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -48,81 +23,42 @@ import java.io.IOException;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetLiteFixture extends PlatformLiteFixture {
|
||||
protected String myFileExt;
|
||||
public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
@NonNls
|
||||
protected final String myFullDataPath;
|
||||
protected PsiFile myFile;
|
||||
private MockPsiManager myPsiManager;
|
||||
private PsiFileFactoryImpl myFileFactory;
|
||||
protected Language myLanguage;
|
||||
protected final ParserDefinition[] myDefinitions;
|
||||
protected JetFile myFile;
|
||||
private JetCoreEnvironment myEnvironment;
|
||||
|
||||
public JetLiteFixture(@NonNls String dataPath) {
|
||||
myFileExt = "jet";
|
||||
myFullDataPath = getTestDataPath() + "/" + dataPath;
|
||||
myDefinitions = new ParserDefinition[] {new JetParserDefinition()};
|
||||
}
|
||||
|
||||
public JetLiteFixture() {
|
||||
myFullDataPath = getTestDataPath();
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return JetTestCaseBase.getTestDataPathBase();
|
||||
return JetTestCaseBuilder.getTestDataPathBase();
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myEnvironment.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initApplication();
|
||||
getApplication().getPicoContainer().registerComponent(new AbstractComponentAdapter("com.intellij.openapi.progress.ProgressManager", Object.class) {
|
||||
@Override
|
||||
public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
|
||||
return new ProgressManagerImpl(getApplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify(PicoContainer container) throws PicoIntrospectionException {
|
||||
}
|
||||
});
|
||||
Extensions.registerAreaClass("IDEA_PROJECT", null);
|
||||
myProject = disposeOnTearDown(new MockProjectEx(getTestRootDisposable()));
|
||||
myPsiManager = new MockPsiManager(myProject);
|
||||
myFileFactory = new PsiFileFactoryImpl(myPsiManager);
|
||||
final MutablePicoContainer appContainer = getApplication().getPicoContainer();
|
||||
registerComponentInstance(appContainer, MessageBus.class, MessageBusFactory.newMessageBus(getApplication()));
|
||||
registerComponentInstance(appContainer, SchemesManagerFactory.class, new MockSchemesManagerFactory());
|
||||
final MockEditorFactory editorFactory = new MockEditorFactory();
|
||||
registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
|
||||
registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(new Function<CharSequence, Document>() {
|
||||
@Override
|
||||
public Document fun(CharSequence charSequence) {
|
||||
return editorFactory.createDocument(charSequence);
|
||||
}
|
||||
}, FileDocumentManagerImpl.DOCUMENT_KEY));
|
||||
registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
|
||||
myLanguage = myLanguage == null && myDefinitions != null && myDefinitions.length > 0
|
||||
? myDefinitions[0].getFileNodeType().getLanguage()
|
||||
: myLanguage;
|
||||
registerComponentInstance(appContainer, FileTypeManager.class, new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt)));
|
||||
registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
|
||||
registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
|
||||
registerApplicationService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
|
||||
myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
|
||||
myProject.registerService(PsiManager.class, myPsiManager);
|
||||
myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));
|
||||
myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager));
|
||||
|
||||
registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
|
||||
|
||||
for (ParserDefinition definition : myDefinitions) {
|
||||
addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
|
||||
}
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable());
|
||||
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||
myEnvironment.addToClasspath(rtJar);
|
||||
myEnvironment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
myFile = null;
|
||||
myProject = null;
|
||||
myPsiManager = null;
|
||||
myEnvironment = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected String loadFile(@NonNls @TestDataFile String name) throws IOException {
|
||||
@@ -136,14 +72,22 @@ public abstract class JetLiteFixture extends PlatformLiteFixture {
|
||||
return text;
|
||||
}
|
||||
|
||||
protected PsiFile createPsiFile(String name, String text) {
|
||||
return createFile(name + "." + myFileExt, text);
|
||||
protected JetFile createPsiFile(String name, String text) {
|
||||
return (JetFile) createFile(name + ".jet", text);
|
||||
}
|
||||
|
||||
protected JetFile loadPsiFile(String name) {
|
||||
try {
|
||||
return createPsiFile(name, loadFile(name));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected PsiFile createFile(@NonNls String name, String text) {
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(name, myLanguage, text);
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(name, JetLanguage.INSTANCE, text);
|
||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||
return myFileFactory.trySetupPsiForFile(virtualFile, myLanguage, true, false);
|
||||
return ((PsiFileFactoryImpl) PsiFileFactory.getInstance(myEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
||||
}
|
||||
|
||||
protected static void ensureParsed(PsiFile file) {
|
||||
@@ -155,28 +99,8 @@ public abstract class JetLiteFixture extends PlatformLiteFixture {
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void registerApplicationService(final Class<T> aClass, T object) {
|
||||
getApplication().registerService(aClass, object);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
getApplication().getPicoContainer().unregisterComponent(aClass.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void addExplicitExtension(final LanguageExtension<T> instance, final Language language, final T object) {
|
||||
instance.addExplicitExtension(language, object);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
instance.removeExplicitExtension(language, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void prepareForTest(String name) throws IOException {
|
||||
String text = loadFile(name + "." + myFileExt);
|
||||
String text = loadFile(name + ".jet");
|
||||
createAndCheckPsiFile(name, text);
|
||||
}
|
||||
|
||||
|
||||
+8
-63
@@ -1,9 +1,6 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,72 +15,20 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
private static FilenameFilter emptyFilter;
|
||||
private boolean checkInfos = false;
|
||||
private String dataPath;
|
||||
protected final String name;
|
||||
|
||||
public JetTestCaseBase(String dataPath, String name) {
|
||||
this.dataPath = dataPath;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public final JetTestCaseBase setCheckInfos(boolean checkInfos) {
|
||||
this.checkInfos = checkInfos;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Sdk jdkFromIdeaHome() {
|
||||
return new JavaSdkImpl().createJdk("JDK", "compiler/testData/mockJDK-1.7/jre", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return getTestDataPathBase();
|
||||
}
|
||||
public abstract class JetTestCaseBuilder {
|
||||
private static FilenameFilter emptyFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static String getTestDataPathBase() {
|
||||
return getHomeDirectory() + "/compiler/testData";
|
||||
}
|
||||
|
||||
public static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(JetTestCaseBase.class, "/org/jetbrains/jet/JetTestCaseBase.class")).getParentFile().getParentFile().getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
doTest(getTestFilePath(), true, checkInfos);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getTestFilePath() {
|
||||
return dataPath + File.separator + name + ".jet";
|
||||
}
|
||||
|
||||
protected String getDataPath() {
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
emptyFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
return new File(PathManager.getResourceRoot(JetTestCaseBuilder.class, "/org/jetbrains/jet/JetTestCaseBuilder.class")).getParentFile().getParentFile().getParent();
|
||||
}
|
||||
|
||||
public interface NamedTestFactory {
|
||||
@@ -8,7 +8,8 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.cfg.LoopInfo;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -20,19 +21,25 @@ import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
|
||||
public class JetControlFlowTest extends JetTestCaseBase {
|
||||
public class JetControlFlowTest extends JetLiteFixture {
|
||||
static {
|
||||
System.setProperty("idea.platform.prefix", "Idea");
|
||||
}
|
||||
|
||||
private String myName;
|
||||
|
||||
public JetControlFlowTest(String dataPath, String name) {
|
||||
super(dataPath, name);
|
||||
super(dataPath);
|
||||
myName = name;
|
||||
}
|
||||
|
||||
|
||||
protected String getTestFilePath() {
|
||||
return myFullDataPath + "/" + myName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
configureByFile(getTestFilePath());
|
||||
JetFile file = (JetFile) getFile();
|
||||
JetFile file = loadPsiFile(myName + ".jet");
|
||||
|
||||
final Map<JetElement, Pseudocode> data = new LinkedHashMap<JetElement, Pseudocode>();
|
||||
final JetPseudocodeTrace pseudocodeTrace = new JetPseudocodeTrace() {
|
||||
@@ -68,14 +75,14 @@ public class JetControlFlowTest extends JetTestCaseBase {
|
||||
});
|
||||
|
||||
try {
|
||||
processCFData(name, data);
|
||||
processCFData(myName, data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if ("true".equals(System.getProperty("jet.control.flow.test.dump.graphs"))) {
|
||||
dumpDot(name, data.values());
|
||||
dumpDot(myName, data.values());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +127,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
|
||||
}
|
||||
}
|
||||
|
||||
String expectedInstructionsFileName = getTestDataPath() + "/" + getTestFilePath().replace(".jet", ".instructions");
|
||||
String expectedInstructionsFileName = getTestFilePath() + ".instructions";
|
||||
File expectedInstructionsFile = new File(expectedInstructionsFileName);
|
||||
if (!expectedInstructionsFile.exists()) {
|
||||
FileUtil.writeToFile(expectedInstructionsFile, instructionDump.toString());
|
||||
@@ -351,7 +358,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
|
||||
}
|
||||
|
||||
private void dumpDot(String name, Collection<Pseudocode> pseudocodes) throws FileNotFoundException {
|
||||
String graphFileName = getTestDataPath() + "/" + getTestFilePath().replace(".jet", ".dot");
|
||||
String graphFileName = getTestDataPath() + "/" + getTestFilePath() + ".dot";
|
||||
File target = new File(graphFileName);
|
||||
|
||||
PrintStream out = new PrintStream(target);
|
||||
@@ -386,7 +393,7 @@ public class JetControlFlowTest extends JetTestCaseBase {
|
||||
|
||||
public static TestSuite suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), "/cfg/", true, new JetTestCaseBase.NamedTestFactory() {
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/cfg/", true, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
|
||||
@@ -2,39 +2,34 @@ package org.jetbrains.jet.checkers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class FullJetPsiCheckerTest extends JetTestCaseBase {
|
||||
public class FullJetPsiCheckerTest extends JetLiteFixture {
|
||||
private final String myDataPath;
|
||||
private String myName;
|
||||
|
||||
public FullJetPsiCheckerTest(@NonNls String dataPath, String name) {
|
||||
super(dataPath, name);
|
||||
myDataPath = dataPath;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runTest() throws Exception {
|
||||
String fileName = name + ".jet";
|
||||
String fullPath = getTestDataPath() + getTestFilePath();
|
||||
String fileName = myName + ".jet";
|
||||
String fullPath = myDataPath + "/" + fileName;
|
||||
|
||||
|
||||
String expectedText = loadFile(fullPath);
|
||||
@@ -42,9 +37,8 @@ public class FullJetPsiCheckerTest extends JetTestCaseBase {
|
||||
List<CheckerTestUtil.DiagnosedRange> diagnosedRanges = Lists.newArrayList();
|
||||
String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||
|
||||
configureFromFileText(fileName, clearText);
|
||||
JetFile jetFile = (JetFile) myFile;
|
||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(jetFile);
|
||||
myFile = createPsiFile(myName, clearText);
|
||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(myFile);
|
||||
|
||||
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
||||
@Override
|
||||
@@ -60,7 +54,7 @@ public class FullJetPsiCheckerTest extends JetTestCaseBase {
|
||||
}
|
||||
});
|
||||
|
||||
String actualText = CheckerTestUtil.addDiagnosticMarkersToText(jetFile, bindingContext).toString();
|
||||
String actualText = CheckerTestUtil.addDiagnosticMarkersToText(myFile, bindingContext).toString();
|
||||
|
||||
assertEquals(expectedText, actualText);
|
||||
|
||||
@@ -69,12 +63,7 @@ public class FullJetPsiCheckerTest extends JetTestCaseBase {
|
||||
// convert(new File(myFullDataPath + "/../../checker/"), new File(myFullDataPath));
|
||||
}
|
||||
|
||||
private String loadFile(String fullPath) throws IOException {
|
||||
final File ioFile = new File(fullPath);
|
||||
String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8);
|
||||
return StringUtil.convertLineSeparators(fileText);
|
||||
}
|
||||
|
||||
/*
|
||||
private void convert(File src, File dest) throws IOException {
|
||||
File[] files = src.listFiles();
|
||||
for (File file : files) {
|
||||
@@ -105,9 +94,10 @@ public class FullJetPsiCheckerTest extends JetTestCaseBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static Test suite() {
|
||||
return JetTestCaseBase.suiteForDirectory(JetTestCaseBase.getTestDataPathBase(), "/checkerWithErrorTypes/full/", true, new JetTestCaseBase.NamedTestFactory() {
|
||||
return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/checkerWithErrorTypes/full/", true, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.jetbrains.jet.checkers;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetPsiCheckerTest extends JetTestCaseBase {
|
||||
|
||||
public JetPsiCheckerTest(String dataPath, String name) {
|
||||
super(dataPath, name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), "/checker/", false, new JetTestCaseBase.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name);
|
||||
}
|
||||
}));
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), "/checker/regression/", false, new JetTestCaseBase.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name);
|
||||
}
|
||||
}));
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), "/checker/infos/", false, new JetTestCaseBase.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name).setCheckInfos(true);
|
||||
}
|
||||
}));
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
@@ -93,7 +93,7 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture {
|
||||
// }
|
||||
|
||||
public static Test suite() {
|
||||
return JetTestCaseBase.suiteForDirectory(JetTestCaseBase.getTestDataPathBase(), "/checkerWithErrorTypes/quick", true, new JetTestCaseBase.NamedTestFactory() {
|
||||
return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/checkerWithErrorTypes/quick", true, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
@@ -21,7 +18,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
private MyClassLoader myClassLoader;
|
||||
|
||||
protected static void assertThrows(Method foo, Class<? extends Throwable> exceptionClass, Object instance, Object... args) throws IllegalAccessException {
|
||||
@@ -43,16 +40,24 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFile = null;
|
||||
myClassLoader = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void loadText(final String text) {
|
||||
myFixture.configureByText(JetFileType.INSTANCE, text);
|
||||
myFile = (JetFile) createFile("a.jet", text);
|
||||
}
|
||||
|
||||
protected void loadFile(final String name) {
|
||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||
@Override
|
||||
protected String loadFile(final String name) {
|
||||
try {
|
||||
final String content = doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
|
||||
myFile = (JetFile) createFile(name, content);
|
||||
return content;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadFile() {
|
||||
@@ -85,8 +90,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
ClassFileFactory codegens = generateClassesInFile();
|
||||
CodegensClassLoader loader = new CodegensClassLoader(codegens);
|
||||
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
final JetNamespace namespace = jetFile.getRootNamespace();
|
||||
final JetNamespace namespace = myFile.getRootNamespace();
|
||||
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
@@ -95,9 +99,8 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected String generateToText() {
|
||||
GenerationState state = new GenerationState(getProject(), true);
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
AnalyzingUtils.checkForSyntacticErrors(jetFile);
|
||||
state.compile(jetFile);
|
||||
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
||||
state.compile(myFile);
|
||||
|
||||
StringBuilder answer = new StringBuilder();
|
||||
|
||||
@@ -117,8 +120,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
protected Class loadRootNamespaceClass(ClassFileFactory state) {
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
final JetNamespace namespace = jetFile.getRootNamespace();
|
||||
final JetNamespace namespace = myFile.getRootNamespace();
|
||||
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||
Map<String, Class> classMap = loadAllClasses(state);
|
||||
return classMap.get(fqName);
|
||||
@@ -151,9 +153,8 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
GenerationState state = new GenerationState(getProject(), false);
|
||||
JetFile jetFile = (JetFile) myFixture.getFile();
|
||||
AnalyzingUtils.checkForSyntacticErrors(jetFile);
|
||||
state.compile(jetFile);
|
||||
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
||||
state.compile(myFile);
|
||||
|
||||
return state.getFactory();
|
||||
} catch (RuntimeException e) {
|
||||
@@ -233,10 +234,4 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
return super.findClass(name);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,41 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testNullableAnyToString () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: Any?) = x.toString()");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something", foo.invoke(null, "something"));
|
||||
assertEquals("null", foo.invoke(null, new Object[]{null}));
|
||||
|
||||
}
|
||||
|
||||
public void testNullableStringPlus () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: String?, y: Any?) = x + y");
|
||||
String text = generateToText();
|
||||
assertTrue(text.contains(".stringPlus"));
|
||||
System.out.println(text);
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something239", foo.invoke(null, "something", 239));
|
||||
assertEquals("null239", foo.invoke(null, null, 239));
|
||||
assertEquals("239null", foo.invoke(null, "239", null));
|
||||
assertEquals("nullnull", foo.invoke(null, null, null));
|
||||
|
||||
}
|
||||
|
||||
public void testNonNullableStringPlus () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: String, y: Any?) = x + y + 120");
|
||||
String text = generateToText();
|
||||
assertFalse(text.contains(".stringPlus"));
|
||||
System.out.println(text);
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something239120", foo.invoke(null, "something", 239));
|
||||
assertEquals("null239120", foo.invoke(null, null, 239));
|
||||
assertEquals("239null120", foo.invoke(null, "239", null));
|
||||
assertEquals("nullnull120", foo.invoke(null, null, null));
|
||||
|
||||
}
|
||||
|
||||
public void testAnyEqualsNullable () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: Any?) = x.equals(\"lala\")");
|
||||
System.out.println(generateToText());
|
||||
@@ -41,4 +76,8 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
assertTrue((Boolean) foo.invoke(null, "lala"));
|
||||
assertFalse((Boolean) foo.invoke(null, "mama"));
|
||||
}
|
||||
|
||||
public void testKt395 () {
|
||||
blackBoxFile("regressions/kt395.jet");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.IntRange;
|
||||
import jet.Tuple2;
|
||||
import jet.Tuple3;
|
||||
import jet.Tuple4;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -48,7 +46,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testLocalProperty() throws Exception {
|
||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/localProperty.jet");
|
||||
loadFile("localProperty.jet");
|
||||
final String text = generateToText();
|
||||
System.out.println(text);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
@@ -101,7 +101,7 @@ public class JetParsingTest extends ParsingTestCase {
|
||||
|
||||
public static TestSuite suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
JetTestCaseBase.NamedTestFactory factory = new JetTestCaseBase.NamedTestFactory() {
|
||||
JetTestCaseBuilder.NamedTestFactory factory = new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
@@ -109,8 +109,8 @@ public class JetParsingTest extends ParsingTestCase {
|
||||
}
|
||||
};
|
||||
String prefix = JetParsingTest.getTestDataDir() + "/psi/";
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(prefix, "/", false, factory));
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(prefix, "examples", true, factory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "/", false, factory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "examples", true, factory));
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
@@ -48,17 +46,7 @@ public class ExpectedResolveData {
|
||||
// this.nameToType = nameToType;
|
||||
}
|
||||
|
||||
public void extractData(final Document document) {
|
||||
new WriteCommandAction.Simple(null) {
|
||||
public void run() {
|
||||
doExtractData(document);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private void doExtractData(Document document) {
|
||||
String text = document.getText();
|
||||
|
||||
public String extractData(String text) {
|
||||
Pattern pattern = Pattern.compile("(~[^~]+~)|(`[^`]+`)");
|
||||
while (true) {
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
@@ -84,11 +72,11 @@ public class ExpectedResolveData {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
document.replaceString(start, matcher.end(), "");
|
||||
text = document.getText();
|
||||
text = text.substring(0, start) + text.substring(matcher.end());
|
||||
}
|
||||
|
||||
System.out.println(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public void checkResult(JetFile file) {
|
||||
|
||||
@@ -1,108 +1,29 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class ExtensibleResolveTestCase extends LightCodeInsightTestCase {
|
||||
private final FileTreeAccessFilter myJavaFilesFilter = new FileTreeAccessFilter();
|
||||
public abstract class ExtensibleResolveTestCase extends JetLiteFixture {
|
||||
private ExpectedResolveData expectedResolveData;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
expectedResolveData = getExpectedResolveData();
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).prepareForTest();
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
}
|
||||
|
||||
protected abstract ExpectedResolveData getExpectedResolveData();
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest(false); // has to cleanup by hand since light project does not get disposed any time soon
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
final Throwable[] throwable = {null};
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRunTest();
|
||||
} catch (Throwable t) {
|
||||
throwable[0] = t;
|
||||
}
|
||||
}
|
||||
}, "", null);
|
||||
if (throwable[0] != null) {
|
||||
throw throwable[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
// ExpectedHighlightingData expectedData = new ExpectedHighlightingData(getEditor().getDocument(), checkWarnings, checkInfos);
|
||||
expectedResolveData.extractData(getEditor().getDocument());
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
getFile().getText(); //to load text
|
||||
myJavaFilesFilter.allowTreeAccessForFile(getVFile());
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter); // check repository work
|
||||
|
||||
Collection<HighlightInfo> infos = doHighlighting();
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
expectedResolveData.checkResult((JetFile) getFile());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<HighlightInfo> doHighlighting() {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
int[] toIgnore = doFolding() ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{Pass.UPDATE_FOLDING};
|
||||
Editor editor = getEditor();
|
||||
PsiFile file = getFile();
|
||||
if (editor instanceof EditorWindow) {
|
||||
editor = ((EditorWindow) editor).getDelegate();
|
||||
file = InjectedLanguageUtil.getTopLevelFile(file);
|
||||
}
|
||||
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
|
||||
}
|
||||
|
||||
protected boolean doFolding() {
|
||||
return false;
|
||||
protected void doTest(@NonNls String filePath) throws Exception {
|
||||
String text = loadFile(filePath);
|
||||
text = expectedResolveData.extractData(text);
|
||||
JetFile jetFile = createPsiFile(new File(filePath).getName(), text);
|
||||
expectedResolveData.checkResult(jetFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -10,7 +9,7 @@ import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
@@ -133,10 +132,12 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
return getHomeDirectory() + "/compiler/testData";
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
*/
|
||||
|
||||
private static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(JetParsingTest.class, "/org/jetbrains/jet/parsing/JetParsingTest.class")).getParentFile().getParentFile().getParent();
|
||||
@@ -149,11 +150,11 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
doTest(path, true, false);
|
||||
doTest(path);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return JetTestCaseBase.suiteForDirectory(getHomeDirectory() + "/compiler/testData/", "/resolve/", true, new JetTestCaseBase.NamedTestFactory() {
|
||||
return JetTestCaseBuilder.suiteForDirectory(getHomeDirectory() + "/compiler/testData/", "/resolve/", true, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class JetDefaultModalityModifiersTest extends LightDaemonAnalyzerTestCase {
|
||||
public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
private JetDefaultModalityModifiersTestCase tc = new JetDefaultModalityModifiersTestCase();
|
||||
|
||||
@Override
|
||||
@@ -27,7 +27,7 @@ public class JetDefaultModalityModifiersTest extends LightDaemonAnalyzerTestCase
|
||||
tc.setUp();
|
||||
}
|
||||
|
||||
public static class JetDefaultModalityModifiersTestCase {
|
||||
public class JetDefaultModalityModifiersTestCase {
|
||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||
private ClassDescriptorResolver classDescriptorResolver;
|
||||
private JetScope scope;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
@@ -11,14 +11,11 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
|
||||
public class JetOverridingTest extends JetLiteFixture {
|
||||
|
||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||
private JetStandardLibrary library;
|
||||
@@ -35,11 +32,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return getHomeDirectory() + "/compiler/testData";
|
||||
}
|
||||
|
||||
private static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(JetParsingTest.class, "/org/jetbrains/jet/parsing/JetParsingTest.class")).getParentFile().getParentFile().getParent();
|
||||
return JetTestCaseBuilder.getTestDataPathBase();
|
||||
}
|
||||
|
||||
public void testBasic() throws Exception {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -21,15 +19,13 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
private JetStandardLibrary library;
|
||||
private JetSemanticServices semanticServices;
|
||||
@@ -38,6 +34,10 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
private JetScope scopeWithImports;
|
||||
private TypeResolver typeResolver;
|
||||
|
||||
public JetTypeCheckerTest() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -51,11 +51,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return getHomeDirectory() + "/compiler/testData";
|
||||
}
|
||||
|
||||
private static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(JetParsingTest.class, "/org/jetbrains/jet/parsing/JetParsingTest.class")).getParentFile().getParentFile().getParent();
|
||||
return JetTestCaseBuilder.getTestDataPathBase();
|
||||
}
|
||||
|
||||
public void testConstants() throws Exception {
|
||||
@@ -544,11 +540,6 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
return new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true).resolveType(scope, JetPsiFactory.createType(getProject(), typeStr));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
private class ClassDefinitions {
|
||||
private Map<String, ClassDescriptor> CLASSES = new HashMap<String, ClassDescriptor>();
|
||||
private String[] CLASS_DECLARATIONS = {
|
||||
|
||||
@@ -10,6 +10,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JetFileFactory extends FileTypeFactory {
|
||||
@Override
|
||||
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
|
||||
consumer.consume(JetFileType.INSTANCE, "jet;jetl;jets;kt");
|
||||
consumer.consume(JetFileType.INSTANCE, "jet;jetl;jets;kt;kts;ktm");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.jetbrains.jet.checkers;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.plugin.quickfix.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetPsiCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
private boolean checkInfos = false;
|
||||
private String myDataPath;
|
||||
private String myName;
|
||||
|
||||
public JetPsiCheckerTest(String dataPath, String name) {
|
||||
myDataPath = dataPath;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
doTest(getTestFilePath(), true, checkInfos);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getTestFilePath() {
|
||||
return myDataPath + File.separator + myName + ".jet";
|
||||
}
|
||||
|
||||
public final JetPsiCheckerTest setCheckInfos(boolean checkInfos) {
|
||||
this.checkInfos = checkInfos;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test" + myName;
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(PluginTestCaseBase.getTestDataPathBase(), "/checker/", false, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name);
|
||||
}
|
||||
}));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(PluginTestCaseBase.getTestDataPathBase(), "/checker/regression/", false, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name);
|
||||
}
|
||||
}));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(PluginTestCaseBase.getTestDataPathBase(), "/checker/infos/", false, new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
return new JetPsiCheckerTest(dataPath, name).setCheckInfos(true);
|
||||
}
|
||||
}));
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.intellij.openapi.projectRoots.Sdk;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -49,7 +49,7 @@ public class JetQuickFixTest extends LightQuickFixTestCase {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
JetTestCaseBase.NamedTestFactory namedTestFactory = new JetTestCaseBase.NamedTestFactory() {
|
||||
JetTestCaseBuilder.NamedTestFactory namedTestFactory = new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
||||
@@ -60,14 +60,14 @@ public class JetQuickFixTest extends LightQuickFixTestCase {
|
||||
List<String> subDirs = Arrays.asList(quickFixTestsFilter != null ? dir.list(quickFixTestsFilter) : dir.list());
|
||||
Collections.sort(subDirs);
|
||||
for (String subDirName : subDirs) {
|
||||
suite.addTest(JetTestCaseBase.suiteForDirectory(getTestDataPathBase(), subDirName, false, fileNameFilter, namedTestFactory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(getTestDataPathBase(), subDirName, false, fileNameFilter, namedTestFactory));
|
||||
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static String getTestDataPathBase() {
|
||||
return JetTestCaseBase.getHomeDirectory() + "/idea/testData/quickfix/";
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/idea/testData/quickfix/";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -91,6 +91,6 @@ public class JetQuickFixTest extends LightQuickFixTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PluginTestCaseBase {
|
||||
public static String getTestDataPathBase() {
|
||||
return JetTestCaseBase.getHomeDirectory() + "/idea/testData";
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/idea/testData";
|
||||
}
|
||||
|
||||
public static Sdk jdkFromIdeaHome() {
|
||||
return new JavaSdkImpl().createJdk("JDK", "compiler/testData/mockJDK-1.7/jre", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace kotlin.modules
|
||||
|
||||
import java.util.*
|
||||
import jet.modules.*
|
||||
|
||||
class ModuleSetBuilder() {
|
||||
val modules: ArrayList<ModuleBuilder> = ArrayList<ModuleBuilder>()
|
||||
|
||||
fun module(name: String, callback: fun ModuleBuilder.()) {
|
||||
val builder = ModuleBuilder(name)
|
||||
builder.callback()
|
||||
}
|
||||
}
|
||||
|
||||
class SourcesBuilder(val parent: ModuleBuilder) {
|
||||
fun files(pattern: String) {
|
||||
parent.addSourceFiles(pattern)
|
||||
}
|
||||
}
|
||||
|
||||
class ClasspathBuilder(val parent: ModuleBuilder) {
|
||||
fun entry(name: String) {
|
||||
parent.addClasspathEntry(name)
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleBuilder(val name: String): IModuleBuilder {
|
||||
val sourceFiles: ArrayList<String?> = ArrayList<String?>()
|
||||
val classpathRoots: ArrayList<String?> = ArrayList<String?>()
|
||||
|
||||
val source: SourcesBuilder
|
||||
get() = SourcesBuilder(this)
|
||||
|
||||
val classpath: ClasspathBuilder
|
||||
get() = ClasspathBuilder(this)
|
||||
|
||||
fun addSourceFiles(pattern: String) {
|
||||
sourceFiles.add(pattern)
|
||||
}
|
||||
|
||||
fun addClasspathEntry(name: String) {
|
||||
classpathRoots.add(name)
|
||||
}
|
||||
|
||||
override fun getSourceFiles(): List<String?>? = sourceFiles
|
||||
override fun getClasspathRoots(): List<String?>? = classpathRoots
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package jet.modules;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public interface IModuleBuilder {
|
||||
List<String> getSourceFiles();
|
||||
List<String> getClasspathRoots();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package jet.runtime;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class Intrinsics {
|
||||
private Intrinsics() {
|
||||
}
|
||||
|
||||
public static String stringPlus(String self, Object other) {
|
||||
return ((self == null) ? "null" : self) + ((other == null) ? "null" : other.toString());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user