FqName*.equalsTo, type safe unlike equals
This commit is contained in:
+1
-1
@@ -603,7 +603,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
||||
private boolean isJavaLangObject(JetType type) {
|
||||
ClassifierDescriptor classifierDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
return classifierDescriptor instanceof ClassDescriptor &&
|
||||
DescriptorUtils.getFQName(classifierDescriptor).equals(JL_OBJECT.toUnsafe());
|
||||
DescriptorUtils.getFQName(classifierDescriptor).equalsTo(JL_OBJECT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equals(JetStandardClasses.STANDARD_CLASSES_FQNAME.toUnsafe())) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equalsTo(JetStandardClasses.STANDARD_CLASSES_FQNAME)) {
|
||||
if (!extendBuiltins) {
|
||||
namespaceMemberScope.importScope(JetStandardClasses.STANDARD_CLASSES);
|
||||
}
|
||||
|
||||
+1
-1
@@ -392,7 +392,7 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
if (namespaceDescriptor != null && classDescriptor != null) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equals(DescriptorUtils.getFQName(classDescriptor))) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equalsTo(DescriptorUtils.getFQName(classDescriptor))) {
|
||||
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classDescriptor);
|
||||
trace.record(BindingContext.RESOLUTION_SCOPE, referenceExpression, resolutionScope);
|
||||
checkVisibility(classDescriptor, trace, referenceExpression, scopeToCheckVisibility);
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class FqName {
|
||||
public class FqName extends FqNameBase {
|
||||
|
||||
public static final FqName ROOT = new FqName("");
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public abstract class FqNameBase {
|
||||
|
||||
protected FqNameBase() {
|
||||
if (!(this instanceof FqName || this instanceof FqNameUnsafe)) {
|
||||
throw new AssertionError("do not use this class directly");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getFqName();
|
||||
|
||||
@NotNull
|
||||
private FqNameUnsafe toFqNameUnsafe() {
|
||||
if (this instanceof FqName) {
|
||||
return ((FqName) this).toUnsafe();
|
||||
}
|
||||
else if (this instanceof FqNameUnsafe) {
|
||||
return ((FqNameUnsafe) this);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@NotNull FqName that) {
|
||||
return equalsTo(that.toUnsafe());
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@NotNull FqNameUnsafe that) {
|
||||
return toFqNameUnsafe().equals(that);
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@NotNull String that) {
|
||||
return getFqName().equals(that);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class FqNameUnsafe {
|
||||
public class FqNameUnsafe extends FqNameBase {
|
||||
|
||||
public static final Name ROOT_NAME = Name.special("<root>");
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
||||
final DeclarationDescriptor containingDeclaration = declarationDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration != null) {
|
||||
FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration);
|
||||
stringBuilder.append(FqName.ROOT.toUnsafe().equals(fqName) ? "root package" : escape(fqName.getFqName()));
|
||||
stringBuilder.append(FqName.ROOT.equalsTo(fqName) ? "root package" : escape(fqName.getFqName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ public class IdeErrorMessages {
|
||||
DeclarationDescriptor containingDeclaration = funDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration != null) {
|
||||
FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration);
|
||||
stringBuilder.append(FqName.ROOT.toUnsafe().equals(fqName) ? "root package" : fqName.getFqName());
|
||||
stringBuilder.append(FqName.ROOT.equalsTo(fqName) ? "root package" : fqName.getFqName());
|
||||
}
|
||||
stringBuilder.append("</li>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user