KT-2874 Exception in front-end when extending Java class
#KT-2874 Fixed
This commit is contained in:
+32
-6
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -241,20 +242,45 @@ public class PositioningStrategies {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TextRange> mark(@NotNull JetModifierListOwner element) {
|
||||
List<JetKeywordToken> visibilityTokens = Lists
|
||||
.newArrayList(JetTokens.PRIVATE_KEYWORD, JetTokens.PROTECTED_KEYWORD, JetTokens.PUBLIC_KEYWORD, JetTokens.INTERNAL_KEYWORD);
|
||||
List<JetKeywordToken> visibilityTokens = Lists.newArrayList(
|
||||
JetTokens.PRIVATE_KEYWORD, JetTokens.PROTECTED_KEYWORD, JetTokens.PUBLIC_KEYWORD, JetTokens.INTERNAL_KEYWORD);
|
||||
List<TextRange> result = Lists.newArrayList();
|
||||
for (JetKeywordToken token : visibilityTokens) {
|
||||
if (element.hasModifier(token)) {
|
||||
//noinspection ConstantConditions
|
||||
result.add(element.getModifierList().getModifierNode(token).getTextRange());
|
||||
}
|
||||
}
|
||||
if (result.isEmpty()) {
|
||||
if (element.hasModifier(JetTokens.OVERRIDE_KEYWORD)) {
|
||||
result.add(element.getModifierList().getModifierNode(JetTokens.OVERRIDE_KEYWORD).getTextRange());
|
||||
|
||||
if (!result.isEmpty()) return result;
|
||||
|
||||
// Try to resolve situation when there's no visibility modifiers written before element
|
||||
|
||||
if (element instanceof PsiNameIdentifierOwner) {
|
||||
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
return ImmutableList.of(nameIdentifier.getTextRange());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
if (element instanceof JetPropertyAccessor) {
|
||||
return ImmutableList.of(((JetPropertyAccessor) element).getNamePlaceholder().getTextRange());
|
||||
}
|
||||
|
||||
if (element instanceof JetClassInitializer) {
|
||||
return ImmutableList.of(element.getTextRange());
|
||||
}
|
||||
|
||||
if (element instanceof JetClassObject) {
|
||||
JetObjectDeclaration objectDeclaration = ((JetClassObject) element).getObjectDeclaration();
|
||||
if (objectDeclaration != null) {
|
||||
return ImmutableList.of(objectDeclaration.getObjectKeyword().getTextRange());
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Can't find text range for element '%s' with the text '%s'",
|
||||
element.getClass().getCanonicalName(), element.getText()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public trait TestTrait {
|
||||
public fun f()
|
||||
}
|
||||
|
||||
class Test: TestTrait {
|
||||
fun f() = 12
|
||||
}
|
||||
|
||||
@@ -61,6 +61,19 @@ public final class JetCompilerMessagingTest extends IDECompilerMessagingTest {
|
||||
});
|
||||
}
|
||||
|
||||
public void testVisibilityError() {
|
||||
doTest(new Function1<MessageChecker, Void>() {
|
||||
@Override
|
||||
public Void invoke(MessageChecker checker) {
|
||||
checker
|
||||
.expect(error().text("'f' hides member of supertype 'TestTrait' and needs 'override' modifier").at("test.kt", 6, 5))
|
||||
.expect(error().text("Cannot weaken access privilege 'public' for 'f' in 'TestTrait'").at("test.kt", 6, 9))
|
||||
;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(@NotNull Function1<MessageChecker, Void> whatToExpect) {
|
||||
performTest(whatToExpect, getCompiler(JetCompiler.class), TEST_DATA_PATH);
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ public final class Message {
|
||||
|
||||
public void check(@NotNull Message other) {
|
||||
checkMessages(other);
|
||||
Assert.assertEquals(other.category, this.category);
|
||||
Assert.assertEquals(other.line, this.line);
|
||||
Assert.assertEquals(other.column, this.column);
|
||||
Assert.assertEquals("Error category for message " + this, this.category, other.category);
|
||||
Assert.assertEquals("Invalid position (different line) for message:\n" + this + "\n", this.line, other.line);
|
||||
Assert.assertEquals("Invalid position (different column) for message:\n" + this + "\n", this.column, other.column);
|
||||
if (this.url != null) {
|
||||
Assert.assertTrue(other.url.endsWith(this.url));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user