Supporting FqNames with spaces/comments inside them for deprecated
This commit is contained in:
@@ -17,12 +17,14 @@
|
|||||||
package org.jetbrains.jet.lang.psi;
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.impl.CheckUtil;
|
import com.intellij.psi.impl.CheckUtil;
|
||||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
@@ -207,6 +209,23 @@ public class JetPsiUtil {
|
|||||||
return firstPart.child(name);
|
return firstPart.child(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return <code>null</code> iff the tye has syntactic errors */
|
||||||
|
@Nullable
|
||||||
|
public static FqName toQualifiedName(@NotNull JetUserType userType) {
|
||||||
|
List<String> reversedNames = Lists.newArrayList();
|
||||||
|
|
||||||
|
JetUserType current = userType;
|
||||||
|
while (current != null) {
|
||||||
|
String name = current.getReferencedName();
|
||||||
|
if (name == null) return null;
|
||||||
|
|
||||||
|
reversedNames.add(name);
|
||||||
|
current = current.getQualifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
return FqName.fromSegments(ContainerUtil.reverse(reversedNames));
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Name getShortName(JetAnnotationEntry annotation) {
|
public static Name getShortName(JetAnnotationEntry annotation) {
|
||||||
JetTypeReference typeReference = annotation.getTypeReference();
|
JetTypeReference typeReference = annotation.getTypeReference();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.name;
|
package org.jetbrains.jet.lang.resolve.name;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -24,6 +25,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class FqName extends FqNameBase {
|
public class FqName extends FqNameBase {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static FqName fromSegments(@NotNull List<String> names) {
|
||||||
|
String fqName = StringUtil.join(names, ".");
|
||||||
|
return new FqName(fqName);
|
||||||
|
}
|
||||||
|
|
||||||
public static final FqName ROOT = new FqName("");
|
public static final FqName ROOT = new FqName("");
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -32,7 +39,6 @@ public class FqName extends FqNameBase {
|
|||||||
// cache
|
// cache
|
||||||
private transient FqName parent;
|
private transient FqName parent;
|
||||||
|
|
||||||
|
|
||||||
public FqName(@NotNull String fqName) {
|
public FqName(@NotNull String fqName) {
|
||||||
this.fqName = new FqNameUnsafe(fqName, this);
|
this.fqName = new FqNameUnsafe(fqName, this);
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -345,15 +345,13 @@ public class KotlinLightClassForExplicitDeclaration extends AbstractLightClass i
|
|||||||
if (typeReference == null) continue;
|
if (typeReference == null) continue;
|
||||||
|
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||||
if (typeElement == null) continue;
|
if (!(typeElement instanceof JetUserType)) continue; // If it's not a user type, it's definitely not a ref to deprecated
|
||||||
|
|
||||||
// typeElement.getText() is either
|
FqName fqName = JetPsiUtil.toQualifiedName((JetUserType) typeElement);
|
||||||
// simple name => we just compare it to "deprecated"
|
if (fqName == null) continue;
|
||||||
// qualified name => we compare to FqName, there may be spaces, comments etc, we do not support these cases
|
|
||||||
// function type, etc => comparisons below fail
|
if (deprecatedFqName.equals(fqName.toUnsafe())) return true;
|
||||||
String text = typeElement.getText();
|
if (deprecatedName.equals(fqName.getFqName())) return true;
|
||||||
if (deprecatedFqName.getFqName().equals(text)) return true;
|
|
||||||
if (deprecatedName.equals(text)) return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ trait Trait
|
|||||||
// Deprecation
|
// Deprecation
|
||||||
deprecated("") class Deprecated
|
deprecated("") class Deprecated
|
||||||
jet.deprecated("") class DeprecatedFQN
|
jet.deprecated("") class DeprecatedFQN
|
||||||
|
jet. deprecated /**/ ("") class DeprecatedFQNSpaces
|
||||||
[deprecated("")] class DeprecatedWithBrackets
|
[deprecated("")] class DeprecatedWithBrackets
|
||||||
[jet.deprecated("")] class DeprecatedWithBracketsFQN
|
[jet.deprecated("")] class DeprecatedWithBracketsFQN
|
||||||
|
[jet
|
||||||
|
./**/deprecated ("")] class DeprecatedWithBracketsFQNSpaces
|
||||||
|
|
||||||
// Generic
|
// Generic
|
||||||
class Generic1<T>
|
class Generic1<T>
|
||||||
|
|||||||
@@ -184,7 +184,23 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDeprecatedFQN() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeprecatedFQNSpaces() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testDeprecatedWithBrackets() throws Exception {
|
public void testDeprecatedWithBrackets() throws Exception {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDeprecatedWithBracketsFQN() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeprecatedWithBracketsFQNSpaces() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,8 +88,10 @@ public abstract class KotlinLightClassTest extends KotlinAsJavaTestBase {
|
|||||||
public void testDeprecation() {
|
public void testDeprecation() {
|
||||||
checkModifiers("test.Deprecated", PUBLIC, FINAL, DEPRECATED);
|
checkModifiers("test.Deprecated", PUBLIC, FINAL, DEPRECATED);
|
||||||
checkModifiers("test.DeprecatedFQN", PUBLIC, FINAL, DEPRECATED);
|
checkModifiers("test.DeprecatedFQN", PUBLIC, FINAL, DEPRECATED);
|
||||||
|
checkModifiers("test.DeprecatedFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||||
checkModifiers("test.DeprecatedWithBrackets", PUBLIC, FINAL, DEPRECATED);
|
checkModifiers("test.DeprecatedWithBrackets", PUBLIC, FINAL, DEPRECATED);
|
||||||
checkModifiers("test.DeprecatedWithBracketsFQN", PUBLIC, FINAL, DEPRECATED);
|
checkModifiers("test.DeprecatedWithBracketsFQN", PUBLIC, FINAL, DEPRECATED);
|
||||||
|
checkModifiers("test.DeprecatedWithBracketsFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGenericity() {
|
public void testGenericity() {
|
||||||
|
|||||||
Reference in New Issue
Block a user