Extract 'descriptors' module
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="util.runtime" />
|
||||
<orderEntry type="library" name="javax.inject" level="project" />
|
||||
<orderEntry type="module" module-name="serialization" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
public static final List<ImportPath> DEFAULT_JET_IMPORTS = ImmutableList.of(
|
||||
new ImportPath("kotlin.*"),
|
||||
new ImportPath("kotlin.io.*"),
|
||||
new ImportPath("jet.*"));
|
||||
|
||||
public static final ModuleConfiguration INSTANCE = new DefaultModuleConfiguration();
|
||||
|
||||
private DefaultModuleConfiguration() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equalsTo(KotlinBuiltIns.getInstance().getBuiltInsPackageFqName())) {
|
||||
namespaceMemberScope.importScope(KotlinBuiltIns.getInstance().getBuiltInsScope());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
public interface ModuleConfiguration {
|
||||
ModuleConfiguration EMPTY = new ModuleConfiguration() {
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EMPTY";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a
|
||||
* Java package with a Kotlin one
|
||||
*/
|
||||
void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public interface PlatformToKotlinClassMap {
|
||||
PlatformToKotlinClassMap EMPTY = new PlatformToKotlinClassMap() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> mapPlatformClass(@NotNull ClassDescriptor classDescriptor) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassDescriptor> mapPlatformClassesInside(@NotNull DeclarationDescriptor containingDeclaration) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
Collection<ClassDescriptor> mapPlatformClass(@NotNull ClassDescriptor classDescriptor);
|
||||
|
||||
@NotNull
|
||||
Collection<ClassDescriptor> mapPlatformClassesInside(@NotNull DeclarationDescriptor containingDeclaration);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot {
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor getReceiverParameter();
|
||||
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor getExpectedThisObject();
|
||||
|
||||
@NotNull
|
||||
List<TypeParameterDescriptor> getTypeParameters();
|
||||
|
||||
/**
|
||||
* Method may return null for not yet fully initialized object or if error occurred.
|
||||
*/
|
||||
@Nullable
|
||||
JetType getReturnType();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
CallableDescriptor getOriginal();
|
||||
|
||||
@Override
|
||||
CallableDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
@NotNull
|
||||
List<ValueParameterDescriptor> getValueParameters();
|
||||
|
||||
@NotNull
|
||||
Set<? extends CallableDescriptor> getOverriddenDescriptors();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface CallableMemberDescriptor extends CallableDescriptor, MemberDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
CallableMemberDescriptor getOriginal();
|
||||
|
||||
void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden);
|
||||
|
||||
enum Kind {
|
||||
DECLARATION,
|
||||
FAKE_OVERRIDE,
|
||||
DELEGATION,
|
||||
SYNTHESIZED
|
||||
;
|
||||
|
||||
public boolean isReal() {
|
||||
return this == DECLARATION || this == DELEGATION || this == SYNTHESIZED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a real function or function projection.
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
@NotNull
|
||||
CallableMemberDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor, ClassOrNamespaceDescriptor {
|
||||
|
||||
@NotNull
|
||||
JetScope getMemberScope(List<TypeProjection> typeArguments);
|
||||
|
||||
@NotNull
|
||||
JetScope getUnsubstitutedInnerClassesScope();
|
||||
|
||||
@NotNull
|
||||
Collection<ConstructorDescriptor> getConstructors();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
/**
|
||||
* @return type A<T> for the class A<T>
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
JetType getDefaultType();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
JetType getClassObjectType();
|
||||
|
||||
@Nullable
|
||||
ClassDescriptor getClassObjectDescriptor();
|
||||
|
||||
@NotNull
|
||||
ClassKind getKind();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
Modality getModality();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this class contains a reference to its outer class (as opposed to static nested class)
|
||||
*/
|
||||
boolean isInner();
|
||||
|
||||
@NotNull
|
||||
ReceiverParameterDescriptor getThisAsReceiverParameter();
|
||||
|
||||
@Nullable
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public enum ClassKind {
|
||||
CLASS,
|
||||
TRAIT,
|
||||
ENUM_CLASS,
|
||||
ENUM_ENTRY,
|
||||
ANNOTATION_CLASS,
|
||||
OBJECT,
|
||||
CLASS_OBJECT;
|
||||
|
||||
public boolean isObject() {
|
||||
return this == OBJECT || this == CLASS_OBJECT || this == ENUM_ENTRY;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public interface ClassOrNamespaceDescriptor extends DeclarationDescriptorNonRoot {
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
|
||||
public interface ClassifierDescriptor extends DeclarationDescriptorNonRoot {
|
||||
@NotNull
|
||||
TypeConstructor getTypeConstructor();
|
||||
|
||||
@NotNull
|
||||
JetType getDefaultType();
|
||||
|
||||
@Nullable
|
||||
JetType getClassObjectType();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ConstructorDescriptor extends FunctionDescriptor {
|
||||
/**
|
||||
* @throws UnsupportedOperationException -- no type parameters supported for constructors
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
List<TypeParameterDescriptor> getTypeParameters();
|
||||
|
||||
/**
|
||||
* @throws UnsupportedOperationException -- return type is not stored for constructors
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
JetType getReturnType();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ClassDescriptor getContainingDeclaration();
|
||||
|
||||
/**
|
||||
* @return "<init>" -- name is not stored for constructors
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
Name getName();
|
||||
|
||||
boolean isPrimary();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
public interface DeclarationDescriptor extends Annotated, Named {
|
||||
/**
|
||||
* @return The descriptor that corresponds to the original declaration of this element.
|
||||
* A descriptor can be obtained from its original by substituting type arguments (of the declaring class
|
||||
* or of the element itself).
|
||||
* returns <code>this</code> object if the current descriptor is original itself
|
||||
*/
|
||||
@NotNull
|
||||
DeclarationDescriptor getOriginal();
|
||||
|
||||
@Nullable
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@Nullable
|
||||
DeclarationDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
<R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data);
|
||||
void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface DeclarationDescriptorNonRoot extends DeclarationDescriptor {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public interface DeclarationDescriptorVisitor<R, D> {
|
||||
R visitNamespaceDescriptor(NamespaceDescriptor descriptor, D data);
|
||||
|
||||
R visitVariableDescriptor(VariableDescriptor descriptor, D data);
|
||||
|
||||
R visitFunctionDescriptor(FunctionDescriptor descriptor, D data);
|
||||
|
||||
R visitTypeParameterDescriptor(TypeParameterDescriptor descriptor, D data);
|
||||
|
||||
R visitClassDescriptor(ClassDescriptor descriptor, D data);
|
||||
|
||||
R visitModuleDeclaration(ModuleDescriptor descriptor, D data);
|
||||
|
||||
R visitConstructorDescriptor(ConstructorDescriptor constructorDescriptor, D data);
|
||||
|
||||
R visitScriptDescriptor(ScriptDescriptor scriptDescriptor, D data);
|
||||
|
||||
R visitPropertyDescriptor(PropertyDescriptor descriptor, D data);
|
||||
|
||||
R visitValueParameterDescriptor(ValueParameterDescriptor descriptor, D data);
|
||||
|
||||
R visitPropertyGetterDescriptor(PropertyGetterDescriptor descriptor, D data);
|
||||
|
||||
R visitPropertySetterDescriptor(PropertySetterDescriptor descriptor, D data);
|
||||
|
||||
R visitReceiverParameterDescriptor(ReceiverParameterDescriptor descriptor, D data);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface DeclarationDescriptorWithVisibility extends DeclarationDescriptor {
|
||||
@NotNull
|
||||
Visibility getVisibility();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface FunctionDescriptor extends CallableMemberDescriptor {
|
||||
@Override
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
FunctionDescriptor getOriginal();
|
||||
|
||||
@Override
|
||||
FunctionDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
Set<? extends FunctionDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
FunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MemberDescriptor extends DeclarationDescriptorNonRoot, DeclarationDescriptorWithVisibility {
|
||||
@NotNull
|
||||
Modality getModality();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
Visibility getVisibility();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public enum Modality {
|
||||
// THE ORDER OF ENTRIES MATTERS HERE
|
||||
FINAL(false),
|
||||
OPEN(true),
|
||||
ABSTRACT(true);
|
||||
|
||||
private final boolean overridable;
|
||||
|
||||
private Modality(boolean overridable) {
|
||||
this.overridable = overridable;
|
||||
}
|
||||
|
||||
public boolean isOverridable() {
|
||||
return overridable;
|
||||
}
|
||||
|
||||
public static Modality convertFromFlags(boolean _abstract, boolean open) {
|
||||
if (_abstract) return ABSTRACT;
|
||||
if (open) return OPEN;
|
||||
return FINAL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModuleDescriptor extends DeclarationDescriptor, NamespaceDescriptorParent {
|
||||
@Override
|
||||
@Nullable
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@Nullable
|
||||
NamespaceDescriptor getNamespace(@NotNull FqName fqName);
|
||||
|
||||
@NotNull
|
||||
ModuleConfiguration getModuleConfiguration();
|
||||
|
||||
@NotNull
|
||||
List<ImportPath> getDefaultImports();
|
||||
|
||||
@NotNull
|
||||
PlatformToKotlinClassMap getPlatformToKotlinClassMap();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ModuleDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
@Override
|
||||
<R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.DeclarationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleDescriptorImpl extends DeclarationDescriptorImpl implements ModuleDescriptor {
|
||||
private NamespaceDescriptor rootNamepsace;
|
||||
private ModuleConfiguration moduleConfiguration;
|
||||
private final List<ImportPath> defaultImports;
|
||||
private final PlatformToKotlinClassMap platformToKotlinClassMap;
|
||||
|
||||
public ModuleDescriptorImpl(
|
||||
@NotNull Name name,
|
||||
@NotNull List<ImportPath> defaultImports,
|
||||
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
||||
) {
|
||||
super(Collections.<AnnotationDescriptor>emptyList(), name);
|
||||
if (!name.isSpecial()) {
|
||||
throw new IllegalArgumentException("module name must be special: " + name);
|
||||
}
|
||||
this.defaultImports = defaultImports;
|
||||
this.platformToKotlinClassMap = platformToKotlinClassMap;
|
||||
}
|
||||
|
||||
public void setRootNamespace(@NotNull NamespaceDescriptor rootNs) {
|
||||
if (this.rootNamepsace != null) {
|
||||
throw new IllegalStateException("setRootNamespace() is called twice");
|
||||
}
|
||||
this.rootNamepsace = rootNs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull FqName fqName) {
|
||||
if (fqName.isRoot()) return rootNamepsace;
|
||||
NamespaceDescriptor current = rootNamepsace;
|
||||
for (Name simpleName : fqName.pathSegments()) {
|
||||
current = current.getMemberScope().getNamespace(simpleName);
|
||||
if (current == null) return null;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ModuleConfiguration getModuleConfiguration() {
|
||||
return moduleConfiguration;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ModuleDescriptorImpl setModuleConfiguration(@NotNull ModuleConfiguration moduleConfiguration) {
|
||||
assert this.moduleConfiguration == null : "Trying to set module configuration twice for " + this;
|
||||
this.moduleConfiguration = moduleConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ImportPath> getDefaultImports() {
|
||||
return defaultImports;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PlatformToKotlinClassMap getPlatformToKotlinClassMap() {
|
||||
return platformToKotlinClassMap;
|
||||
}
|
||||
|
||||
public NamespaceDescriptorImpl getRootNamespaceDescriptorImpl() {
|
||||
return (NamespaceDescriptorImpl) rootNamepsace;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ModuleDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleDeclaration(this, data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
if (namespaceDescriptor.getContainingDeclaration() != this) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
setRootNamespace(namespaceDescriptor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public interface Named {
|
||||
@NotNull
|
||||
Name getName();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
public interface NamespaceDescriptor extends ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
|
||||
@NotNull
|
||||
JetScope getMemberScope();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
NamespaceDescriptorParent getContainingDeclaration();
|
||||
|
||||
@NotNull
|
||||
FqName getFqName();
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PropertyAccessorDescriptor extends FunctionDescriptor {
|
||||
boolean hasBody();
|
||||
|
||||
boolean isDefault();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
PropertyAccessorDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
PropertyDescriptor getCorrespondingProperty();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
PropertyAccessorDescriptor copy(
|
||||
DeclarationDescriptor newOwner,
|
||||
Modality modality,
|
||||
Visibility visibility,
|
||||
Kind kind,
|
||||
boolean copyOverrides
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface PropertyDescriptor extends VariableDescriptor, CallableMemberDescriptor {
|
||||
@Nullable
|
||||
PropertyGetterDescriptor getGetter();
|
||||
|
||||
@Nullable
|
||||
PropertySetterDescriptor getSetter();
|
||||
|
||||
@NotNull
|
||||
List<PropertyAccessorDescriptor> getAccessors();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
PropertyDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
Set<? extends PropertyDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@Override
|
||||
PropertyDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
PropertyGetterDescriptor getOriginal();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
PropertySetterDescriptor getOriginal();
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
public interface ReceiverParameterDescriptor extends DeclarationDescriptor {
|
||||
|
||||
// This field exists for better readability of the client code
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = null;
|
||||
|
||||
@NotNull
|
||||
JetType getType();
|
||||
|
||||
@NotNull
|
||||
ReceiverValue getValue();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ScriptReceiver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
public static final String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
|
||||
private static final Name NAME = Name.special("<script>");
|
||||
|
||||
private final int priority;
|
||||
|
||||
private JetType returnType;
|
||||
private List<ValueParameterDescriptor> valueParameters;
|
||||
|
||||
private final ScriptCodeDescriptor scriptCodeDescriptor = new ScriptCodeDescriptor(this);
|
||||
private final ReceiverParameterDescriptor implicitReceiver = new ReceiverParameterDescriptorImpl(this,
|
||||
// Putting Any here makes no sense,
|
||||
// it is simply copied from someplace else
|
||||
// during a refactoring
|
||||
KotlinBuiltIns.getInstance().getAnyType(),
|
||||
new ScriptReceiver(this));
|
||||
|
||||
private final ClassDescriptorImpl classDescriptor;
|
||||
|
||||
private final WritableScopeImpl classScope;
|
||||
|
||||
public ScriptDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int priority,
|
||||
@NotNull JetScope scriptScope,
|
||||
@NotNull Name className
|
||||
) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
|
||||
this.priority = priority;
|
||||
|
||||
classDescriptor = new ClassDescriptorImpl(
|
||||
containingDeclaration,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
className);
|
||||
classScope = new WritableScopeImpl(scriptScope, containingDeclaration, RedeclarationHandler.DO_NOTHING, "script members");
|
||||
classScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
classDescriptor.initialize(
|
||||
false,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()),
|
||||
classScope,
|
||||
new HashSet<ConstructorDescriptor>(),
|
||||
null,
|
||||
false);
|
||||
}
|
||||
|
||||
public void initialize(
|
||||
@NotNull JetType returnType,
|
||||
@NotNull List<? extends PropertyDescriptorImpl> properties,
|
||||
@NotNull List<? extends FunctionDescriptor> functions
|
||||
) {
|
||||
this.returnType = returnType;
|
||||
scriptCodeDescriptor.initialize(implicitReceiver, valueParameters, returnType);
|
||||
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
Name.identifier(LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(
|
||||
returnType,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
classDescriptor.getThisAsReceiverParameter(),
|
||||
ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER);
|
||||
propertyDescriptor.initialize(null, null);
|
||||
classScope.addPropertyDescriptor(propertyDescriptor);
|
||||
|
||||
for (PropertyDescriptorImpl property : properties) {
|
||||
initializeWithDefaultGetterSetter(property);
|
||||
classScope.addPropertyDescriptor(property);
|
||||
}
|
||||
|
||||
for (FunctionDescriptor function : functions) {
|
||||
classScope.addFunctionDescriptor(function);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) {
|
||||
PropertyGetterDescriptorImpl getter = propertyDescriptor.getGetter();
|
||||
if (getter == null && propertyDescriptor.getVisibility() != Visibilities.PRIVATE) {
|
||||
getter = DescriptorFactory.createDefaultGetter(propertyDescriptor);
|
||||
getter.initialize(propertyDescriptor.getType());
|
||||
}
|
||||
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if (setter == null && propertyDescriptor.isVar()) {
|
||||
setter = DescriptorFactory.createDefaultSetter(propertyDescriptor);
|
||||
}
|
||||
propertyDescriptor.initialize(getter, setter);
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
return valueParameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ScriptCodeDescriptor getScriptCodeDescriptor() {
|
||||
return scriptCodeDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||
return implicitReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new IllegalStateException("nothing to substitute in script");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitScriptDescriptor(this, data);
|
||||
}
|
||||
|
||||
public void setValueParameters(@NotNull List<ValueParameterDescriptor> valueParameters) {
|
||||
this.valueParameters = valueParameters;
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
new ConstructorDescriptorImpl(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), true)
|
||||
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC);
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||
|
||||
classDescriptor.getConstructors().add(constructorDescriptor);
|
||||
classDescriptor.setPrimaryConstructor(constructorDescriptor);
|
||||
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
parameter.getName(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(
|
||||
parameter.getType(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
classDescriptor.getThisAsReceiverParameter(), ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER);
|
||||
//PropertyGetterDescriptor getter = DescriptorResolver.createDefaultGetter(propertyDescriptor);
|
||||
//getter.initialize(propertyDescriptor.getType());
|
||||
propertyDescriptor.initialize(null, null);
|
||||
classScope.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getClassDescriptor() {
|
||||
return classDescriptor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Simple functions are the ones with 'fun' keyword and function literals
|
||||
*/
|
||||
public interface SimpleFunctionDescriptor extends FunctionDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
SimpleFunctionDescriptor getOriginal();
|
||||
|
||||
boolean isInline();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface TypeParameterDescriptor extends ClassifierDescriptor {
|
||||
boolean isReified();
|
||||
|
||||
@NotNull
|
||||
Variance getVariance();
|
||||
|
||||
@NotNull
|
||||
Set<JetType> getUpperBounds();
|
||||
|
||||
@NotNull
|
||||
JetType getUpperBoundsAsType();
|
||||
|
||||
@NotNull
|
||||
Set<JetType> getLowerBounds();
|
||||
|
||||
@NotNull
|
||||
JetType getLowerBoundsAsType();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
TypeConstructor getTypeConstructor();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@Deprecated // Use the static method TypeParameterDescriptor.substitute()
|
||||
TypeParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
int getIndex();
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ValueParameterDescriptor extends VariableDescriptor {
|
||||
/**
|
||||
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
|
||||
*
|
||||
* @return the parameter index
|
||||
*/
|
||||
int getIndex();
|
||||
|
||||
/**
|
||||
* The front-end relies on this property when resolving function calls
|
||||
*
|
||||
* @return {@code true} iff the parameter has a default value, i.e. declares it or inherits
|
||||
* by overriding a parameter in an overridden function.
|
||||
*/
|
||||
boolean hasDefaultValue();
|
||||
|
||||
/**
|
||||
* The back-end should relies on this property when generating function signatures
|
||||
*
|
||||
* @return {@code true} iff the parameter declares a default value, i.e. explicitly specifies it in the function header
|
||||
*/
|
||||
boolean declaresDefaultValue();
|
||||
|
||||
@Nullable JetType getVarargElementType();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
JetType getType();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ValueParameterDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
ValueParameterDescriptor copy(DeclarationDescriptor newOwner, Name newName);
|
||||
|
||||
/**
|
||||
* Parameter p1 overrides p2 iff
|
||||
* a) their respective owners (function declarations) f1 override f2
|
||||
* b) p1 and p2 have the same indices in the owners' parameter lists
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
Set<? extends ValueParameterDescriptor> getOverriddenDescriptors();
|
||||
|
||||
void addOverriddenDescriptor(@NotNull ValueParameterDescriptor overridden);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
public interface VariableDescriptor extends CallableDescriptor {
|
||||
@NotNull
|
||||
JetType getType();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@Override
|
||||
VariableDescriptor substitute(@NotNull TypeSubstitutor substitutor);
|
||||
|
||||
boolean isVar();
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface VariableDescriptorForObject extends VariableDescriptor {
|
||||
@NotNull
|
||||
ClassDescriptor getObjectClass();
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Visibilities {
|
||||
public static final Visibility PRIVATE = new Visibility("private", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
DeclarationDescriptor parent = what;
|
||||
while (parent != null) {
|
||||
parent = parent.getContainingDeclaration();
|
||||
if ((parent instanceof ClassDescriptor && !DescriptorUtils.isClassObject(parent)) ||
|
||||
parent instanceof NamespaceDescriptor) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DeclarationDescriptor fromParent = from;
|
||||
while (fromParent != null) {
|
||||
if (parent == fromParent) {
|
||||
return true;
|
||||
}
|
||||
fromParent = fromParent.getContainingDeclaration();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility PROTECTED = new Visibility("protected", true) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||
if (classDescriptor == null) return false;
|
||||
|
||||
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
|
||||
if (fromClass == null) return false;
|
||||
if (DescriptorUtils.isSubclass(fromClass, classDescriptor)) {
|
||||
return true;
|
||||
}
|
||||
return isVisible(what, fromClass.getContainingDeclaration());
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility INTERNAL = new Visibility("internal", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return DescriptorUtils.isInSameModule(what, from);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility PUBLIC = new Visibility("public", true) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility LOCAL = new Visibility("local", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException(); //This method shouldn't be invoked for LOCAL visibility
|
||||
}
|
||||
};
|
||||
|
||||
public static final Visibility INHERITED = new Visibility("inherited", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
throw new IllegalStateException("Visibility is unknown yet"); //This method shouldn't be invoked for INHERITED visibility
|
||||
}
|
||||
};
|
||||
|
||||
/* Visibility for fake override invisible members (they are created for better error reporting) */
|
||||
public static final Visibility INVISIBLE_FAKE = new Visibility("invisible_fake", false) {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Set<Visibility> INVISIBLE_FROM_OTHER_MODULES = Sets.newHashSet(PRIVATE, INTERNAL, LOCAL);
|
||||
|
||||
private Visibilities() {
|
||||
}
|
||||
|
||||
public static boolean isVisible(@Nullable DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return findInvisibleMember(what, from) == null;
|
||||
}
|
||||
|
||||
public static DeclarationDescriptorWithVisibility findInvisibleMember(
|
||||
@Nullable DeclarationDescriptorWithVisibility what,
|
||||
@NotNull DeclarationDescriptor from
|
||||
) {
|
||||
DeclarationDescriptorWithVisibility parent = what;
|
||||
while (parent != null && parent.getVisibility() != LOCAL) {
|
||||
if (!parent.getVisibility().isVisible(parent, from)) {
|
||||
return parent;
|
||||
}
|
||||
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Map<Visibility, Integer> ORDERED_VISIBILITIES = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
ORDERED_VISIBILITIES.put(PRIVATE, 0);
|
||||
ORDERED_VISIBILITIES.put(INTERNAL, 1);
|
||||
ORDERED_VISIBILITIES.put(PROTECTED, 1);
|
||||
ORDERED_VISIBILITIES.put(PUBLIC, 2);
|
||||
}
|
||||
|
||||
/*package*/
|
||||
@Nullable
|
||||
static Integer compareLocal(@NotNull Visibility first, @NotNull Visibility second) {
|
||||
if (first == second) return 0;
|
||||
Integer firstIndex = ORDERED_VISIBILITIES.get(first);
|
||||
Integer secondIndex = ORDERED_VISIBILITIES.get(second);
|
||||
if (firstIndex == null || secondIndex == null || firstIndex.equals(secondIndex)) {
|
||||
return null;
|
||||
}
|
||||
return firstIndex - secondIndex;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer compare(@NotNull Visibility first, @NotNull Visibility second) {
|
||||
Integer result = first.compareTo(second);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
Integer oppositeResult = second.compareTo(first);
|
||||
if (oppositeResult != null) {
|
||||
return -oppositeResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Visibility {
|
||||
private final boolean isPublicAPI;
|
||||
private final String name;
|
||||
|
||||
protected Visibility(@NotNull String name, boolean isPublicAPI) {
|
||||
this.isPublicAPI = isPublicAPI;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isPublicAPI() {
|
||||
return isPublicAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if the answer is unknown
|
||||
*/
|
||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||
return Visibilities.compareLocal(this, visibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Visibility normalize() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Annotated {
|
||||
List<AnnotationDescriptor> getAnnotations();
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AnnotatedImpl implements Annotated {
|
||||
private final List<AnnotationDescriptor> annotations;
|
||||
|
||||
public AnnotatedImpl(List<AnnotationDescriptor> annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||
|
||||
public interface AnnotationArgumentVisitor<R, D> {
|
||||
R visitLongValue(@NotNull LongValue value, D data);
|
||||
|
||||
R visitIntValue(IntValue value, D data);
|
||||
|
||||
R visitErrorValue(ErrorValue value, D data);
|
||||
|
||||
R visitShortValue(ShortValue value, D data);
|
||||
|
||||
R visitByteValue(ByteValue value, D data);
|
||||
|
||||
R visitDoubleValue(DoubleValue value, D data);
|
||||
|
||||
R visitFloatValue(FloatValue value, D data);
|
||||
|
||||
R visitBooleanValue(BooleanValue value, D data);
|
||||
|
||||
R visitCharValue(CharValue value, D data);
|
||||
|
||||
R visitStringValue(StringValue value, D data);
|
||||
|
||||
R visitNullValue(NullValue value, D data);
|
||||
|
||||
R visitEnumValue(EnumValue value, D data);
|
||||
|
||||
R visitArrayValue(ArrayValue value, D data);
|
||||
|
||||
R visitAnnotationValue(AnnotationValue value, D data);
|
||||
|
||||
R visitJavaClassValue(JavaClassValue value, D data);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnnotationDescriptor {
|
||||
private JetType annotationType;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) {
|
||||
return valueArguments.get(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||
return Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||
valueArguments.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotationType.toString() + DescriptorUtils.getSortedValueArguments(this, null);
|
||||
}
|
||||
}
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractLazyTypeParameterDescriptor implements TypeParameterDescriptor {
|
||||
|
||||
private final Variance variance;
|
||||
private final boolean reified;
|
||||
private final int index;
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final Name name;
|
||||
|
||||
private final NotNullLazyValue<TypeConstructor> typeConstructor;
|
||||
private final NotNullLazyValue<JetType> defaultType;
|
||||
private final NotNullLazyValue<Set<JetType>> upperBounds;
|
||||
private final NotNullLazyValue<JetType> upperBoundsAsType;
|
||||
|
||||
public AbstractLazyTypeParameterDescriptor(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull Variance variance,
|
||||
boolean isReified,
|
||||
int index
|
||||
) {
|
||||
this.variance = variance;
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.reified = isReified;
|
||||
|
||||
this.typeConstructor = storageManager.createLazyValue(new Computable<TypeConstructor>() {
|
||||
@Override
|
||||
public TypeConstructor compute() {
|
||||
return createTypeConstructor();
|
||||
}
|
||||
});
|
||||
this.defaultType = storageManager.createLazyValue(new Computable<JetType>() {
|
||||
@Override
|
||||
public JetType compute() {
|
||||
return createDefaultType();
|
||||
}
|
||||
});
|
||||
this.upperBounds = storageManager.createLazyValue(new Computable<Set<JetType>>() {
|
||||
@Override
|
||||
public Set<JetType> compute() {
|
||||
return resolveUpperBounds();
|
||||
}
|
||||
});
|
||||
this.upperBoundsAsType = storageManager.createLazyValue(new Computable<JetType>() {
|
||||
@Override
|
||||
public JetType compute() {
|
||||
return computeUpperBoundsAsType();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReified() {
|
||||
return reified;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Variance getVariance() {
|
||||
return variance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getUpperBounds() {
|
||||
return upperBounds.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Set<JetType> resolveUpperBounds();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getUpperBoundsAsType() {
|
||||
return upperBoundsAsType.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType computeUpperBoundsAsType() {
|
||||
Set<JetType> upperBounds = getUpperBounds();
|
||||
assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName();
|
||||
JetType upperBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
|
||||
if (upperBoundsAsType == null) {
|
||||
upperBoundsAsType = KotlinBuiltIns.getInstance().getNothingType();
|
||||
}
|
||||
return upperBoundsAsType;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getLowerBounds() {
|
||||
return Collections.singleton(getLowerBoundsAsType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getLowerBoundsAsType() {
|
||||
return KotlinBuiltIns.getInstance().getNothingType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TypeConstructor createTypeConstructor() {
|
||||
return new TypeConstructor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return AbstractLazyTypeParameterDescriptor.this.getUpperBounds();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSealed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return AbstractLazyTypeParameterDescriptor.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return AbstractLazyTypeParameterDescriptor.this.getAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName().toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
return defaultType.compute();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType createDefaultType() {
|
||||
return new JetTypeImpl(getTypeConstructor(), new LazyScopeAdapter(new RecursionIntolerantLazyValue<JetScope>() {
|
||||
@Override
|
||||
protected JetScope compute() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOriginal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public TypeParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException("Don't call substitute() on type parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitTypeParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
visitor.visitTypeParameterDescriptor(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return Collections.emptyList(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return DescriptorRenderer.DEBUG_TEXT.render(this);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return this.getClass().getName() + "@" + System.identityHashCode(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorNonRootImpl implements NamespaceDescriptor {
|
||||
public AbstractNamespaceDescriptorImpl(
|
||||
@NotNull NamespaceDescriptorParent containingDeclaration,
|
||||
List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name) {
|
||||
|
||||
super(containingDeclaration, annotations, name);
|
||||
|
||||
boolean rootAccordingToContainer = containingDeclaration instanceof ModuleDescriptor;
|
||||
if (rootAccordingToContainer != name.isSpecial()) {
|
||||
throw new IllegalStateException("something is wrong, name: " + name + ", container: " + containingDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NamespaceDescriptorParent getContainingDeclaration() {
|
||||
return (NamespaceDescriptorParent) super.getContainingDeclaration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
throw new IllegalStateException("immutable");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespaceDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException("This operation does not make sense for a namespace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNamespaceDescriptor(this, data);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class AbstractReceiverParameterDescriptor extends DeclarationDescriptorImpl implements ReceiverParameterDescriptor {
|
||||
private static final Name RECEIVER_PARAMETER_NAME = Name.special("<this>");
|
||||
|
||||
public AbstractReceiverParameterDescriptor() {
|
||||
super(Collections.<AnnotationDescriptor>emptyList(), RECEIVER_PARAMETER_NAME);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
if (substitutor.isEmpty()) return this;
|
||||
JetType substitutedType = substitutor.substitute(getType(), Variance.INVARIANT);
|
||||
if (substitutedType == null) return null;
|
||||
|
||||
return new ReceiverParameterDescriptorImpl(getContainingDeclaration(), substitutedType, new TransientReceiver(substitutedType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitReceiverParameterDescriptor(this, data);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AnonymousFunctionDescriptor extends SimpleFunctionDescriptorImpl {
|
||||
public AnonymousFunctionDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, Name.special("<anonymous>"), kind);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ClassDescriptorBase implements ClassDescriptor {
|
||||
|
||||
protected JetType defaultType;
|
||||
|
||||
protected abstract JetScope getScopeForMemberLookup();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Illegal number of type arguments: expected "
|
||||
+ getTypeConstructor().getParameters().size() + " but was " + typeArguments.size()
|
||||
+ " for " + getTypeConstructor() + " " + getTypeConstructor().getParameters();
|
||||
if (typeArguments.isEmpty()) return getScopeForMemberLookup();
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = getTypeConstructor().getParameters();
|
||||
Map<TypeConstructor, TypeProjection> substitutionContext = SubstitutionUtils.buildSubstitutionContext(typeParameters, typeArguments);
|
||||
|
||||
// Unsafe substitutor is OK, because no recursion can hurt us upon a trivial substitution:
|
||||
// all the types are written explicitly in the code already, they can not get infinite.
|
||||
// One exception is *-projections, but they need to be handled separately anyways.
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.createUnsafe(substitutionContext);
|
||||
return new SubstitutingScope(getScopeForMemberLookup(), substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
if (substitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return new LazySubstitutingClassDescriptor(this, substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
if (defaultType == null) {
|
||||
defaultType = TypeUtils.makeUnsubstitutedType(this, getScopeForMemberLookup());
|
||||
}
|
||||
return defaultType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
visitor.visitClassDescriptor(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassDescriptor(this, data);
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptor {
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private JetScope memberDeclarations;
|
||||
private Set<ConstructorDescriptor> constructors;
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private ReceiverParameterDescriptor thisAsReceiverParameter;
|
||||
private final Modality modality;
|
||||
private ClassDescriptor classObjectDescriptor;
|
||||
private final ClassKind kind;
|
||||
private boolean isInner;
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Name name
|
||||
) {
|
||||
this(containingDeclaration, ClassKind.CLASS, annotations, modality, name);
|
||||
}
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull ClassKind kind,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Name name) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.kind = kind;
|
||||
this.modality = modality;
|
||||
}
|
||||
|
||||
|
||||
public final ClassDescriptorImpl initialize(
|
||||
boolean sealed,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor,
|
||||
boolean isInner
|
||||
) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName().asString(), typeParameters, supertypes);
|
||||
this.memberDeclarations = memberDeclarations;
|
||||
this.constructors = constructors;
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
this.isInner = isInner;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) {
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
}
|
||||
|
||||
public void setClassObjectDescriptor(@NotNull ClassDescriptor classObjectDescriptor) {
|
||||
this.classObjectDescriptor = classObjectDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
assert typeArguments.size() == typeConstructor.getParameters().size() : typeArguments;
|
||||
if (typeConstructor.getParameters().isEmpty()) {
|
||||
return memberDeclarations;
|
||||
}
|
||||
Map<TypeConstructor, TypeProjection> substitutionContext = SubstitutionUtils
|
||||
.buildSubstitutionContext(typeConstructor.getParameters(), typeArguments);
|
||||
return new SubstitutingScope(memberDeclarations, TypeSubstitutor.create(substitutionContext));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
return TypeUtils.makeUnsubstitutedType(this, memberDeclarations);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
return getClassObjectDescriptor().getDefaultType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClassObjectDescriptor() {
|
||||
return classObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInner() {
|
||||
return isInner;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||
if (thisAsReceiverParameter == null) {
|
||||
thisAsReceiverParameter = DescriptorFactory.createLazyReceiverParameterDescriptor(this);
|
||||
}
|
||||
return thisAsReceiverParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getUnsubstitutedInnerClassesScope() {
|
||||
return JetScope.EMPTY;
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements ConstructorDescriptor {
|
||||
|
||||
private final boolean isPrimary;
|
||||
|
||||
private static final Name NAME = Name.special("<init>");
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
this(containingDeclaration, annotations, isPrimary, Kind.DECLARATION);
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary, Kind kind) {
|
||||
super(containingDeclaration, annotations, NAME, kind);
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ConstructorDescriptor original, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
super(containingDeclaration, original, annotations, NAME, Kind.DECLARATION);
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility) {
|
||||
return initialize(typeParameters, unsubstitutedValueParameters, visibility, false);
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility, boolean isStatic) {
|
||||
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ReceiverParameterDescriptor getExpectedThisObject(@NotNull ClassDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
return DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getContainingDeclaration() {
|
||||
return (ClassDescriptor) super.getContainingDeclaration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor getOriginal() {
|
||||
return (ConstructorDescriptor) super.getOriginal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitConstructorDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimary() {
|
||||
return isPrimary;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends FunctionDescriptor> getOverriddenDescriptors() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overriddenFunction) {
|
||||
throw new UnsupportedOperationException("Constructors cannot override anything");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
if (kind != Kind.DECLARATION) {
|
||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
||||
"copy from: " + this + "\n" +
|
||||
"newOwner: " + newOwner + "\n" +
|
||||
"kind: " + kind);
|
||||
}
|
||||
return new ConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
isPrimary);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
throw new UnsupportedOperationException("Constructors should not be copied for overriding");
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements DeclarationDescriptor {
|
||||
|
||||
@NotNull
|
||||
private final Name name;
|
||||
|
||||
public DeclarationDescriptorImpl(@NotNull List<AnnotationDescriptor> annotations, @NotNull Name name) {
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOriginal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
accept(visitor, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return DescriptorRenderer.DEBUG_TEXT.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]";
|
||||
} catch (Throwable e) {
|
||||
// DescriptionRenderer may throw if this is not yet completely initialized
|
||||
// It is very inconvenient while debugging
|
||||
return this.getClass().getName() + "@" + System.identityHashCode(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorNonRoot;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DeclarationDescriptorNonRootImpl
|
||||
extends DeclarationDescriptorImpl
|
||||
implements DeclarationDescriptorNonRoot {
|
||||
|
||||
@NotNull
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
|
||||
public DeclarationDescriptorNonRootImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name) {
|
||||
super(annotations, name);
|
||||
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
|
||||
public class DeclarationDescriptorVisitorEmptyBodies<R, D> implements DeclarationDescriptorVisitor<R, D> {
|
||||
public R visitDeclarationDescriptor(DeclarationDescriptor descriptor, D data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitVariableDescriptor(VariableDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitFunctionDescriptor(FunctionDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitTypeParameterDescriptor(TypeParameterDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitNamespaceDescriptor(NamespaceDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitClassDescriptor(ClassDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitModuleDeclaration(ModuleDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitConstructorDescriptor(ConstructorDescriptor constructorDescriptor, D data) {
|
||||
return visitFunctionDescriptor(constructorDescriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitScriptDescriptor(ScriptDescriptor scriptDescriptor, D data) {
|
||||
return visitDeclarationDescriptor(scriptDescriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitPropertyDescriptor(PropertyDescriptor descriptor, D data) {
|
||||
return visitVariableDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitValueParameterDescriptor(ValueParameterDescriptor descriptor, D data) {
|
||||
return visitVariableDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitPropertyGetterDescriptor(PropertyGetterDescriptor descriptor, D data) {
|
||||
return visitPropertyAccessorDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
private R visitPropertyAccessorDescriptor(PropertyAccessorDescriptor descriptor, D data) {
|
||||
return visitFunctionDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitPropertySetterDescriptor(PropertySetterDescriptor descriptor, D data) {
|
||||
return visitPropertyAccessorDescriptor(descriptor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitReceiverParameterDescriptor(ReceiverParameterDescriptor descriptor, D data) {
|
||||
return visitDeclarationDescriptor(descriptor, data);
|
||||
}
|
||||
}
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRootImpl implements FunctionDescriptor {
|
||||
|
||||
protected List<TypeParameterDescriptor> typeParameters;
|
||||
protected List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
||||
protected JetType unsubstitutedReturnType;
|
||||
private ReceiverParameterDescriptor receiverParameter;
|
||||
protected ReceiverParameterDescriptor expectedThisObject;
|
||||
|
||||
protected Modality modality;
|
||||
protected Visibility visibility;
|
||||
protected final Set<FunctionDescriptor> overriddenFunctions = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
|
||||
private final FunctionDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.original = this;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull FunctionDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.original = original;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverParameterType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
@Nullable Modality modality,
|
||||
@NotNull Visibility visibility) {
|
||||
this.typeParameters = Lists.newArrayList(typeParameters);
|
||||
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
|
||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverParameterType);
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); ++i) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
|
||||
if (typeParameterDescriptor.getIndex() != i) {
|
||||
throw new IllegalStateException(typeParameterDescriptor + " index is " + typeParameterDescriptor.getIndex() + " but position is " + i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < unsubstitutedValueParameters.size(); ++i) {
|
||||
// TODO fill me
|
||||
int firstValueParameterOffset = 0; // receiverParameter.exists() ? 1 : 0;
|
||||
ValueParameterDescriptor valueParameterDescriptor = unsubstitutedValueParameters.get(i);
|
||||
if (valueParameterDescriptor.getIndex() != i + firstValueParameterOffset) {
|
||||
throw new IllegalStateException(valueParameterDescriptor + "index is " + valueParameterDescriptor.getIndex() + " but position is " + i);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public void setReturnType(@NotNull JetType unsubstitutedReturnType) {
|
||||
if (this.unsubstitutedReturnType != null) {
|
||||
// TODO: uncomment and fix tests
|
||||
//throw new IllegalStateException("returnType already set");
|
||||
}
|
||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends FunctionDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenFunctions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overriddenFunction) {
|
||||
overriddenFunctions.add((FunctionDescriptor) overriddenFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
return unsubstitutedValueParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return unsubstitutedReturnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getOriginal() {
|
||||
return original == this ? this : original.getOriginal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
}
|
||||
|
||||
protected FunctionDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, preserveOriginal, kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
JetType substitutedReceiverParameterType = null;
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverParameterType = substitutor.substitute(getReceiverParameter().getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverParameterType == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThis = null;
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThis = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThis == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = getSubstitutedValueParameters(substitutedDescriptor, this, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JetType substitutedReturnType = substitutor.substitute(getReturnType(), Variance.OUT_VARIANCE);
|
||||
if (substitutedReturnType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
substitutedDescriptor.initialize(
|
||||
substitutedReceiverParameterType,
|
||||
substitutedExpectedThis,
|
||||
substitutedTypeParameters,
|
||||
substitutedValueParameters,
|
||||
substitutedReturnType,
|
||||
newModality,
|
||||
newVisibility
|
||||
);
|
||||
if (copyOverrides) {
|
||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||
OverridingUtil.bindOverride(substitutedDescriptor, overriddenFunction.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind);
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFunctionDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeSubstitutor substitutor) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor unsubstitutedValueParameter : unsubstitutedValueParameters) {
|
||||
// TODO : Lazy?
|
||||
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
|
||||
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
|
||||
JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
|
||||
if (substitutedType == null) return null;
|
||||
result.add(new ValueParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
unsubstitutedValueParameter,
|
||||
unsubstitutedValueParameter.getAnnotations(),
|
||||
substitutedType,
|
||||
substituteVarargElementType
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
private final ClassDescriptor original;
|
||||
private final TypeSubstitutor originalSubstitutor;
|
||||
private TypeSubstitutor newSubstitutor;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private TypeConstructor typeConstructor;
|
||||
private JetType superclassType;
|
||||
|
||||
public LazySubstitutingClassDescriptor(ClassDescriptor descriptor, TypeSubstitutor substitutor) {
|
||||
this.original = descriptor;
|
||||
this.originalSubstitutor = substitutor;
|
||||
}
|
||||
|
||||
private TypeSubstitutor getSubstitutor() {
|
||||
if (newSubstitutor == null) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
newSubstitutor = originalSubstitutor;
|
||||
}
|
||||
else {
|
||||
typeParameters = Lists.newArrayList();
|
||||
newSubstitutor = DescriptorSubstitutor.substituteTypeParameters(original.getTypeConstructor().getParameters(), originalSubstitutor, this, typeParameters);
|
||||
}
|
||||
}
|
||||
return newSubstitutor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
TypeConstructor originalTypeConstructor = original.getTypeConstructor();
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return originalTypeConstructor;
|
||||
}
|
||||
|
||||
if (typeConstructor == null) {
|
||||
TypeSubstitutor substitutor = getSubstitutor();
|
||||
|
||||
Collection<JetType> supertypes = Lists.newArrayList();
|
||||
for (JetType supertype : originalTypeConstructor.getSupertypes()) {
|
||||
supertypes.add(substitutor.substitute(supertype, Variance.INVARIANT));
|
||||
}
|
||||
|
||||
typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
originalTypeConstructor.getAnnotations(),
|
||||
originalTypeConstructor.isSealed(),
|
||||
originalTypeConstructor.toString(),
|
||||
typeParameters,
|
||||
supertypes
|
||||
);
|
||||
}
|
||||
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
JetScope memberScope = original.getMemberScope(typeArguments);
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return memberScope;
|
||||
}
|
||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
Collection<ConstructorDescriptor> r = Lists.newArrayList();
|
||||
for (ConstructorDescriptor constructor : original.getConstructors()) {
|
||||
r.add((ConstructorDescriptor) constructor.substitute(getSubstitutor()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return original.getAnnotations();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
return original.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOriginal() {
|
||||
return original.getOriginal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return original.getContainingDeclaration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
if (substitutor.isEmpty()) return this;
|
||||
return new LazySubstitutingClassDescriptor(this, TypeSubstitutor.create(substitutor.getSubstitution(), getSubstitutor().getSubstitution()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
return original.getClassObjectType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClassObjectDescriptor() {
|
||||
return original.getClassObjectDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getKind() {
|
||||
return original.getKind();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Modality getModality() {
|
||||
return original.getModality();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return original.getVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInner() {
|
||||
return original.isInner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getUnsubstitutedInnerClassesScope() {
|
||||
return original.getUnsubstitutedInnerClassesScope();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return original.getUnsubstitutedPrimaryConstructor();
|
||||
}
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
|
||||
private final Set<CallableMemberDescriptor> declaredCallableMembers = Sets.newLinkedHashSet();
|
||||
private final Set<CallableMemberDescriptor> allCallableMembers = Sets.newLinkedHashSet(); // includes fake overrides
|
||||
private final Set<PropertyDescriptor> properties = Sets.newLinkedHashSet();
|
||||
private final Set<SimpleFunctionDescriptor> functions = Sets.newLinkedHashSet();
|
||||
|
||||
private final WritableScope scopeForMemberResolution;
|
||||
// This scope contains type parameters but does not contain inner classes
|
||||
private final WritableScope scopeForSupertypeResolution;
|
||||
private WritableScope scopeForInitializers = null; //contains members + primary constructor value parameters + map for backing fields
|
||||
|
||||
public MutableClassDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetScope outerScope, ClassKind kind, boolean isInner, Name name) {
|
||||
super(containingDeclaration, kind, isInner);
|
||||
|
||||
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
|
||||
|
||||
setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler, "MemberLookup")
|
||||
.changeLockLevel(WritableScope.LockLevel.BOTH));
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler, "SupertypeResolution")
|
||||
.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler, "MemberResolution")
|
||||
.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
if (getKind() == ClassKind.TRAIT) {
|
||||
setUpScopeForInitializers(this);
|
||||
}
|
||||
|
||||
setName(name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||
assert primaryConstructor == null : "Primary constructor assigned twice " + this;
|
||||
primaryConstructor = constructorDescriptor;
|
||||
|
||||
constructors.add(constructorDescriptor);
|
||||
|
||||
if (defaultType != null) {
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
|
||||
if (constructorDescriptor.isPrimary()) {
|
||||
setUpScopeForInitializers(constructorDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void addConstructorParametersToInitializersScope(@NotNull Collection<? extends VariableDescriptor> variables) {
|
||||
WritableScope scope = getWritableScopeForInitializers();
|
||||
for (VariableDescriptor variable : variables) {
|
||||
scope.addVariableDescriptor(variable);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<SimpleFunctionDescriptor> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<PropertyDescriptor> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<CallableMemberDescriptor> getDeclaredCallableMembers() {
|
||||
return declaredCallableMembers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<CallableMemberDescriptor> getAllCallableMembers() {
|
||||
return allCallableMembers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeParameterDescriptors(List<TypeParameterDescriptor> typeParameters) {
|
||||
super.setTypeParameterDescriptors(typeParameters);
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
scopeForSupertypeResolution.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull Name name) {
|
||||
super.setName(name);
|
||||
scopeForMemberResolution.addLabeledDeclaration(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTypeConstructor() {
|
||||
super.createTypeConstructor();
|
||||
for (FunctionDescriptor functionDescriptor : getConstructors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
scopeForMemberResolution.setImplicitReceiver(getThisAsReceiverParameter());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForSupertypeResolution() {
|
||||
return scopeForSupertypeResolution;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberResolution() {
|
||||
return scopeForMemberResolution;
|
||||
}
|
||||
|
||||
private WritableScope getWritableScopeForInitializers() {
|
||||
if (scopeForInitializers == null) {
|
||||
throw new IllegalStateException("Scope for initializers queried before the primary constructor is set");
|
||||
}
|
||||
return scopeForInitializers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForInitializers() {
|
||||
return getWritableScopeForInitializers();
|
||||
}
|
||||
|
||||
private void setUpScopeForInitializers(@NotNull DeclarationDescriptor containingDeclaration) {
|
||||
this.scopeForInitializers = new WritableScopeImpl(
|
||||
scopeForMemberResolution, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Initializers")
|
||||
.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockScopes() {
|
||||
super.lockScopes();
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
getWritableScopeForInitializers().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
}
|
||||
|
||||
private NamespaceLikeBuilder builder = null;
|
||||
|
||||
@Override
|
||||
public NamespaceLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
final NamespaceLikeBuilder superBuilder = super.getBuilder();
|
||||
builder = new NamespaceLikeBuilderDummy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return superBuilder.getOwnerForChildren();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
|
||||
superBuilder.addObjectDescriptor(objectDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
superBuilder.addClassifierDescriptor(classDescriptor);
|
||||
scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
superBuilder.addFunctionDescriptor(functionDescriptor);
|
||||
functions.add(functionDescriptor);
|
||||
if (functionDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(functionDescriptor);
|
||||
}
|
||||
allCallableMembers.add(functionDescriptor);
|
||||
scopeForMemberResolution.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
||||
if (r != ClassObjectStatus.OK) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// Members of the class object are accessible from the class
|
||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
superBuilder.addPropertyDescriptor(propertyDescriptor);
|
||||
properties.add(propertyDescriptor);
|
||||
if (propertyDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(propertyDescriptor);
|
||||
}
|
||||
allCallableMembers.add(propertyDescriptor);
|
||||
scopeForMemberResolution.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
|
||||
private List<AnnotationDescriptor> annotations = Lists.newArrayList();
|
||||
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = Lists.newArrayList();
|
||||
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private Modality modality;
|
||||
private Visibility visibility;
|
||||
|
||||
private final boolean isInner;
|
||||
|
||||
private MutableClassDescriptorLite classObjectDescriptor;
|
||||
private JetType classObjectType;
|
||||
private final ClassKind kind;
|
||||
|
||||
private JetScope scopeForMemberLookup;
|
||||
private JetScope innerClassesScope;
|
||||
|
||||
private ReceiverParameterDescriptor implicitReceiver;
|
||||
|
||||
private Name name;
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
|
||||
public MutableClassDescriptorLite(@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull ClassKind kind,
|
||||
boolean isInner
|
||||
) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.kind = kind;
|
||||
this.isInner = isInner;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(@NotNull Name name) {
|
||||
assert this.name == null : this.name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOriginal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
public void setScopeForMemberLookup(JetScope scopeForMemberLookup) {
|
||||
this.scopeForMemberLookup = scopeForMemberLookup;
|
||||
this.innerClassesScope = new InnerClassesScopeWrapper(scopeForMemberLookup);
|
||||
}
|
||||
|
||||
public void createTypeConstructor() {
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO : pass annotations from the class?
|
||||
!getModality().isOverridable(),
|
||||
getName().asString(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
}
|
||||
|
||||
private WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
// hack
|
||||
return (WritableScope) scopeForMemberLookup;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberLookup() {
|
||||
return scopeForMemberLookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
if (classObjectType == null && classObjectDescriptor != null) {
|
||||
classObjectType = classObjectDescriptor.getDefaultType();
|
||||
}
|
||||
return classObjectType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setModality(Modality modality) {
|
||||
this.modality = modality;
|
||||
}
|
||||
|
||||
public void setVisibility(Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInner() {
|
||||
return isInner;
|
||||
}
|
||||
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
public void setSupertypes(@NotNull Collection<JetType> supertypes) {
|
||||
this.supertypes = supertypes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MutableClassDescriptorLite getClassObjectDescriptor() {
|
||||
return classObjectDescriptor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getUnsubstitutedInnerClassesScope() {
|
||||
return innerClassesScope;
|
||||
}
|
||||
|
||||
|
||||
public void addSupertype(@NotNull JetType supertype) {
|
||||
assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
|
||||
if (TypeUtils.getClassDescriptor(supertype) != null) {
|
||||
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
|
||||
supertypes.add(supertype);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTypeParameterDescriptors(List<TypeParameterDescriptor> typeParameters) {
|
||||
if (this.typeParameters != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.typeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
this.typeParameters.add(typeParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void lockScopes() {
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (classObjectDescriptor != null) {
|
||||
classObjectDescriptor.lockScopes();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
|
||||
if (implicitReceiver == null) {
|
||||
implicitReceiver = DescriptorFactory.createLazyReceiverParameterDescriptor(this);
|
||||
}
|
||||
return implicitReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
|
||||
} catch (Throwable e) {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public void setAnnotations(List<AnnotationDescriptor> annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
private NamespaceLikeBuilder builder = null;
|
||||
public NamespaceLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
builder = new NamespaceLikeBuilderDummy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return MutableClassDescriptorLite.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addObjectDescriptor(objectDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
if (getKind().isObject() || isInner()) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (MutableClassDescriptorLite.this.classObjectDescriptor != null) {
|
||||
return ClassObjectStatus.DUPLICATE;
|
||||
}
|
||||
|
||||
assert classObjectDescriptor.getKind() == ClassKind.CLASS_OBJECT;
|
||||
MutableClassDescriptorLite.this.classObjectDescriptor = classObjectDescriptor;
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl {
|
||||
|
||||
private WritableScope memberScope;
|
||||
|
||||
public NamespaceDescriptorImpl(@NotNull NamespaceDescriptorParent containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull WritableScope memberScope) {
|
||||
if (this.memberScope != null) {
|
||||
throw new IllegalStateException("Namespace member scope reinitialize");
|
||||
}
|
||||
|
||||
this.memberScope = memberScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public WritableScope getMemberScope() {
|
||||
return memberScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
getMemberScope().addNamespace(namespaceDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FqName getFqName() {
|
||||
return DescriptorUtils.getFQName(this).toSafe();
|
||||
}
|
||||
|
||||
private NamespaceLikeBuilder builder = null;
|
||||
public NamespaceLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
builder = new NamespaceLikeBuilder() {
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
getMemberScope().addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
|
||||
getMemberScope().addObjectDescriptor(objectDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
getMemberScope().addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
getMemberScope().addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return NamespaceDescriptorImpl.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
throw new IllegalStateException("Must be guaranteed not to happen by the parser");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
|
||||
public interface NamespaceDescriptorParent extends DeclarationDescriptor {
|
||||
|
||||
void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor);
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
|
||||
public interface NamespaceLikeBuilder {
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor getOwnerForChildren();
|
||||
|
||||
void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor);
|
||||
|
||||
void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor);
|
||||
|
||||
void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor);
|
||||
|
||||
void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor);
|
||||
|
||||
enum ClassObjectStatus {
|
||||
OK,
|
||||
DUPLICATE,
|
||||
NOT_ALLOWED
|
||||
}
|
||||
|
||||
ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
|
||||
public class NamespaceLikeBuilderDummy implements NamespaceLikeBuilder {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescriptorNonRootImpl implements PropertyAccessorDescriptor {
|
||||
|
||||
private final boolean hasBody;
|
||||
private final boolean isDefault;
|
||||
private final Modality modality;
|
||||
private final PropertyDescriptor correspondingProperty;
|
||||
private final Kind kind;
|
||||
private Visibility visibility;
|
||||
|
||||
public PropertyAccessorDescriptorImpl(
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
boolean hasBody,
|
||||
boolean isDefault,
|
||||
Kind kind
|
||||
) {
|
||||
super(correspondingProperty.getContainingDeclaration(), annotations, name);
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.correspondingProperty = correspondingProperty;
|
||||
this.hasBody = hasBody;
|
||||
this.isDefault = isDefault;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBody() {
|
||||
return hasBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public void setVisibility(Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PropertyDescriptor getCorrespondingProperty() {
|
||||
return correspondingProperty;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return getCorrespondingProperty().getReceiverParameter();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return getCorrespondingProperty().getExpectedThisObject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyAccessorDescriptor copy(
|
||||
DeclarationDescriptor newOwner,
|
||||
Modality modality,
|
||||
Visibility visibility,
|
||||
Kind kind,
|
||||
boolean copyOverrides
|
||||
) {
|
||||
throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
|
||||
}
|
||||
|
||||
protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) {
|
||||
Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors();
|
||||
Set<PropertyAccessorDescriptor> overriddenAccessors = Sets.newHashSet();
|
||||
for (PropertyDescriptor overriddenProperty : overriddenProperties) {
|
||||
PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter();
|
||||
if (accessorDescriptor != null) {
|
||||
overriddenAccessors.add(accessorDescriptor);
|
||||
}
|
||||
}
|
||||
return overriddenAccessors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract PropertyAccessorDescriptor getOriginal();
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PropertyDescriptorForObjectImpl extends PropertyDescriptorImpl implements VariableDescriptorForObject {
|
||||
|
||||
private final ClassDescriptor objectClass;
|
||||
|
||||
public PropertyDescriptorForObjectImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Visibility visibility,
|
||||
@NotNull Name name,
|
||||
@NotNull ClassDescriptor objectClass
|
||||
) {
|
||||
super(containingDeclaration, annotations, Modality.FINAL, visibility, false, name, Kind.DECLARATION);
|
||||
this.objectClass = objectClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getObjectClass() {
|
||||
return objectClass;
|
||||
}
|
||||
}
|
||||
+317
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor {
|
||||
|
||||
private final Modality modality;
|
||||
private Visibility visibility;
|
||||
private final boolean isVar;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
private ReceiverParameterDescriptor expectedThisObject;
|
||||
private ReceiverParameterDescriptor receiverParameter;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private PropertyGetterDescriptorImpl getter;
|
||||
private PropertySetterDescriptor setter;
|
||||
|
||||
private PropertyDescriptorImpl(
|
||||
@Nullable PropertyDescriptor original,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.isVar = isVar;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public PropertyDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@Nullable JetType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable JetType receiverType
|
||||
) {
|
||||
ReceiverParameterDescriptor receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverType);
|
||||
setType(outType, typeParameters, expectedThisObject, receiverParameter);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter
|
||||
) {
|
||||
setOutType(outType);
|
||||
|
||||
this.typeParameters = Lists.newArrayList(typeParameters);
|
||||
|
||||
this.receiverParameter = receiverParameter;
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
}
|
||||
|
||||
public void initialize(@Nullable PropertyGetterDescriptorImpl getter, @Nullable PropertySetterDescriptor setter) {
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PropertyGetterDescriptorImpl getGetter() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PropertySetterDescriptor getSetter() {
|
||||
return setter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<PropertyAccessorDescriptor> getAccessors() {
|
||||
List<PropertyAccessorDescriptor> r = Lists.newArrayListWithCapacity(2);
|
||||
if (getter != null) {
|
||||
r.add(getter);
|
||||
}
|
||||
if (setter != null) {
|
||||
r.add(setter);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
}
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptorImpl substitutedDescriptor = new PropertyDescriptorImpl(preserveOriginal ? getOriginal() : null, newOwner,
|
||||
getAnnotations(), newModality, newVisibility, isVar(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
JetType originalOutType = getType();
|
||||
JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
|
||||
if (outType == null) {
|
||||
return null; // TODO : tell the user that the property was projected out
|
||||
}
|
||||
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThisObject;
|
||||
ReceiverParameterDescriptor expectedThisObject = getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThisObject = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThisObject == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedExpectedThisObject = null;
|
||||
}
|
||||
|
||||
JetType substitutedReceiverType;
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverType = substitutor.substitute(receiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverType == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedReceiverType = null;
|
||||
}
|
||||
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
|
||||
|
||||
PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl(
|
||||
substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility),
|
||||
getter.hasBody(), getter.isDefault(), kind, getter.getOriginal());
|
||||
if (newGetter != null) {
|
||||
JetType returnType = getter.getReturnType();
|
||||
newGetter.initialize(returnType != null ? substitutor.substitute(returnType, Variance.OUT_VARIANCE) : null);
|
||||
}
|
||||
PropertySetterDescriptorImpl newSetter = setter == null ? null : new PropertySetterDescriptorImpl(
|
||||
substitutedDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), false),
|
||||
convertVisibility(setter.getVisibility(), newVisibility), setter.hasBody(), setter.isDefault(), kind, setter.getOriginal());
|
||||
if (newSetter != null) {
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(newSetter, setter, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
if (substitutedValueParameters.size() != 1) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
newSetter.initialize(substitutedValueParameters.get(0));
|
||||
}
|
||||
|
||||
substitutedDescriptor.initialize(newGetter, newSetter);
|
||||
|
||||
if (copyOverrides) {
|
||||
for (PropertyDescriptor propertyDescriptor : overriddenProperties) {
|
||||
OverridingUtil.bindOverride(substitutedDescriptor, propertyDescriptor.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Visibility convertVisibility(Visibility orig, Visibility candidate) {
|
||||
if (candidate == Visibilities.INHERITED) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Integer result = Visibilities.compare(orig, candidate);
|
||||
return result != null && result < 0 ? candidate : orig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertyDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor getOriginal() {
|
||||
return original == this ? this : original.getOriginal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||
overriddenProperties.add((PropertyDescriptorImpl) overridden);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenProperties;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PropertyGetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertyGetterDescriptor {
|
||||
private JetType returnType;
|
||||
|
||||
@NotNull
|
||||
private final PropertyGetterDescriptor original;
|
||||
|
||||
public PropertyGetterDescriptorImpl(
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null);
|
||||
}
|
||||
|
||||
public PropertyGetterDescriptorImpl(
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault,
|
||||
@NotNull Kind kind,
|
||||
@Nullable PropertyGetterDescriptor original
|
||||
)
|
||||
{
|
||||
super(modality, visibility, correspondingProperty, annotations, Name.special("<get-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind);
|
||||
this.original = original != null ? original : this;
|
||||
}
|
||||
|
||||
public void initialize(JetType returnType) {
|
||||
this.returnType = returnType == null ? getCorrespondingProperty().getType() : returnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
|
||||
return super.getOverriddenDescriptors(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertyGetterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyGetterDescriptor getOriginal() {
|
||||
return this.original;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertySetterDescriptor {
|
||||
|
||||
private ValueParameterDescriptor parameter;
|
||||
@NotNull
|
||||
private final PropertySetterDescriptor original;
|
||||
|
||||
public PropertySetterDescriptorImpl(
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null);
|
||||
}
|
||||
|
||||
public PropertySetterDescriptorImpl(
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault,
|
||||
@NotNull Kind kind,
|
||||
@Nullable PropertySetterDescriptor original
|
||||
) {
|
||||
super(modality, visibility, correspondingProperty, annotations, Name.special("<set-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind);
|
||||
this.original = original != null ? original : this;
|
||||
}
|
||||
|
||||
public void initialize(@NotNull ValueParameterDescriptor parameter) {
|
||||
assert this.parameter == null;
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public void initializeDefault() {
|
||||
assert parameter == null;
|
||||
parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), Name.special("<set-?>"), getCorrespondingProperty().getReturnType(), false, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
|
||||
return super.getOverriddenDescriptors(false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
if (parameter == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return Collections.singletonList(parameter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return KotlinBuiltIns.getInstance().getUnitType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertySetterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertySetterDescriptor getOriginal() {
|
||||
return this.original;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class ReceiverParameterDescriptorImpl extends AbstractReceiverParameterDescriptor {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final JetType type;
|
||||
private final ReceiverValue value;
|
||||
|
||||
public ReceiverParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetType type,
|
||||
@NotNull ReceiverValue value
|
||||
) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
|
||||
|
||||
public ScriptCodeDescriptor(@NotNull ScriptDescriptor containingDeclaration) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), Name.special("<script-code>"), Kind.DECLARATION);
|
||||
setVisibility(Visibilities.LOCAL);
|
||||
}
|
||||
|
||||
public void initialize(
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull JetType returnType) {
|
||||
super.initialize(null, expectedThisObject, Collections.<TypeParameterDescriptor>emptyList(), valueParameters, returnType, Modality.FINAL, Visibilities.LOCAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
throw new IllegalStateException("no need to copy script code descriptor");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
throw new IllegalStateException("no need to copy script code descriptor");
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl implements SimpleFunctionDescriptor {
|
||||
|
||||
private boolean isInline = false;
|
||||
|
||||
public SimpleFunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, kind);
|
||||
}
|
||||
|
||||
private SimpleFunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull SimpleFunctionDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind) {
|
||||
super(containingDeclaration, original, annotations, name, kind);
|
||||
}
|
||||
|
||||
public SimpleFunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverParameterType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
@Nullable Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isInline) {
|
||||
super.initialize(receiverParameterType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
|
||||
this.isInline = isInline;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor getOriginal() {
|
||||
return (SimpleFunctionDescriptor) super.getOriginal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
if (preserveOriginal) {
|
||||
return new SimpleFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
getOriginal(),
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName(),
|
||||
kind);
|
||||
}
|
||||
else {
|
||||
return new SimpleFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName(),
|
||||
kind);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
SimpleFunctionDescriptorImpl copy = (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
copy.isInline = isInline;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInline() {
|
||||
return isInline;
|
||||
}
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImpl implements TypeParameterDescriptor {
|
||||
public static TypeParameterDescriptor createWithDefaultBound(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
boolean reified,
|
||||
@NotNull Variance variance,
|
||||
@NotNull Name name,
|
||||
int index) {
|
||||
TypeParameterDescriptorImpl typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index);
|
||||
typeParameterDescriptor.addUpperBound(KotlinBuiltIns.getInstance().getDefaultBound());
|
||||
typeParameterDescriptor.setInitialized();
|
||||
return typeParameterDescriptor;
|
||||
}
|
||||
|
||||
public static TypeParameterDescriptorImpl createForFurtherModification(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
boolean reified,
|
||||
@NotNull Variance variance,
|
||||
@NotNull Name name,
|
||||
int index) {
|
||||
return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index);
|
||||
}
|
||||
|
||||
// 0-based
|
||||
private final int index;
|
||||
private final Variance variance;
|
||||
private final Set<JetType> upperBounds;
|
||||
private JetType upperBoundsAsType;
|
||||
private final TypeConstructor typeConstructor;
|
||||
private JetType defaultType;
|
||||
private final Set<JetType> classObjectUpperBounds = Sets.newLinkedHashSet();
|
||||
private JetType classObjectBoundsAsType;
|
||||
|
||||
private final boolean reified;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private TypeParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
boolean reified,
|
||||
@NotNull Variance variance,
|
||||
@NotNull Name name,
|
||||
int index) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.index = index;
|
||||
this.variance = variance;
|
||||
this.upperBounds = Sets.newLinkedHashSet();
|
||||
this.reified = reified;
|
||||
// TODO: Should we actually pass the annotations on to the type constructor?
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
annotations,
|
||||
false,
|
||||
name.asString(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
upperBounds);
|
||||
}
|
||||
|
||||
private void checkInitialized() {
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("Type parameter descriptor in not initialized: " + nameForAssertions());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUninitialized() {
|
||||
if (initialized) {
|
||||
throw new IllegalStateException("Type parameter descriptor is already initialized: " + nameForAssertions());
|
||||
}
|
||||
}
|
||||
|
||||
private String nameForAssertions() {
|
||||
return getName() + " declared in " + DescriptorUtils.getFQName(getContainingDeclaration());
|
||||
}
|
||||
|
||||
public void setInitialized() {
|
||||
checkUninitialized();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReified() {
|
||||
checkInitialized();
|
||||
return reified;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Variance getVariance() {
|
||||
return variance;
|
||||
}
|
||||
|
||||
public void addUpperBound(@NotNull JetType bound) {
|
||||
checkUninitialized();
|
||||
doAddUpperBound(bound);
|
||||
}
|
||||
|
||||
private void doAddUpperBound(JetType bound) {
|
||||
upperBounds.add(bound); // TODO : Duplicates?
|
||||
}
|
||||
|
||||
public void addDefaultUpperBound() {
|
||||
checkUninitialized();
|
||||
|
||||
if (upperBounds.isEmpty()) {
|
||||
doAddUpperBound(KotlinBuiltIns.getInstance().getDefaultBound());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<JetType> getUpperBounds() {
|
||||
checkInitialized();
|
||||
return upperBounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getUpperBoundsAsType() {
|
||||
checkInitialized();
|
||||
if (upperBoundsAsType == null) {
|
||||
assert upperBounds != null : "Upper bound list is null in " + getName();
|
||||
assert upperBounds.size() > 0 : "Upper bound list is empty in " + getName();
|
||||
upperBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
|
||||
if (upperBoundsAsType == null) {
|
||||
upperBoundsAsType = KotlinBuiltIns.getInstance().getNothingType();
|
||||
}
|
||||
}
|
||||
return upperBoundsAsType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<JetType> getLowerBounds() {
|
||||
//checkInitialized();
|
||||
return Collections.singleton(KotlinBuiltIns.getInstance().getNothingType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getLowerBoundsAsType() {
|
||||
checkInitialized();
|
||||
return KotlinBuiltIns.getInstance().getNothingType();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
//checkInitialized();
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return DescriptorRenderer.TEXT.render(this);
|
||||
} catch (Exception e) {
|
||||
return this.getClass().getName() + "@" + System.identityHashCode(this);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public TypeParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
checkInitialized();
|
||||
return visitor.visitTypeParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
//checkInitialized();
|
||||
if (defaultType == null) {
|
||||
defaultType = new JetTypeImpl(
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
getTypeConstructor(),
|
||||
TypeUtils.hasNullableLowerBound(this),
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
new LazyScopeAdapter(new RecursionIntolerantLazyValue<JetScope>() {
|
||||
@Override
|
||||
protected JetScope compute() {
|
||||
return getUpperBoundsAsType().getMemberScope();
|
||||
}
|
||||
}));
|
||||
}
|
||||
return defaultType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
checkInitialized();
|
||||
if (classObjectUpperBounds.isEmpty()) return null;
|
||||
|
||||
if (classObjectBoundsAsType == null) {
|
||||
classObjectBoundsAsType = TypeUtils.intersect(JetTypeChecker.INSTANCE, classObjectUpperBounds);
|
||||
if (classObjectBoundsAsType == null) {
|
||||
classObjectBoundsAsType = KotlinBuiltIns.getInstance().getNothingType();
|
||||
}
|
||||
}
|
||||
return classObjectBoundsAsType;
|
||||
}
|
||||
|
||||
public void addClassObjectBound(@NotNull JetType bound) {
|
||||
checkUninitialized();
|
||||
classObjectUpperBounds.add(bound); // TODO : Duplicates?
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
checkInitialized();
|
||||
return index;
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ValueParameterDescriptorImpl extends VariableDescriptorImpl implements ValueParameterDescriptor {
|
||||
private Boolean hasDefaultValue;
|
||||
private final boolean declaresDefaultValue;
|
||||
|
||||
private final JetType varargElementType;
|
||||
private final int index;
|
||||
private final ValueParameterDescriptor original;
|
||||
|
||||
private final Set<ValueParameterDescriptor> overriddenDescriptors = Sets.newLinkedHashSet(); // Linked is essential
|
||||
private boolean overriddenDescriptorsLocked = false;
|
||||
private final Set<? extends ValueParameterDescriptor> readOnlyOverriddenDescriptors = Collections.unmodifiableSet(overriddenDescriptors);
|
||||
|
||||
public ValueParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
boolean declaresDefaultValue,
|
||||
@Nullable JetType varargElementType
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, outType);
|
||||
this.original = this;
|
||||
this.index = index;
|
||||
this.declaresDefaultValue = declaresDefaultValue;
|
||||
this.varargElementType = varargElementType;
|
||||
}
|
||||
|
||||
public ValueParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull ValueParameterDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull JetType outType,
|
||||
@Nullable JetType varargElementType
|
||||
) {
|
||||
super(containingDeclaration, annotations, original.getName(), outType);
|
||||
this.original = original;
|
||||
this.index = original.getIndex();
|
||||
this.declaresDefaultValue = original.declaresDefaultValue();
|
||||
this.varargElementType = varargElementType;
|
||||
}
|
||||
|
||||
public void setType(@NotNull JetType type) {
|
||||
setOutType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDefaultValue() {
|
||||
computeDefaultValuePresence();
|
||||
return hasDefaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean declaresDefaultValue() {
|
||||
return declaresDefaultValue && ((CallableMemberDescriptor) getContainingDeclaration()).getKind().isReal();
|
||||
}
|
||||
|
||||
private void computeDefaultValuePresence() {
|
||||
if (hasDefaultValue != null) return;
|
||||
overriddenDescriptorsLocked = true;
|
||||
if (declaresDefaultValue) {
|
||||
hasDefaultValue = true;
|
||||
}
|
||||
else {
|
||||
for (ValueParameterDescriptor descriptor : overriddenDescriptors) {
|
||||
if (descriptor.hasDefaultValue()) {
|
||||
hasDefaultValue = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
hasDefaultValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetType getVarargElementType() {
|
||||
return varargElementType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor getOriginal() {
|
||||
return original == this ? this : original.getOriginal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitValueParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner, @NotNull Name newName) {
|
||||
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), newName, getType(), declaresDefaultValue(), varargElementType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return Visibilities.LOCAL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends ValueParameterDescriptor> getOverriddenDescriptors() {
|
||||
return readOnlyOverriddenDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull ValueParameterDescriptor overridden) {
|
||||
assert !overriddenDescriptorsLocked : "Adding more overridden descriptors is not allowed at this point: " +
|
||||
"the presence of the default value has already been calculated";
|
||||
overriddenDescriptors.add(overridden);
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRootImpl implements VariableDescriptor {
|
||||
private JetType outType;
|
||||
|
||||
public VariableDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name,
|
||||
@Nullable JetType outType) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
|
||||
this.outType = outType;
|
||||
}
|
||||
|
||||
protected VariableDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Name name
|
||||
)
|
||||
{
|
||||
this(containingDeclaration, annotations, name, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
return outType;
|
||||
}
|
||||
|
||||
public void setOutType(JetType outType) {
|
||||
assert this.outType == null;
|
||||
this.outType = outType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VariableDescriptor getOriginal() {
|
||||
return (VariableDescriptor) super.getOriginal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends CallableDescriptor> getOverriddenDescriptors() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getDefaultConstructorVisibility;
|
||||
|
||||
public class DescriptorFactory {
|
||||
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
|
||||
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
|
||||
|
||||
private DescriptorFactory() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createDefaultSetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createSetter(propertyDescriptor, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createSetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
|
||||
PropertySetterDescriptorImpl setterDescriptor = new PropertySetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
setterDescriptor.initializeDefault();
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createDefaultGetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createGetter(propertyDescriptor, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createGetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
|
||||
return new PropertyGetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
getDefaultConstructorVisibility(containingClass));
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUES_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUE_OF_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
values,
|
||||
0,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Name.identifier("value"),
|
||||
KotlinBuiltIns.getInstance().getStringType(),
|
||||
false,
|
||||
null);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singletonList(parameterDescriptor),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ReceiverParameterDescriptor createReceiverParameterForCallable(
|
||||
@NotNull CallableDescriptor owner,
|
||||
@Nullable JetType receiverParameterType
|
||||
) {
|
||||
return receiverParameterType == null
|
||||
? NO_RECEIVER_PARAMETER
|
||||
: new ReceiverParameterDescriptorImpl(owner, receiverParameterType, new ExtensionReceiver(owner, receiverParameterType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ReceiverParameterDescriptor createLazyReceiverParameterDescriptor(@NotNull final ClassDescriptor classDescriptor) {
|
||||
return new AbstractReceiverParameterDescriptor() {
|
||||
private ClassReceiver value;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
// This must be lazy, thus the inner class
|
||||
return classDescriptor.getDefaultType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getValue() {
|
||||
if (value == null) {
|
||||
value = new ClassReceiver(classDescriptor);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "class " + classDescriptor.getName() + "::this";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
public class DescriptorUtils {
|
||||
public static final Name ROOT_NAMESPACE_NAME = Name.special("<root namespace>");
|
||||
|
||||
private DescriptorUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends CallableDescriptor> D substituteBounds(@NotNull D functionDescriptor) {
|
||||
List<TypeParameterDescriptor> typeParameters = functionDescriptor.getTypeParameters();
|
||||
if (typeParameters.isEmpty()) return functionDescriptor;
|
||||
|
||||
// TODO: this does not handle any recursion in the bounds
|
||||
@SuppressWarnings("unchecked")
|
||||
D substitutedFunction = (D) functionDescriptor.substitute(DescriptorSubstitutor.createUpperBoundsSubstitutor(typeParameters));
|
||||
assert substitutedFunction != null : "Substituting upper bounds should always be legal";
|
||||
|
||||
return substitutedFunction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Modality convertModality(@NotNull Modality modality, boolean makeNonAbstract) {
|
||||
if (makeNonAbstract && modality == Modality.ABSTRACT) return Modality.OPEN;
|
||||
return modality;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ReceiverParameterDescriptor getExpectedThisObjectIfNeeded(@NotNull DeclarationDescriptor containingDeclaration) {
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
return classDescriptor.getThisAsReceiverParameter();
|
||||
}
|
||||
else if (containingDeclaration instanceof ScriptDescriptor) {
|
||||
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) containingDeclaration;
|
||||
return scriptDescriptor.getThisAsReceiverParameter();
|
||||
}
|
||||
return NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
/**
|
||||
* The primary case for local extensions is the following:
|
||||
*
|
||||
* I had a locally declared extension function or a local variable of function type called foo
|
||||
* And I called it on my x
|
||||
* Now, someone added function foo() to the class of x
|
||||
* My code should not change
|
||||
*
|
||||
* thus
|
||||
*
|
||||
* local extension prevail over members (and members prevail over all non-local extensions)
|
||||
*/
|
||||
public static boolean isLocal(DeclarationDescriptor containerOfTheCurrentLocality, DeclarationDescriptor candidate) {
|
||||
if (candidate instanceof ValueParameterDescriptor) {
|
||||
return true;
|
||||
}
|
||||
DeclarationDescriptor parent = candidate.getContainingDeclaration();
|
||||
if (!(parent instanceof FunctionDescriptor)) {
|
||||
return false;
|
||||
}
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) parent;
|
||||
DeclarationDescriptor current = containerOfTheCurrentLocality;
|
||||
while (current != null) {
|
||||
if (current == functionDescriptor) {
|
||||
return true;
|
||||
}
|
||||
current = current.getContainingDeclaration();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqNameUnsafe getFQName(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
if (descriptor instanceof ModuleDescriptor || containingDeclaration instanceof ModuleDescriptor) {
|
||||
return FqName.ROOT.toUnsafe();
|
||||
}
|
||||
|
||||
if (containingDeclaration == null) {
|
||||
if (descriptor instanceof NamespaceDescriptor) {
|
||||
// TODO: namespace must always have parent
|
||||
if (descriptor.getName().equals(Name.identifier("jet"))) {
|
||||
return FqNameUnsafe.topLevel(Name.identifier("jet"));
|
||||
}
|
||||
if (descriptor.getName().equals(Name.special("<java_root>"))) {
|
||||
return FqName.ROOT.toUnsafe();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("descriptor is not module descriptor and has null containingDeclaration: " + descriptor);
|
||||
}
|
||||
|
||||
if (containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.CLASS_OBJECT) {
|
||||
DeclarationDescriptor classOfClassObject = containingDeclaration.getContainingDeclaration();
|
||||
assert classOfClassObject != null;
|
||||
return getFQName(classOfClassObject).child(descriptor.getName());
|
||||
}
|
||||
|
||||
return getFQName(containingDeclaration).child(descriptor.getName());
|
||||
}
|
||||
|
||||
public static boolean isTopLevelDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||
return descriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||
ModuleDescriptor parentModule = getParentOfType(first, ModuleDescriptorImpl.class, false);
|
||||
ModuleDescriptor fromModule = getParentOfType(second, ModuleDescriptorImpl.class, false);
|
||||
assert parentModule != null && fromModule != null;
|
||||
return parentModule.equals(fromModule);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DeclarationDescriptor findTopLevelParent(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
DeclarationDescriptor descriptor = declarationDescriptor;
|
||||
if (declarationDescriptor instanceof PropertyAccessorDescriptor) {
|
||||
descriptor = ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty();
|
||||
}
|
||||
while (!(descriptor == null || isTopLevelDeclaration(descriptor))) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
@NotNull Class<D> aClass
|
||||
) {
|
||||
return getParentOfType(descriptor, aClass, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
@NotNull Class<D> aClass,
|
||||
boolean strict
|
||||
) {
|
||||
if (descriptor == null) return null;
|
||||
if (strict) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
while (descriptor != null) {
|
||||
if (aClass.isInstance(descriptor)) {
|
||||
//noinspection unchecked
|
||||
return (D) descriptor;
|
||||
}
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isAncestor(
|
||||
@Nullable DeclarationDescriptor ancestor,
|
||||
@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
boolean strict
|
||||
) {
|
||||
if (ancestor == null) return false;
|
||||
DeclarationDescriptor descriptor = strict ? declarationDescriptor.getContainingDeclaration() : declarationDescriptor;
|
||||
while (descriptor != null) {
|
||||
if (ancestor == descriptor) return true;
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSubclass(@NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) {
|
||||
return isSubtypeOfClass(subClass.getDefaultType(), superClass.getOriginal());
|
||||
}
|
||||
|
||||
private static boolean isSubtypeOfClass(@NotNull JetType type, @NotNull DeclarationDescriptor superClass) {
|
||||
DeclarationDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (descriptor != null && superClass == descriptor.getOriginal()) {
|
||||
return true;
|
||||
}
|
||||
for (JetType superType : type.getConstructor().getSupertypes()) {
|
||||
if (isSubtypeOfClass(superType, superClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addSuperTypes(@NotNull JetType type, @NotNull Set<JetType> set) {
|
||||
set.add(type);
|
||||
|
||||
for (JetType jetType : type.getConstructor().getSupertypes()) {
|
||||
addSuperTypes(jetType, set);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRootNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
return namespaceDescriptor.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isFunctionLiteral(@NotNull FunctionDescriptor descriptor) {
|
||||
return descriptor instanceof AnonymousFunctionDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isClassObject(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.CLASS_OBJECT);
|
||||
}
|
||||
|
||||
public static boolean isAnonymous(@NotNull ClassifierDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.OBJECT) && descriptor.getName().isSpecial();
|
||||
}
|
||||
|
||||
public static boolean isEnumEntry(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.ENUM_ENTRY);
|
||||
}
|
||||
|
||||
public static boolean isEnumClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.ENUM_CLASS);
|
||||
}
|
||||
|
||||
public static boolean isAnnotationClass(@Nullable DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.ANNOTATION_CLASS);
|
||||
}
|
||||
|
||||
public static boolean isTrait(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.TRAIT);
|
||||
}
|
||||
|
||||
public static boolean isClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.CLASS);
|
||||
}
|
||||
|
||||
public static boolean isKindOf(@Nullable DeclarationDescriptor descriptor, @NotNull ClassKind classKind) {
|
||||
return descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == classKind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<ClassDescriptor> getSuperclassDescriptors(@NotNull ClassDescriptor classDescriptor) {
|
||||
Collection<JetType> superclassTypes = classDescriptor.getTypeConstructor().getSupertypes();
|
||||
List<ClassDescriptor> superClassDescriptors = new ArrayList<ClassDescriptor>();
|
||||
for (JetType type : superclassTypes) {
|
||||
ClassDescriptor result = getClassDescriptorForType(type);
|
||||
if (!isAny(result)) {
|
||||
superClassDescriptors.add(result);
|
||||
}
|
||||
}
|
||||
return superClassDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getClassDescriptorForType(@NotNull JetType type) {
|
||||
return getClassDescriptorForTypeConstructor(type.getConstructor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getClassDescriptorForTypeConstructor(@NotNull TypeConstructor typeConstructor) {
|
||||
ClassifierDescriptor descriptor = typeConstructor.getDeclarationDescriptor();
|
||||
assert descriptor instanceof ClassDescriptor
|
||||
: "Classifier descriptor of a type should be of type ClassDescriptor: " + typeConstructor;
|
||||
return (ClassDescriptor) descriptor;
|
||||
}
|
||||
|
||||
public static boolean isAny(@NotNull DeclarationDescriptor superClassDescriptor) {
|
||||
return superClassDescriptor.equals(KotlinBuiltIns.getInstance().getAny());
|
||||
}
|
||||
|
||||
public static boolean inStaticContext(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
return true;
|
||||
}
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
|
||||
if (classDescriptor.getKind().isObject()) {
|
||||
return inStaticContext(classDescriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Name getClassObjectName(@NotNull Name className) {
|
||||
return Name.special("<class-object-for-" + className.asString() + ">");
|
||||
}
|
||||
|
||||
public static boolean isEnumClassObject(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == ClassKind.CLASS_OBJECT) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
if ((containing instanceof ClassDescriptor) && ((ClassDescriptor) containing).getKind() == ClassKind.ENUM_CLASS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Visibility getDefaultConstructorVisibility(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassKind classKind = classDescriptor.getKind();
|
||||
if (classKind == ClassKind.ENUM_CLASS) {
|
||||
return Visibilities.PRIVATE;
|
||||
}
|
||||
if (classKind.isObject()) {
|
||||
return Visibilities.PRIVATE;
|
||||
}
|
||||
assert classKind == ClassKind.CLASS || classKind == ClassKind.TRAIT || classKind == ClassKind.ANNOTATION_CLASS;
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getSortedValueArguments(
|
||||
@NotNull AnnotationDescriptor descriptor,
|
||||
@Nullable DescriptorRenderer rendererForTypesIfNecessary
|
||||
) {
|
||||
List<String> resultList = Lists.newArrayList();
|
||||
for (Map.Entry<ValueParameterDescriptor, CompileTimeConstant<?>> entry : descriptor.getAllValueArguments().entrySet()) {
|
||||
CompileTimeConstant<?> value = entry.getValue();
|
||||
String typeSuffix = rendererForTypesIfNecessary == null
|
||||
? ""
|
||||
: ": " + rendererForTypesIfNecessary.renderType(value.getType(KotlinBuiltIns.getInstance()));
|
||||
resultList.add(entry.getKey().getName().asString() + " = " + value.toString() + typeSuffix);
|
||||
}
|
||||
Collections.sort(resultList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getInnerClassByName(@NotNull ClassDescriptor classDescriptor, @NotNull String innerClassName) {
|
||||
ClassifierDescriptor classifier = classDescriptor.getDefaultType().getMemberScope().getClassifier(Name.identifier(innerClassName));
|
||||
assert classifier instanceof ClassDescriptor :
|
||||
"Inner class " + innerClassName + " in " + classDescriptor + " should be instance of ClassDescriptor, but was: "
|
||||
+ (classifier == null ? "null" : classifier.getClass());
|
||||
return (ClassDescriptor) classifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptor getConstructorOfDataClass(ClassDescriptor classDescriptor) {
|
||||
ConstructorDescriptor descriptor = getConstructorDescriptorIfOnlyOne(classDescriptor);
|
||||
assert descriptor != null : "Data class must have only one constructor: " + classDescriptor.getConstructors();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptor getConstructorOfSingletonObject(ClassDescriptor classDescriptor) {
|
||||
ConstructorDescriptor descriptor = getConstructorDescriptorIfOnlyOne(classDescriptor);
|
||||
assert descriptor != null : "Class of singleton object must have only one constructor: " + classDescriptor.getConstructors();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ConstructorDescriptor getConstructorDescriptorIfOnlyOne(ClassDescriptor classDescriptor) {
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
return constructors.size() != 1 ? null : constructors.iterator().next();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType getReceiverParameterType(@Nullable ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (receiverParameterDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
return receiverParameterDescriptor.getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getVarargParameterType(@NotNull JetType elementType) {
|
||||
JetType primitiveArrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(elementType);
|
||||
return primitiveArrayType != null ? primitiveArrayType : KotlinBuiltIns.getInstance().getArrayType(Variance.INVARIANT, elementType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetType> getValueParametersTypes(@NotNull List<ValueParameterDescriptor> valueParameters) {
|
||||
List<JetType> parameterTypes = Lists.newArrayList();
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
parameterTypes.add(parameter.getType());
|
||||
}
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
public static boolean isConstructorOfStaticNestedClass(@Nullable CallableDescriptor descriptor) {
|
||||
return descriptor instanceof ConstructorDescriptor && isStaticNestedClass(descriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if descriptor is a class inside another class and does not have access to the outer class
|
||||
*/
|
||||
public static boolean isStaticNestedClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
return descriptor instanceof ClassDescriptor &&
|
||||
containing instanceof ClassDescriptor &&
|
||||
!((ClassDescriptor) descriptor).isInner() &&
|
||||
!((ClassDescriptor) containing).getKind().isObject();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getContainingClass(@NotNull JetScope scope) {
|
||||
DeclarationDescriptor containingDeclaration = scope.getContainingDeclaration();
|
||||
return getParentOfType(containingDeclaration, ClassDescriptor.class, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetScope getStaticNestedClassesScope(@NotNull ClassDescriptor descriptor) {
|
||||
JetScope innerClassesScope = descriptor.getUnsubstitutedInnerClassesScope();
|
||||
return new FilteringScope(innerClassesScope, new Predicate<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).isInner();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
JetType nullableString = TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getStringType());
|
||||
return "valueOf".equals(functionDescriptor.getName().asString())
|
||||
&& methodTypeParameters.size() == 1
|
||||
&& JetTypeChecker.INSTANCE.isSubtypeOf(methodTypeParameters.get(0).getType(), nullableString);
|
||||
}
|
||||
|
||||
public static boolean isEnumValuesMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
return "values".equals(functionDescriptor.getName().asString())
|
||||
&& methodTypeParameters.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<ClassDescriptor> getAllSuperClasses(@NotNull ClassDescriptor klass) {
|
||||
Set<JetType> allSupertypes = TypeUtils.getAllSupertypes(klass.getDefaultType());
|
||||
Set<ClassDescriptor> allSuperclasses = Sets.newHashSet();
|
||||
for (JetType supertype : allSupertypes) {
|
||||
ClassDescriptor superclass = TypeUtils.getClassDescriptor(supertype);
|
||||
assert superclass != null;
|
||||
allSuperclasses.add(superclass);
|
||||
}
|
||||
return allSuperclasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true iff {@code descriptor}'s first non-class container is a namespace
|
||||
*/
|
||||
public static boolean isTopLevelOrInnerClass(@NotNull ClassDescriptor descriptor) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
return isTopLevelDeclaration(descriptor) ||
|
||||
containing instanceof ClassDescriptor && isTopLevelOrInnerClass((ClassDescriptor) containing);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetScope getEnumEntriesScope(@NotNull ClassDescriptor enumClass) {
|
||||
assert enumClass.getKind() == ClassKind.ENUM_CLASS : "Only enum classes have enum entries: " + enumClass;
|
||||
ClassDescriptor classObject = enumClass.getClassObjectDescriptor();
|
||||
assert classObject != null : "Enum class should have a class object: " + enumClass;
|
||||
return classObject.getDefaultType().getMemberScope();
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
|
||||
public interface ExternalOverridabilityCondition {
|
||||
boolean isOverridable(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public final class ImportPath {
|
||||
private final @NotNull FqName fqName;
|
||||
private final @Nullable Name alias;
|
||||
private final boolean isAllUnder;
|
||||
|
||||
public ImportPath(@NotNull FqName fqName, boolean isAllUnder) {
|
||||
this(fqName, isAllUnder, null);
|
||||
}
|
||||
|
||||
public ImportPath(@NotNull FqName fqName, boolean isAllUnder, @Nullable Name alias) {
|
||||
this.fqName = fqName;
|
||||
this.isAllUnder = isAllUnder;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public ImportPath(@NotNull String pathStr) {
|
||||
if (pathStr.endsWith(".*")) {
|
||||
this.isAllUnder = true;
|
||||
this.fqName = new FqName(pathStr.substring(0, pathStr.length() - 2));
|
||||
}
|
||||
else {
|
||||
this.isAllUnder = false;
|
||||
this.fqName = new FqName(pathStr);
|
||||
}
|
||||
|
||||
alias = null;
|
||||
}
|
||||
|
||||
public String getPathStr() {
|
||||
return fqName.asString() + (isAllUnder ? ".*" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPathStr() + (alias != null ? " as " + alias.asString() : "");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FqName fqnPart() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Name getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public boolean hasAlias() {
|
||||
return alias != null;
|
||||
}
|
||||
|
||||
public boolean isAllUnder() {
|
||||
return isAllUnder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Name getImportedName() {
|
||||
if (!isAllUnder()) {
|
||||
return alias != null ? alias : fqName.shortName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ImportPath path = (ImportPath) o;
|
||||
|
||||
if (isAllUnder != path.isAllUnder) return false;
|
||||
if (alias != null ? !alias.equals(path.alias) : path.alias != null) return false;
|
||||
if (!fqName.equals(path.fqName)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = fqName.hashCode();
|
||||
result = 31 * result + (alias != null ? alias.hashCode() : 0);
|
||||
result = 31 * result + (isAllUnder ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,650 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyAccessorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.CONFLICT;
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE;
|
||||
|
||||
public class OverridingUtil {
|
||||
|
||||
private static final List<ExternalOverridabilityCondition> EXTERNAL_CONDITIONS =
|
||||
ContainerUtil.collect(ServiceLoader.load(
|
||||
ExternalOverridabilityCondition.class,
|
||||
ExternalOverridabilityCondition.class.getClassLoader()).iterator()
|
||||
);
|
||||
|
||||
private OverridingUtil() {
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> Set<D> filterOverrides(Set<D> candidateSet) {
|
||||
return filterOverrides(candidateSet, Function.ID);
|
||||
}
|
||||
|
||||
public static <D> Set<D> filterOverrides(Set<D> candidateSet, Function<? super D, ? extends CallableDescriptor> transform) {
|
||||
Set<D> candidates = Sets.newLinkedHashSet();
|
||||
outerLoop:
|
||||
for (D meD : candidateSet) {
|
||||
CallableDescriptor me = transform.fun(meD);
|
||||
for (D otherD : candidateSet) {
|
||||
CallableDescriptor other = transform.fun(otherD);
|
||||
if (me == other) continue;
|
||||
if (overrides(other, me)) {
|
||||
continue outerLoop;
|
||||
}
|
||||
}
|
||||
for (D otherD : candidates) {
|
||||
CallableDescriptor other = transform.fun(otherD);
|
||||
if (me.getOriginal() == other.getOriginal()
|
||||
&& isOverridableBy(other, me).getResult() == OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
&& isOverridableBy(me, other).getResult() == OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
continue outerLoop;
|
||||
}
|
||||
}
|
||||
// System.out.println(me);
|
||||
candidates.add(meD);
|
||||
}
|
||||
// Set<D> candidates = Sets.newLinkedHashSet(candidateSet);
|
||||
// for (D descriptor : candidateSet) {
|
||||
// Set<CallableDescriptor> overriddenDescriptors = Sets.newHashSet();
|
||||
// getAllOverriddenDescriptors(descriptor.getOriginal(), overriddenDescriptors);
|
||||
// candidates.removeAll(overriddenDescriptors);
|
||||
// }
|
||||
return candidates;
|
||||
}
|
||||
|
||||
public static <Descriptor extends CallableDescriptor> boolean overrides(@NotNull Descriptor f, @NotNull Descriptor g) {
|
||||
Set<CallableDescriptor> overriddenDescriptors = Sets.newHashSet();
|
||||
getAllOverriddenDescriptors(f.getOriginal(), overriddenDescriptors);
|
||||
CallableDescriptor originalG = g.getOriginal();
|
||||
for (CallableDescriptor overriddenFunction : overriddenDescriptors) {
|
||||
if (originalG.equals(overriddenFunction.getOriginal())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void getAllOverriddenDescriptors(@NotNull CallableDescriptor current, @NotNull Set<CallableDescriptor> overriddenDescriptors) {
|
||||
if (overriddenDescriptors.contains(current)) return;
|
||||
for (CallableDescriptor descriptor : current.getOriginal().getOverriddenDescriptors()) {
|
||||
getAllOverriddenDescriptors(descriptor, overriddenDescriptors);
|
||||
overriddenDescriptors.add(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo isOverridableBy(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
if (superDescriptor instanceof FunctionDescriptor) {
|
||||
if (!(subDescriptor instanceof FunctionDescriptor)) return OverrideCompatibilityInfo.memberKindMismatch();
|
||||
}
|
||||
else if (superDescriptor instanceof PropertyDescriptor) {
|
||||
if (!(subDescriptor instanceof PropertyDescriptor)) return OverrideCompatibilityInfo.memberKindMismatch();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("This type of CallableDescriptor cannot be checked for overridability: " + superDescriptor);
|
||||
}
|
||||
|
||||
// TODO: check outside of this method
|
||||
if (!superDescriptor.getName().equals(subDescriptor.getName())) {
|
||||
return OverrideCompatibilityInfo.nameMismatch();
|
||||
}
|
||||
|
||||
return isOverridableByImpl(superDescriptor, subDescriptor, true);
|
||||
}
|
||||
|
||||
private static List<JetType> compiledValueParameters(CallableDescriptor callableDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = callableDescriptor.getReceiverParameter();
|
||||
ArrayList<JetType> parameters = new ArrayList<JetType>();
|
||||
if (receiverParameter != null) {
|
||||
parameters.add(receiverParameter.getType());
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : callableDescriptor.getValueParameters()) {
|
||||
parameters.add(valueParameterDescriptor.getType());
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param forOverride true for override, false for overload
|
||||
*/
|
||||
static OverrideCompatibilityInfo isOverridableByImpl(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor, boolean forOverride) {
|
||||
|
||||
// TODO : Visibility
|
||||
|
||||
if ((superDescriptor.getReceiverParameter() == null) != (subDescriptor.getReceiverParameter() == null)) {
|
||||
return OverrideCompatibilityInfo.receiverPresenceMismatch();
|
||||
}
|
||||
|
||||
if (superDescriptor.getValueParameters().size() != subDescriptor.getValueParameters().size()) {
|
||||
return OverrideCompatibilityInfo.valueParameterNumberMismatch();
|
||||
}
|
||||
|
||||
List<JetType> superValueParameters = compiledValueParameters(superDescriptor);
|
||||
List<JetType> subValueParameters = compiledValueParameters(subDescriptor);
|
||||
|
||||
if (forOverride) {
|
||||
if (superDescriptor.getTypeParameters().size() != subDescriptor.getTypeParameters().size()) {
|
||||
for (int i = 0; i < superValueParameters.size(); ++i) {
|
||||
JetType superValueParameterType = getUpperBound(superValueParameters.get(i));
|
||||
JetType subValueParameterType = getUpperBound(subValueParameters.get(i));
|
||||
// TODO: compare erasure
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(superValueParameterType, subValueParameterType)) {
|
||||
return OverrideCompatibilityInfo.typeParameterNumberMismatch();
|
||||
}
|
||||
}
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(null, null, OverrideCompatibilityInfo.Result.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
if (forOverride) {
|
||||
|
||||
List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
|
||||
List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();
|
||||
|
||||
BiMap<TypeConstructor, TypeConstructor> axioms = HashBiMap.create();
|
||||
for (int i = 0, typeParametersSize = superTypeParameters.size(); i < typeParametersSize; i++) {
|
||||
TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
|
||||
TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
|
||||
axioms.put(superTypeParameter.getTypeConstructor(), subTypeParameter.getTypeConstructor());
|
||||
}
|
||||
|
||||
for (int i = 0, typeParametersSize = superTypeParameters.size(); i < typeParametersSize; i++) {
|
||||
TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
|
||||
TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
|
||||
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(superTypeParameter.getUpperBoundsAsType(), subTypeParameter.getUpperBoundsAsType(), axioms)) {
|
||||
return OverrideCompatibilityInfo.boundsMismatch(superTypeParameter, subTypeParameter);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0, unsubstitutedValueParametersSize = superValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
|
||||
JetType superValueParameter = superValueParameters.get(i);
|
||||
JetType subValueParameter = subValueParameters.get(i);
|
||||
|
||||
boolean bothErrors = superValueParameter.isError() && subValueParameter.isError();
|
||||
if (!bothErrors && !JetTypeChecker.INSTANCE.equalTypes(superValueParameter, subValueParameter, axioms)) {
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameter, subValueParameter, OverrideCompatibilityInfo.Result.INCOMPATIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
for (ExternalOverridabilityCondition externalCondition : EXTERNAL_CONDITIONS) {
|
||||
if (!externalCondition.isOverridable(superDescriptor, subDescriptor)) {
|
||||
return OverrideCompatibilityInfo.externalConditionFailed(externalCondition.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
for (int i = 0; i < superValueParameters.size(); ++i) {
|
||||
JetType superValueParameterType = getUpperBound(superValueParameters.get(i));
|
||||
JetType subValueParameterType = getUpperBound(subValueParameters.get(i));
|
||||
// TODO: compare erasure
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(superValueParameterType, subValueParameterType)) {
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, OverrideCompatibilityInfo.Result.INCOMPATIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
return OverrideCompatibilityInfo.success();
|
||||
|
||||
}
|
||||
|
||||
// TODO : Default values, varargs etc
|
||||
|
||||
return OverrideCompatibilityInfo.success();
|
||||
}
|
||||
|
||||
private static JetType getUpperBound(JetType type) {
|
||||
if (type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) {
|
||||
return type;
|
||||
}
|
||||
else if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
||||
return ((TypeParameterDescriptor) type.getConstructor().getDeclarationDescriptor()).getUpperBoundsAsType();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("unknown type constructor: " + type.getConstructor().getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isReturnTypeOkForOverride(@NotNull JetTypeChecker typeChecker, @NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
TypeSubstitutor typeSubstitutor = prepareTypeSubstitutor(superDescriptor, subDescriptor);
|
||||
if (typeSubstitutor == null) return false;
|
||||
|
||||
JetType superReturnType = superDescriptor.getReturnType();
|
||||
assert superReturnType != null;
|
||||
|
||||
JetType subReturnType = subDescriptor.getReturnType();
|
||||
assert subReturnType != null;
|
||||
|
||||
JetType substitutedSuperReturnType = typeSubstitutor.substitute(superReturnType, Variance.OUT_VARIANCE);
|
||||
assert substitutedSuperReturnType != null;
|
||||
|
||||
return typeChecker.isSubtypeOf(subReturnType, substitutedSuperReturnType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static TypeSubstitutor prepareTypeSubstitutor(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
|
||||
List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();
|
||||
if (subTypeParameters.size() != superTypeParameters.size()) return null;
|
||||
|
||||
Map<TypeConstructor, TypeProjection> substitutionContext = Maps.newHashMap();
|
||||
for (int i = 0; i < superTypeParameters.size(); i++) {
|
||||
TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
|
||||
TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
|
||||
substitutionContext.put(
|
||||
superTypeParameter.getTypeConstructor(),
|
||||
new TypeProjection(subTypeParameter.getDefaultType()));
|
||||
}
|
||||
return TypeSubstitutor.create(substitutionContext);
|
||||
}
|
||||
|
||||
public static boolean isPropertyTypeOkForOverride(@NotNull JetTypeChecker typeChecker, @NotNull PropertyDescriptor superDescriptor, @NotNull PropertyDescriptor subDescriptor) {
|
||||
TypeSubstitutor typeSubstitutor = prepareTypeSubstitutor(superDescriptor, subDescriptor);
|
||||
JetType substitutedSuperReturnType = typeSubstitutor.substitute(superDescriptor.getReturnType(), Variance.OUT_VARIANCE);
|
||||
assert substitutedSuperReturnType != null;
|
||||
if (superDescriptor.isVar() && !typeChecker.equalTypes(subDescriptor.getReturnType(), substitutedSuperReturnType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get overridden descriptors that are declarations or delegations.
|
||||
*
|
||||
* @see CallableMemberDescriptor.Kind#isReal()
|
||||
*/
|
||||
public static Collection<CallableMemberDescriptor> getOverriddenDeclarations(CallableMemberDescriptor descriptor) {
|
||||
Map<ClassDescriptor, CallableMemberDescriptor> result = Maps.newHashMap();
|
||||
getOverriddenDeclarations(descriptor, result);
|
||||
return result.values();
|
||||
}
|
||||
|
||||
private static void getOverriddenDeclarations(CallableMemberDescriptor descriptor, Map<ClassDescriptor, CallableMemberDescriptor> r) {
|
||||
if (descriptor.getKind().isReal()) {
|
||||
r.put((ClassDescriptor) descriptor.getContainingDeclaration(), descriptor);
|
||||
}
|
||||
else {
|
||||
if (descriptor.getOverriddenDescriptors().isEmpty()) {
|
||||
throw new IllegalStateException("No overridden descriptors found for (fake override) " + descriptor);
|
||||
}
|
||||
for (CallableMemberDescriptor overridden : descriptor.getOverriddenDescriptors()) {
|
||||
getOverriddenDeclarations(overridden, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void bindOverride(CallableMemberDescriptor fromCurrent, CallableMemberDescriptor fromSupertype) {
|
||||
fromCurrent.addOverriddenDescriptor(fromSupertype);
|
||||
|
||||
for (ValueParameterDescriptor parameterFromCurrent : fromCurrent.getValueParameters()) {
|
||||
assert parameterFromCurrent.getIndex() < fromSupertype.getValueParameters().size()
|
||||
: "An override relation between functions implies that they have the same number of value parameters";
|
||||
ValueParameterDescriptor parameterFromSupertype = fromSupertype.getValueParameters().get(parameterFromCurrent.getIndex());
|
||||
parameterFromCurrent.addOverriddenDescriptor(parameterFromSupertype);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateOverridesInFunctionGroup(
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@NotNull Name name, //DO NOT DELETE THIS PARAMETER: needed to make sure all descriptors have the same name
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromSupertypes,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromCurrent,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> notOverridden = Sets.newLinkedHashSet(membersFromSupertypes);
|
||||
|
||||
for (CallableMemberDescriptor fromCurrent : membersFromCurrent) {
|
||||
Collection<CallableMemberDescriptor> bound =
|
||||
extractAndBindOverridesForMember(fromCurrent, membersFromSupertypes, current, sink);
|
||||
notOverridden.removeAll(bound);
|
||||
}
|
||||
|
||||
createAndBindFakeOverrides(current, notOverridden, sink);
|
||||
}
|
||||
|
||||
private static Collection<CallableMemberDescriptor> extractAndBindOverridesForMember(
|
||||
@NotNull CallableMemberDescriptor fromCurrent,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> descriptorsFromSuper,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> bound = Lists.newArrayList();
|
||||
for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
|
||||
OverrideCompatibilityInfo.Result result = isOverridableBy(fromSupertype, fromCurrent).getResult();
|
||||
|
||||
boolean isVisible = Visibilities.isVisible(fromSupertype, current);
|
||||
switch (result) {
|
||||
case OVERRIDABLE:
|
||||
if (isVisible) {
|
||||
bindOverride(fromCurrent, fromSupertype);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case CONFLICT:
|
||||
if (isVisible) {
|
||||
sink.conflict(fromSupertype, fromCurrent);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case INCOMPATIBLE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bound;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverrides(
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> notOverridden,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Queue<CallableMemberDescriptor> fromSuperQueue = new LinkedList<CallableMemberDescriptor>(notOverridden);
|
||||
while (!fromSuperQueue.isEmpty()) {
|
||||
CallableMemberDescriptor notOverriddenFromSuper = VisibilityUtil.findMemberWithMaxVisibility(fromSuperQueue);
|
||||
Collection<CallableMemberDescriptor> overridables =
|
||||
extractMembersOverridableInBothWays(notOverriddenFromSuper, fromSuperQueue, sink);
|
||||
createAndBindFakeOverride(overridables, current, sink);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMoreSpecific(@NotNull CallableMemberDescriptor a, @NotNull CallableMemberDescriptor b) {
|
||||
if (a instanceof SimpleFunctionDescriptor) {
|
||||
assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();
|
||||
|
||||
JetType aReturnType = a.getReturnType();
|
||||
assert aReturnType != null;
|
||||
JetType bReturnType = b.getReturnType();
|
||||
assert bReturnType != null;
|
||||
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(aReturnType, bReturnType);
|
||||
}
|
||||
if (a instanceof PropertyDescriptor) {
|
||||
assert b instanceof PropertyDescriptor : "b is " + b.getClass();
|
||||
|
||||
if (((PropertyDescriptor) a).isVar() || ((PropertyDescriptor) b).isVar()) {
|
||||
return ((PropertyDescriptor) a).isVar();
|
||||
}
|
||||
|
||||
// both vals
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(((PropertyDescriptor) a).getType(), ((PropertyDescriptor) b).getType());
|
||||
}
|
||||
throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
|
||||
}
|
||||
|
||||
private static CallableMemberDescriptor selectMostSpecificMemberFromSuper(@NotNull Collection<CallableMemberDescriptor> overridables) {
|
||||
CallableMemberDescriptor result = null;
|
||||
for (CallableMemberDescriptor overridable : overridables) {
|
||||
if (result == null || isMoreSpecific(overridable, result)) {
|
||||
result = overridable;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverride(
|
||||
@NotNull Collection<CallableMemberDescriptor> overridables,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> visibleOverridables = filterVisibleFakeOverrides(current, overridables);
|
||||
Modality modality = getMinimalModality(visibleOverridables);
|
||||
boolean allInvisible = visibleOverridables.isEmpty();
|
||||
Collection<CallableMemberDescriptor> effectiveOverridden = allInvisible ? overridables : visibleOverridables;
|
||||
Visibility visibility = allInvisible ? Visibilities.INVISIBLE_FAKE : Visibilities.INHERITED;
|
||||
CallableMemberDescriptor mostSpecific = selectMostSpecificMemberFromSuper(effectiveOverridden);
|
||||
CallableMemberDescriptor fakeOverride =
|
||||
mostSpecific.copy(current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||
for (CallableMemberDescriptor descriptor : effectiveOverridden) {
|
||||
bindOverride(fakeOverride, descriptor);
|
||||
}
|
||||
sink.addToScope(fakeOverride);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Modality getMinimalModality(@NotNull Collection<CallableMemberDescriptor> descriptors) {
|
||||
Modality modality = Modality.ABSTRACT;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
if (descriptor.getModality().compareTo(modality) < 0) {
|
||||
modality = descriptor.getModality();
|
||||
}
|
||||
}
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> filterVisibleFakeOverrides(
|
||||
@NotNull final ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> toFilter
|
||||
) {
|
||||
return Collections2.filter(toFilter, new Predicate<CallableMemberDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable CallableMemberDescriptor descriptor) {
|
||||
//nested class could capture private member, so check for private visibility added
|
||||
return descriptor != null &&
|
||||
descriptor.getVisibility() != Visibilities.PRIVATE &&
|
||||
Visibilities.isVisible(descriptor, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> extractMembersOverridableInBothWays(
|
||||
@NotNull CallableMemberDescriptor overrider,
|
||||
@NotNull Queue<CallableMemberDescriptor> extractFrom,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> overridable = Lists.newArrayList();
|
||||
overridable.add(overrider);
|
||||
for (Iterator<CallableMemberDescriptor> iterator = extractFrom.iterator(); iterator.hasNext(); ) {
|
||||
CallableMemberDescriptor candidate = iterator.next();
|
||||
if (overrider == candidate) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
OverrideCompatibilityInfo.Result result1 = isOverridableBy(candidate, overrider).getResult();
|
||||
OverrideCompatibilityInfo.Result result2 = isOverridableBy(overrider, candidate).getResult();
|
||||
if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
|
||||
overridable.add(candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
else if (result1 == CONFLICT || result2 == CONFLICT) {
|
||||
sink.conflict(overrider, candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return overridable;
|
||||
}
|
||||
|
||||
public static void resolveUnknownVisibilityForMember(
|
||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||
@NotNull NotInferredVisibilitySink sink
|
||||
) {
|
||||
for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
|
||||
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
||||
resolveUnknownVisibilityForMember(descriptor, sink);
|
||||
}
|
||||
}
|
||||
|
||||
if (memberDescriptor.getVisibility() != Visibilities.INHERITED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Visibility visibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||
if (visibility == null) {
|
||||
sink.cannotInferVisibility(memberDescriptor);
|
||||
visibility = Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||
((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
||||
resolveUnknownVisibilityForMember(accessor, sink);
|
||||
}
|
||||
}
|
||||
else if (memberDescriptor instanceof FunctionDescriptorImpl) {
|
||||
((FunctionDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
else {
|
||||
assert memberDescriptor instanceof PropertyAccessorDescriptorImpl;
|
||||
((PropertyAccessorDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Visibility findMaxVisibility(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||
if (descriptors.isEmpty()) {
|
||||
return Visibilities.INTERNAL;
|
||||
}
|
||||
Visibility maxVisibility = null;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Visibility visibility = descriptor.getVisibility();
|
||||
assert visibility != Visibilities.INHERITED;
|
||||
if (maxVisibility == null) {
|
||||
maxVisibility = visibility;
|
||||
continue;
|
||||
}
|
||||
Integer compareResult = Visibilities.compare(visibility, maxVisibility);
|
||||
if (compareResult == null) {
|
||||
maxVisibility = null;
|
||||
}
|
||||
else if (compareResult > 0) {
|
||||
maxVisibility = visibility;
|
||||
}
|
||||
}
|
||||
if (maxVisibility == null) {
|
||||
return null;
|
||||
}
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
|
||||
if (compareResult == null || compareResult < 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return maxVisibility;
|
||||
}
|
||||
|
||||
public interface DescriptorSink {
|
||||
void addToScope(@NotNull CallableMemberDescriptor fakeOverride);
|
||||
|
||||
void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent);
|
||||
}
|
||||
|
||||
public interface NotInferredVisibilitySink {
|
||||
void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor);
|
||||
}
|
||||
|
||||
public static class OverrideCompatibilityInfo {
|
||||
|
||||
public enum Result {
|
||||
OVERRIDABLE,
|
||||
INCOMPATIBLE,
|
||||
CONFLICT,
|
||||
}
|
||||
|
||||
private static final OverrideCompatibilityInfo SUCCESS = new OverrideCompatibilityInfo(Result.OVERRIDABLE, "SUCCESS");
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo success() {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo nameMismatch() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "nameMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo typeParameterNumberMismatch() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "typeParameterNumberMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo receiverPresenceMismatch() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "receiverPresenceMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo valueParameterNumberMismatch() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "valueParameterNumberMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo boundsMismatch(TypeParameterDescriptor superTypeParameter, TypeParameterDescriptor subTypeParameter) {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "boundsMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo valueParameterTypeMismatch(JetType superValueParameter, JetType subValueParameter, Result result) {
|
||||
return new OverrideCompatibilityInfo(result, "valueParameterTypeMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo memberKindMismatch() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "memberKindMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo returnTypeMismatch(JetType substitutedSuperReturnType, JetType unsubstitutedSubReturnType) {
|
||||
return new OverrideCompatibilityInfo(Result.CONFLICT, "returnTypeMismatch: " + unsubstitutedSubReturnType + " >< " + substitutedSuperReturnType); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo varOverriddenByVal() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "varOverriddenByVal"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo externalConditionFailed(Class<? extends ExternalOverridabilityCondition> conditionClass) {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "externalConditionFailed: " + conditionClass.getName()); // TODO
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final Result overridable;
|
||||
private final String message;
|
||||
|
||||
public OverrideCompatibilityInfo(Result success, String message) {
|
||||
this.overridable = success;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return overridable;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public class VisibilityUtil {
|
||||
@NotNull
|
||||
public static CallableMemberDescriptor findMemberWithMaxVisibility(@NotNull Queue<CallableMemberDescriptor> descriptors) {
|
||||
CallableMemberDescriptor descriptor = descriptors.element();
|
||||
for (CallableMemberDescriptor candidate : descriptors) {
|
||||
Integer result = Visibilities.compare(descriptor.getVisibility(), candidate.getVisibility());
|
||||
if (result != null && result < 0) {
|
||||
descriptor = candidate;
|
||||
}
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ConstraintPosition {
|
||||
public static final ConstraintPosition RECEIVER_POSITION = new ConstraintPosition("RECEIVER_POSITION");
|
||||
public static final ConstraintPosition EXPECTED_TYPE_POSITION = new ConstraintPosition("EXPECTED_TYPE_POSITION");
|
||||
public static final ConstraintPosition BOUND_CONSTRAINT_POSITION = new ConstraintPosition("BOUND_CONSTRAINT_POSITION");
|
||||
public static final ConstraintPosition FROM_COMPLETER = new ConstraintPosition("FROM_COMPLETER");
|
||||
public static final ConstraintPosition SPECIAL = new ConstraintPosition("SPECIAL");
|
||||
|
||||
private static final Map<Integer, ConstraintPosition> valueParameterPositions = Maps.newHashMap();
|
||||
|
||||
public static ConstraintPosition getValueParameterPosition(int index) {
|
||||
ConstraintPosition position = valueParameterPositions.get(index);
|
||||
if (position == null) {
|
||||
position = new ConstraintPosition("VALUE_PARAMETER_POSITION(" + index + ")");
|
||||
valueParameterPositions.put(index, position);
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private final String debugName;
|
||||
|
||||
private ConstraintPosition(String name) {
|
||||
debugName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ConstraintSystem {
|
||||
|
||||
/**
|
||||
* Registers a variable in a constraint system.
|
||||
*/
|
||||
void registerTypeVariable(@NotNull TypeParameterDescriptor typeVariable, @NotNull Variance positionVariance);
|
||||
|
||||
/**
|
||||
* Returns a set of all registered type variables.
|
||||
*/
|
||||
@NotNull
|
||||
Set<TypeParameterDescriptor> getTypeVariables();
|
||||
|
||||
/**
|
||||
* Adds a constraint that the constraining type is a subtype of the subject type.<p/>
|
||||
* Asserts that only subject type may contain registered type variables. <p/>
|
||||
*
|
||||
* For example, for {@code "fun <T> id(t: T) {}"} to infer <tt>T</tt> in invocation <tt>"id(1)"</tt>
|
||||
* should be generated a constraint <tt>"Int is a subtype of T"</tt> where T is a subject type, and Int is a constraining type.
|
||||
*/
|
||||
void addSubtypeConstraint(@Nullable JetType constrainingType, @NotNull JetType subjectType, @NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
/**
|
||||
* Adds a constraint that the constraining type is a supertype of the subject type. <p/>
|
||||
* Asserts that only subject type may contain registered type variables. <p/>
|
||||
*
|
||||
* For example, for {@code "fun <T> create() : T"} to infer <tt>T</tt> in invocation <tt>"val i: Int = create()"</tt>
|
||||
* should be generated a constraint <tt>"Int is a supertype of T"</tt> where T is a subject type, and Int is a constraining type.
|
||||
*/
|
||||
void addSupertypeConstraint(@Nullable JetType constrainingType, @NotNull JetType subjectType, @NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
@NotNull
|
||||
ConstraintSystemStatus getStatus();
|
||||
|
||||
/**
|
||||
* Returns the resulting type constraints of solving the constraint system for specific type variable. <p/>
|
||||
* Returns null if the type variable was not registered.
|
||||
*/
|
||||
@NotNull
|
||||
TypeConstraints getTypeConstraints(@NotNull TypeParameterDescriptor typeVariable);
|
||||
|
||||
/**
|
||||
* Returns a result of solving the constraint system (mapping from the type variable to the resulting type projection). <p/>
|
||||
* In the resulting substitution should be concerned: <p/>
|
||||
* - type constraints <p/>
|
||||
* - variance of the type variable // not implemented yet <p/>
|
||||
* - type parameter bounds (that can bind type variables with each other). // not implemented yet
|
||||
* If the addition of the 'expected type' constraint made the system fail,
|
||||
* this constraint is not included in the resulting substitution.
|
||||
*/
|
||||
@NotNull
|
||||
TypeSubstitutor getResultingSubstitutor();
|
||||
|
||||
/**
|
||||
* Returns a current result of solving the constraint system (mapping from the type variable to the resulting type projection).
|
||||
* If there is no information for type parameter, returns type projection for DONT_CARE type.
|
||||
*/
|
||||
@NotNull
|
||||
TypeSubstitutor getCurrentSubstitutor();
|
||||
|
||||
ConstraintSystem copy();
|
||||
}
|
||||
+423
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
|
||||
import org.jetbrains.jet.lang.types.checker.TypingConstraints;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.BoundKind;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.BoundKind.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.*;
|
||||
|
||||
public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
|
||||
public enum ConstraintKind {
|
||||
SUB_TYPE, EQUAL
|
||||
}
|
||||
|
||||
private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap();
|
||||
private final Set<ConstraintPosition> errorConstraintPositions = Sets.newHashSet();
|
||||
private final TypeSubstitutor resultingSubstitutor;
|
||||
private final TypeSubstitutor currentSubstitutor;
|
||||
private boolean hasErrorInConstrainingTypes;
|
||||
|
||||
@Nullable
|
||||
private ConstraintSystem systemWithoutExpectedTypeConstraint;
|
||||
|
||||
private final ConstraintSystemStatus constraintSystemStatus = new ConstraintSystemStatus() {
|
||||
@Override
|
||||
public boolean isSuccessful() {
|
||||
return !hasContradiction() && !hasUnknownParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContradiction() {
|
||||
return hasTypeConstructorMismatch() || hasConflictingConstraints();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConflictingConstraints() {
|
||||
for (TypeParameterDescriptor typeParameter : typeParameterConstraints.keySet()) {
|
||||
TypeConstraints typeConstraints = getTypeConstraints(typeParameter);
|
||||
if (typeConstraints.getValues().size() > 1) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnknownParameters() {
|
||||
for (TypeConstraintsImpl constraints : typeParameterConstraints.values()) {
|
||||
if (constraints.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTypeConstructorMismatch() {
|
||||
return !errorConstraintPositions.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition) {
|
||||
return errorConstraintPositions.contains(constraintPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOnlyExpectedTypeMismatch() {
|
||||
if (systemWithoutExpectedTypeConstraint == null) {
|
||||
// the expected type constraint isn't added, there can't be an error with it
|
||||
return false;
|
||||
}
|
||||
if (!isSuccessful() && systemWithoutExpectedTypeConstraint.getStatus().isSuccessful()) {
|
||||
return true;
|
||||
}
|
||||
if (errorConstraintPositions.size() == 1 && errorConstraintPositions.contains(ConstraintPosition.EXPECTED_TYPE_POSITION)) {
|
||||
// if systemWithoutExpectedTypeConstraint has unknown type parameters, it's not successful,
|
||||
// but there can be expected type mismatch after expected type is added
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasErrorInConstrainingTypes() {
|
||||
return hasErrorInConstrainingTypes;
|
||||
}
|
||||
};
|
||||
|
||||
public ConstraintSystemImpl() {
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(
|
||||
TypeUtils.CANT_INFER_TYPE_PARAMETER));
|
||||
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(TypeUtils.DONT_CARE));
|
||||
}
|
||||
|
||||
private TypeSubstitutor createTypeSubstitutorWithDefaultForUnknownTypeParameter(@Nullable final TypeProjection defaultTypeProjection) {
|
||||
return TypeSubstitutor.create(new TypeSubstitution() {
|
||||
@Override
|
||||
public TypeProjection get(TypeConstructor key) {
|
||||
DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor();
|
||||
if (declarationDescriptor instanceof TypeParameterDescriptor) {
|
||||
TypeParameterDescriptor descriptor = (TypeParameterDescriptor) declarationDescriptor;
|
||||
|
||||
if (typeParameterConstraints.containsKey(descriptor)) {
|
||||
JetType value = getTypeConstraints(descriptor).getValue();
|
||||
if (value != null && !TypeUtils.equalsOrContainsAsArgument(value, TypeUtils.DONT_CARE)) {
|
||||
return new TypeProjection(value);
|
||||
}
|
||||
return defaultTypeProjection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return typeParameterConstraints.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstraintSystemStatus getStatus() {
|
||||
return constraintSystemStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTypeVariable(@NotNull TypeParameterDescriptor typeVariable, @NotNull Variance positionVariance) {
|
||||
typeParameterConstraints.put(typeVariable, new TypeConstraintsImpl(positionVariance));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConstraintSystem copy() {
|
||||
return replaceTypeVariables(Functions.<TypeParameterDescriptor>identity(), true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConstraintSystem replaceTypeVariables(@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
||||
return replaceTypeVariables(typeVariablesMap, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ConstraintSystem replaceTypeVariables(
|
||||
@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap,
|
||||
boolean recreateTypeConstraints
|
||||
) {
|
||||
ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl();
|
||||
for (Map.Entry<TypeParameterDescriptor, TypeConstraintsImpl> entry : typeParameterConstraints.entrySet()) {
|
||||
TypeParameterDescriptor typeParameter = entry.getKey();
|
||||
TypeConstraintsImpl typeConstraints = entry.getValue();
|
||||
|
||||
TypeParameterDescriptor newTypeParameter = typeVariablesMap.apply(typeParameter);
|
||||
assert newTypeParameter != null;
|
||||
newConstraintSystem.typeParameterConstraints.put(newTypeParameter, recreateTypeConstraints ? typeConstraints.copy() : typeConstraints);
|
||||
}
|
||||
newConstraintSystem.errorConstraintPositions.addAll(errorConstraintPositions);
|
||||
newConstraintSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes;
|
||||
return newConstraintSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupertypeConstraint(
|
||||
@Nullable JetType constrainingType,
|
||||
@NotNull JetType subjectType,
|
||||
@NotNull ConstraintPosition constraintPosition
|
||||
) {
|
||||
if (constrainingType != null && TypeUtils.noExpectedType(constrainingType)) return;
|
||||
|
||||
if (constraintPosition == ConstraintPosition.EXPECTED_TYPE_POSITION) {
|
||||
systemWithoutExpectedTypeConstraint = copy();
|
||||
}
|
||||
addConstraint(SUB_TYPE, subjectType, constrainingType, constraintPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubtypeConstraint(
|
||||
@Nullable JetType constrainingType,
|
||||
@NotNull JetType subjectType,
|
||||
@NotNull ConstraintPosition constraintPosition
|
||||
) {
|
||||
addConstraint(SUB_TYPE, constrainingType, subjectType, constraintPosition);
|
||||
}
|
||||
|
||||
private void addConstraint(
|
||||
@NotNull ConstraintKind constraintKind,
|
||||
@Nullable JetType subType,
|
||||
@Nullable JetType superType,
|
||||
@NotNull final ConstraintPosition constraintPosition
|
||||
) {
|
||||
TypeCheckingProcedure typeCheckingProcedure = new TypeCheckingProcedure(new TypingConstraints() {
|
||||
@Override
|
||||
public boolean assertEqualTypes(
|
||||
@NotNull JetType a, @NotNull JetType b, @NotNull TypeCheckingProcedure typeCheckingProcedure
|
||||
) {
|
||||
doAddConstraint(EQUAL, a, b, constraintPosition, typeCheckingProcedure);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean assertEqualTypeConstructors(
|
||||
@NotNull TypeConstructor a, @NotNull TypeConstructor b
|
||||
) {
|
||||
throw new IllegalStateException("'assertEqualTypeConstructors' shouldn't be invoked inside 'isSubtypeOf'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean assertSubtype(
|
||||
@NotNull JetType subtype, @NotNull JetType supertype, @NotNull TypeCheckingProcedure typeCheckingProcedure
|
||||
) {
|
||||
doAddConstraint(SUB_TYPE, subtype, supertype, constraintPosition, typeCheckingProcedure);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noCorrespondingSupertype(
|
||||
@NotNull JetType subtype, @NotNull JetType supertype
|
||||
) {
|
||||
errorConstraintPositions.add(constraintPosition);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
doAddConstraint(constraintKind, subType, superType, constraintPosition, typeCheckingProcedure);
|
||||
}
|
||||
|
||||
private boolean isErrorOrSpecialType(@Nullable JetType type) {
|
||||
if (type == TypeUtils.DONT_CARE || type == TypeUtils.CANT_INFER_TYPE_PARAMETER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type == null || (type.isError() && type != TypeUtils.PLACEHOLDER_FUNCTION_TYPE)) {
|
||||
hasErrorInConstrainingTypes = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void doAddConstraint(
|
||||
@NotNull ConstraintKind constraintKind,
|
||||
@Nullable JetType subType,
|
||||
@Nullable JetType superType,
|
||||
@NotNull ConstraintPosition constraintPosition,
|
||||
@NotNull TypeCheckingProcedure typeCheckingProcedure
|
||||
) {
|
||||
|
||||
if (isErrorOrSpecialType(subType) || isErrorOrSpecialType(superType)) return;
|
||||
assert subType != null && superType != null;
|
||||
|
||||
assert superType != TypeUtils.PLACEHOLDER_FUNCTION_TYPE : "The type for " + constraintPosition + " shouldn't be a placeholder for function type";
|
||||
|
||||
KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance();
|
||||
if (subType == TypeUtils.PLACEHOLDER_FUNCTION_TYPE) {
|
||||
if (!kotlinBuiltIns.isFunctionOrExtensionFunctionType(superType)) {
|
||||
if (isMyTypeVariable(superType)) {
|
||||
// a constraint binds type parameter and any function type, so there is no new info and no error
|
||||
return;
|
||||
}
|
||||
errorConstraintPositions.add(constraintPosition);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// todo temporary hack
|
||||
// function literal without declaring receiver type { x -> ... }
|
||||
// can be considered as extension function if one is expected
|
||||
// (special type constructor for function/ extension function should be introduced like PLACEHOLDER_FUNCTION_TYPE)
|
||||
if (constraintKind == SUB_TYPE && kotlinBuiltIns.isFunctionType(subType) && kotlinBuiltIns.isExtensionFunctionType(superType)) {
|
||||
subType = createCorrespondingExtensionFunctionType(subType, TypeUtils.DONT_CARE);
|
||||
}
|
||||
|
||||
// can be equal for the recursive invocations:
|
||||
// fun <T> foo(i: Int) : T { ... return foo(i); } => T <: T
|
||||
if (subType.equals(superType)) return;
|
||||
|
||||
assert !isMyTypeVariable(subType) || !isMyTypeVariable(superType) :
|
||||
"The constraint shouldn't contain different type variables on both sides: " + subType + " <: " + superType;
|
||||
|
||||
|
||||
if (isMyTypeVariable(subType)) {
|
||||
generateTypeParameterConstraint(subType, superType, constraintKind == SUB_TYPE ? UPPER_BOUND : EXACT_BOUND);
|
||||
return;
|
||||
}
|
||||
if (isMyTypeVariable(superType)) {
|
||||
generateTypeParameterConstraint(superType, subType, constraintKind == SUB_TYPE ? LOWER_BOUND : EXACT_BOUND);
|
||||
return;
|
||||
}
|
||||
// if superType is nullable and subType is not nullable, unsafe call error will be generated later,
|
||||
// but constraint system should be solved anyway
|
||||
typeCheckingProcedure.isSubtypeOf(TypeUtils.makeNotNullable(subType), TypeUtils.makeNotNullable(superType));
|
||||
}
|
||||
|
||||
private void generateTypeParameterConstraint(
|
||||
@NotNull JetType parameterType,
|
||||
@NotNull JetType constrainingType,
|
||||
@NotNull BoundKind boundKind
|
||||
) {
|
||||
TypeConstraintsImpl typeConstraints = getTypeConstraints(parameterType);
|
||||
assert typeConstraints != null : "constraint should be generated only for type variables";
|
||||
|
||||
if (parameterType.isNullable()) {
|
||||
// For parameter type T constraint T? <: Int? should transform to T <: Int
|
||||
constrainingType = TypeUtils.makeNotNullable(constrainingType);
|
||||
}
|
||||
typeConstraints.addBound(boundKind, constrainingType);
|
||||
}
|
||||
|
||||
public void processDeclaredBoundConstraints() {
|
||||
for (Map.Entry<TypeParameterDescriptor, TypeConstraintsImpl> entry : typeParameterConstraints.entrySet()) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = entry.getKey();
|
||||
TypeConstraintsImpl typeConstraints = entry.getValue();
|
||||
for (JetType declaredUpperBound : typeParameterDescriptor.getUpperBounds()) {
|
||||
//todo order matters here
|
||||
for (JetType lowerOrExactBound : Sets.union(typeConstraints.getLowerBounds(), typeConstraints.getExactBounds())) {
|
||||
addSubtypeConstraint(lowerOrExactBound, declaredUpperBound, ConstraintPosition.BOUND_CONSTRAINT_POSITION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<TypeParameterDescriptor> getTypeVariables() {
|
||||
return typeParameterConstraints.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TypeConstraints getTypeConstraints(@NotNull TypeParameterDescriptor typeVariable) {
|
||||
TypeConstraintsImpl typeConstraints = typeParameterConstraints.get(typeVariable);
|
||||
assert typeConstraints != null : "TypeParameterDescriptor is not a type variable for constraint system: " + typeVariable;
|
||||
return typeConstraints;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TypeConstraintsImpl getTypeConstraints(@NotNull JetType type) {
|
||||
ClassifierDescriptor parameterDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (parameterDescriptor instanceof TypeParameterDescriptor) {
|
||||
return typeParameterConstraints.get(parameterDescriptor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isMyTypeVariable(@NotNull JetType type) {
|
||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
return descriptor instanceof TypeParameterDescriptor && typeParameterConstraints.get(descriptor) != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitutor getResultingSubstitutor() {
|
||||
if (getStatus().hasOnlyExpectedTypeMismatch()) {
|
||||
assert systemWithoutExpectedTypeConstraint != null;
|
||||
return systemWithoutExpectedTypeConstraint.getResultingSubstitutor();
|
||||
}
|
||||
return resultingSubstitutor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeSubstitutor getCurrentSubstitutor() {
|
||||
return currentSubstitutor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType createCorrespondingExtensionFunctionType(@NotNull JetType functionType, @NotNull JetType receiverType) {
|
||||
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
|
||||
|
||||
List<TypeProjection> typeArguments = functionType.getArguments();
|
||||
assert !typeArguments.isEmpty();
|
||||
|
||||
List<JetType> arguments = Lists.newArrayList();
|
||||
// excluding the last type argument of the function type, which is the return type
|
||||
int index = 0;
|
||||
int lastIndex = typeArguments.size() - 1;
|
||||
for (TypeProjection typeArgument : typeArguments) {
|
||||
if (index < lastIndex) {
|
||||
arguments.add(typeArgument.getType());
|
||||
}
|
||||
index++;
|
||||
}
|
||||
JetType returnType = typeArguments.get(lastIndex).getType();
|
||||
return KotlinBuiltIns.getInstance().getFunctionType(functionType.getAnnotations(), receiverType, arguments, returnType);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
public interface ConstraintSystemStatus {
|
||||
/**
|
||||
* Returns <tt>true</tt> if constraint system has a solution (has no contradiction and has enough information to infer each registered type variable).
|
||||
*/
|
||||
boolean isSuccessful();
|
||||
|
||||
/**
|
||||
* Return <tt>true</tt> if constraint system has no contradiction (it can be not successful because of the lack of information for a type variable).
|
||||
*/
|
||||
boolean hasContradiction();
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if type constraints for some type variable are contradicting. <p/>
|
||||
*
|
||||
* For example, for <pre>fun <R> foo(r: R, t: java.util.List<R>) {}</pre> in invocation <tt>foo(1, arrayList("s"))</tt>
|
||||
* type variable <tt>R</tt> has two conflicting constraints: <p/>
|
||||
* - <tt>"R is a supertype of Int"</tt> <p/>
|
||||
* - <tt>"List<R> is a supertype of List<String>"</tt> which leads to <tt>"R is equal to String"</tt>
|
||||
*/
|
||||
boolean hasConflictingConstraints();
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if there is no information for some registered type variable.
|
||||
*
|
||||
* For example, for <pre>fun <E> newList()</pre> in invocation <tt>"val nl = newList()"</tt>
|
||||
* there is no information to infer type variable <tt>E</tt>.
|
||||
*/
|
||||
boolean hasUnknownParameters();
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if some constraint cannot be processed because of type constructor mismatch.
|
||||
*
|
||||
* For example, for <pre>fun <R> foo(t: List<R>) {}</pre> in invocation <tt>foo(hashSet("s"))</tt>
|
||||
* there is type constructor mismatch: <tt>"HashSet<String> cannot be a subtype of List<R>"</tt>.
|
||||
*/
|
||||
boolean hasTypeConstructorMismatch();
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if there is type constructor mismatch error at a specific {@code constraintPosition}.
|
||||
*
|
||||
* For example, for <pre>fun <R> foo(t: List<R>) {}</pre> in invocation <tt>foo(hashSet("s"))</tt>
|
||||
* there is type constructor mismatch: <tt>"HashSet<String> cannot be a subtype of List<R>"</tt>
|
||||
* at a constraint position {@code ConstraintPosition.getValueParameterPosition(0)}.
|
||||
*/
|
||||
boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if there is type constructor mismatch only in {@link ConstraintPosition.EXPECTED_TYPE_POSITION}.
|
||||
*/
|
||||
boolean hasOnlyExpectedTypeMismatch();
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if there is an error in constraining types. <p/>
|
||||
* Is used not to generate type inference error if there was one in argument types.
|
||||
*/
|
||||
boolean hasErrorInConstrainingTypes();
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public interface TypeConstraints {
|
||||
@NotNull
|
||||
Set<JetType> getLowerBounds();
|
||||
|
||||
@NotNull
|
||||
Set<JetType> getUpperBounds();
|
||||
|
||||
@NotNull
|
||||
Set<JetType> getExactBounds();
|
||||
|
||||
@NotNull
|
||||
Variance getVarianceOfPosition();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
@Nullable
|
||||
JetType getValue();
|
||||
|
||||
@NotNull
|
||||
Collection<JetType> getValues();
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeConstraintsImpl implements TypeConstraints {
|
||||
private final Variance varianceOfPosition;
|
||||
private final Set<JetType> upperBounds = Sets.newLinkedHashSet();
|
||||
private final Set<JetType> lowerBounds = Sets.newLinkedHashSet();
|
||||
private final Set<JetType> exactBounds = Sets.newLinkedHashSet();
|
||||
|
||||
private Collection<JetType> resultValues;
|
||||
|
||||
public TypeConstraintsImpl(Variance varianceOfPosition) {
|
||||
this.varianceOfPosition = varianceOfPosition;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Variance getVarianceOfPosition() {
|
||||
return varianceOfPosition;
|
||||
}
|
||||
|
||||
public void addBound(@NotNull BoundKind boundKind, @NotNull JetType type) {
|
||||
resultValues = null;
|
||||
switch (boundKind) {
|
||||
case LOWER_BOUND:
|
||||
lowerBounds.add(type);
|
||||
break;
|
||||
case UPPER_BOUND:
|
||||
upperBounds.add(type);
|
||||
break;
|
||||
case EXACT_BOUND:
|
||||
exactBounds.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return upperBounds.isEmpty() && lowerBounds.isEmpty() && exactBounds.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getLowerBounds() {
|
||||
return lowerBounds;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getUpperBounds() {
|
||||
return upperBounds;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<JetType> getExactBounds() {
|
||||
return exactBounds;
|
||||
}
|
||||
|
||||
/*package*/ TypeConstraintsImpl copy() {
|
||||
TypeConstraintsImpl typeConstraints = new TypeConstraintsImpl(varianceOfPosition);
|
||||
typeConstraints.upperBounds.addAll(upperBounds);
|
||||
typeConstraints.lowerBounds.addAll(lowerBounds);
|
||||
typeConstraints.exactBounds.addAll(exactBounds);
|
||||
typeConstraints.resultValues = resultValues;
|
||||
return typeConstraints;
|
||||
}
|
||||
|
||||
public static enum BoundKind {
|
||||
LOWER_BOUND, UPPER_BOUND, EXACT_BOUND
|
||||
}
|
||||
|
||||
private Collection<Pair<BoundKind, JetType>> getAllBounds() {
|
||||
Collection<Pair<BoundKind, JetType>> result = Lists.newArrayList();
|
||||
for (JetType exactBound : exactBounds) {
|
||||
result.add(Pair.create(BoundKind.EXACT_BOUND, exactBound));
|
||||
}
|
||||
for (JetType exactBound : upperBounds) {
|
||||
result.add(Pair.create(BoundKind.UPPER_BOUND, exactBound));
|
||||
}
|
||||
for (JetType exactBound : lowerBounds) {
|
||||
result.add(Pair.create(BoundKind.LOWER_BOUND, exactBound));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetType getValue() {
|
||||
Collection<JetType> values = getValues();
|
||||
if (values.size() == 1) {
|
||||
return values.iterator().next();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetType> getValues() {
|
||||
if (resultValues == null) {
|
||||
resultValues = computeValues();
|
||||
}
|
||||
return resultValues;
|
||||
}
|
||||
|
||||
private Collection<JetType> computeValues() {
|
||||
Set<JetType> values = Sets.newLinkedHashSet();
|
||||
if (isEmpty()) {
|
||||
return values;
|
||||
}
|
||||
TypeConstraints withoutErrorTypes = filterNotContainingErrorType(values);
|
||||
Collection<JetType> exactBounds = withoutErrorTypes.getExactBounds();
|
||||
if (exactBounds.size() == 1) {
|
||||
JetType exactBound = exactBounds.iterator().next();
|
||||
if (trySuggestion(exactBound)) {
|
||||
return Collections.singleton(exactBound);
|
||||
}
|
||||
}
|
||||
values.addAll(exactBounds);
|
||||
|
||||
Pair<Collection<JetType>, Collection<JetType>> pair =
|
||||
TypeUtils.filterNumberTypes(withoutErrorTypes.getLowerBounds());
|
||||
Collection<JetType> generalLowerBounds = pair.getFirst();
|
||||
Collection<JetType> numberLowerBounds = pair.getSecond();
|
||||
|
||||
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(generalLowerBounds);
|
||||
if (trySuggestion(superTypeOfLowerBounds)) {
|
||||
return Collections.singleton(superTypeOfLowerBounds);
|
||||
}
|
||||
ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values);
|
||||
|
||||
Collection<JetType> upperBounds = withoutErrorTypes.getUpperBounds();
|
||||
for (JetType upperBound : upperBounds) {
|
||||
if (trySuggestion(upperBound)) {
|
||||
return Collections.singleton(upperBound);
|
||||
}
|
||||
}
|
||||
//todo
|
||||
//fun <T> foo(t: T, consumer: Consumer<T>): T
|
||||
//foo(1, c: Consumer<Any>) - infer Int, not Any here
|
||||
|
||||
values.addAll(withoutErrorTypes.getUpperBounds());
|
||||
|
||||
JetType superTypeOfNumberLowerBounds = TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds);
|
||||
if (trySuggestion(superTypeOfNumberLowerBounds)) {
|
||||
return Collections.singleton(superTypeOfNumberLowerBounds);
|
||||
}
|
||||
ContainerUtil.addIfNotNull(superTypeOfNumberLowerBounds, values);
|
||||
|
||||
if (superTypeOfLowerBounds != null && superTypeOfNumberLowerBounds != null) {
|
||||
JetType superTypeOfAllLowerBounds = CommonSupertypes.commonSupertypeForNonDenotableTypes(
|
||||
Lists.newArrayList(superTypeOfLowerBounds, superTypeOfNumberLowerBounds));
|
||||
if (trySuggestion(superTypeOfAllLowerBounds)) {
|
||||
return Collections.singleton(superTypeOfAllLowerBounds);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private boolean trySuggestion(
|
||||
@Nullable JetType suggestion
|
||||
) {
|
||||
if (suggestion == null) return false;
|
||||
if (!suggestion.getConstructor().isDenotable()) return false;
|
||||
if (getExactBounds().size() > 1) return false;
|
||||
|
||||
for (JetType exactBound : getExactBounds()) {
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(exactBound, suggestion)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (JetType lowerBound : getLowerBounds()) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(lowerBound, suggestion)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (JetType upperBound : getUpperBounds()) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(suggestion, upperBound)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TypeConstraints filterNotContainingErrorType(
|
||||
@NotNull Collection<JetType> values
|
||||
) {
|
||||
TypeConstraintsImpl typeConstraintsWithoutErrorType = new TypeConstraintsImpl(getVarianceOfPosition());
|
||||
Collection<Pair<TypeConstraintsImpl.BoundKind, JetType>> allBounds = getAllBounds();
|
||||
for (Pair<TypeConstraintsImpl.BoundKind, JetType> pair : allBounds) {
|
||||
TypeConstraintsImpl.BoundKind boundKind = pair.getFirst();
|
||||
JetType type = pair.getSecond();
|
||||
if (ErrorUtils.containsErrorType(type)) {
|
||||
values.add(type);
|
||||
}
|
||||
else if (type != null) {
|
||||
typeConstraintsWithoutErrorType.addBound(boundKind, type);
|
||||
}
|
||||
}
|
||||
return typeConstraintsWithoutErrorType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public class AnnotationValue implements CompileTimeConstant<AnnotationDescriptor> {
|
||||
|
||||
private final AnnotationDescriptor value;
|
||||
|
||||
public AnnotationValue(@NotNull AnnotationDescriptor value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AnnotationDescriptor getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return value.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitAnnotationValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ArrayValue implements CompileTimeConstant<List<CompileTimeConstant<?>>> {
|
||||
|
||||
private final List<CompileTimeConstant<?>> value;
|
||||
private final JetType type;
|
||||
|
||||
public ArrayValue(@NotNull List<CompileTimeConstant<?>> value, @NotNull JetType type) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<CompileTimeConstant<?>> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitArrayValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ArrayValue that = (ArrayValue) o;
|
||||
|
||||
if (value == null) {
|
||||
return that.value == null;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Object thisObject : value) {
|
||||
if (!thisObject.equals(that.value.get(i))) {
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 0;
|
||||
if (value == null) return hashCode;
|
||||
for (Object o : value) {
|
||||
hashCode += o.hashCode();
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class BooleanValue implements CompileTimeConstant<Boolean> {
|
||||
|
||||
public static final BooleanValue FALSE = new BooleanValue(false);
|
||||
public static final BooleanValue TRUE = new BooleanValue(true);
|
||||
|
||||
private final boolean value;
|
||||
|
||||
private BooleanValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BooleanValue valueOf(boolean value) {
|
||||
return value ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getBooleanType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitBooleanValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class ByteValue implements CompileTimeConstant<Byte> {
|
||||
public static final Function<Long, ByteValue> CREATE = new Function<Long, ByteValue>() {
|
||||
@Override
|
||||
public ByteValue apply(@Nullable Long input) {
|
||||
assert input != null;
|
||||
return new ByteValue(input.byteValue());
|
||||
}
|
||||
};
|
||||
|
||||
private final byte value;
|
||||
|
||||
public ByteValue(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getByteType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitByteValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toByte()";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class CharValue implements CompileTimeConstant<Character> {
|
||||
|
||||
private final char value;
|
||||
|
||||
public CharValue(char value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getCharType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitCharValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "#" + ((int) value) + "(" + value + ")";
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public interface CompileTimeConstant<T> {
|
||||
T getValue();
|
||||
|
||||
@NotNull
|
||||
JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns);
|
||||
|
||||
<R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class DoubleValue implements CompileTimeConstant<Double> {
|
||||
private final double value;
|
||||
|
||||
public DoubleValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getDoubleType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitDoubleValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toDouble()";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public class EnumValue implements CompileTimeConstant<PropertyDescriptor> {
|
||||
|
||||
private final PropertyDescriptor value;
|
||||
|
||||
public EnumValue(@NotNull PropertyDescriptor value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PropertyDescriptor getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return value.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitEnumValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.getType() + "." + value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
EnumValue enumValue = (EnumValue) o;
|
||||
|
||||
return value.equals(enumValue.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public abstract class ErrorValue implements CompileTimeConstant<Void> {
|
||||
|
||||
@Override
|
||||
@Deprecated // Should not be called, for this is not a real value, but a indication of an error
|
||||
public Void getValue() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitErrorValue(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ErrorValue create(@NotNull String message) {
|
||||
return new ErrorValueWithMessage(message);
|
||||
}
|
||||
|
||||
public static class ErrorValueWithMessage extends ErrorValue {
|
||||
private final String message;
|
||||
|
||||
public ErrorValueWithMessage(@NotNull String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return ErrorUtils.createErrorType(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class FloatValue implements CompileTimeConstant<Float> {
|
||||
private final float value;
|
||||
|
||||
public FloatValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getFloatType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFloatValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toFloat()";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class IntValue implements CompileTimeConstant<Integer> {
|
||||
public static final Function<Long, IntValue> CREATE = new Function<Long, IntValue>() {
|
||||
@Override
|
||||
public IntValue apply(@Nullable Long input) {
|
||||
assert input != null;
|
||||
return new IntValue(input.intValue());
|
||||
}
|
||||
};
|
||||
|
||||
private final int value;
|
||||
|
||||
public IntValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getIntType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitIntValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toInt()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
IntValue intValue = (IntValue) o;
|
||||
|
||||
if (value != intValue.value) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
public class JavaClassValue implements CompileTimeConstant<JetType> {
|
||||
|
||||
private final JetType value;
|
||||
|
||||
public JavaClassValue(JetType value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getValue() {
|
||||
return value.getArguments().iterator().next().getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitJavaClassValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue() + ".class";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class LongValue implements CompileTimeConstant<Long> {
|
||||
public static final Function<Long, LongValue> CREATE = new Function<Long, LongValue>() {
|
||||
@Override
|
||||
public LongValue apply(@Nullable Long input) {
|
||||
return new LongValue(input);
|
||||
}
|
||||
};
|
||||
|
||||
private final long value;
|
||||
|
||||
public LongValue(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getLongType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitLongValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toLong()";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class NullValue implements CompileTimeConstant<Void> {
|
||||
|
||||
public static final NullValue NULL = new NullValue();
|
||||
|
||||
private NullValue() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return KotlinBuiltIns.getInstance().getNullableNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNullValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class NumberValueTypeConstructor implements TypeConstructor {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSealed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDenotable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class ShortValue implements CompileTimeConstant<Short> {
|
||||
public static final Function<Long, ShortValue> CREATE = new Function<Long, ShortValue>() {
|
||||
@Override
|
||||
public ShortValue apply(@Nullable Long input) {
|
||||
assert input != null;
|
||||
return new ShortValue(input.shortValue());
|
||||
}
|
||||
};
|
||||
|
||||
private final short value;
|
||||
|
||||
public ShortValue(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getShortType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitShortValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value + ".toShort()";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class StringValue implements CompileTimeConstant<String> {
|
||||
|
||||
private final String value;
|
||||
|
||||
public StringValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
return kotlinBuiltIns.getStringType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitStringValue(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
StringValue that = (StringValue) o;
|
||||
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value != null ? value.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ConcurrentWeakValueHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.utils.WrappedValues;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
protected final Object lock = new Object() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LockBasedStorageManager centralized lock";
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunctionToNotNull<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||
@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunction<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
private static <K, V> ConcurrentMap<K, V> createConcurrentMap(ReferenceKind referenceKind) {
|
||||
return (referenceKind == ReferenceKind.WEAK) ? new ConcurrentWeakValueHashMap<K, V>() : new ConcurrentHashMap<K, V>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NotNullLazyValue<T> createLazyValue(@NotNull Computable<T> computable) {
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NotNullLazyValue<T> createLazyValueWithPostCompute(@NotNull Computable<T> computable, @NotNull final Consumer<T> postCompute) {
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable) {
|
||||
@Override
|
||||
protected void postCompute(@NotNull T value) {
|
||||
postCompute.consume(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NullableLazyValue<T> createNullableLazyValue(@NotNull Computable<T> computable) {
|
||||
return new LockBasedLazyValue<T>(lock, computable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NullableLazyValue<T> createNullableLazyValueWithPostCompute(
|
||||
@NotNull Computable<T> computable, @NotNull final Consumer<T> postCompute
|
||||
) {
|
||||
return new LockBasedLazyValue<T>(lock, computable) {
|
||||
@Override
|
||||
protected void postCompute(@Nullable T value) {
|
||||
postCompute.consume(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T compute(@NotNull Computable<T> computable) {
|
||||
synchronized (lock) {
|
||||
return computable.compute();
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockBasedLazyValue<T> implements NullableLazyValue<T> {
|
||||
private final Object lock;
|
||||
private final Computable<T> computable;
|
||||
|
||||
@Nullable
|
||||
private volatile Object value = null;
|
||||
|
||||
public LockBasedLazyValue(@NotNull Object lock, @NotNull Computable<T> computable) {
|
||||
this.lock = lock;
|
||||
this.computable = computable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T compute() {
|
||||
Object _value = value;
|
||||
if (_value != null) return WrappedValues.unescapeExceptionOrNull(_value);
|
||||
|
||||
synchronized (lock) {
|
||||
_value = value;
|
||||
if (_value != null) return WrappedValues.unescapeExceptionOrNull(_value);
|
||||
|
||||
try {
|
||||
T typedValue = computable.compute();
|
||||
value = WrappedValues.escapeNull(typedValue);
|
||||
postCompute(typedValue);
|
||||
return typedValue;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
value = WrappedValues.escapeThrowable(throwable);
|
||||
throw ExceptionUtils.rethrow(throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void postCompute(T value) {
|
||||
// Doing something in post-compute helps prevent infinite recursion
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockBasedNotNullLazyValue<T> extends LockBasedLazyValue<T> implements NotNullLazyValue<T> {
|
||||
|
||||
public LockBasedNotNullLazyValue(@NotNull Object lock, @NotNull Computable<T> computable) {
|
||||
super(lock, computable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public T compute() {
|
||||
T result = super.compute();
|
||||
assert result != null : "compute() returned null";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MapBasedMemoizedFunction<K, V> implements MemoizedFunctionToNullable<K, V> {
|
||||
private final Object lock;
|
||||
private final ConcurrentMap<K, Object> cache;
|
||||
private final Function<K, V> compute;
|
||||
|
||||
public MapBasedMemoizedFunction(@NotNull Object lock, @NotNull ConcurrentMap<K, Object> map, @NotNull Function<K, V> compute) {
|
||||
this.lock = lock;
|
||||
this.cache = map;
|
||||
this.compute = compute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public V fun(@NotNull K input) {
|
||||
Object value = cache.get(input);
|
||||
if (value != null) return WrappedValues.unescapeExceptionOrNull(value);
|
||||
|
||||
synchronized (lock) {
|
||||
value = cache.get(input);
|
||||
if (value != null) return WrappedValues.unescapeExceptionOrNull(value);
|
||||
|
||||
try {
|
||||
V typedValue = compute.fun(input);
|
||||
Object oldValue = cache.put(input, WrappedValues.escapeNull(typedValue));
|
||||
assert oldValue == null : "Race condition detected";
|
||||
|
||||
return typedValue;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable));
|
||||
assert oldValue == null : "Race condition detected";
|
||||
|
||||
throw ExceptionUtils.rethrow(throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MapBasedMemoizedFunctionToNotNull<K, V> extends MapBasedMemoizedFunction<K, V> implements MemoizedFunctionToNotNull<K, V> {
|
||||
|
||||
public MapBasedMemoizedFunctionToNotNull(
|
||||
@NotNull Object lock,
|
||||
@NotNull ConcurrentMap<K, Object> map,
|
||||
@NotNull Function<K, V> compute
|
||||
) {
|
||||
super(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public V fun(@NotNull K input) {
|
||||
V result = super.fun(input);
|
||||
assert result != null : "compute() returned null";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MemoizedFunctionToNotNull<P, R> extends Function<P, R> {
|
||||
@Override
|
||||
@NotNull
|
||||
R fun(P p);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface MemoizedFunctionToNullable<P, R> extends Function<P, R> {
|
||||
@Override
|
||||
@Nullable
|
||||
R fun(P p);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user