KT-3945 Fixed - Prohibit modifiers for packages
This commit is contained in:
committed by
Alexander Udalov
parent
c7ea464636
commit
f554ff3c8c
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -59,6 +60,20 @@ public class JetModifierList extends JetElementImpl {
|
||||
return answer != null ? answer : Collections.<JetAnnotationEntry>emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ASTNode> getModifierNodes() {
|
||||
List<ASTNode> modifierNodes = new ArrayList<ASTNode>();
|
||||
|
||||
ASTNode node = getNode().getFirstChildNode();
|
||||
while (node != null) {
|
||||
if (node.getElementType() instanceof JetKeywordToken) {
|
||||
modifierNodes.add(node);
|
||||
}
|
||||
node = node.getTreeNext();
|
||||
}
|
||||
return modifierNodes;
|
||||
}
|
||||
|
||||
public boolean hasModifier(JetToken token) {
|
||||
return getModifierNode(token) != null;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -29,10 +31,12 @@ import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptorLite;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceLikeBuilder;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetAnnotationElementType;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -88,6 +92,7 @@ public class DeclarationResolver {
|
||||
|
||||
|
||||
public void process(@NotNull JetScope rootScope) {
|
||||
resolveNamespaceHeaders();
|
||||
resolveAnnotationConstructors();
|
||||
resolveConstructorHeaders();
|
||||
resolveAnnotationStubsOnClassesAndConstructors();
|
||||
@@ -98,6 +103,29 @@ public class DeclarationResolver {
|
||||
checkRedeclarationsInInnerClassNames();
|
||||
}
|
||||
|
||||
private void resolveNamespaceHeaders() {
|
||||
for (JetFile file : context.getNamespaceDescriptors().keySet()) {
|
||||
JetNamespaceHeader namespaceHeader = file.getNamespaceHeader();
|
||||
|
||||
if (namespaceHeader != null) {
|
||||
PsiElement firstChild = namespaceHeader.getFirstChild();
|
||||
|
||||
if (firstChild instanceof JetModifierList) {
|
||||
JetModifierList modifierList = (JetModifierList) firstChild;
|
||||
|
||||
for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) {
|
||||
JetReferenceExpression reference = annotationEntry.getCalleeExpression().getConstructorReferenceExpression();
|
||||
trace.report(UNRESOLVED_REFERENCE.on(reference, reference));
|
||||
}
|
||||
|
||||
for (ASTNode node : modifierList.getModifierNodes()) {
|
||||
trace.report(ILLEGAL_MODIFIER.on(node.getPsi(), (JetKeywordToken) node.getElementType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveAnnotationConstructors() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package illegal_modifiers
|
||||
<!UNRESOLVED_REFERENCE!>myAnnotation<!> <!ILLEGAL_MODIFIER!>public<!> package illegal_modifiers
|
||||
|
||||
abstract class A() {
|
||||
<!INCOMPATIBLE_MODIFIERS!>abstract<!> <!INCOMPATIBLE_MODIFIERS!>final<!> fun f()
|
||||
|
||||
Reference in New Issue
Block a user