Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public class ClassFileFactory {
|
|||||||
|
|
||||||
NamespaceCodegen forNamespace(JetNamespace namespace) {
|
NamespaceCodegen forNamespace(JetNamespace namespace) {
|
||||||
assert !isDone : "Already done!";
|
assert !isDone : "Already done!";
|
||||||
String fqName = CodegenUtil.getFQName(namespace);
|
String fqName = JetPsiUtil.getFQName(namespace);
|
||||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||||
if (codegen == null) {
|
if (codegen == null) {
|
||||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class");
|
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class");
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
|
||||||
import gnu.trove.THashSet;
|
import gnu.trove.THashSet;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -108,40 +105,6 @@ public class CodegenUtil {
|
|||||||
return hasTypeInfoField(outerClassDescriptor.getDefaultType());
|
return hasTypeInfoField(outerClassDescriptor.getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFQName(JetNamespace jetNamespace) {
|
|
||||||
JetNamespace parent = PsiTreeUtil.getParentOfType(jetNamespace, JetNamespace.class);
|
|
||||||
if (parent != null) {
|
|
||||||
String parentFQName = getFQName(parent);
|
|
||||||
if (parentFQName.length() > 0) {
|
|
||||||
return parentFQName + "." + getFQName(jetNamespace.getHeader());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFQName(jetNamespace.getHeader()); // TODO: Must include module root namespace
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getFQName(JetNamespaceHeader header) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (Iterator<JetSimpleNameExpression> iterator = header.getParentNamespaceNames().iterator(); iterator.hasNext(); ) {
|
|
||||||
JetSimpleNameExpression nameExpression = iterator.next();
|
|
||||||
builder.append(nameExpression.getReferencedName());
|
|
||||||
builder.append(".");
|
|
||||||
}
|
|
||||||
// PsiElement nameIdentifier = header.getNameIdentifier();
|
|
||||||
builder.append(header.getName());
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFQName(JetClass jetClass) {
|
|
||||||
JetNamedDeclaration parent = PsiTreeUtil.getParentOfType(jetClass, JetNamespace.class, JetClass.class);
|
|
||||||
if (parent instanceof JetNamespace) {
|
|
||||||
return getFQName(((JetNamespace) parent)) + "." + jetClass.getName();
|
|
||||||
}
|
|
||||||
if (parent instanceof JetClass) {
|
|
||||||
return getFQName(((JetClass) parent)) + "." + jetClass.getName();
|
|
||||||
}
|
|
||||||
return jetClass.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) {
|
public static FunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) {
|
||||||
int arity = fd.getValueParameters().size();
|
int arity = fd.getValueParameters().size();
|
||||||
FunctionDescriptorImpl invokeDescriptor = new FunctionDescriptorImpl(
|
FunctionDescriptorImpl invokeDescriptor = new FunctionDescriptorImpl(
|
||||||
|
|||||||
@@ -801,7 +801,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
JetType defaultType = descriptor.getDefaultType();
|
JetType defaultType = descriptor.getDefaultType();
|
||||||
if(CodegenUtil.hasTypeInfoField(defaultType)) {
|
if(CodegenUtil.hasTypeInfoField(defaultType)) {
|
||||||
if(!CodegenUtil.hasDerivedTypeInfoField(defaultType, true)) {
|
if(!CodegenUtil.hasDerivedTypeInfoField(defaultType, true)) {
|
||||||
v.newField(myClass, Opcodes.ACC_PRIVATE, "$typeInfo", "Ljet/typeinfo/TypeInfo;", null, null);
|
v.newField(myClass, Opcodes.ACC_PROTECTED, "$typeInfo", "Ljet/typeinfo/TypeInfo;", null, null);
|
||||||
|
|
||||||
MethodVisitor mv = v.newMethod(myClass, Opcodes.ACC_PUBLIC, "getTypeInfo", "()Ljet/typeinfo/TypeInfo;", null, null);
|
MethodVisitor mv = v.newMethod(myClass, Opcodes.ACC_PUBLIC, "getTypeInfo", "()Ljet/typeinfo/TypeInfo;", null, null);
|
||||||
InstructionAdapter iv = null;
|
InstructionAdapter iv = null;
|
||||||
|
|||||||
@@ -629,7 +629,7 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
String baseName;
|
String baseName;
|
||||||
if (container instanceof JetNamespace) {
|
if (container instanceof JetNamespace) {
|
||||||
baseName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(((JetNamespace) container)));
|
baseName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(((JetNamespace) container)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClassDescriptor aClass = bindingContext.get(BindingContext.CLASS, container);
|
ClassDescriptor aClass = bindingContext.get(BindingContext.CLASS, container);
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ public class SignatureUtil {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append("T");
|
sb.append("T");
|
||||||
sb.append(descriptor.getContainingDeclaration().getName());
|
JetType defaultType = ((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType();
|
||||||
sb.append(";");
|
Type type = typeMapper.mapType(defaultType, OwnerKind.IMPLEMENTATION);
|
||||||
|
sb.append(type.getDescriptor());
|
||||||
sb.append(descriptor.getName());
|
sb.append(descriptor.getName());
|
||||||
sb.append(";");
|
sb.append(";");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ import com.intellij.openapi.application.PathManager;
|
|||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import jet.modules.IModuleBuilder;
|
import jet.modules.IModuleBuilder;
|
||||||
@@ -15,16 +12,15 @@ import jet.modules.IModuleSetBuilder;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetCoreEnvironment;
|
import org.jetbrains.jet.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
@@ -332,7 +328,7 @@ public class CompileEnvironment {
|
|||||||
String mainClass = null;
|
String mainClass = null;
|
||||||
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
||||||
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
||||||
mainClass = CodegenUtil.getFQName(namespace) + ".namespace";
|
mainClass = JetPsiUtil.getFQName(namespace) + ".namespace";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -76,6 +76,14 @@ public class JavaDescriptorResolver {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptor resolveClass(@NotNull PsiClass psiClass) {
|
public ClassDescriptor resolveClass(@NotNull PsiClass psiClass) {
|
||||||
String qualifiedName = psiClass.getQualifiedName();
|
String qualifiedName = psiClass.getQualifiedName();
|
||||||
|
|
||||||
|
// First, let's check that this is a real Java class, not a Java's view on a Kotlin class:
|
||||||
|
ClassDescriptor kotlinClassDescriptor = semanticServices.getKotlinClassDescriptor(qualifiedName);
|
||||||
|
if (kotlinClassDescriptor != null) {
|
||||||
|
return kotlinClassDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not let's take a descriptor of a Java class
|
||||||
ClassDescriptor classDescriptor = classDescriptorCache.get(qualifiedName);
|
ClassDescriptor classDescriptor = classDescriptorCache.get(qualifiedName);
|
||||||
if (classDescriptor == null) {
|
if (classDescriptor == null) {
|
||||||
classDescriptor = createJavaClassDescriptor(psiClass);
|
classDescriptor = createJavaClassDescriptor(psiClass);
|
||||||
@@ -86,6 +94,13 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ClassDescriptor resolveClass(@NotNull String qualifiedName) {
|
public ClassDescriptor resolveClass(@NotNull String qualifiedName) {
|
||||||
|
// First, let's check that this is a real Java class, not a Java's view on a Kotlin class:
|
||||||
|
ClassDescriptor kotlinClassDescriptor = semanticServices.getKotlinClassDescriptor(qualifiedName);
|
||||||
|
if (kotlinClassDescriptor != null) {
|
||||||
|
return kotlinClassDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not let's take a descriptor of a Java class
|
||||||
ClassDescriptor classDescriptor = classDescriptorCache.get(qualifiedName);
|
ClassDescriptor classDescriptor = classDescriptorCache.get(qualifiedName);
|
||||||
if (classDescriptor == null) {
|
if (classDescriptor == null) {
|
||||||
PsiClass psiClass = findClass(qualifiedName);
|
PsiClass psiClass = findClass(qualifiedName);
|
||||||
|
|||||||
+16
-4
@@ -5,10 +5,7 @@ import com.intellij.psi.PsiClass;
|
|||||||
import com.intellij.psi.PsiModifier;
|
import com.intellij.psi.PsiModifier;
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -44,6 +41,13 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
public Set<FunctionDescriptor> getFunctions(@NotNull String name) {
|
||||||
|
// If this package is actually a Kotlin namespace, then we access it through a namespace descriptor, and
|
||||||
|
// Kotlin functions are already there
|
||||||
|
NamespaceDescriptor kotlinNamespaceDescriptor = semanticServices.getKotlinNamespaceDescriptor(packageFQN);
|
||||||
|
if (kotlinNamespaceDescriptor != null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: what is GlobalSearchScope
|
// TODO: what is GlobalSearchScope
|
||||||
PsiClass psiClass = semanticServices.getDescriptorResolver().javaFacade.findClass(getQualifiedName("namespace"));
|
PsiClass psiClass = semanticServices.getDescriptorResolver().javaFacade.findClass(getQualifiedName("namespace"));
|
||||||
if (psiClass == null) {
|
if (psiClass == null) {
|
||||||
@@ -54,7 +58,9 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(psiClass.getQualifiedName());
|
||||||
return semanticServices.getDescriptorResolver().resolveFunctionGroup(containingDescriptor, psiClass, null, name, true);
|
return semanticServices.getDescriptorResolver().resolveFunctionGroup(containingDescriptor, psiClass, null, name, true);
|
||||||
|
// return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -79,6 +85,12 @@ public class JavaPackageScope extends JetScopeImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (PsiClass psiClass : javaPackage.getClasses()) {
|
for (PsiClass psiClass : javaPackage.getClasses()) {
|
||||||
|
// If this is a Kotlin class, we have already taken it through a containing namespace descriptor
|
||||||
|
ClassDescriptor kotlinClassDescriptor = semanticServices.getKotlinClassDescriptor(psiClass.getQualifiedName());
|
||||||
|
if (kotlinClassDescriptor != null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
|
if (psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
|
||||||
allDescriptors.add(descriptorResolver.resolveClass(psiClass));
|
allDescriptors.add(descriptorResolver.resolveClass(psiClass));
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -2,7 +2,11 @@ package org.jetbrains.jet.lang.resolve.java;
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,4 +43,14 @@ public class JavaSemanticServices {
|
|||||||
public JetSemanticServices getJetSemanticServices() {
|
public JetSemanticServices getJetSemanticServices() {
|
||||||
return jetSemanticServices;
|
return jetSemanticServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ClassDescriptor getKotlinClassDescriptor(String qualifiedName) {
|
||||||
|
return getTrace().get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, qualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public NamespaceDescriptor getKotlinNamespaceDescriptor(String qualifiedName) {
|
||||||
|
return getTrace().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, qualifiedName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,4 +104,38 @@ public class JetPsiUtil {
|
|||||||
return unquoteIdentifier(quoted);
|
return unquoteIdentifier(quoted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFQName(JetNamespace jetNamespace) {
|
||||||
|
JetNamespace parent = PsiTreeUtil.getParentOfType(jetNamespace, JetNamespace.class);
|
||||||
|
if (parent != null) {
|
||||||
|
String parentFQName = getFQName(parent);
|
||||||
|
if (parentFQName.length() > 0) {
|
||||||
|
return parentFQName + "." + getFQName(jetNamespace.getHeader());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getFQName(jetNamespace.getHeader()); // TODO: Must include module root namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFQName(JetNamespaceHeader header) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (Iterator<JetSimpleNameExpression> iterator = header.getParentNamespaceNames().iterator(); iterator.hasNext(); ) {
|
||||||
|
JetSimpleNameExpression nameExpression = iterator.next();
|
||||||
|
builder.append(nameExpression.getReferencedName());
|
||||||
|
builder.append(".");
|
||||||
|
}
|
||||||
|
// PsiElement nameIdentifier = header.getNameIdentifier();
|
||||||
|
builder.append(header.getName());
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFQName(JetClass jetClass) {
|
||||||
|
JetNamedDeclaration parent = PsiTreeUtil.getParentOfType(jetClass, JetNamespace.class, JetClass.class);
|
||||||
|
if (parent instanceof JetNamespace) {
|
||||||
|
return getFQName(((JetNamespace) parent)) + "." + jetClass.getName();
|
||||||
|
}
|
||||||
|
if (parent instanceof JetClass) {
|
||||||
|
return getFQName(((JetClass) parent)) + "." + jetClass.getName();
|
||||||
|
}
|
||||||
|
return jetClass.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import org.jetbrains.jet.util.slicedmap.*;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.util.slicedmap.RewritePolicy.DO_NOTHING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
@@ -26,12 +28,12 @@ public interface BindingContext {
|
|||||||
|
|
||||||
WritableSlice<JetExpression, CompileTimeConstant<?>> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
|
WritableSlice<JetExpression, CompileTimeConstant<?>> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
|
||||||
WritableSlice<JetTypeReference, JetType> TYPE = Slices.createSimpleSlice();
|
WritableSlice<JetTypeReference, JetType> TYPE = Slices.createSimpleSlice();
|
||||||
WritableSlice<JetExpression, JetType> EXPRESSION_TYPE = new BasicWritableSlice<JetExpression, JetType>(RewritePolicy.DO_NOTHING);
|
WritableSlice<JetExpression, JetType> EXPRESSION_TYPE = new BasicWritableSlice<JetExpression, JetType>(DO_NOTHING);
|
||||||
|
|
||||||
WritableSlice<JetReferenceExpression, DeclarationDescriptor> REFERENCE_TARGET = new BasicWritableSlice<JetReferenceExpression, DeclarationDescriptor>(RewritePolicy.DO_NOTHING);
|
WritableSlice<JetReferenceExpression, DeclarationDescriptor> REFERENCE_TARGET = new BasicWritableSlice<JetReferenceExpression, DeclarationDescriptor>(DO_NOTHING);
|
||||||
WritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>> RESOLVED_CALL = new BasicWritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>>(RewritePolicy.DO_NOTHING);
|
WritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>> RESOLVED_CALL = new BasicWritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>>(DO_NOTHING);
|
||||||
|
|
||||||
WritableSlice<JetReferenceExpression, Collection<? extends ResolvedCallImpl<? extends DeclarationDescriptor>>> AMBIGUOUS_REFERENCE_TARGET = new BasicWritableSlice<JetReferenceExpression, Collection<? extends ResolvedCallImpl<? extends DeclarationDescriptor>>>(RewritePolicy.DO_NOTHING);
|
WritableSlice<JetReferenceExpression, Collection<? extends ResolvedCallImpl<? extends DeclarationDescriptor>>> AMBIGUOUS_REFERENCE_TARGET = new BasicWritableSlice<JetReferenceExpression, Collection<? extends ResolvedCallImpl<? extends DeclarationDescriptor>>>(DO_NOTHING);
|
||||||
|
|
||||||
WritableSlice<JetExpression, FunctionDescriptor> LOOP_RANGE_ITERATOR = Slices.createSimpleSlice();
|
WritableSlice<JetExpression, FunctionDescriptor> LOOP_RANGE_ITERATOR = Slices.createSimpleSlice();
|
||||||
WritableSlice<JetExpression, CallableDescriptor> LOOP_RANGE_HAS_NEXT = Slices.createSimpleSlice();
|
WritableSlice<JetExpression, CallableDescriptor> LOOP_RANGE_HAS_NEXT = Slices.createSimpleSlice();
|
||||||
@@ -61,7 +63,7 @@ public interface BindingContext {
|
|||||||
|
|
||||||
WritableSlice<Box<DeferredType>, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
|
WritableSlice<Box<DeferredType>, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
|
||||||
|
|
||||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(RewritePolicy.DO_NOTHING) {
|
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||||
@Override
|
@Override
|
||||||
public Boolean computeValue(SlicedMap map, PropertyDescriptor propertyDescriptor, Boolean backingFieldRequired, boolean valueNotFound) {
|
public Boolean computeValue(SlicedMap map, PropertyDescriptor propertyDescriptor, Boolean backingFieldRequired, boolean valueNotFound) {
|
||||||
backingFieldRequired = valueNotFound ? false : backingFieldRequired;
|
backingFieldRequired = valueNotFound ? false : backingFieldRequired;
|
||||||
@@ -92,7 +94,7 @@ public interface BindingContext {
|
|||||||
};
|
};
|
||||||
WritableSlice<PropertyDescriptor, Boolean> IS_INITIALIZED = Slices.createSimpleSetSlice();
|
WritableSlice<PropertyDescriptor, Boolean> IS_INITIALIZED = Slices.createSimpleSetSlice();
|
||||||
|
|
||||||
WritableSlice<JetFunctionLiteralExpression, Boolean> BLOCK = new Slices.SetSlice<JetFunctionLiteralExpression>(RewritePolicy.DO_NOTHING) {
|
WritableSlice<JetFunctionLiteralExpression, Boolean> BLOCK = new Slices.SetSlice<JetFunctionLiteralExpression>(DO_NOTHING) {
|
||||||
@Override
|
@Override
|
||||||
public Boolean computeValue(SlicedMap map, JetFunctionLiteralExpression expression, Boolean isBlock, boolean valueNotFound) {
|
public Boolean computeValue(SlicedMap map, JetFunctionLiteralExpression expression, Boolean isBlock, boolean valueNotFound) {
|
||||||
isBlock = valueNotFound ? false : isBlock;
|
isBlock = valueNotFound ? false : isBlock;
|
||||||
@@ -136,6 +138,9 @@ public interface BindingContext {
|
|||||||
WritableSlice<JetReferenceExpression, PsiElement> LABEL_TARGET = Slices.<JetReferenceExpression, PsiElement>sliceBuilder().build();
|
WritableSlice<JetReferenceExpression, PsiElement> LABEL_TARGET = Slices.<JetReferenceExpression, PsiElement>sliceBuilder().build();
|
||||||
WritableSlice<JetParameter, PropertyDescriptor> VALUE_PARAMETER_AS_PROPERTY = Slices.<JetParameter, PropertyDescriptor>sliceBuilder().build();
|
WritableSlice<JetParameter, PropertyDescriptor> VALUE_PARAMETER_AS_PROPERTY = Slices.<JetParameter, PropertyDescriptor>sliceBuilder().build();
|
||||||
|
|
||||||
|
WritableSlice<String, ClassDescriptor> FQNAME_TO_CLASS_DESCRIPTOR = new BasicWritableSlice<String, ClassDescriptor>(DO_NOTHING);
|
||||||
|
WritableSlice<String, NamespaceDescriptor> FQNAME_TO_NAMESPACE_DESCRIPTOR = new BasicWritableSlice<String, NamespaceDescriptor>(DO_NOTHING);
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
@Deprecated // This field is needed only for the side effects of its initializer
|
@Deprecated // This field is needed only for the side effects of its initializer
|
||||||
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
|
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.jetbrains.jet.lang.types.TypeConstructor;
|
|||||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -91,6 +90,7 @@ public class TypeHierarchyResolver {
|
|||||||
@Override
|
@Override
|
||||||
public void visitClass(JetClass klass) {
|
public void visitClass(JetClass klass) {
|
||||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, getClassKind(klass));
|
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, getClassKind(klass));
|
||||||
|
context.getTrace().record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(klass), mutableClassDescriptor);
|
||||||
|
|
||||||
if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
||||||
MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(context.getTrace(), mutableClassDescriptor, outerScope, ClassKind.OBJECT);
|
MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(context.getTrace(), mutableClassDescriptor, outerScope, ClassKind.OBJECT);
|
||||||
@@ -217,6 +217,7 @@ public class TypeHierarchyResolver {
|
|||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
|
context.getTrace().record(FQNAME_TO_NAMESPACE_DESCRIPTOR, DescriptorUtils.getFQName(namespaceDescriptor), namespaceDescriptor);
|
||||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
namespaceDescriptor.initialize(scope);
|
namespaceDescriptor.initialize(scope);
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
|
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
|
||||||
candidateCall.setStatus(OTHER_ERROR);
|
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+1
@@ -409,6 +409,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
KnownType knownBoundType = (KnownType) upperBound;
|
KnownType knownBoundType = (KnownType) upperBound;
|
||||||
boolean ok = constraintExpander.isSubtypeOf(jetType, knownBoundType.getType());
|
boolean ok = constraintExpander.isSubtypeOf(jetType, knownBoundType.getType());
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
listener.error("Error while expanding '" + jetType + " :< " + knownBoundType.getType() + "'");
|
||||||
return new Solution().registerError("Mismatch while expanding constraints");
|
return new Solution().registerError("Mismatch while expanding constraints");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
open class A<T> () {
|
||||||
|
fun plus(e: T) = B<T> (e)
|
||||||
|
}
|
||||||
|
|
||||||
|
class B<T> (val e: T) : A<T>() {
|
||||||
|
fun add() = B<T> (e)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = if( A<String>().plus("239").add().e == "239" ) "OK" else "fail"
|
||||||
@@ -1,24 +1,17 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -99,7 +92,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
|||||||
GeneratedClassLoader loader = new GeneratedClassLoader(codegens);
|
GeneratedClassLoader loader = new GeneratedClassLoader(codegens);
|
||||||
|
|
||||||
final JetNamespace namespace = myFile.getRootNamespace();
|
final JetNamespace namespace = myFile.getRootNamespace();
|
||||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(namespace)).replace("/", ".");
|
||||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
Method method = namespaceClass.getMethod("box");
|
Method method = namespaceClass.getMethod("box");
|
||||||
return (String) method.invoke(null);
|
return (String) method.invoke(null);
|
||||||
@@ -120,7 +113,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
|||||||
|
|
||||||
protected Class loadRootNamespaceClass(ClassFileFactory state) {
|
protected Class loadRootNamespaceClass(ClassFileFactory state) {
|
||||||
final JetNamespace namespace = myFile.getRootNamespace();
|
final JetNamespace namespace = myFile.getRootNamespace();
|
||||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(namespace)).replace("/", ".");
|
||||||
Map<String, Class> classMap = loadAllClasses(state);
|
Map<String, Class> classMap = loadAllClasses(state);
|
||||||
return classMap.get(fqName);
|
return classMap.get(fqName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,5 +142,10 @@ public class TypeInfoTest extends CodegenTestCase {
|
|||||||
blackBoxFile("typeInfo/inner.jet");
|
blackBoxFile("typeInfo/inner.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInheritance() throws Exception {
|
||||||
|
blackBoxFile("typeInfo/inheritance.jet");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,9 @@
|
|||||||
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>
|
<java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>
|
||||||
-->
|
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.plugin.java.JetCodeBlockModificationListener"/>
|
||||||
|
|
||||||
<toolWindow id="CodeWindow"
|
<toolWindow id="CodeWindow"
|
||||||
factoryClass="org.jetbrains.jet.plugin.internal.codewindow.BytecodeToolwindow$Factory"
|
factoryClass="org.jetbrains.jet.plugin.internal.codewindow.BytecodeToolwindow$Factory"
|
||||||
anchor="right"/>
|
anchor="right"/>
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import com.sun.jdi.ReferenceType;
|
|||||||
import com.sun.jdi.request.ClassPrepareRequest;
|
import com.sun.jdi.request.ClassPrepareRequest;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.JetTypeMapper;
|
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||||
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
||||||
@@ -113,10 +112,10 @@ public class JetPositionManager implements PositionManager {
|
|||||||
else {
|
else {
|
||||||
JetNamespace namespace = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetNamespace.class);
|
JetNamespace namespace = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetNamespace.class);
|
||||||
if (namespace != null) {
|
if (namespace != null) {
|
||||||
names.add(NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)));
|
names.add(NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(namespace)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
names.add(NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(file.getRootNamespace())));
|
names.add(NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(file.getRootNamespace())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
|||||||
@@ -15,11 +15,7 @@ import com.intellij.psi.impl.file.PsiPackageImpl;
|
|||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -52,7 +48,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
|||||||
final List<JetFile> filesInScope = collectProjectFiles(project, scope);
|
final List<JetFile> filesInScope = collectProjectFiles(project, scope);
|
||||||
for (JetFile file : filesInScope) {
|
for (JetFile file : filesInScope) {
|
||||||
JetNamespace rootNamespace = file.getRootNamespace();
|
JetNamespace rootNamespace = file.getRootNamespace();
|
||||||
final String packageName = CodegenUtil.getFQName(rootNamespace);
|
final String packageName = JetPsiUtil.getFQName(rootNamespace);
|
||||||
if (packageName != null && qualifiedName.startsWith(packageName)) {
|
if (packageName != null && qualifiedName.startsWith(packageName)) {
|
||||||
if (qualifiedName.equals(fqn(packageName, "namespace"))) {
|
if (qualifiedName.equals(fqn(packageName, "namespace"))) {
|
||||||
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
||||||
@@ -77,7 +73,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
|||||||
String packageFQN = psiPackage.getQualifiedName();
|
String packageFQN = psiPackage.getQualifiedName();
|
||||||
for (JetFile psiFile : collectProjectFiles(project, GlobalSearchScope.allScope(project))) {
|
for (JetFile psiFile : collectProjectFiles(project, GlobalSearchScope.allScope(project))) {
|
||||||
final JetNamespace rootNamespace = psiFile.getRootNamespace();
|
final JetNamespace rootNamespace = psiFile.getRootNamespace();
|
||||||
if (packageFQN.equals(CodegenUtil.getFQName(rootNamespace))) {
|
if (packageFQN.equals(JetPsiUtil.getFQName(rootNamespace))) {
|
||||||
answer.add("namespace");
|
answer.add("namespace");
|
||||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||||
if (declaration instanceof JetClassOrObject) {
|
if (declaration instanceof JetClassOrObject) {
|
||||||
@@ -100,7 +96,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
|||||||
final List<JetFile> psiFiles = collectProjectFiles(project, GlobalSearchScope.allScope(project));
|
final List<JetFile> psiFiles = collectProjectFiles(project, GlobalSearchScope.allScope(project));
|
||||||
|
|
||||||
for (JetFile psiFile : psiFiles) {
|
for (JetFile psiFile : psiFiles) {
|
||||||
if (qualifiedName.equals(CodegenUtil.getFQName(psiFile.getRootNamespace()))) {
|
if (qualifiedName.equals(JetPsiUtil.getFQName(psiFile.getRootNamespace()))) {
|
||||||
return new PsiPackageImpl(psiFile.getManager(), qualifiedName);
|
return new PsiPackageImpl(psiFile.getManager(), qualifiedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +112,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
|||||||
String packageFQN = psiPackage.getQualifiedName();
|
String packageFQN = psiPackage.getQualifiedName();
|
||||||
for (JetFile file : filesInScope) {
|
for (JetFile file : filesInScope) {
|
||||||
final JetNamespace rootNamespace = file.getRootNamespace();
|
final JetNamespace rootNamespace = file.getRootNamespace();
|
||||||
if (packageFQN.equals(CodegenUtil.getFQName(rootNamespace))) {
|
if (packageFQN.equals(JetPsiUtil.getFQName(rootNamespace))) {
|
||||||
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
||||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||||
if (declaration instanceof JetClassOrObject) {
|
if (declaration instanceof JetClassOrObject) {
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
package org.jetbrains.jet.plugin.java;
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
|
import com.intellij.psi.*;
|
||||||
|
import com.intellij.psi.impl.PsiModificationTrackerImpl;
|
||||||
|
import com.intellij.psi.impl.PsiTreeChangeEventImpl;
|
||||||
|
import com.intellij.psi.impl.PsiTreeChangePreprocessor;
|
||||||
|
import com.intellij.psi.util.PsiModificationTracker;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
|
public class JetCodeBlockModificationListener implements PsiTreeChangePreprocessor {
|
||||||
|
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetCodeBlockModificationListener");
|
||||||
|
|
||||||
|
private final PsiModificationTrackerImpl myModificationTracker;
|
||||||
|
|
||||||
|
public JetCodeBlockModificationListener(final PsiModificationTracker modificationTracker) {
|
||||||
|
myModificationTracker = (PsiModificationTrackerImpl) modificationTracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeChanged(final PsiTreeChangeEventImpl event) {
|
||||||
|
switch (event.getCode()) {
|
||||||
|
case BEFORE_CHILDREN_CHANGE:
|
||||||
|
case BEFORE_PROPERTY_CHANGE:
|
||||||
|
case BEFORE_CHILD_MOVEMENT:
|
||||||
|
case BEFORE_CHILD_REPLACEMENT:
|
||||||
|
case BEFORE_CHILD_ADDITION:
|
||||||
|
case BEFORE_CHILD_REMOVAL:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHILD_ADDED:
|
||||||
|
case CHILD_REMOVED:
|
||||||
|
case CHILD_REPLACED:
|
||||||
|
processChange(event.getParent(), event.getOldChild(), event.getChild());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHILDREN_CHANGED:
|
||||||
|
// general childrenChanged() event after each change
|
||||||
|
if (!event.isGenericChildrenChange()) {
|
||||||
|
processChange(event.getParent(), event.getParent(), null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHILD_MOVED:
|
||||||
|
case PROPERTY_CHANGED:
|
||||||
|
myModificationTracker.incCounter();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
LOG.error("Unknown code:" + event.getCode());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processChange(final PsiElement parent, final PsiElement child1, final PsiElement child2) {
|
||||||
|
try {
|
||||||
|
if (!isInsideCodeBlock(parent)) {
|
||||||
|
if (parent != null && parent.getContainingFile() instanceof JetFile) {
|
||||||
|
myModificationTracker.incCounter();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
myModificationTracker.incOutOfCodeBlockModificationCounter();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (containsClassesInside(child1) || child2 != child1 && containsClassesInside(child2)) {
|
||||||
|
myModificationTracker.incCounter();
|
||||||
|
}
|
||||||
|
} catch (PsiInvalidElementAccessException e) {
|
||||||
|
myModificationTracker.incCounter(); // Shall not happen actually, just a pre-release paranoia
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsClassesInside(final PsiElement element) {
|
||||||
|
if (element == null) return false;
|
||||||
|
if (element instanceof PsiClass) return true;
|
||||||
|
|
||||||
|
PsiElement child = element.getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
if (containsClassesInside(child)) return true;
|
||||||
|
child = child.getNextSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isInsideCodeBlock(PsiElement element) {
|
||||||
|
if (element instanceof PsiFileSystemItem) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element == null || element.getParent() == null) return true;
|
||||||
|
|
||||||
|
PsiElement parent = element;
|
||||||
|
while (true) {
|
||||||
|
if (parent instanceof PsiFile || parent instanceof PsiDirectory || parent == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (parent instanceof JetClass) return false; // anonymous or local class
|
||||||
|
if (parent instanceof JetBlockExpression) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,14 +15,18 @@ import com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl;
|
|||||||
import com.intellij.psi.impl.light.AbstractLightClass;
|
import com.intellij.psi.impl.light.AbstractLightClass;
|
||||||
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import com.intellij.psi.util.CachedValue;
|
||||||
|
import com.intellij.psi.util.CachedValueProvider;
|
||||||
|
import com.intellij.psi.util.CachedValuesManager;
|
||||||
|
import com.intellij.psi.util.PsiModificationTracker;
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilder;
|
import org.jetbrains.jet.codegen.ClassBuilder;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker;
|
import org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker;
|
||||||
@@ -33,7 +37,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMarker {
|
public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMarker {
|
||||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetLightClass");
|
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetLightClass");
|
||||||
private final static Key<PsiJavaFileStub> JAVA_API_STUB = Key.create("JAVA_API_STUB");
|
private final static Key<CachedValue<PsiJavaFileStub>> JAVA_API_STUB = Key.create("JAVA_API_STUB");
|
||||||
|
|
||||||
private final JetFile file;
|
private final JetFile file;
|
||||||
private final String className;
|
private final String className;
|
||||||
@@ -75,20 +79,30 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQualifiedName() {
|
||||||
|
String fqName = JetPsiUtil.getFQName(file.getRootNamespace());
|
||||||
|
return fqName.length() == 0 ? className : fqName + "." + className;
|
||||||
|
}
|
||||||
|
|
||||||
private PsiJavaFileStub getStub() {
|
private PsiJavaFileStub getStub() {
|
||||||
PsiJavaFileStub answer = file.getUserData(JAVA_API_STUB);
|
CachedValue<PsiJavaFileStub> answer = file.getUserData(JAVA_API_STUB);
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = calcStub();
|
answer = CachedValuesManager.getManager(getProject()).createCachedValue(new CachedValueProvider<PsiJavaFileStub>() {
|
||||||
|
@Override
|
||||||
|
public Result<PsiJavaFileStub> compute() {
|
||||||
|
return Result.create(calcStub(), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
file.putUserData(JAVA_API_STUB, answer);
|
file.putUserData(JAVA_API_STUB, answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return answer;
|
return answer.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PsiJavaFileStub calcStub() {
|
private PsiJavaFileStub calcStub() {
|
||||||
final PsiJavaFileStubImpl answer = new PsiJavaFileStubImpl(CodegenUtil.getFQName(file.getRootNamespace()), true);
|
final PsiJavaFileStubImpl answer = new PsiJavaFileStubImpl(JetPsiUtil.getFQName(file.getRootNamespace()), true);
|
||||||
final Project project = getProject();
|
final Project project = getProject();
|
||||||
|
|
||||||
final Stack<StubElement> stubStack = new Stack<StubElement>();
|
final Stack<StubElement> stubStack = new Stack<StubElement>();
|
||||||
@@ -134,7 +148,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
|||||||
finally {
|
finally {
|
||||||
final StubElement pop = stubStack.pop();
|
final StubElement pop = stubStack.pop();
|
||||||
if (pop != answer) {
|
if (pop != answer) {
|
||||||
LOG.error("Unbalanced stack operations");
|
LOG.error("Unbalanced stack operations: " + pop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,5 +162,5 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
|||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import com.intellij.openapi.module.Module;
|
|||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,14 +34,14 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
|
|||||||
JetClass containingClass = (JetClass) location.getParentElement(JetClass.class);
|
JetClass containingClass = (JetClass) location.getParentElement(JetClass.class);
|
||||||
if (containingClass != null && JetMainDetector.hasMain(containingClass.getDeclarations())) {
|
if (containingClass != null && JetMainDetector.hasMain(containingClass.getDeclarations())) {
|
||||||
mySourceElement = containingClass;
|
mySourceElement = containingClass;
|
||||||
return createConfigurationByQName(location.getModule(), configurationContext, CodegenUtil.getFQName(containingClass));
|
return createConfigurationByQName(location.getModule(), configurationContext, JetPsiUtil.getFQName(containingClass));
|
||||||
}
|
}
|
||||||
PsiFile psiFile = location.getPsiElement().getContainingFile();
|
PsiFile psiFile = location.getPsiElement().getContainingFile();
|
||||||
if (psiFile instanceof JetFile) {
|
if (psiFile instanceof JetFile) {
|
||||||
JetNamespace namespace = ((JetFile) psiFile).getRootNamespace();
|
JetNamespace namespace = ((JetFile) psiFile).getRootNamespace();
|
||||||
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
||||||
mySourceElement = namespace;
|
mySourceElement = namespace;
|
||||||
String fqName = CodegenUtil.getFQName(namespace);
|
String fqName = JetPsiUtil.getFQName(namespace);
|
||||||
String className = fqName.length() == 0 ? "namespace" : fqName + ".namespace";
|
String className = fqName.length() == 0 ? "namespace" : fqName + ".namespace";
|
||||||
return createConfigurationByQName(location.getModule(), configurationContext, className);
|
return createConfigurationByQName(location.getModule(), configurationContext, className);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -669,7 +669,9 @@ public abstract class TypeInfo<T> implements JetObject {
|
|||||||
|
|
||||||
private TypeInfo parseTypeVar(Signature signature) {
|
private TypeInfo parseTypeVar(Signature signature) {
|
||||||
TypeInfoVariance variance = parseVariance();
|
TypeInfoVariance variance = parseVariance();
|
||||||
String klazz = parseName();
|
assert string[cur] == 'L';
|
||||||
|
cur++;
|
||||||
|
String klazz = parseName().replace('/','.');
|
||||||
String name = parseName();
|
String name = parseName();
|
||||||
boolean nullable = false;
|
boolean nullable = false;
|
||||||
if(string[cur] == '?') {
|
if(string[cur] == '?') {
|
||||||
|
|||||||
Reference in New Issue
Block a user