getElement() and getRangeInElement() are expected to return non-nullable values
This commit is contained in:
@@ -207,8 +207,12 @@ public class JetParsing extends AbstractJetParsing {
|
||||
advance(); // DOT
|
||||
|
||||
reference = mark();
|
||||
expect(IDENTIFIER, "Qualified name must be a '.'-separated identifier list", TokenSet.create(AS_KEYWORD, DOT, SEMICOLON));
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
if (expect(IDENTIFIER, "Qualified name must be a '.'-separated identifier list", TokenSet.create(AS_KEYWORD, DOT, SEMICOLON))) {
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
}
|
||||
else {
|
||||
reference.drop();
|
||||
}
|
||||
|
||||
PsiBuilder.Marker precede = qualifiedName.precede();
|
||||
qualifiedName.done(DOT_QUALIFIED_EXPRESSION);
|
||||
@@ -817,7 +821,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
errorAndAdvance("Expecting 'val' or 'var'");
|
||||
}
|
||||
|
||||
boolean typeParametersDeclared = at(LT) ? parseTypeParameterList(TokenSet.create(IDENTIFIER, EQ, COLON, SEMICOLON)) : false;
|
||||
boolean typeParametersDeclared = at(LT) && parseTypeParameterList(TokenSet.create(IDENTIFIER, EQ, COLON, SEMICOLON));
|
||||
|
||||
TokenSet propertyNameFollow = TokenSet.create(COLON, EQ, LBRACE, SEMICOLON, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, CLASS_KEYWORD);
|
||||
|
||||
@@ -1236,8 +1240,11 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
PsiBuilder.Marker reference = mark();
|
||||
expect(IDENTIFIER, "Expecting type parameter name", TokenSet.orSet(TokenSet.create(COLON, COMMA), TYPE_REF_FIRST));
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
if (expect(IDENTIFIER, "Expecting type parameter name", TokenSet.orSet(TokenSet.create(COLON, COMMA), TYPE_REF_FIRST))) {
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
} else {
|
||||
reference.drop();
|
||||
}
|
||||
|
||||
expect(COLON, "Expecting ':' before the upper bound", TYPE_REF_FIRST);
|
||||
|
||||
@@ -1394,8 +1401,13 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
PsiBuilder.Marker reference = mark();
|
||||
while (true) {
|
||||
expect(IDENTIFIER, "Expecting type name", TokenSet.orSet(JetExpressionParsing.EXPRESSION_FIRST, JetExpressionParsing.EXPRESSION_FOLLOW));
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
if (expect(IDENTIFIER, "Expecting type name", TokenSet.orSet(JetExpressionParsing.EXPRESSION_FIRST, JetExpressionParsing.EXPRESSION_FOLLOW))) {
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
}
|
||||
else {
|
||||
reference.drop();
|
||||
break;
|
||||
}
|
||||
|
||||
parseTypeArgumentList(-1);
|
||||
if (!at(DOT)) {
|
||||
|
||||
@@ -81,27 +81,27 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
public String getReferencedName() {
|
||||
PsiElement referencedNameElement = getReferencedNameElement();
|
||||
if (referencedNameElement == null) {
|
||||
return null;
|
||||
}
|
||||
String text = referencedNameElement.getNode().getText();
|
||||
String text = getReferencedNameElement().getNode().getText();
|
||||
return text != null ? JetPsiUtil.unquoteIdentifierOrFieldReference(text) : null;
|
||||
}
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
@NotNull
|
||||
public PsiElement getReferencedNameElement() {
|
||||
PsiElement element = findChildByType(REFERENCE_TOKENS);
|
||||
if (element == null) {
|
||||
element = findChildByType(JetExpressionParsing.ALL_OPERATIONS);
|
||||
}
|
||||
return element;
|
||||
|
||||
if (element != null) {
|
||||
return element;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
public IElementType getReferencedNameElementType() {
|
||||
PsiElement element = getReferencedNameElement();
|
||||
return element == null ? null : element.getNode().getElementType();
|
||||
return getReferencedNameElement().getNode().getElementType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -194,27 +194,31 @@ public class ImportsResolver {
|
||||
}
|
||||
|
||||
JetExpression selectorExpression = importedReference.getSelectorExpression();
|
||||
assert selectorExpression instanceof JetSimpleNameExpression;
|
||||
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
||||
JetSimpleNameExpression lastReference = getLastReference(receiverExpression);
|
||||
if (lastReference == null || !canImportMembersFrom(declarationDescriptors, lastReference)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Collection<? extends DeclarationDescriptor> result;
|
||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
result = lookupDescriptorsForSimpleNameReference(selector, ((NamespaceDescriptor) declarationDescriptor).getMemberScope(), true);
|
||||
if (!result.isEmpty()) return result;
|
||||
|
||||
if (selectorExpression instanceof JetSimpleNameExpression) {
|
||||
JetSimpleNameExpression selector = (JetSimpleNameExpression) selectorExpression;
|
||||
JetSimpleNameExpression lastReference = getLastReference(receiverExpression);
|
||||
if (lastReference == null || !canImportMembersFrom(declarationDescriptors, lastReference)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
result = lookupObjectMembers((ClassDescriptor) declarationDescriptor, selector);
|
||||
if (!result.isEmpty()) return result;
|
||||
}
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
result = lookupVariableMembers((VariableDescriptor) declarationDescriptor, selector);
|
||||
if (!result.isEmpty()) return result;
|
||||
|
||||
Collection<? extends DeclarationDescriptor> result;
|
||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
result = lookupDescriptorsForSimpleNameReference(selector, ((NamespaceDescriptor) declarationDescriptor).getMemberScope(), true);
|
||||
if (!result.isEmpty()) return result;
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
result = lookupObjectMembers((ClassDescriptor) declarationDescriptor, selector);
|
||||
if (!result.isEmpty()) return result;
|
||||
}
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
result = lookupVariableMembers((VariableDescriptor) declarationDescriptor, selector);
|
||||
if (!result.isEmpty()) return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,8 @@ JetFile: Imports_ERR.jet
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(as)('as')
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(as)('as')
|
||||
PsiWhiteSpace(' ')
|
||||
ANNOTATION_ENTRY
|
||||
CONSTRUCTOR_CALLEE
|
||||
@@ -122,9 +121,8 @@ JetFile: Imports_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(MUL)('*')
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(MUL)('*')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(as)('as')
|
||||
@@ -156,9 +154,8 @@ JetFile: Imports_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(MUL)('*')
|
||||
PsiErrorElement:Expecting type name
|
||||
PsiElement(MUL)('*')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(as)('as')
|
||||
@@ -182,10 +179,9 @@ JetFile: Imports_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(SEMICOLON)(';')
|
||||
PsiWhiteSpace('\n')
|
||||
IMPORT_DIRECTIVE
|
||||
@@ -199,10 +195,9 @@ JetFile: Imports_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
PsiElement(DOT)('.')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(SEMICOLON)(';')
|
||||
PsiWhiteSpace('\n')
|
||||
IMPORT_DIRECTIVE
|
||||
@@ -212,10 +207,9 @@ JetFile: Imports_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(DOT)('.')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiErrorElement:Qualified name must be a '.'-separated identifier list
|
||||
<empty list>
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(as)('as')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('bar')
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.references;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetContainerNode;
|
||||
@@ -44,7 +45,7 @@ class JetArrayAccessReference extends JetPsiReference implements MultiRangeRefer
|
||||
return indicesNode == null ? PsiReference.EMPTY_ARRAY : new PsiReference[] { new JetArrayAccessReference(expression) };
|
||||
}
|
||||
|
||||
public JetArrayAccessReference(JetArrayAccessExpression expression) {
|
||||
public JetArrayAccessReference(@NotNull JetArrayAccessExpression expression) {
|
||||
super(expression);
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.plugin.references;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.TipsManager;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -33,7 +32,7 @@ public class JetPackageReference extends JetPsiReference {
|
||||
|
||||
private JetNamespaceHeader packageExpression;
|
||||
|
||||
public JetPackageReference(JetNamespaceHeader expression) {
|
||||
public JetPackageReference(@NotNull JetNamespaceHeader expression) {
|
||||
super(expression);
|
||||
packageExpression = expression;
|
||||
}
|
||||
@@ -48,11 +47,10 @@ public class JetPackageReference extends JetPsiReference {
|
||||
bindingContext, TipsManager.getReferenceVariants(packageExpression, bindingContext));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
PsiElement element = getElement();
|
||||
if (element == null) return null;
|
||||
return new TextRange(0, element.getTextLength());
|
||||
return new TextRange(0, getElement().getTextLength());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.intellij.psi.ResolveResult;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
@@ -36,12 +37,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DESCRIPTOR_TO_DECLARATION;
|
||||
|
||||
public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
|
||||
@NotNull
|
||||
protected final JetReferenceExpression myExpression;
|
||||
|
||||
protected JetPsiReference(JetReferenceExpression expression) {
|
||||
protected JetPsiReference(@NotNull JetReferenceExpression expression) {
|
||||
this.myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return myExpression;
|
||||
@@ -69,6 +73,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException();
|
||||
@@ -90,6 +95,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PsiElement doResolve() {
|
||||
JetFile file = (JetFile) getElement().getContainingFile();
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||
|
||||
@@ -33,23 +33,29 @@ import org.jetbrains.jet.plugin.completion.DescriptorLookupConverter;
|
||||
*/
|
||||
public class JetSimpleNameReference extends JetPsiReference {
|
||||
|
||||
@NotNull
|
||||
private final JetSimpleNameExpression myExpression;
|
||||
|
||||
public JetSimpleNameReference(JetSimpleNameExpression jetSimpleNameExpression) {
|
||||
public JetSimpleNameReference(@NotNull JetSimpleNameExpression jetSimpleNameExpression) {
|
||||
super(jetSimpleNameExpression);
|
||||
myExpression = jetSimpleNameExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return myExpression.getReferencedNameElement();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetSimpleNameExpression getExpression() {
|
||||
return myExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
PsiElement element = getElement();
|
||||
if (element == null) return null;
|
||||
return new TextRange(0, element.getTextLength());
|
||||
return new TextRange(0, getElement().getTextLength());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user