getElement() and getRangeInElement() are expected to return non-nullable values

This commit is contained in:
Nikolay Krasko
2012-02-24 19:29:21 +04:00
parent 7f97f9710e
commit 782ea7b1c3
8 changed files with 87 additions and 66 deletions
@@ -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();
}
+15 -21
View File
@@ -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')