Name class

In the most places in frontend identifier is stored in Name class, was in String.
Name has two advantages over String:
* validation: you cannot accidentally create identifier with dot, for example
* readability: if you see String, you don't now whether it is
  identifier, fq name, jvm class name or something else

Name's disadvantage is (small) performance overhead. We have no value types in JVM.
This commit is contained in:
Stepan Koltsov
2012-05-23 02:52:32 +04:00
parent c15ff2dee0
commit 33a59ff5fe
152 changed files with 962 additions and 726 deletions
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.util.QualifiedNamesUtil;
import java.util.HashSet;
@@ -117,7 +118,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
for (JetFile file : filesInScope) {
final FqName packageName = JetPsiUtil.getFQName(file);
if (packageName != null && qualifiedName.getFqName().startsWith(packageName.getFqName())) {
if (qualifiedName.equals(QualifiedNamesUtil.combine(packageName, JvmAbi.PACKAGE_CLASS))) {
if (qualifiedName.equals(QualifiedNamesUtil.combine(packageName, Name.identifier(JvmAbi.PACKAGE_CLASS)))) {
answer.add(new JetLightClass(psiManager, file, qualifiedName));
}
else {
@@ -134,7 +135,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
if (declaration instanceof JetClassOrObject) {
String localName = getLocalName(declaration);
if (localName != null) {
FqName fqn = QualifiedNamesUtil.combine(containerFqn, localName);
FqName fqn = QualifiedNamesUtil.combine(containerFqn, Name.identifier(localName));
if (qualifiedName.equals(fqn)) {
answer.add(new JetLightClass(psiManager, file, qualifiedName));
}
@@ -227,12 +228,12 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
FqName packageFQN = new FqName(psiPackage.getQualifiedName());
for (JetFile file : filesInScope) {
if (packageFQN.equals(JetPsiUtil.getFQName(file))) {
answer.add(new JetLightClass(psiManager, file, QualifiedNamesUtil.combine(packageFQN, JvmAbi.PACKAGE_CLASS)));
answer.add(new JetLightClass(psiManager, file, QualifiedNamesUtil.combine(packageFQN, Name.identifier(JvmAbi.PACKAGE_CLASS))));
for (JetDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof JetClassOrObject) {
String localName = getLocalName(declaration);
if (localName != null) {
answer.add(new JetLightClass(psiManager, file, QualifiedNamesUtil.combine(packageFQN, localName)));
answer.add(new JetLightClass(psiManager, file, QualifiedNamesUtil.combine(packageFQN, Name.identifier(localName))));
}
}
}
@@ -72,7 +72,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
@Override
public String getName() {
return QualifiedNamesUtil.fqnToShortName(qualifiedName);
return QualifiedNamesUtil.fqnToShortName(qualifiedName).getName();
}
@Override