Safe identifier for the case of no name in PSI moved to 'descriptors' module, to be used in 'descriptor.loader.java'

This commit is contained in:
Andrey Breslav
2014-06-10 12:47:46 +04:00
parent bb581bb645
commit d2ce6f5787
6 changed files with 42 additions and 16 deletions
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetNamedDeclarationUtil;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.name.NamePackage;
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import java.util.Collection;
@@ -36,12 +37,6 @@ import java.util.Collections;
public class ResolveSessionUtils {
// This name is used as a key for the case when something has no name _due to a syntactic error_
// Example: fun (x: Int) = 5
// There's no name for this function in the PSI
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
public static final Name NO_NAME_FOR_LAZY_RESOLVE = Name.identifier("no_name_in_PSI_for_lazy_resolve_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
public static final Predicate<ClassDescriptor> NON_SINGLETON_FILTER = new Predicate<ClassDescriptor>() {
@Override
public boolean apply(@Nullable ClassDescriptor descriptor) {
@@ -148,7 +143,7 @@ public class ResolveSessionUtils {
@NotNull
public static Name safeNameForLazyResolve(@Nullable Name name) {
return name != null && !name.isSpecial() ? name : NO_NAME_FOR_LAZY_RESOLVE;
return SpecialNames.safeIdentifier(name);
}
@Nullable
@@ -0,0 +1,17 @@
// FILE: p/Nameless.java
package p;
public class Nameless {
void () {}
int ;
}
// FILE: k.kt
import p.*
class K : Nameless() {
fun<!SYNTAX!><!> () {}
val<!SYNTAX!><!> : Int = 1
}
@@ -5911,6 +5911,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/recovery"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("namelessInJava.kt")
public void testNamelessInJava() throws Exception {
doTest("compiler/testData/diagnostics/tests/recovery/namelessInJava.kt");
}
@TestMetadata("namelessMembers.kt")
public void testNamelessMembers() throws Exception {
doTest("compiler/testData/diagnostics/tests/recovery/namelessMembers.kt");
@@ -32,12 +32,12 @@ import org.jetbrains.jet.lang.resolve.java.lazy.findJavaClass
import org.jetbrains.jet.lang.resolve.java.lazy.findClassInJava
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPackageFragmentDescriptor
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaMemberScope.MethodSignatureData
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
import org.jetbrains.jet.lang.resolve.name.SpecialNames
public abstract class LazyJavaPackageFragmentScope(
c: LazyJavaResolverContext,
@@ -104,7 +104,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> {
name ->
val fqName = fqName.child(name)
val fqName = fqName.child(SpecialNames.safeIdentifier(name))
val (jClass, kClass) = c.findClassInJava(fqName)
if (kClass != null)
kClass
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.resolve.name;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SpecialNames {
public static final Name NO_NAME_PROVIDED = Name.special("<no name provided>");
@@ -24,7 +25,16 @@ public class SpecialNames {
private static final String CLASS_OBJECT_FOR = "<class-object-for-";
private SpecialNames() {}
// This name is used as a key for the case when something has no name _due to a syntactic error_
// Example: fun (x: Int) = 5
// There's no name for this function in the PSI
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
public static final Name SAFE_IDENTIFIER_FOR_NO_NAME = Name.identifier("no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
@NotNull
public static Name safeIdentifier(@Nullable Name name) {
return name != null && !name.isSpecial() ? name : SAFE_IDENTIFIER_FOR_NO_NAME;
}
@NotNull
public static Name getClassObjectName(@NotNull Name className) {
@@ -34,4 +44,7 @@ public class SpecialNames {
public static boolean isClassObjectName(@NotNull Name name) {
return name.isSpecial() && name.asString().startsWith(CLASS_OBJECT_FOR);
}
private SpecialNames() {}
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.plugin.stubs;
import com.intellij.lang.FileASTNode;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.psi.stubs.StubElement;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
@@ -24,20 +23,17 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.stubs.elements.JetFileStubBuilder;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPlaceHolderStubImpl;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
import java.io.File;
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.NO_NAME_FOR_LAZY_RESOLVE;
public abstract class AbstractStubBuilderTest extends LightCodeInsightFixtureTestCase {
protected void doTest(@NotNull String sourcePath) {
JetFile file = (JetFile) myFixture.configureByFile(sourcePath);
JetFileStubBuilder jetStubBuilder = new JetFileStubBuilder();
StubElement lighterTree = jetStubBuilder.buildStubTree(file);
String stubTree = DebugUtil.stubTreeToString(lighterTree)
.replace(NO_NAME_FOR_LAZY_RESOLVE.asString(), "<no name>");
.replace(SpecialNames.SAFE_IDENTIFIER_FOR_NO_NAME.asString(), "<no name>");
String expectedFile = sourcePath.replace(".kt", ".expected");
JetTestUtils.assertEqualsToFile(new File(expectedFile), stubTree);
}