Removed LabelName class, used Name instead

This commit is contained in:
Svetlana Isakova
2014-05-12 17:56:01 +04:00
parent 98f80fe1e0
commit 3bcdbee2bf
19 changed files with 40 additions and 114 deletions
@@ -1,65 +0,0 @@
/*
* 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 LabelName {
@NotNull
private final String name;
public LabelName(@NotNull String name) {
if (name.startsWith("@")) {
// label may contain @, and may not contain
//throw new IllegalArgumentException("@ must be chopped: " + name);
}
if (name.length() == 0) {
// label can be empty
//throw new IllegalStateException("label cannot be empty");
}
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LabelName name1 = (LabelName) o;
if (!name.equals(name1.name)) return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
}
@@ -68,6 +68,13 @@ public final class Name implements Comparable<Name> {
return new Name(name, false);
}
@NotNull
public static Name identifierForLabel(@NotNull String name) {
// might be empty ('@' label)
if (name.isEmpty()) return identifierNoValidate(name);
return identifier(name);
}
@NotNull
public static Name special(@NotNull String name) {
if (!name.startsWith("<")) {
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
@@ -74,7 +73,7 @@ public abstract class AbstractScopeAdapter implements JetScope {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
return getWorkerScope().getDeclarationsByLabel(labelName);
}
@@ -21,7 +21,6 @@ import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
@@ -90,7 +89,7 @@ public class ChainedScope implements JetScope {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
ArrayList<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
for (JetScope jetScope : scopeChain) {
result.addAll(jetScope.getDeclarationsByLabel(labelName));
@@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
@@ -91,7 +90,7 @@ public class FilteringScope implements JetScope {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
return Collections2.filter(workerScope.getDeclarationsByLabel(labelName), predicate);
}
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
@@ -54,7 +53,7 @@ public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
return Collections2.filter(actualScope.getDeclarationsByLabel(labelName), IS_CLASS);
}
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ReadOnly;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
@@ -72,7 +71,7 @@ public interface JetScope {
@NotNull
@ReadOnly
Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName);
Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName);
/**
* All visible descriptors from current scope.
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.Printer;
@@ -59,7 +58,7 @@ public abstract class JetScopeImpl implements JetScope {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
return Collections.emptyList();
}
@@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.utils.Printer;
@@ -123,7 +122,7 @@ public class SubstitutingScope implements JetScope {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
throw new UnsupportedOperationException(); // TODO
}
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.utils.Printer;
@@ -57,7 +56,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
private Map<Name, PackageViewDescriptor> packageAliases;
@Nullable
private Map<LabelName, List<DeclarationDescriptor>> labelsToDescriptors;
private Map<Name, List<DeclarationDescriptor>> labelsToDescriptors;
@Nullable
private ReceiverParameterDescriptor implicitReceiver;
@@ -140,20 +139,20 @@ public class WritableScopeImpl extends WritableScopeWithImports {
}
@NotNull
private Map<LabelName, List<DeclarationDescriptor>> getLabelsToDescriptors() {
private Map<Name, List<DeclarationDescriptor>> getLabelsToDescriptors() {
if (labelsToDescriptors == null) {
labelsToDescriptors = new HashMap<LabelName, List<DeclarationDescriptor>>();
labelsToDescriptors = new HashMap<Name, List<DeclarationDescriptor>>();
}
return labelsToDescriptors;
}
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
checkMayRead();
Collection<DeclarationDescriptor> superResult = super.getDeclarationsByLabel(labelName);
Map<LabelName, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
Map<Name, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(labelName);
if (declarationDescriptors == null) {
return superResult;
@@ -168,8 +167,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
checkMayWrite();
Map<LabelName, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
LabelName name = new LabelName(descriptor.getName().asString());
Map<Name, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
Name name = descriptor.getName();
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(name);
if (declarationDescriptors == null) {
declarationDescriptors = new ArrayList<DeclarationDescriptor>();
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.jet.lang.resolve.ImportPath;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor;
@@ -122,7 +121,7 @@ public class ErrorUtils {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
return Collections.emptyList();
}
@@ -194,7 +193,7 @@ public class ErrorUtils {
@NotNull
@Override
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull LabelName labelName) {
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
throw new IllegalStateException();
}