Merge remote branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2011-10-14 07:43:02 +02:00
198 changed files with 5644 additions and 2010 deletions
@@ -97,6 +97,15 @@ public class JetHighlighter extends SyntaxHighlighterBase {
JET_AUTO_CAST_EXPRESSION = TextAttributesKey.createTextAttributesKey("JET.AUTO.CAST.EXPRESSION", clone);
}
public static final TextAttributesKey JET_WRAPPED_INTO_REF;
static {
TextAttributes attributes = new TextAttributes();
attributes.setEffectType(EffectType.LINE_UNDERSCORE);
attributes.setEffectColor(Color.BLACK);
JET_WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey("JET.WRAPPED.INTO.REF", attributes);
}
public static final TextAttributesKey JET_AUTOCREATED_IT;
static {
@@ -15,6 +15,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.AnalyzerFacade;
@@ -91,7 +92,7 @@ public class DebugInfoAnnotator implements Annotator {
target = labelTarget.getText();
}
else {
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, expression);
Collection<? extends ResolvedCall<? extends DeclarationDescriptor>> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, expression);
if (declarationDescriptors != null) {
target = "[" + declarationDescriptors.size() + " descriptors]";
}
@@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.annotations;
import com.google.common.collect.Sets;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
@@ -117,9 +118,28 @@ public class JetPsiChecker implements Annotator {
holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlighter.JET_AUTOCREATED_IT);
}
}
markVariableAsWrappedIfNeeded(expression.getNode(), target);
super.visitSimpleNameExpression(expression);
}
private void markVariableAsWrappedIfNeeded(ASTNode node, DeclarationDescriptor target) {
if (target instanceof VariableDescriptor) {
VariableDescriptor variableDescriptor = (VariableDescriptor) target;
if (bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor)) {
holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes(JetHighlighter.JET_WRAPPED_INTO_REF);
}
}
}
@Override
public void visitProperty(JetProperty property) {
DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property);
markVariableAsWrappedIfNeeded(property.getNameIdentifier().getNode(), declarationDescriptor);
super.visitProperty(property);
}
@Override
public void visitExpression(JetExpression expression) {
JetType autoCast = bindingContext.get(AUTOCAST, expression);
@@ -12,8 +12,8 @@ import org.jetbrains.jet.lang.psi.*;
/**
* @author svtk
*/
public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> {
public AddFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) {
public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
public AddFunctionBodyFix(@NotNull JetFunction element) {
super(element);
}
@@ -37,7 +37,7 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrProperty
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetFunctionOrPropertyAccessor newElement = (JetFunctionOrPropertyAccessor) element.copy();
JetFunction newElement = (JetFunction) element.copy();
JetExpression bodyExpression = newElement.getBodyExpression();
if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) {
newElement.add(JetPsiFactory.createWhiteSpace(project));
@@ -48,12 +48,12 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrProperty
element.replace(newElement);
}
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() {
public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunction>() {
@Override
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor;
return new AddFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement());
public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunction;
return new AddFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
}
};
}
@@ -4,11 +4,13 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetToken;
@@ -17,19 +19,39 @@ import org.jetbrains.jet.lexer.JetTokens;
/**
* @author svtk
*/
public class AddModifierFix extends ModifierFix {
public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
private final JetKeywordToken modifier;
private final JetToken[] modifiersThanCanBeReplaced;
private AddModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier, JetToken[] modifiersThanCanBeReplaced) {
super(element, modifier);
super(element);
this.modifier = modifier;
this.modifiersThanCanBeReplaced = modifiersThanCanBeReplaced;
}
@NotNull
/*package*/ static String getElementName(JetModifierListOwner modifierListOwner) {
String name = null;
if (modifierListOwner instanceof PsiNameIdentifierOwner) {
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) modifierListOwner).getNameIdentifier();
if (nameIdentifier != null) {
name = nameIdentifier.getText();
}
}
else if (modifierListOwner instanceof JetPropertyAccessor) {
name = ((JetPropertyAccessor) modifierListOwner).getNamePlaceholder().getText();
}
if (name == null) {
name = modifierListOwner.getText();
}
return "'" + name + "'";
}
@NotNull
@Override
public String getText() {
if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
return "Make " + getElementName() + " " + modifier.getValue();
return "Make " + getElementName(element) + " " + modifier.getValue();
}
return "Add '" + modifier.getValue() + "' modifier";
}
@@ -0,0 +1,92 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author svtk
*/
public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
private JetType type;
public AddReturnTypeFix(@NotNull JetNamedDeclaration element, JetType type) {
super(element);
this.type = type;
}
@NotNull
@Override
public String getText() {
return "Add return type declaration";
}
@NotNull
@Override
public String getFamilyName() {
return "Add return type declaration";
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiElement newElement;
if (element instanceof JetProperty) {
newElement = addPropertyType(project, (JetProperty) element, type);
}
else {
assert element instanceof JetFunction;
newElement = addFunctionType(project, (JetFunction) element, type);
}
ImportClassHelper.perform(type, element, newElement);
}
@Override
public boolean startInWriteAction() {
return true;
}
public static JetProperty addPropertyType(Project project, JetProperty property, JetType type) {
JetProperty newProperty = (JetProperty) property.copy();
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
PsiElement nameIdentifier = newProperty.getNameIdentifier();
addTypeReference(newProperty, typeReference, colon, nameIdentifier);
return newProperty;
}
public static JetFunction addFunctionType(Project project, JetFunction function, JetType type) {
JetFunction newFunction = (JetFunction) function.copy();
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
JetParameterList valueParameterList = newFunction.getValueParameterList();
addTypeReference(newFunction, typeReference, colon, valueParameterList);
return newFunction;
}
private static void addTypeReference(JetNamedDeclaration element, JetTypeReference typeReference, Pair<PsiElement, PsiElement> colon, PsiElement anchor) {
assert anchor != null;
element.addAfter(typeReference, anchor);
element.addRangeAfter(colon.getFirst(), colon.getSecond(), anchor);
}
public static JetIntentionActionFactory<JetNamedDeclaration> createFactory() {
return new JetIntentionActionFactory<JetNamedDeclaration>() {
@Override
public JetIntentionAction<JetNamedDeclaration> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetNamedDeclaration;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
return new AddReturnTypeFix((JetNamedDeclaration) diagnostic.getPsiElement(), type);
}
};
}
}
@@ -1,38 +0,0 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lexer.JetKeywordToken;
/**
* @author svtk
*/
public abstract class ModifierFix extends JetIntentionAction<JetModifierListOwner> {
protected final JetKeywordToken modifier;
protected ModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier) {
super(element);
this.modifier = modifier;
}
@NotNull
protected String getElementName() {
String name = null;
if (element instanceof PsiNameIdentifierOwner) {
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
if (nameIdentifier != null) {
name = nameIdentifier.getText();
}
}
else if (element instanceof JetPropertyAccessor) {
name = ((JetPropertyAccessor) element).getNamePlaceholder().getText();
}
if (name == null) {
name = element.getText();
}
return "'" + name + "'";
}
}
@@ -1,9 +1,11 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.extapi.psi.ASTDelegatePsiElement;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
@@ -69,4 +71,12 @@ public class QuickFixUtil {
}
};
}
public static boolean removePossiblyWhiteSpace(ASTDelegatePsiElement element, PsiElement possiblyWhiteSpace) {
if (possiblyWhiteSpace instanceof PsiWhiteSpace) {
element.deleteChildInternal(possiblyWhiteSpace.getNode());
return true;
}
return false;
}
}
@@ -29,7 +29,7 @@ public class QuickFixes {
}
static {
JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD);
JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD);
JetIntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD});
add(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
@@ -53,22 +53,21 @@ public class QuickFixes {
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
JetIntentionActionFactory<JetFunction> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeFunctionBodyFactory);
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
JetIntentionActionFactory<JetFunction> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
add(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory);
add(Errors.NON_MEMBER_ABSTRACT_ACCESSOR, removeAbstractModifierFactory);
add(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD));
add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListFactory(JetTokens.OVERRIDE_KEYWORD));
add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
add(Errors.VAL_WITH_SETTER, ChangeVariableMutabilityFix.createFactory());
@@ -84,10 +83,10 @@ public class QuickFixes {
add(Errors.UNNECESSARY_SAFE_CALL, ReplaceSafeCallToDotCall.createFactory());
JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveRedundantModifierFix.createFactory();
JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory(true);
add(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createFactory(JetTokens.FINAL_KEYWORD));
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
@@ -96,14 +95,15 @@ public class QuickFixes {
add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory);
JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createFactory(JetTokens.OPEN_KEYWORD);
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS));
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
add(Errors.NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.PROPERTY));
add(Errors.NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY, removeOpenModifierFactory);
add(Errors.ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.PROPERTY));
add(Errors.ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY, removeAbstractModifierFactory);
JetIntentionActionFactory<JetModifierList> removeModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory();
add(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
add(Errors.ILLEGAL_MODIFIER, removeModifierFactory);
add(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory());
}
}
}
@@ -4,18 +4,22 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lexer.JetTokens;
/**
* @author svtk
*/
public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> {
public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunction> {
public RemoveFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) {
public RemoveFunctionBodyFix(@NotNull JetFunction element) {
super(element);
}
@@ -39,25 +43,41 @@ public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunctionOrPrope
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetFunctionOrPropertyAccessor newElement = (JetFunctionOrPropertyAccessor) element.copy();
JetExpression bodyExpression = newElement.getBodyExpression();
if (bodyExpression != null) {
PsiElement prevSibling = bodyExpression.getPrevSibling();
if (prevSibling instanceof PsiWhiteSpace) {
((JetElement)newElement).deleteChildInternal(prevSibling.getNode());
}
((JetElement)newElement).deleteChildInternal(bodyExpression.getNode());
JetFunction function = (JetFunction) element.copy();
JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
if (function.hasBlockBody()) {
PsiElement prevElement = bodyExpression.getPrevSibling();
QuickFixUtil.removePossiblyWhiteSpace(function, prevElement);
function.deleteChildInternal(bodyExpression.getNode());
}
element.replace(newElement);
else {
PsiElement prevElement = bodyExpression.getPrevSibling();
PsiElement prevPrevElement = prevElement.getPrevSibling();
QuickFixUtil.removePossiblyWhiteSpace(function, prevElement);
removePossiblyEquationSign(function, prevElement);
removePossiblyEquationSign(function, prevPrevElement);
function.deleteChildInternal(bodyExpression.getNode());
}
element.replace(function);
}
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() {
private static boolean removePossiblyEquationSign(@NotNull JetElement element, @Nullable PsiElement possiblyEq) {
if (possiblyEq instanceof LeafPsiElement && ((LeafPsiElement)possiblyEq).getElementType() == JetTokens.EQ) {
QuickFixUtil.removePossiblyWhiteSpace(element, possiblyEq.getNextSibling());
element.deleteChildInternal(possiblyEq.getNode());
return true;
}
return false;
}
public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunction>() {
@Override
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor;
return new RemoveFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement());
public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunction;
return new RemoveFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
}
};
}
}
}
@@ -1,14 +1,15 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.extapi.psi.ASTDelegatePsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetModifierList;
@@ -20,35 +21,31 @@ import org.jetbrains.jet.lexer.JetTokens;
/**
* @author svtk
*/
public class RemoveModifierFix extends ModifierFix {
public class RemoveModifierFix {
private final JetKeywordToken modifier;
private final boolean isRedundant;
public RemoveModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier) {
super(element, modifier);
public RemoveModifierFix(JetKeywordToken modifier, boolean isRedundant) {
this.modifier = modifier;
this.isRedundant = isRedundant;
}
@NotNull
@Override
public String getText() {
if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
return "Make " + getElementName() + " not " + modifier.getValue();
private static String makeText(@Nullable JetModifierListOwner element, JetKeywordToken modifier, boolean isRedundant) {
if (isRedundant) {
return "Remove redundant '" + modifier.getValue() + "' modifier";
}
if (element != null && modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
return "Make " + AddModifierFix.getElementName(element) + " not " + modifier.getValue();
}
return "Remove '" + modifier.getValue() + "' modifier";
}
@NotNull
@Override
public String getFamilyName() {
return "Remove modifier";
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
private static String getFamilyName() {
return "Remove modifier fix";
}
@NotNull
/*package*/ static <T extends JetModifierListOwner> T removeModifier(T element, JetToken modifier) {
private static <T extends JetModifierListOwner> T removeModifier(T element, JetToken modifier) {
JetModifierList modifierList = element.getModifierList();
assert modifierList != null;
removeModifierFromList(modifierList, modifier);
@@ -56,38 +53,128 @@ public class RemoveModifierFix extends ModifierFix {
PsiElement whiteSpace = modifierList.getNextSibling();
assert element instanceof JetElement;
((JetElement) element).deleteChildInternal(modifierList.getNode());
removeWhiteSpace((JetElement) element, whiteSpace);
QuickFixUtil.removePossiblyWhiteSpace((JetElement) element, whiteSpace);
}
return element;
}
/*package*/ static JetModifierList removeModifierFromList(@NotNull JetModifierList modifierList, JetToken modifier) {
@NotNull
private static JetModifierList removeModifierFromList(@NotNull JetModifierList modifierList, JetToken modifier) {
assert modifierList.hasModifier(modifier);
ASTNode modifierNode = modifierList.getModifierNode(modifier);
PsiElement whiteSpace = modifierNode.getPsi().getNextSibling();
boolean wsRemoved = removeWhiteSpace(modifierList, whiteSpace);
boolean wsRemoved = QuickFixUtil.removePossiblyWhiteSpace(modifierList, whiteSpace);
modifierList.deleteChildInternal(modifierNode);
if (!wsRemoved) {
removeWhiteSpace(modifierList, modifierList.getLastChild());
QuickFixUtil.removePossiblyWhiteSpace(modifierList, modifierList.getLastChild());
}
return modifierList;
}
private static boolean removeWhiteSpace(ASTDelegatePsiElement element, PsiElement subElement) {
if (subElement instanceof PsiWhiteSpace) {
element.deleteChildInternal(subElement.getNode());
return true;
private class RemoveModifierFromListOwner extends JetIntentionAction<JetModifierListOwner> {
public RemoveModifierFromListOwner(@NotNull JetModifierListOwner element) {
super(element);
}
@NotNull
@Override
public String getText() {
return makeText(element, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
}
return false;
}
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
private class RemoveModifierFromList extends JetIntentionAction<JetModifierList> {
public RemoveModifierFromList(@NotNull JetModifierList element) {
super(element);
}
@NotNull
@Override
public String getText() {
return makeText(null, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierList newElement = (JetModifierList) element.copy();
element.replace(RemoveModifierFix.removeModifierFromList(newElement, modifier));
}
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return new RemoveModifierFix((JetModifierListOwner) diagnostic.getPsiElement(), modifier);
return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}
}
private static RemoveModifierFix createRemoveModifierFixFromDiagnostic(DiagnosticWithPsiElement diagnostic, boolean isRedundant) {
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
return new RemoveModifierFix(modifier, isRedundant);
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListOwnerFactory(modifier, false);
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory() {
return createRemoveModifierFromListFactory(false);
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListFactory(modifier, false);
}
}
@@ -2,7 +2,6 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
@@ -97,7 +96,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
newElement.deleteChildRange(nextSibling, initializer);
if (newElement.getPropertyTypeRef() == null && type != null) {
newElement = addPropertyType(project, newElement, type);
newElement = AddReturnTypeFix.addPropertyType(project, newElement, type);
needImport = true;
}
}
@@ -108,17 +107,6 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
}
}
public static JetProperty addPropertyType(Project project, JetProperty property, JetType type) {
JetProperty newProperty = (JetProperty) property.copy();
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
PsiElement nameIdentifier = newProperty.getNameIdentifier();
assert nameIdentifier != null;
newProperty.addAfter(typeReference, nameIdentifier);
newProperty.addRangeAfter(colon.getFirst(), colon.getSecond(), nameIdentifier);
return newProperty;
}
public static JetIntentionActionFactory<JetProperty> createFactory() {
return new JetIntentionActionFactory<JetProperty>() {
@Override
@@ -1,54 +0,0 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lexer.JetKeywordToken;
/**
* @author svtk
*/
public class RemoveRedundantModifierFix extends JetIntentionAction<JetModifierList> {
private JetKeywordToken redundantModifier;
public RemoveRedundantModifierFix(@NotNull JetModifierList element, @NotNull JetKeywordToken redundantModifier) {
super(element);
this.redundantModifier = redundantModifier;
}
@NotNull
@Override
public String getText() {
return "Remove redundant '" + redundantModifier + "' modifier";
}
@NotNull
@Override
public String getFamilyName() {
return "Remove redundant modifier";
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierList newElement = (JetModifierList) element.copy();
element.replace(RemoveModifierFix.removeModifierFromList(newElement, redundantModifier));
}
public static JetIntentionActionFactory<JetModifierList> createFactory() {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
return new RemoveRedundantModifierFix((JetModifierList) diagnostic.getPsiElement(), modifier);
}
};
}
}
@@ -11,6 +11,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.plugin.AnalyzerFacade;
import java.util.Collection;
@@ -80,7 +81,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
if (psiElement != null) {
return psiElement;
}
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
Collection<? extends ResolvedCall<? extends DeclarationDescriptor>> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
if (declarationDescriptors != null) return null;
return file;
}
@@ -88,12 +89,12 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
protected ResolveResult[] doMultiResolve() {
JetFile file = (JetFile) getElement().getContainingFile();
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(file);
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
if (declarationDescriptors == null) return ResolveResult.EMPTY_ARRAY;
ResolveResult[] results = new ResolveResult[declarationDescriptors.size()];
Collection<? extends ResolvedCall<? extends DeclarationDescriptor>> resolvedCalls = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
if (resolvedCalls == null) return ResolveResult.EMPTY_ARRAY;
ResolveResult[] results = new ResolveResult[resolvedCalls.size()];
int i = 0;
for (DeclarationDescriptor descriptor : declarationDescriptors) {
PsiElement element = bindingContext.get(DESCRIPTOR_TO_DECLARATION, descriptor);
for (ResolvedCall<? extends DeclarationDescriptor> resolvedCall : resolvedCalls) {
PsiElement element = bindingContext.get(DESCRIPTOR_TO_DECLARATION, resolvedCall.getResultingDescriptor());
if (element != null) {
results[i] = new PsiElementResolveResult(element, true);
i++;
@@ -38,7 +38,9 @@ class JetSimpleNameReference extends JetPsiReference {
@Override
public TextRange getRangeInElement() {
return new TextRange(0, getElement().getTextLength());
PsiElement element = getElement();
if (element == null) return null;
return new TextRange(0, element.getTextLength());
}
@NotNull
@@ -2,7 +2,7 @@ package org.jetbrains.jet.plugin.run;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.RunConfigurationExtension;
import com.intellij.execution.JavaRunConfigurationExtensionManager;
import com.intellij.execution.configurations.*;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.runners.ExecutionEnvironment;
@@ -49,14 +49,15 @@ public class JetRunConfiguration extends ModuleBasedConfiguration<RunConfigurati
public void readExternal(final Element element) throws InvalidDataException {
PathMacroManager.getInstance(getProject()).expandPaths(element);
super.readExternal(element);
RunConfigurationExtension.readSettings(this, element);
JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
DefaultJDOMExternalizer.readExternal(this, element);
readModule(element);
}
public void writeExternal(final Element element) throws WriteExternalException {
super.writeExternal(element);
RunConfigurationExtension.writeSettings(this, element);
JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
DefaultJDOMExternalizer.writeExternal(this, element);
writeModule(element);
PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
@@ -36,15 +36,3 @@ l1:
error:
<ERROR>
=====================
== a ==
val a = Array<Int>
---------------------
l0:
<START>
r(Array)
r(Array<Int>)
l1:
<END>
error:
<ERROR>
=====================
@@ -55,56 +55,3 @@ l1:
error:
<ERROR>
=====================
== x ==
var x = 1
---------------------
l0:
<START>
r(1)
l1:
<END>
error:
<ERROR>
=====================
== y ==
val y = true && false
---------------------
l0:
<START>
r(true)
jf(l2)
r(false)
l2:
r(true && false)
l1:
<END>
error:
<ERROR>
=====================
== z ==
val z = false && true
---------------------
l0:
<START>
r(false)
jf(l2)
r(true)
l2:
r(false && true)
l1:
<END>
error:
<ERROR>
=====================
== t ==
val t = Test()
---------------------
l0:
<START>
r(Test)
r(Test())
l1:
<END>
error:
<ERROR>
=====================
+1 -1
View File
@@ -23,7 +23,7 @@ class WithPC1(a : Int) {
this(s : String) : this(1) {}
this(b : Char) : <error>this("", 2)</error> {}
this(b : Char) : <error>this</error>("", 2) {}
this(b : Byte) : this(""), <error>this(1)</error> {}
}
+3 -3
View File
@@ -16,7 +16,7 @@ class A
fun A.plus(a : Any) {
1.foo()
true.<error>foo()</error>
true.<error>foo</error>()
1
}
@@ -55,10 +55,10 @@ namespace null_safety {
val command = parse("")
command<error>.</error>foo
command.foo
command.equals(null)
command<warning>?.</warning>equals(null)
command?.equals(null)
command.equals1(null)
command<warning>?.</warning>equals1(null)
+2 -2
View File
@@ -136,9 +136,9 @@ fun tf() : Int {
}
fun failtest(a : Int) : Int {
<error>if (fail() || true) {
if (fail() || <error>true</error>) {
}</error>
}
<error>return 1</error>
}
+3 -1
View File
@@ -1,3 +1,5 @@
fun Int.foo() : Boolean = true
fun foo() : Int {
val s = ""
val x = 1
@@ -17,7 +19,7 @@ fun foo() : Int {
else => 1
}
return when (<warning>x</warning>?:null) {
<error>.</error>equals(1) => 1
<error>.</error>foo() => 1
?.equals(1).equals(2) => 1
}
}
+51 -53
View File
@@ -1,4 +1,4 @@
<info>open</info> class A() {
<info descr="null">open</info> class A() {
fun foo() {}
}
@@ -9,25 +9,25 @@ class B() : A() {
fun f9() {
val a : A?
a?.foo()
a?.<error>bar</error>()
a?.<error descr="Unresolved reference: bar">bar</error>()
if (a is B) {
<info descr="Automatically cast to B">a</info>.bar()
a.foo()
<info descr="Automatically cast to A">a</info>.foo()
}
a?.foo()
a?.<error>bar</error>()
a?.<error descr="Unresolved reference: bar">bar</error>()
if (!(a is B)) {
a?.<error>bar</error>()
a?.<error descr="Unresolved reference: bar">bar</error>()
a?.foo()
}
if (!(a is B) || <info descr="Automatically cast to B">a</info>.bar() == ()) {
a?.<error>bar</error>()
a?.<error descr="Unresolved reference: bar">bar</error>()
}
if (!(a is B)) {
return;
}
<info descr="Automatically cast to B">a</info>.bar()
a.foo()
<info descr="Automatically cast to A">a</info>.foo()
}
fun f10() {
@@ -47,19 +47,17 @@ class C() : A() {
}
fun f10(a : A?) {
if (a is B) {
if (a is C) {
<info descr="Automatically cast to C">a</info>.bar();
}
}
}
fun f11(a : A?) {
when (a) {
is B => <info descr="Automatically cast to B">a</info>.bar()
is A => a.foo()
is Any => a.foo()
is Any? => a.<error>bar</error>()
is A => <info descr="Automatically cast to A">a</info>.foo()
is Any => <info descr="Automatically cast to A">a</info>.foo()
is Any? => a.<error descr="Unresolved reference: bar">bar</error>()
else => a?.foo()
}
}
@@ -67,21 +65,21 @@ fun f11(a : A?) {
fun f12(a : A?) {
when (a) {
is B => <info descr="Automatically cast to B">a</info>.bar()
is A => a.foo()
is Any => a.foo();
is Any? => a.<error>bar</error>()
is val c : <error>B</error> => c.foo()
is A => <info descr="Automatically cast to A">a</info>.foo()
is Any => <info descr="Automatically cast to A">a</info>.foo();
is Any? => a.<error descr="Unresolved reference: bar">bar</error>()
is val c : <error descr="[TYPE_MISMATCH_IN_BINDING_PATTERN] B must be a supertype of A?. Use is to match against B">B</error> => c.foo()
is val c is C => <info descr="Automatically cast to C">c</info>.bar()
is val c is C => <info descr="Automatically cast to C">a</info>.bar()
else => a?.foo()
}
if (a is val b) {
a?.<error>bar</error>()
a?.<error descr="Unresolved reference: bar">bar</error>()
b?.foo()
}
if (a is val b is B) {
b.foo()
<info descr="Automatically cast to A">b</info>.foo()
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Automatically cast to B">b</info>.bar()
}
@@ -89,41 +87,41 @@ fun f12(a : A?) {
fun f13(a : A?) {
if (a is val c is B) {
c.foo()
<info descr="Automatically cast to A">c</info>.foo()
<info descr="Automatically cast to B">c</info>.bar()
}
else {
a?.foo()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.bar()
}
a?.foo()
if (!(a is val c is B)) {
a?.foo()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.bar()
}
else {
a.foo()
<error>c</error>.bar()
<info descr="Automatically cast to A">a</info>.foo()
<error descr="Unresolved reference: c">c</error>.bar()
}
a?.foo()
if (a is val c is B && a.foo() == () && <info descr="Automatically cast to B">c</info>.bar() == ()) {
c.foo()
if (a is val c is B && <info descr="Automatically cast to A">a</info>.foo() == () && <info descr="Automatically cast to B">c</info>.bar() == ()) {
<info descr="Automatically cast to A">c</info>.foo()
<info descr="Automatically cast to B">c</info>.bar()
}
else {
a?.foo()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.bar()
}
if (!(a is val c is B) || !(a is val x is C)) {
<error>x</error>
<error>c</error>
<error descr="Unresolved reference: x">x</error>
<error descr="Unresolved reference: c">c</error>
}
else {
<error>x</error>
<error>c</error>
<error descr="Unresolved reference: x">x</error>
<error descr="Unresolved reference: c">c</error>
}
if (!(a is val c is B) || !(a is val c is C)) {
@@ -131,38 +129,38 @@ fun f13(a : A?) {
if (!(a is val c is B)) return
<info descr="Automatically cast to B">a</info>.bar()
<error>c</error>.foo()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.foo()
<error descr="Unresolved reference: c">c</error>.bar()
}
fun f14(a : A?) {
while (!(a is val c is B)) {
}
<info descr="Automatically cast to B">a</info>.bar()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.bar()
}
fun f15(a : A?) {
do {
} while (!(a is val c is B))
<info descr="Automatically cast to B">a</info>.bar()
<error>c</error>.bar()
<error descr="Unresolved reference: c">c</error>.bar()
}
fun getStringLength(obj : Any) : Char? {
if (obj !is String)
return null
return <info>obj</info>.get(0) // no cast to String is needed
return <info descr="Automatically cast to String">obj</info>.get(0) // no cast to String is needed
}
fun toInt(i: Int?): Int = if (i != null) <info descr="Automatically cast to Int">i</info> else 0
fun illegalWhenBody(a: Any): Int = when(a) {
is Int => <info descr="Automatically cast to Int">a</info>
is String => <error>a</error>
is String => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any but Int was expected">a</error>
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int => return <info descr="Automatically cast to Int">a</info>
is String => return <error>a</error>
is String => return <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any but Int was expected">a</error>
}
}
fun declarations(a: Any?) {
@@ -188,17 +186,17 @@ fun vars(a: Any?) {
}
fun tuples(a: Any?) {
if (a != null) {
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error>a</error>)
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
}
if (a is String) {
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
val s: (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
}
fun illegalTupleReturnType(): (Any, String) = (<error>a</error>, <error>a</error>)
fun illegalTupleReturnType(): (Any, String) = (<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
if (a is String) {
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
}
val illegalFunctionLiteral: Function0<Int> = <error>{ <error>a</error> }</error>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error>a</error> }
val illegalFunctionLiteral: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
if (a is Int) {
val legalFunctionLiteral: Function0<Int> = { <info descr="Automatically cast to Int">a</info> }
@@ -213,43 +211,43 @@ fun returnFunctionLiteral(a: Any?): Function0<Int> =
if (a is Int) { (): Int => <info descr="Automatically cast to Int">a</info> }
else { () => 1 }
fun illegalTupleReturnType(a: Any): (Any, String) = (a, <error>a</error>)
fun illegalTupleReturnType(a: Any): (Any, String) = (a, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any but String was expected">a</error>)
fun declarationInsidePattern(x: (Any, Any)): String = when(x) { is (val a is String, *) => <info descr="Automatically cast to String">a</info>; else => "something" }
fun mergeAutocasts(a: Any?) {
if (a is String || a is Int) {
a.<error>compareTo</error>("")
a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
a.toString()
}
if (a is Int || a is String) {
a.<error>compareTo</error>("")
a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
}
when (a) {
is String, is Any => a.<error>compareTo</error>("")
is String, is Any => a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
}
if (a is String && a is Any) {
val i: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
}
if (a is String && <info descr="Automatically cast to String">a</info>.compareTo("") == 0) {}
if (a is String || a.<error>compareTo</error>("") == 0) {}
if (a is String || a.<error descr="Unresolved reference: compareTo">compareTo</error>("") == 0) {}
}
//mutability
fun f(): String {
var a: Any = 11
if (a is String) {
val i: String = <error>a</error>
<error>a</error>.compareTo("f")
val f: Function0<String> = { <error>a</error> }
return <error>a</error>
val i: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
<error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>.compareTo("f")
val f: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error> }
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
}
return ""
}
fun foo(var a: Any): Int {
if (a is Int) {
return <error>a</error>
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to Int is impossible, because a could have changed since the is-check">a</error>
}
return 1
}
@@ -35,8 +35,6 @@
var <error>v5</error> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x}
var <error>v6</error> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){}
<info>abstract</info> val v7 : Int <info>abstract</info> <info>get</info>
<info>abstract</info> var v8 : Int <info>abstract</info> <info>get</info> <info>abstract</info> <info>set</info>
var <error>v9</error> : Int <info>set</info>
var <error>v10</error> : Int <info>get</info>
@@ -0,0 +1,18 @@
fun notContainsBreak() {
var <info>a</info> = 1
val v = {
<info>a</info> = 2
}
var <info>x</info> = 1
val b = object {
fun foo() {
<info>x</info> = 2
}
}
var <info>y</info> = 1
fun foo() {
<info>y</info> = 1
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
abstract class XXX {
abstract val a : Int abstract get
abstract val a : Int get
}
@@ -29,19 +29,19 @@ class MyClass() {
<!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors
var i: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {}
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
abstract class MyAbstractClass() {
@@ -73,19 +73,19 @@ abstract class MyAbstractClass() {
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors
var i: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j1: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {}
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
trait MyTrait {
@@ -117,19 +117,19 @@ trait MyTrait {
<!REDUNDANT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors
var i: Int abstract get abstract set
var i1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var k: Int abstract set
var k1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var k: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int abstract get abstract set
var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {}
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
enum class MyEnum() {
@@ -161,19 +161,19 @@ enum class MyEnum() {
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors
var i: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {}
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
abstract enum class MyAbstractEnum() {}
@@ -207,19 +207,19 @@ namespace MyNamespace {
<!NON_MEMBER_ABSTRACT_FUNCTION!>abstract<!> fun j() {}
//property accessors
var i: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED!>k<!>: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var k1: Int = 0; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var <!MUST_BE_INITIALIZED!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {}
var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
}
//creating an instance
@@ -25,4 +25,61 @@ class C {
<!NOT_A_LOOP_LABEL!>break@f<!>
}
fun containsBreak(a: String?, b: String?) {
while (a == null) {
break;
}
a<!UNSAFE_CALL!>.<!>compareTo("2")
}
fun notContainsBreak(a: String?, b: String?) {
while (a == null) {
while (b == null) {
break;
}
}
a.compareTo("2")
}
fun containsBreakWithLabel(a: String?) {
@loop while(a == null) {
break@loop
}
a?.compareTo("2")
}
fun containsIllegalBreak(a: String?) {
@loop while(a == null) {
<!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@label<!><!>
}
a.compareTo("2")
}
fun containsBreakToOuterLoop(a: String?, b: String?) {
@loop while(b == null) {
while(a == null) {
break@loop
}
a.compareTo("2")
}
}
fun containsBreakInsideLoopWithLabel(a: String?, array: Array<Int>) {
@ while(a == null) {
for (el in array) {
break@
}
}
a<!UNSAFE_CALL!>.<!>compareTo("2")
}
fun unresolvedBreak(a: String?, array: Array<Int>) {
while(a == null) {
@ for (el in array) {
break
}
if (true) break else <!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@<!><!>
}
a<!UNSAFE_CALL!>.<!>compareTo("2")
}
}
@@ -22,7 +22,7 @@ class WithPC1(a : Int) {
this(s : String) : this(1) {}
this(b : Char) : <!NONE_APPLICABLE!>this("", 2)<!> {}
this(b : Char) : <!NONE_APPLICABLE!>this<!>("", 2) {}
this(b : Byte) : this(""), <!MANY_CALLS_TO_THIS!>this(1)<!> {}
}
@@ -16,7 +16,7 @@ class A
fun A.plus(a : Any) {
1.foo()
true.<!NONE_APPLICABLE!>foo()<!>
true.<!NONE_APPLICABLE!>foo<!>()
1
}
@@ -55,10 +55,10 @@ namespace null_safety {
val command = parse("")
command<!UNSAFE_CALL!>.<!>foo
command.foo
command.equals(null)
command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null)
command?.equals(null)
command.equals1(null)
command<!UNNECESSARY_SAFE_CALL!>?.<!>equals1(null)
@@ -164,3 +164,46 @@ fun f(): Int {
}
fun f(): Int = if (1 < 2) 1 else returnNothing()
public fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = 1
class B() {
protected fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = "ss"
}
fun testFunctionLiterals() {
val endsWithVarDeclaration : fun() : Boolean = {
<!EXPECTED_TYPE_MISMATCH!>val x = 2<!>
}
val endsWithAssignment = { () : Int =>
val x = 1
<!EXPECTED_TYPE_MISMATCH!>x = 333<!>
}
val endsWithReAssignment = { () : Int =>
val x = 1
<!EXPECTED_TYPE_MISMATCH!>x += 333<!>
}
val endsWithFunDeclaration : fun() : String = {
val x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
}
val endsWithObjectDeclaration : fun() : Int = {
val x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>object A {}<!>
}
val expectedUnitReturnType1 = { () : Unit =>
val x = 1
}
val expectedUnitReturnType2 = { () : Unit =>
fun meow() : Unit {}
object A {}
}
}
@@ -7,7 +7,7 @@ abstract class A() {
open var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>r<!>: String
get
<!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> protected set
<!ILLEGAL_MODIFIER!>abstract<!> protected set
}
<!TRAIT_CAN_NOT_BE_FINAL!>final<!> trait T {}
@@ -15,7 +15,7 @@ abstract class A() {
class FinalClass() {
<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> fun foo() {}
val i: Int = 1
<!NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY!>open<!> get(): Int = $i
<!ILLEGAL_MODIFIER!>open<!> get(): Int = $i
var j: Int = 1
<!NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY!>open<!> set(v: Int) {}
<!ILLEGAL_MODIFIER!>open<!> set(v: Int) {}
}
@@ -4,5 +4,5 @@ namespace a {
}
val x = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND, UNRESOLVED_REFERENCE!>a<!>
val x = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND!>a<!>
val y2 = <!NAMESPACE_IS_NOT_AN_EXPRESSION!>namespace<!>
@@ -0,0 +1,11 @@
namespace foo
class X {}
val s = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND!>java<!>
val ss = <!NO_CLASS_OBJECT!>System<!>
val sss = <!NO_CLASS_OBJECT!>X<!>
val xs = java.<!EXPRESSION_EXPECTED_NAMESPACE_FOUND!>lang<!>
val xss = java.lang.<!NO_CLASS_OBJECT!>System<!>
val xsss = foo.<!NO_CLASS_OBJECT!>X<!>
val xssss = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND!>foo<!>
@@ -25,4 +25,5 @@ class Test() {
<!UNRESOLVED_REFERENCE!>$b<!> = <!UNRESOLVED_REFERENCE!>$a<!>
a = <!UNRESOLVED_REFERENCE!>$b<!>
}
public val <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>i<!> = 1
}
@@ -0,0 +1,17 @@
namespace return
class A {
fun outer() {
fun inner() {
if (1 < 2)
return@inner
else
return@outer
}
if (1 < 2)
<!NOT_A_RETURN_LABEL!>return@A<!>
else if (2 < 3)
<!NOT_A_RETURN_LABEL!>return<!UNRESOLVED_REFERENCE!>@inner<!><!>
return@outer
}
}
@@ -136,16 +136,16 @@ fun tf() : Int {
}
fun failtest(a : Int) : Int {
<!UNREACHABLE_BECAUSE_OF_NOTHING!>if (fail() || true) {
if (fail() || <!UNREACHABLE_CODE!>true<!>) {
}<!>
<!UNREACHABLE_BECAUSE_OF_NOTHING!>return 1<!>
}
<!UNREACHABLE_CODE!>return 1<!>
}
fun foo(a : Nothing) : Unit {
1
a
<!UNREACHABLE_BECAUSE_OF_NOTHING!>2<!>
<!UNREACHABLE_CODE!>2<!>
}
fun fail() : Nothing {
@@ -1,3 +1,5 @@
fun Int.foo() : Boolean = true
fun foo() : Int {
val s = ""
val x = 1
@@ -17,7 +19,8 @@ fun foo() : Int {
else => 1
}
return when (<!USELESS_ELVIS!>x<!>?:null) {
<!UNSAFE_CALL!>.<!>equals(1) => 1
<!UNSAFE_CALL!>.<!>foo() => 1
.equals(1) => 1
?.equals(1).equals(2) => 1
}
}
@@ -47,11 +47,9 @@ class C() : A() {
}
fun f10(a : A?) {
if (a is B) {
if (a is C) {
a.bar();
}
}
}
fun f11(a : A?) {
@@ -35,10 +35,12 @@ abstract class Test() {
var <!MUST_BE_INITIALIZED!>v5<!> : Int get() = 1; set(x){$v5 = x}
var <!MUST_BE_INITIALIZED!>v6<!> : Int get() = $v6 + 1; set(x){}
abstract val v7 : Int abstract get
abstract var v8 : Int abstract get abstract set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v9<!> : Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v10<!> : Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get
abstract val v7 : Int get
abstract var v8 : Int get set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v9<!> : Int set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v10<!> : Int get
abstract val v11 : Int <!ILLEGAL_MODIFIER!>abstract<!> get
abstract var v12 : Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
}
@@ -1,4 +1,4 @@
abstract class XXX {
abstract val a : Int abstract get
abstract val a : Int get
}
@@ -0,0 +1,16 @@
trait B {
fun bar() {}
}
class C() {
fun bar() {
}
}
fun test(a : Any?) {
if (a is B) {
if (a is C) {
a.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar()<!>;
}
}
}
@@ -0,0 +1,41 @@
class A() {
fun plus(i : Int) {}
fun minus() {}
fun contains(a : Any?) : Boolean = true
}
fun A.div(i : Int) {}
fun A?.times(i : Int) {}
fun test(x : Int?, a : A?) {
x<!UNSAFE_CALL!>.<!>plus(1)
x?.plus(1)
x <!UNSAFE_INFIX_CALL!>plus<!> 1
x <!UNSAFE_INFIX_CALL!>+<!> 1
<!UNSAFE_CALL!>-<!>x
x<!UNSAFE_CALL!>.<!>minus()
x?.minus()
a<!UNSAFE_CALL!>.<!>plus(1)
a?.plus(1)
a <!UNSAFE_INFIX_CALL!>plus<!> 1
a <!UNSAFE_INFIX_CALL!>+<!> 1
<!UNSAFE_CALL!>-<!>a
a<!UNSAFE_CALL!>.<!>minus()
a?.minus()
a<!UNSAFE_CALL!>.<!>div(1)
a <!UNSAFE_INFIX_CALL!>/<!> 1
a <!UNSAFE_INFIX_CALL!>div<!> 1
a?.div(1)
a.times(1)
a * 1
a times 1
a<!UNNECESSARY_SAFE_CALL!>?.<!>times(1)
1 <!UNSAFE_INFIX_CALL!>in<!> a
a <!UNSAFE_INFIX_CALL!>contains<!> 1
a<!UNSAFE_CALL!>.<!>contains(1)
a?.contains(1)
}
@@ -0,0 +1,9 @@
class Foo {
fun foo() {}
}
fun Any?.foo() {}
fun test(f : Foo?) {
f.foo()
}
@@ -0,0 +1,44 @@
class A {
fun foo() {}
}
fun A.bar() {}
fun A?.buzz() {}
fun test(a : A?) {
a<!UNSAFE_CALL!>.<!>foo() // error
a<!UNSAFE_CALL!>.<!>bar() // error
a.buzz()
a?.foo()
a?.bar()
a<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
}
fun A.test() {
foo()
bar()
buzz()
this.foo()
this.bar()
this.buzz()
this<!UNNECESSARY_SAFE_CALL!>?.<!>foo() // warning
this<!UNNECESSARY_SAFE_CALL!>?.<!>bar() // warning
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
}
fun A?.test() {
<!UNSAFE_CALL!>foo<!>() // error
<!UNSAFE_CALL!>bar<!>() // error
buzz()
this<!UNSAFE_CALL!>.<!>foo() // error
this<!UNSAFE_CALL!>.<!>bar() // error
this.buzz()
this?.foo()
this?.bar()
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
}
+1 -1
View File
@@ -3,7 +3,7 @@ class Outer() {
val outer: Outer get() = this@Outer
}
public val x = Inner()
public val x : Inner = Inner()
}
fun box() : String {
@@ -1,5 +1,5 @@
open class Base() {
public val plain = 239
val plain = 239
public val read : Int
get() = 239
@@ -1,5 +1,5 @@
class Outer() {
public val s = "xyzzy"
val s = "xyzzy"
open class InnerBase(public val name: String) {
}
@@ -7,7 +7,7 @@ class Outer() {
class InnerDerived(): InnerBase(s) {
}
public val x = InnerDerived()
val x = InnerDerived()
}
fun box() : String {
@@ -0,0 +1,24 @@
import java.util.ArrayList
fun launch(f : fun() : Unit) {
f()
}
fun box(): String {
val list = ArrayList<Int>()
val foo : fun() : Unit = {
list.add(2) //first exception
}
foo()
launch({
list.add(3)
})
val bar = {
val x = 1 //second exception
}
bar()
return if (list.size() == 2 && list.get(0) == 2 && list.get(1) == 3) "OK" else "fail"
}
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any
}
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any
}
@@ -1,2 +0,0 @@
// "Make 'get' not abstract" "true"
val i : Int = 0; <caret>get
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any { return "a" }
}
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any = 1
}
@@ -1,2 +0,0 @@
// "Make 'get' not abstract" "true"
val i : Int = 0; <caret>abstract get
@@ -1,5 +0,0 @@
// "Make 'i' open" "true"
open class A() {
open val i: Int = 1
<caret>open get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'get' not open" "true"
open class A() {
val i: Int = 1
<caret>get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'i' open" "true"
open class A() {
val i: Int = 1
<caret>open get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'get' not open" "true"
open class A() {
val i: Int = 1
<caret>open get(): Int = $i
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "true"
namespace a
class A() {
protected fun <caret>foo() : Int = 1
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "true"
namespace a
class A() {
public fun <caret>foo() : String = "a"
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "true"
namespace a
import java.util.List
public val <caret>l : List<Int>? = java.util.Collections.emptyList<Int>()
@@ -0,0 +1,6 @@
// "Add return type declaration" "false"
namespace a
class A() {
internal protected fun <caret>foo() = 1
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "true"
namespace a
class A() {
protected fun <caret>foo() = 1
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "false"
namespace a
class A() {
public fun <caret>foo()
}
@@ -0,0 +1,6 @@
// "Add return type declaration" "true"
namespace a
class A() {
public fun <caret>foo() = "a"
}
@@ -0,0 +1,4 @@
// "Add return type declaration" "true"
namespace a
public val <caret>l = java.util.Collections.emptyList<Int>()
@@ -58,4 +58,46 @@ public class ArrayGenTest extends CodegenTestCase {
System.out.println(invoke.getClass());
assertTrue(invoke instanceof Integer);
}
public void testIterator () throws Exception {
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testPrimitiveIterator () throws Exception {
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testLongIterator () throws Exception {
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testCharIterator () throws Exception {
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testArrayIndices () throws Exception {
loadText("fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testCharIndices () throws Exception {
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
}
@@ -178,4 +178,16 @@ public class ClassGenTest extends CodegenTestCase {
blackBoxFile("regressions/kt48.jet");
System.out.println(generateToText());
}
public void testKt309 () throws Exception {
loadText("fun box() = null");
final Method method = generateFunction("box");
assertEquals(method.getReturnType().getName(), "java.lang.Object");
System.out.println(generateToText());
}
public void testKt343 () throws Exception {
blackBoxFile("regressions/kt343.jet");
System.out.println(generateToText());
}
}
@@ -6,6 +6,7 @@ package org.jetbrains.jet.codegen;
public class ClosuresGenTest extends CodegenTestCase {
public void testSimplestClosure() throws Exception {
blackBoxFile("classes/simplestClosure.jet");
System.out.println(generateToText());
}
public void testSimplestClosureAndBoxing() throws Exception {
@@ -2,6 +2,8 @@ package org.jetbrains.jet.codegen;
import jet.IntRange;
import jet.Tuple2;
import jet.Tuple3;
import jet.Tuple4;
import jet.typeinfo.TypeInfo;
import org.jetbrains.jet.parsing.JetParsingTest;
@@ -9,6 +11,7 @@ import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author yole
@@ -489,12 +492,23 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testTupleLiteral() throws Exception {
loadText("fun foo() = (1, \"foo\")");
System.out.println(generateToText());
final Method main = generateFunction();
Tuple2 tuple2 = (Tuple2) main.invoke(null);
assertEquals(1, tuple2._1);
assertEquals("foo", tuple2._2);
}
public void testParametrizedTupleLiteral() throws Exception {
loadText("fun <E,D> E.foo(extra: java.util.List<D>) = (1, \"foo\", this, extra)");
System.out.println(generateToText());
final Method main = generateFunction();
Tuple4 tuple4 = (Tuple4) main.invoke(null, "aaa", Arrays.asList(10), TypeInfo.STRING_TYPE_INFO, TypeInfo.INT_TYPE_INFO);
assertEquals(1, tuple4._1);
assertEquals("foo", tuple4._2);
assertEquals("aaa", tuple4._3);
}
public void testPredicateOperator() throws Exception {
loadText("fun foo(s: String) = s?startsWith(\"J\")");
final Method main = generateFunction();
@@ -90,13 +90,13 @@ public class PatternMatchingTest extends CodegenTestCase {
Method foo = generateFunction();
final Object result;
try {
result = foo.invoke(null, new Tuple2<Integer, Integer>(1, 2));
result = foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2));
} catch (Exception e) {
System.out.println(generateToText());
throw e;
}
assertEquals("one,two", result);
assertEquals("something", foo.invoke(null, new Tuple2<String, String>("not", "tuple")));
assertEquals("something", foo.invoke(null, new Tuple2<String, String>(null, "not", "tuple")));
}
public void testCall() throws Exception {
@@ -119,8 +119,8 @@ public class PatternMatchingTest extends CodegenTestCase {
public void testNames() throws Exception {
loadText("fun foo(x: (Any, Any)) = when(x) { is (val a is String, *) => a; else => \"something\" }");
Method foo = generateFunction();
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>("JetBrains", "s.r.o.")));
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(1, 2)));
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>(null, "JetBrains", "s.r.o.")));
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2)));
}
public void testMultipleConditions() throws Exception {
@@ -34,7 +34,7 @@ public class PropertyGenTest extends CodegenTestCase {
}
public void testPublicVar() throws Exception {
loadText("class PublicVar() { public var foo = 0; }");
loadText("class PublicVar() { public var foo : Int = 0; }");
final Class aClass = loadImplementationClass(generateClassesInFile(), "PublicVar");
final Object instance = aClass.newInstance();
Method setter = findMethodByName(aClass, "setFoo");
@@ -44,7 +44,7 @@ public class PropertyGenTest extends CodegenTestCase {
}
public void testAccessorsInInterface() {
loadText("class AccessorsInInterface() { public var foo = 0; }");
loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
final Class aClass = loadClass("AccessorsInInterface", generateClassesInFile());
assertNotNull(findMethodByName(aClass, "getFoo"));
assertNotNull(findMethodByName(aClass, "setFoo"));
@@ -108,7 +108,7 @@ public class PropertyGenTest extends CodegenTestCase {
}
public void testInitializersForNamespaceProperties() throws Exception {
loadText("public val x = System.currentTimeMillis()");
loadText("val x = System.currentTimeMillis()");
final Method method = generateFunction("getX");
assertIsCurrentTime((Long) method.invoke(null));
}
@@ -136,7 +136,7 @@ public class PropertyGenTest extends CodegenTestCase {
}
public void testKt160() throws Exception {
loadText("public val s = java.lang.Double.toString(1.0)");
loadText("internal val s = java.lang.Double.toString(1.0)");
final Method method = generateFunction("getS");
assertEquals(method.invoke(null), "1.0");
}
@@ -1,6 +1,7 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.jet.JetTestCaseBase;
/**
@@ -21,5 +22,10 @@ public class TypeAdditionFixTests extends LightQuickFixTestCase {
protected String getTestDataPath() {
return JetTestCaseBase.getTestDataPathBase();
}
@Override
protected Sdk getProjectJDK() {
return JetTestCaseBase.jdkFromIdeaHome();
}
}
@@ -12,12 +12,13 @@ import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestCaseBase;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResult;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.expressions.JetTypeInferrerServices;
import org.jetbrains.jet.parsing.JetParsingTest;
import java.io.File;
@@ -105,16 +106,16 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
@NotNull
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, List<TypeProjection> typeArguments, String name, JetType... parameterType) {
List<JetType> parameterTypeList = Arrays.asList(parameterType);
JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext(), JetFlowInformationProvider.NONE);
JetTypeInferrerServices typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
OverloadResolutionResult<FunctionDescriptor> functions = typeInferrerServices.getCallResolver().resolveExactSignature(
OverloadResolutionResults<FunctionDescriptor> functions = typeInferrerServices.getCallResolver().resolveExactSignature(
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
for (FunctionDescriptor function : functions.getDescriptors()) {
List<ValueParameterDescriptor> unsubstitutedValueParameters = function.getValueParameters();
for (ResolvedCall<FunctionDescriptor> resolvedCall : functions.getResults()) {
List<ValueParameterDescriptor> unsubstitutedValueParameters = resolvedCall.getResultingDescriptor().getValueParameters();
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
if (unsubstitutedValueParameter.getOutType().equals(parameterType[i])) {
return function;
return resolvedCall.getResultingDescriptor();
}
}
}
@@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestCaseBase;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
@@ -21,6 +20,7 @@ import org.jetbrains.jet.lang.resolve.scopes.*;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.expressions.JetTypeInferrer;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.parsing.JetParsingTest;
@@ -493,14 +493,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(String expression, JetType expectedType) {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).getType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
assertTrue(type + " != " + expectedType, type.equals(expectedType));
}
private void assertErrorType(String expression) {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).safeGetType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).safeGetType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
}
@@ -523,7 +523,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).getType(addImports(scope), jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(addImports(scope), jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type);
}