JetSimpleNameExpression's name is not null

Modify usages accordingly
This commit is contained in:
Alexander Udalov
2013-01-14 21:20:46 +04:00
parent 173dfc4811
commit 949f5ed834
11 changed files with 9 additions and 33 deletions
@@ -293,7 +293,6 @@ public class JetControlFlowProcessor {
if (baseExpression == null) return; if (baseExpression == null) return;
if (JetTokens.LABELS.contains(operationType)) { if (JetTokens.LABELS.contains(operationType)) {
String referencedName = operationSign.getReferencedName(); String referencedName = operationSign.getReferencedName();
referencedName = referencedName == null ? " <?>" : referencedName;
visitLabeledExpression(referencedName.substring(1), baseExpression); visitLabeledExpression(referencedName.substring(1), baseExpression);
} }
else { else {
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.psi;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.text.StringUtil;
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;
@@ -339,7 +338,7 @@ public class JetPsiUtil {
} }
//noinspection ConstantConditions //noinspection ConstantConditions
return StringUtil.isNotEmpty(aliasName) ? Name.identifier(aliasName) : null; return !aliasName.isEmpty() ? Name.identifier(aliasName) : null;
} }
@Nullable @Nullable
@@ -72,19 +72,16 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
parent.getParent() instanceof JetImportDirective; parent.getParent() instanceof JetImportDirective;
} }
@Nullable @IfNotParsed @NotNull
public String getReferencedName() { public String getReferencedName() {
String text = getReferencedNameElement().getNode().getText(); String text = getReferencedNameElement().getNode().getText();
return text != null ? JetPsiUtil.unquoteIdentifierOrFieldReference(text) : null; return JetPsiUtil.unquoteIdentifierOrFieldReference(text);
} }
@Nullable @NotNull
public Name getReferencedNameAsName() { public Name getReferencedNameAsName() {
String name = getReferencedName(); String name = getReferencedName();
if (name != null && name.length() == 0) { return Name.identifierNoValidate(name);
// TODO: fix parser or do something // stepan.koltsov@
}
return name != null ? Name.identifierNoValidate(name) : null;
} }
@NotNull @NotNull
@@ -592,9 +592,6 @@ public class DescriptorResolver {
continue; continue;
} }
Name referencedName = subjectTypeParameterName.getReferencedNameAsName(); Name referencedName = subjectTypeParameterName.getReferencedNameAsName();
if (referencedName == null) {
continue;
}
TypeParameterDescriptorImpl typeParameterDescriptor = parameterByName.get(referencedName); TypeParameterDescriptorImpl typeParameterDescriptor = parameterByName.get(referencedName);
JetTypeReference boundTypeReference = constraint.getBoundTypeReference(); JetTypeReference boundTypeReference = constraint.getBoundTypeReference();
JetType bound = null; JetType bound = null;
@@ -78,7 +78,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
} }
for (JetSimpleNameExpression nameExpression : namespaceHeader.getParentNamespaceNames()) { for (JetSimpleNameExpression nameExpression : namespaceHeader.getParentNamespaceNames()) {
Name namespaceName = JetPsiUtil.safeName(nameExpression.getReferencedName()); Name namespaceName = Name.identifier(nameExpression.getReferencedName());
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded( NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(
null, currentOwner, namespaceName, nameExpression, handler); null, currentOwner, namespaceName, nameExpression, handler);
@@ -227,12 +227,7 @@ public class QualifiedExpressionResolver {
@NotNull @NotNull
private LookupResult lookupSimpleNameReference(@NotNull JetSimpleNameExpression referenceExpression, private LookupResult lookupSimpleNameReference(@NotNull JetSimpleNameExpression referenceExpression,
@NotNull JetScope outerScope, boolean onlyClasses, boolean namespaceLevel) { @NotNull JetScope outerScope, boolean onlyClasses, boolean namespaceLevel) {
Name referencedName = referenceExpression.getReferencedNameAsName(); Name referencedName = referenceExpression.getReferencedNameAsName();
if (referencedName == null) {
//to store a scope where we tried to resolve this reference
return new SuccessfulLookupResult(Collections.<DeclarationDescriptor>emptyList(), outerScope, namespaceLevel);
}
Set<DeclarationDescriptor> descriptors = Sets.newHashSet(); Set<DeclarationDescriptor> descriptors = Sets.newHashSet();
NamespaceDescriptor namespaceDescriptor = outerScope.getNamespace(referencedName); NamespaceDescriptor namespaceDescriptor = outerScope.getNamespace(referencedName);
@@ -90,9 +90,6 @@ public class CallResolver {
assert calleeExpression instanceof JetSimpleNameExpression; assert calleeExpression instanceof JetSimpleNameExpression;
JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression; JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression;
Name referencedName = nameExpression.getReferencedNameAsName(); Name referencedName = nameExpression.getReferencedNameAsName();
if (referencedName == null) {
return OverloadResolutionResultsImpl.nameNotFound();
}
List<CallableDescriptorCollector<? extends VariableDescriptor>> callableDescriptorCollectors = Lists.newArrayList(); List<CallableDescriptorCollector<? extends VariableDescriptor>> callableDescriptorCollectors = Lists.newArrayList();
if (nameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { if (nameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
referencedName = Name.identifier(referencedName.getName().substring(1)); referencedName = Name.identifier(referencedName.getName().substring(1));
@@ -146,7 +143,6 @@ public class CallResolver {
ExpressionTypingUtils.checkWrappingInRef(expression, context.trace, context.scope); ExpressionTypingUtils.checkWrappingInRef(expression, context.trace, context.scope);
Name name = expression.getReferencedNameAsName(); Name name = expression.getReferencedNameAsName();
if (name == null) return checkArgumentTypesAndFail(context);
prioritizedTasks = TaskPrioritizer.<CallableDescriptor, FunctionDescriptor>computePrioritizedTasks(context, name, functionReference, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES); prioritizedTasks = TaskPrioritizer.<CallableDescriptor, FunctionDescriptor>computePrioritizedTasks(context, name, functionReference, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES);
ResolutionTask.DescriptorCheckStrategy abstractConstructorCheck = new ResolutionTask.DescriptorCheckStrategy() { ResolutionTask.DescriptorCheckStrategy abstractConstructorCheck = new ResolutionTask.DescriptorCheckStrategy() {
@@ -1017,7 +1017,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
assert JetTokens.LABELS.contains(operationSign.getReferencedNameElementType()); assert JetTokens.LABELS.contains(operationSign.getReferencedNameElementType());
String referencedName = operationSign.getReferencedName(); String referencedName = operationSign.getReferencedName();
referencedName = referencedName == null ? " <?>" : referencedName;
context.labelResolver.enterLabeledElement(new LabelName(referencedName.substring(1)), baseExpression); context.labelResolver.enterLabeledElement(new LabelName(referencedName.substring(1)), baseExpression);
// TODO : Some processing for the label? // TODO : Some processing for the label?
JetTypeInfo typeInfo = facade.getTypeInfo(baseExpression, context, isStatement); JetTypeInfo typeInfo = facade.getTypeInfo(baseExpression, context, isStatement);
@@ -1062,11 +1061,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
DataFlowInfo dataFlowInfo = context.dataFlowInfo; DataFlowInfo dataFlowInfo = context.dataFlowInfo;
if (operationType == JetTokens.IDENTIFIER) { if (operationType == JetTokens.IDENTIFIER) {
Name referencedName = operationSign.getReferencedNameAsName(); Name referencedName = operationSign.getReferencedNameAsName();
if (referencedName != null) { JetTypeInfo typeInfo = getTypeInfoForBinaryCall(context.scope, referencedName, context, expression);
JetTypeInfo typeInfo = getTypeInfoForBinaryCall(context.scope, referencedName, context, expression); result = typeInfo.getType();
result = typeInfo.getType(); dataFlowInfo = typeInfo.getDataFlowInfo();
dataFlowInfo = typeInfo.getDataFlowInfo();
}
} }
else if (OperatorConventions.BINARY_OPERATION_NAMES.containsKey(operationType)) { else if (OperatorConventions.BINARY_OPERATION_NAMES.containsKey(operationType)) {
JetTypeInfo typeInfo = getTypeInfoForBinaryCall(context.scope, OperatorConventions.BINARY_OPERATION_NAMES.get(operationType), JetTypeInfo typeInfo = getTypeInfoForBinaryCall(context.scope, OperatorConventions.BINARY_OPERATION_NAMES.get(operationType),
@@ -198,7 +198,6 @@ public class JetImportOptimizer implements ImportOptimizer {
FqName fqName = null; FqName fqName = null;
for (JetSimpleNameExpression nameExpression : simpleNameExpressions) { for (JetSimpleNameExpression nameExpression : simpleNameExpressions) {
Name referencedName = nameExpression.getReferencedNameAsName(); Name referencedName = nameExpression.getReferencedNameAsName();
assert referencedName != null;
if (fqName == null) { if (fqName == null) {
fqName = new FqName(referencedName.getName()); fqName = new FqName(referencedName.getName());
} else { } else {
@@ -86,8 +86,6 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
return Collections.emptyList(); return Collections.emptyList();
} }
assert referenceName != null;
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) element.getContainingFile()); ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) element.getContainingFile());
List<FqName> result = Lists.newArrayList(); List<FqName> result = Lists.newArrayList();
@@ -200,7 +200,6 @@ public class JetNameSuggester {
@Override @Override
public void visitSimpleNameExpression(JetSimpleNameExpression expression) { public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
String referenceName = expression.getReferencedName(); String referenceName = expression.getReferencedName();
if (referenceName == null) return;
if (referenceName.equals(referenceName.toUpperCase())) { if (referenceName.equals(referenceName.toUpperCase())) {
addName(result, referenceName, validator); addName(result, referenceName, validator);
} }