This commit is contained in:
Svetlana Isakova
2012-08-17 15:53:11 +04:00
committed by Andrey Breslav
parent 115bd21bea
commit 3e5026407d
17 changed files with 24 additions and 31 deletions
@@ -49,7 +49,7 @@ public class PositioningStrategies {
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
returnTypeRef = property.getPropertyTypeRef(); returnTypeRef = property.getTypeRef();
nameNode = getNameNode(property); nameNode = getNameNode(property);
} }
else if (declaration instanceof JetPropertyAccessor) { else if (declaration instanceof JetPropertyAccessor) {
@@ -108,7 +108,7 @@ public class PositioningStrategies {
else if (element instanceof JetProperty) { else if (element instanceof JetProperty) {
JetProperty property = (JetProperty) element; JetProperty property = (JetProperty) element;
PsiElement endOfSignatureElement; PsiElement endOfSignatureElement;
JetTypeReference propertyTypeRef = property.getPropertyTypeRef(); JetTypeReference propertyTypeRef = property.getTypeRef();
PsiElement nameIdentifier = property.getNameIdentifier(); PsiElement nameIdentifier = property.getNameIdentifier();
if (propertyTypeRef != null) { if (propertyTypeRef != null) {
endOfSignatureElement = propertyTypeRef; endOfSignatureElement = propertyTypeRef;
@@ -45,7 +45,7 @@ public final class JetModifiableBlockHelper {
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
if (property.getPropertyTypeRef() != null) { if (property.getTypeRef() != null) {
return takePartInDeclarationTypeInference(property); return takePartInDeclarationTypeInference(property);
} }
@@ -71,7 +71,7 @@ public final class JetModifiableBlockHelper {
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
if (property.getPropertyTypeRef() == null) { if (property.getTypeRef() == null) {
return true; return true;
} }
} }
@@ -37,7 +37,7 @@ public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed impl
} }
@Override @Override
public JetTypeReference getPropertyTypeRef() { public JetTypeReference getTypeRef() {
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE); return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
} }
@@ -116,7 +116,7 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
@Override @Override
@Nullable @Nullable
public JetTypeReference getPropertyTypeRef() { public JetTypeReference getTypeRef() {
ASTNode node = getNode().getFirstChildNode(); ASTNode node = getNode().getFirstChildNode();
boolean passedColon = false; boolean passedColon = false;
while (node != null) { while (node != null) {
@@ -59,7 +59,7 @@ public class JetPsiFactory {
public static JetTypeReference createType(Project project, String type) { public static JetTypeReference createType(Project project, String type) {
JetProperty property = createProperty(project, "val x : " + type); JetProperty property = createProperty(project, "val x : " + type);
return property.getPropertyTypeRef(); return property.getTypeRef();
} }
//the pair contains the first and the last elements of a range //the pair contains the first and the last elements of a range
@@ -188,7 +188,7 @@ public class JetPsiUtil {
} }
if (pattern instanceof JetBindingPattern) { if (pattern instanceof JetBindingPattern) {
JetBindingPattern bindingPattern = (JetBindingPattern) pattern; JetBindingPattern bindingPattern = (JetBindingPattern) pattern;
if (bindingPattern.getVariableDeclaration().getPropertyTypeRef() == null && bindingPattern.getCondition() == null) { if (bindingPattern.getVariableDeclaration().getTypeRef() == null && bindingPattern.getCondition() == null) {
return true; return true;
} }
} }
@@ -30,5 +30,5 @@ public interface JetVariableDeclaration extends JetDeclaration, JetWithExpressio
ASTNode getValOrVarNode(); ASTNode getValOrVarNode();
@Nullable @Nullable
JetTypeReference getPropertyTypeRef(); JetTypeReference getTypeRef();
} }
@@ -68,7 +68,7 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
@Override @Override
public PsiJetPropertyStub createStub(@NotNull JetProperty psi, StubElement parentStub) { public PsiJetPropertyStub createStub(@NotNull JetProperty psi, StubElement parentStub) {
JetTypeReference typeRef = psi.getPropertyTypeRef(); JetTypeReference typeRef = psi.getTypeRef();
JetExpression expression = psi.getInitializer(); JetExpression expression = psi.getInitializer();
assert !psi.isLocal() : "Should not store local property"; assert !psi.isLocal() : "Should not store local property";
@@ -455,7 +455,7 @@ public class BodyResolver {
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) { private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15 //JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; JetType expectedTypeForInitializer = property.getTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope(scope, propertyDescriptor.getTypeParameters(), ReceiverDescriptor.NO_RECEIVER, trace); JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope(scope, propertyDescriptor.getTypeParameters(), ReceiverDescriptor.NO_RECEIVER, trace);
JetType type = expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, DataFlowInfo.EMPTY, trace); JetType type = expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, DataFlowInfo.EMPTY, trace);
// //
@@ -144,7 +144,7 @@ public class DeclarationsChecker {
private void checkDeclaredTypeInPublicMember(JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) { private void checkDeclaredTypeInPublicMember(JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) {
boolean hasDeferredType; boolean hasDeferredType;
if (member instanceof JetProperty) { if (member instanceof JetProperty) {
hasDeferredType = ((JetProperty) member).getPropertyTypeRef() == null && DescriptorResolver.hasBody((JetProperty) member); hasDeferredType = ((JetProperty) member).getTypeRef() == null && DescriptorResolver.hasBody((JetProperty) member);
} }
else { else {
assert member instanceof JetFunction; assert member instanceof JetFunction;
@@ -204,7 +204,7 @@ public class DeclarationsChecker {
(setter != null && setter.getBodyExpression() != null); (setter != null && setter.getBodyExpression() != null);
if (propertyDescriptor.getModality() == Modality.ABSTRACT) { if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
if (property.getInitializer() == null && property.getPropertyTypeRef() == null) { if (property.getInitializer() == null && property.getTypeRef() == null) {
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)); trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
} }
return; return;
@@ -229,7 +229,7 @@ public class DeclarationsChecker {
trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property)); trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property));
} }
} }
if (!error && property.getPropertyTypeRef() == null) { if (!error && property.getTypeRef() == null) {
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)); trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
} }
return; return;
@@ -823,7 +823,7 @@ public class DescriptorResolver {
final BindingTrace trace final BindingTrace trace
) { ) {
// TODO : receiver? // TODO : receiver?
JetTypeReference propertyTypeRef = property.getPropertyTypeRef(); JetTypeReference propertyTypeRef = property.getTypeRef();
if (propertyTypeRef == null) { if (propertyTypeRef == null) {
final JetExpression initializer = property.getInitializer(); final JetExpression initializer = property.getInitializer();
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.types.expressions;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IElementType;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -110,7 +109,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
VariableDescriptor propertyDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo, context.trace); VariableDescriptor propertyDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo, context.trace);
JetExpression initializer = property.getInitializer(); JetExpression initializer = property.getInitializer();
if (property.getPropertyTypeRef() != null && initializer != null) { if (property.getTypeRef() != null && initializer != null) {
JetType outType = propertyDescriptor.getType(); JetType outType = propertyDescriptor.getType();
JetType initializerType = facade.getTypeInfo(initializer, context.replaceExpectedType(outType).replaceScope(scope)).getType(); JetType initializerType = facade.getTypeInfo(initializer, context.replaceExpectedType(outType).replaceScope(scope)).getType();
} }
@@ -297,7 +297,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
@Override @Override
public void visitBindingPattern(JetBindingPattern pattern) { public void visitBindingPattern(JetBindingPattern pattern) {
JetProperty variableDeclaration = pattern.getVariableDeclaration(); JetProperty variableDeclaration = pattern.getVariableDeclaration();
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef(); JetTypeReference propertyTypeRef = variableDeclaration.getTypeRef();
JetType type = propertyTypeRef == null ? subjectType : context.expressionTypingServices.getTypeResolver().resolveType(context.scope, propertyTypeRef, context.trace, true); JetType type = propertyTypeRef == null ? subjectType : context.expressionTypingServices.getTypeResolver().resolveType(context.scope, propertyTypeRef, context.trace, true);
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type, context.trace); VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type, context.trace);
scopeToExtend.addVariableDescriptor(variableDescriptor); scopeToExtend.addVariableDescriptor(variableDescriptor);
@@ -731,7 +731,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
declaration.accept(new JetVisitorVoid() { declaration.accept(new JetVisitorVoid() {
@Override @Override
public void visitProperty(JetProperty property) { public void visitProperty(JetProperty property) {
if (property.getPropertyTypeRef() != null) { if (property.getTypeRef() != null) {
memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property, JetTestUtils.DUMMY_TRACE)); memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property, JetTestUtils.DUMMY_TRACE));
} }
else { else {
@@ -67,7 +67,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
} }
if (parent instanceof JetProperty) { if (parent instanceof JetProperty) {
JetProperty property = (JetProperty) parent; JetProperty property = (JetProperty) parent;
if (property.getPropertyTypeRef() == null) { if (property.getTypeRef() == null) {
addTypeAnnotation(project, property, type); addTypeAnnotation(project, property, type);
} }
else { else {
@@ -105,7 +105,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
} }
JetNamedDeclaration declaration = (JetNamedDeclaration) parent; JetNamedDeclaration declaration = (JetNamedDeclaration) parent;
if (declaration instanceof JetProperty && !PsiTreeUtil.isAncestor(((JetProperty) declaration).getInitializer(), element, false)) { if (declaration instanceof JetProperty && !PsiTreeUtil.isAncestor(((JetProperty) declaration).getInitializer(), element, false)) {
if (((JetProperty) declaration).getPropertyTypeRef() != null) { if (((JetProperty) declaration).getTypeRef() != null) {
setText(JetBundle.message("specify.type.explicitly.remove.action.name")); setText(JetBundle.message("specify.type.explicitly.remove.action.name"));
return true; return true;
} }
@@ -173,7 +173,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
} }
public static void addTypeAnnotation(Project project, JetProperty property, @NotNull JetType exprType) { public static void addTypeAnnotation(Project project, JetProperty property, @NotNull JetType exprType) {
if (property.getPropertyTypeRef() != null) return; if (property.getTypeRef() != null) return;
PsiElement anchor = property.getNameIdentifier(); PsiElement anchor = property.getNameIdentifier();
if (anchor == null) return; if (anchor == null) return;
anchor = anchor.getNextSibling(); anchor = anchor.getNextSibling();
@@ -227,7 +227,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
} }
public static void removeTypeAnnotation(JetProperty property) { public static void removeTypeAnnotation(JetProperty property) {
removeTypeAnnotation(property, property.getPropertyTypeRef()); removeTypeAnnotation(property, property.getTypeRef());
} }
public static void removeTypeAnnotation(JetParameter parameter) { public static void removeTypeAnnotation(JetParameter parameter) {
@@ -22,15 +22,9 @@ import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode;
import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings; import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import org.jetbrains.jet.plugin.structureView.JetStructureViewElement;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@@ -69,7 +63,7 @@ public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration>
text = CLASS_INITIALIZER; text = CLASS_INITIALIZER;
} else if (declaration instanceof JetProperty) { } else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
JetTypeReference ref = property.getPropertyTypeRef(); JetTypeReference ref = property.getTypeRef();
if (ref != null) { if (ref != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " "; if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":"; text += ":";
@@ -114,7 +114,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
assert nextSibling != null; assert nextSibling != null;
newElement.deleteChildRange(nextSibling, initializer); newElement.deleteChildRange(nextSibling, initializer);
if (newElement.getPropertyTypeRef() == null && type != null) { if (newElement.getTypeRef() == null && type != null) {
typeToAdd = type; typeToAdd = type;
} }
} }