Extract SpecialNames utility class
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
|
||||
|
||||
@@ -77,7 +78,7 @@ public class MemberCodegen extends ParentCodegenAwareImpl {
|
||||
public void genClassOrObject(CodegenContext parentContext, JetClassOrObject aClass) {
|
||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||
|
||||
if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(JetPsiUtil.NO_NAME_PROVIDED)) {
|
||||
if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(SpecialNames.NO_NAME_PROVIDED)) {
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) {
|
||||
throw new IllegalStateException(
|
||||
"Generating bad descriptor in ClassBuilderMode = " + state.getClassBuilderMode() + ": " + descriptor);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
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.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
@@ -170,7 +171,7 @@ public class IntrinsicMethods {
|
||||
}
|
||||
|
||||
private void registerStaticField(@NotNull FqName classFqName, @NotNull Name propertyName) {
|
||||
FqNameUnsafe classObjectFqName = classFqName.toUnsafe().child(getClassObjectName(classFqName.shortName()));
|
||||
FqNameUnsafe classObjectFqName = classFqName.toUnsafe().child(SpecialNames.getClassObjectName(classFqName.shortName()));
|
||||
intrinsicsMap.registerIntrinsic(classObjectFqName, propertyName, -1, new StaticField(classFqName, propertyName));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.descriptors.serialization.TypeDeserializer.TypeParameterResolver.NONE;
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public class DeserializedClassDescriptor extends AbstractClassDescriptor implements ClassDescriptor {
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
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.name.SpecialNames;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class JetNamespaceHeader extends JetReferenceExpression {
|
||||
@NotNull
|
||||
public Name getNameAsName() {
|
||||
PsiElement nameIdentifier = getNameIdentifier();
|
||||
return nameIdentifier == null ? DescriptorUtils.ROOT_NAMESPACE_NAME : Name.identifier(nameIdentifier.getText());
|
||||
return nameIdentifier == null ? SpecialNames.ROOT_NAMESPACE : Name.identifier(nameIdentifier.getText());
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.parsing.JetExpressionParsing;
|
||||
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.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
@@ -47,9 +48,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JetPsiUtil {
|
||||
|
||||
public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
|
||||
|
||||
private JetPsiUtil() {
|
||||
}
|
||||
|
||||
@@ -131,7 +129,7 @@ public class JetPsiUtil {
|
||||
|
||||
@NotNull
|
||||
public static Name safeName(@Nullable String name) {
|
||||
return name == null ? NO_NAME_PROVIDED : Name.identifier(name);
|
||||
return name == null ? SpecialNames.NO_NAME_PROVIDED : Name.identifier(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
|
||||
public class JetModuleUtil {
|
||||
public static NamespaceType getRootNamespaceType(JetElement expression) {
|
||||
// TODO: this is a stub: at least the modules' root namespaces must be indexed here
|
||||
return new NamespaceType(DescriptorUtils.ROOT_NAMESPACE_NAME, JetScope.EMPTY);
|
||||
return new NamespaceType(SpecialNames.ROOT_NAMESPACE, JetScope.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.FQNAME_TO_CLASS_DESCRIPTOR;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
|
||||
import static org.jetbrains.jet.lang.resolve.ModifiersChecker.getDefaultClassVisibility;
|
||||
import static org.jetbrains.jet.lang.resolve.ModifiersChecker.resolveVisibilityFromModifiers;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public class TypeHierarchyResolver {
|
||||
@NotNull
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
||||
@@ -42,6 +41,7 @@ import org.jetbrains.jet.lang.resolve.lazy.storage.LazyResolveStorageManager;
|
||||
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.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
@@ -215,7 +215,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
// build descriptors for such class objects.
|
||||
final JetClassLikeInfo classObjectInfo = parentClassDescriptor.getClassObjectInfo(classObject);
|
||||
if (classObjectInfo != null) {
|
||||
final Name name = DescriptorUtils.getClassObjectName(parentClassDescriptor.getName());
|
||||
final Name name = SpecialNames.getClassObjectName(parentClassDescriptor.getName());
|
||||
return storageManager.compute(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
|
||||
+1
-1
@@ -53,8 +53,8 @@ import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
|
||||
import static org.jetbrains.jet.lang.resolve.ModifiersChecker.*;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDescriptor, ClassDescriptor {
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
@@ -663,7 +664,7 @@ public class JetTestUtils {
|
||||
public static NamespaceDescriptorImpl createTestNamespace(@NotNull Name testPackageName) {
|
||||
ModuleDescriptorImpl module = AnalyzerFacadeForJVM.createJavaModule("<test module>");
|
||||
NamespaceDescriptorImpl rootNamespace =
|
||||
new NamespaceDescriptorImpl(module, Collections.<AnnotationDescriptor>emptyList(), DescriptorUtils.ROOT_NAMESPACE_NAME);
|
||||
new NamespaceDescriptorImpl(module, Collections.<AnnotationDescriptor>emptyList(), SpecialNames.ROOT_NAMESPACE);
|
||||
module.setRootNamespace(rootNamespace);
|
||||
NamespaceDescriptorImpl test = new NamespaceDescriptorImpl(rootNamespace, Collections.<AnnotationDescriptor>emptyList(), testPackageName);
|
||||
test.initialize(new WritableScopeImpl(JetScope.EMPTY, test, RedeclarationHandler.DO_NOTHING, "members of test namespace"));
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public class JavaEnumClassObjectDescriptor extends MutableClassDescriptorLite {
|
||||
private ConstructorDescriptor constructor;
|
||||
|
||||
+2
-2
@@ -50,8 +50,8 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
|
||||
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.INCLUDE_KOTLIN_SOURCES;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public final class JavaClassResolver {
|
||||
@NotNull
|
||||
@@ -401,7 +401,7 @@ public final class JavaClassResolver {
|
||||
if (JvmAbi.CLASS_OBJECT_CLASS_NAME.equals(segment.asString())) {
|
||||
assert !correctedSegments.isEmpty();
|
||||
Name previous = correctedSegments.get(correctedSegments.size() - 1);
|
||||
correctedSegments.add(DescriptorUtils.getClassObjectName(previous));
|
||||
correctedSegments.add(getClassObjectName(previous));
|
||||
}
|
||||
else {
|
||||
correctedSegments.add(segment);
|
||||
|
||||
@@ -28,6 +28,7 @@ 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.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
@@ -40,8 +41,6 @@ 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() {
|
||||
}
|
||||
|
||||
@@ -306,11 +305,6 @@ public class DescriptorUtils {
|
||||
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();
|
||||
|
||||
@@ -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.name;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SpecialNames {
|
||||
public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
|
||||
public static final Name ROOT_NAMESPACE = Name.special("<root namespace>");
|
||||
|
||||
private SpecialNames() {}
|
||||
|
||||
@NotNull
|
||||
public static Name getClassObjectName(@NotNull Name className) {
|
||||
return Name.special("<class-object-for-" + className.asString() + ">");
|
||||
}
|
||||
}
|
||||
@@ -28,14 +28,15 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
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.types.*;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
@@ -163,7 +164,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
private static void loadBuiltIns(@NotNull ModuleDescriptorImpl module) throws IOException {
|
||||
NamespaceDescriptorImpl rootNamespace =
|
||||
new NamespaceDescriptorImpl(module, Collections.<AnnotationDescriptor>emptyList(), DescriptorUtils.ROOT_NAMESPACE_NAME);
|
||||
new NamespaceDescriptorImpl(module, Collections.<AnnotationDescriptor>emptyList(), SpecialNames.ROOT_NAMESPACE);
|
||||
rootNamespace.initialize(
|
||||
new WritableScopeImpl(JetScope.EMPTY, rootNamespace, RedeclarationHandler.DO_NOTHING, "members of root namespace"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user