Diagnostic parameter types added; opportunity to import class of known type added
This commit is contained in:
+3
-1
@@ -20,6 +20,8 @@ import java.util.*;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JavaDescriptorResolver {
|
||||
|
||||
public static String JAVA_ROOT = "<java_root>";
|
||||
|
||||
/*package*/ static final DeclarationDescriptor JAVA_METHOD_TYPE_PARAMETER_PARENT = new DeclarationDescriptorImpl(null, Collections.<AnnotationDescriptor>emptyList(), "<java_generic_method>") {
|
||||
|
||||
@@ -263,7 +265,7 @@ public class JavaDescriptorResolver {
|
||||
JavaNamespaceDescriptor namespaceDescriptor = new JavaNamespaceDescriptor(
|
||||
resolveParentDescriptor(psiPackage),
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
name == null ? "<java_root>" : name
|
||||
name == null ? JAVA_ROOT : name
|
||||
);
|
||||
|
||||
namespaceDescriptor.setMemberScope(new JavaPackageScope(psiPackage.getQualifiedName(), namespaceDescriptor, semanticServices));
|
||||
|
||||
+7
-7
@@ -27,22 +27,22 @@ public abstract class DiagnosticFactoryWithPsiElement1<T extends PsiElement, A>
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull A argument) {
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T element, @NotNull A argument) {
|
||||
return on(element, element.getTextRange(), argument);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A argument) {
|
||||
return on(element, node.getTextRange(), argument);
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A argument) {
|
||||
return on(elementToBlame, nodeToMark.getTextRange(), argument);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull PsiElement psiElement, @NotNull A argument) {
|
||||
return on(element, psiElement.getTextRange(), argument);
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark, @NotNull A argument) {
|
||||
return on(elementToBlame, elementToMark.getTextRange(), argument);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Diagnostic on(@NotNull T element, @NotNull TextRange textRange, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), element, textRange);
|
||||
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), elementToBlame, textRangeToMark);
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -31,12 +31,16 @@ public abstract class DiagnosticFactoryWithPsiElement2<T extends PsiElement, A,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull A a, @NotNull B b) {
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T element, @NotNull A a, @NotNull B b) {
|
||||
return on(element, element.getNode(), a, b);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A a, @NotNull B b) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b), element, node.getTextRange());
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b) {
|
||||
return makeDiagnostic(new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b), elementToBlame, nodeToMark.getTextRange()));
|
||||
}
|
||||
|
||||
public DiagnosticWithPsiElement<T> makeDiagnostic(DiagnosticWithPsiElement<T> diagnostic) {
|
||||
return diagnostic;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -34,23 +34,23 @@ public abstract class DiagnosticFactoryWithPsiElement3<T extends PsiElement, A,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return on(element, element, a, b, c);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull PsiElement psiElement, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return on(element, psiElement.getTextRange(), a, b, c);
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return on(elementToBlame, elementToMark.getTextRange(), a, b, c);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return on(element, node.getTextRange(), a, b, c);
|
||||
public DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return on(elementToBlame, nodeToMark.getTextRange(), a, b, c);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Diagnostic on(@NotNull T element, @NotNull TextRange textRange, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b, c), element, textRange);
|
||||
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b, c), elementToBlame, textRangeToMark);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface DiagnosticParameter<P> {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticParameterImpl<P> implements DiagnosticParameter<P> {
|
||||
private final String value;
|
||||
|
||||
public DiagnosticParameterImpl(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface DiagnosticParameters {
|
||||
DiagnosticParameter<JetKeywordToken> MODIFIER = new DiagnosticParameterImpl<JetKeywordToken>("MODIFIER");
|
||||
DiagnosticParameter<JetModifierListOwner> CLASS = new DiagnosticParameterImpl<JetModifierListOwner>("CLASS");
|
||||
DiagnosticParameter<JetType> TYPE = new DiagnosticParameterImpl<JetType>("TYPE");
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithAdditionalInfo<T extends PsiElement, I> extends DiagnosticWithPsiElementImpl<T> {
|
||||
private final I info;
|
||||
|
||||
public DiagnosticWithAdditionalInfo(DiagnosticFactory factory, Severity severity, String message, T psiElement, I info) {
|
||||
super(factory, severity, message, psiElement);
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public DiagnosticWithAdditionalInfo(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange, I info) {
|
||||
super(factory, severity, message, psiElement, textRange);
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public I getInfo() {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithAdditionalInfoFactory1<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
|
||||
public static <T extends PsiElement, A> DiagnosticWithAdditionalInfoFactory1<T, A> create(Severity severity, String messageStub) {
|
||||
return new DiagnosticWithAdditionalInfoFactory1<T, A>(severity, messageStub);
|
||||
}
|
||||
|
||||
protected DiagnosticWithAdditionalInfoFactory1(Severity severity, String message) {
|
||||
super(severity, message);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Diagnostic on(@NotNull T element, @NotNull TextRange textRange, @NotNull A argument) {
|
||||
return new DiagnosticWithAdditionalInfo<T, A>(this, severity, makeMessage(argument), element, textRange, argument);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.util.slicedmap.MutableSlicedMap;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.SlicedMapImpl;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithParameters<T extends PsiElement> extends DiagnosticWithPsiElementImpl<T> {
|
||||
|
||||
private final Map<DiagnosticParameter, Object> map = Maps.newHashMap();
|
||||
|
||||
public DiagnosticWithParameters(DiagnosticWithPsiElement<T> diagnostic) {
|
||||
super(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), diagnostic.getPsiElement(), diagnostic.getTextRange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter) {
|
||||
map.put(parameterType, parameter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <P> P getParameter(DiagnosticParameter<P> parameterType) {
|
||||
return (P) map.get(parameterType);
|
||||
}
|
||||
|
||||
public <P> boolean hasParameter(DiagnosticParameter<P> parameterType) {
|
||||
return getParameter(parameterType) != null;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithParametersFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
|
||||
public static <T extends PsiElement, A> DiagnosticWithParametersFactory<T, A> create(Severity severity, String messageStub, DiagnosticParameter<A> diagnosticParameter) {
|
||||
return new DiagnosticWithParametersFactory<T, A>(severity, messageStub, diagnosticParameter);
|
||||
}
|
||||
|
||||
private final DiagnosticParameter<A> diagnosticParameter;
|
||||
|
||||
protected DiagnosticWithParametersFactory(Severity severity, String message, DiagnosticParameter<A> diagnosticParameter) {
|
||||
super(severity, message);
|
||||
this.diagnosticParameter = diagnosticParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DiagnosticWithPsiElement<T> on(@NotNull T elementToBlame, @NotNull TextRange textRangeToMark, @NotNull A argument) {
|
||||
return super.on(elementToBlame, textRangeToMark, argument).add(diagnosticParameter, argument);
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface DiagnosticWithPsiElement<T extends PsiElement> extends DiagnosticWithTextRange {
|
||||
@NotNull
|
||||
T getPsiElement();
|
||||
|
||||
<P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter);
|
||||
}
|
||||
|
||||
+5
@@ -24,4 +24,9 @@ public class DiagnosticWithPsiElementImpl<T extends PsiElement> extends GenericD
|
||||
public T getPsiElement() {
|
||||
return psiElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P> DiagnosticWithPsiElement<T> add(DiagnosticParameter<P> parameterType, P parameter) {
|
||||
return (new DiagnosticWithParameters<T>(this)).add(parameterType, parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ public interface Errors {
|
||||
PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = new PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken>(Severity.WARNING, "Modifier {0} is redundant because {1} is present") {
|
||||
@NotNull
|
||||
@Override
|
||||
public Diagnostic on(@NotNull JetModifierList element, @NotNull ASTNode node, @NotNull JetKeywordToken redundantModifier, @NotNull JetKeywordToken presentModifier) {
|
||||
return new DiagnosticWithAdditionalInfo<JetModifierList, JetKeywordToken>(this, severity, makeMessage(redundantModifier, presentModifier), element, node.getTextRange(), redundantModifier);
|
||||
public DiagnosticWithPsiElement<JetModifierList> on(@NotNull JetModifierList elementToBlame, @NotNull ASTNode nodeToMark, @NotNull JetKeywordToken redundantModifier, @NotNull JetKeywordToken presentModifier) {
|
||||
return super.on(elementToBlame, nodeToMark, redundantModifier, presentModifier).add(DiagnosticParameters.MODIFIER, redundantModifier);
|
||||
}
|
||||
};
|
||||
SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces");
|
||||
@@ -88,27 +88,26 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory FUNCTION_WITH_NO_TYPE_NO_BODY = SimpleDiagnosticFactory.create(ERROR, "This function must either declare a return type or have a body element");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "This property cannot be declared abstract");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_NOT_IN_CLASS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait");
|
||||
//TODO pass String instead of JetType or ensure JetType's value is computed
|
||||
DiagnosticWithAdditionalInfoFactory1<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithAdditionalInfoFactory1.create(ERROR, "Property with initializer cannot be abstract");
|
||||
DiagnosticWithAdditionalInfoFactory1<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithAdditionalInfoFactory1.create(ERROR, "Property with getter implementation cannot be abstract");
|
||||
DiagnosticWithAdditionalInfoFactory1<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithAdditionalInfoFactory1.create(ERROR, "Property with setter implementation cannot be abstract");
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParametersFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParametersFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParametersFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field");
|
||||
SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "Property must be initialized");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits");
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParametersFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
|
||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
|
||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetModifierListOwner> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetModifierListOwner>(ERROR, "Abstract property {0} in non-abstract class {1}") {
|
||||
@NotNull
|
||||
protected Diagnostic on(@NotNull JetModifierListOwner element, @NotNull TextRange textRange, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass jetClass) {
|
||||
return new DiagnosticWithAdditionalInfo<JetModifierListOwner, JetClass>(this, severity, makeMessage(s, classDescriptor, jetClass), element, textRange, jetClass);
|
||||
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetModifierListOwner aClass) {
|
||||
return super.on(elementToBlame, textRangeToMark, s, classDescriptor, aClass).add(DiagnosticParameters.CLASS, aClass);
|
||||
}
|
||||
};
|
||||
PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetModifierListOwner> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetModifierListOwner>(ERROR, "Abstract function {0} in non-abstract class {1}") {
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull JetFunctionOrPropertyAccessor element, @NotNull ASTNode node, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetModifierListOwner jetClass) {
|
||||
return new DiagnosticWithAdditionalInfo<JetFunctionOrPropertyAccessor, JetModifierListOwner>(this, severity, makeMessage(s, classDescriptor, jetClass), element, node.getTextRange(), jetClass);
|
||||
public DiagnosticWithPsiElement<JetFunctionOrPropertyAccessor> on(@NotNull JetFunctionOrPropertyAccessor elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetModifierListOwner modifierListOwner) {
|
||||
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
|
||||
}
|
||||
};
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunctionOrPropertyAccessor, FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
|
||||
@@ -162,8 +161,8 @@ public interface Errors {
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST_STATIC_ASSERT_IS_FINE = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed, use ':' instead");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed");
|
||||
SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed");
|
||||
DiagnosticWithAdditionalInfoFactory1<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithAdditionalInfoFactory1.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}");
|
||||
DiagnosticWithAdditionalInfoFactory1<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithAdditionalInfoFactory1.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}");
|
||||
DiagnosticWithParametersFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParametersFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParametersFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Classifier {0} does not have a class object", NAME);
|
||||
SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
|
||||
|
||||
|
||||
@@ -74,6 +74,11 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
|
||||
public Severity getSeverity() {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P> DiagnosticWithPsiElement<PsiElement> add(DiagnosticParameter<P> parameterType, P parameter) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,13 +17,13 @@ public abstract class SimpleDiagnosticFactoryWithPsiElement<T extends PsiElement
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, element, node.getTextRange());
|
||||
public Diagnostic on(@NotNull T elementToBlame, @NotNull ASTNode nodeToMark) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, elementToBlame, nodeToMark.getTextRange());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull PsiElement psiElement) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, element, psiElement.getTextRange());
|
||||
public Diagnostic on(@NotNull T elementToBlame, @NotNull PsiElement elementToMark) {
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, elementToBlame, elementToMark.getTextRange());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -28,12 +28,21 @@ public class JetPsiFactory {
|
||||
JetProperty property = createProperty(project, "val x : Int");
|
||||
return new PsiElement[] { property.findElementAt(5), property.findElementAt(6), property.findElementAt(7) };
|
||||
}
|
||||
|
||||
|
||||
public static PsiElement createWhiteSpace(Project project) {
|
||||
JetProperty property = createProperty(project, "val x");
|
||||
return createWhiteSpace(project, " ");
|
||||
}
|
||||
|
||||
public static PsiElement createWhiteSpace(Project project, String text) {
|
||||
JetProperty property = createProperty(project, "val" + text + "x");
|
||||
return property.findElementAt(3);
|
||||
}
|
||||
|
||||
// public static PsiElement createEndOfLine(Project project) {
|
||||
// JetNamedFunction function = createFunction(project, "fun f { \n }");
|
||||
// return function.findElementAt(8);
|
||||
// }
|
||||
|
||||
public static JetClass createClass(Project project, String text) {
|
||||
return createDeclaration(project, text, JetClass.class);
|
||||
}
|
||||
@@ -80,4 +89,14 @@ public class JetPsiFactory {
|
||||
JetNamedFunction function = createFunction(project, "fun foo() {}");
|
||||
return function.getBodyExpression();
|
||||
}
|
||||
|
||||
public static JetNamespace createNamespace(Project project, String text) {
|
||||
JetFile file = createFile(project, text);
|
||||
return file.getRootNamespace();
|
||||
}
|
||||
|
||||
public static JetImportDirective createImportDirective(Project project, String classPath) {
|
||||
JetNamespace namespace = createNamespace(project, "import " + classPath);
|
||||
return namespace.getImportDirectives().iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,8 +517,6 @@ public class BodyResolver {
|
||||
|
||||
if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
|
||||
JetType returnType = propertyDescriptor.getReturnType();
|
||||
//TODO We need ensure here that jet type is computed or pass it's computed name to quick fix instead
|
||||
returnType.equals(new Object());
|
||||
|
||||
JetExpression initializer = property.getInitializer();
|
||||
if (initializer != null) {
|
||||
@@ -568,7 +566,7 @@ public class BodyResolver {
|
||||
}
|
||||
if (inTrait) {
|
||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed in traits");
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(initializer));
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(property, initializer, propertyDescriptor.getReturnType()));
|
||||
}
|
||||
else if (!backingFieldRequired) {
|
||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no backing field");
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.jetbrains.jet.plugin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class JetPluginUtil {
|
||||
@NotNull
|
||||
public static String computeTypeFullName(JetType type) {
|
||||
LinkedList<String> fullName = computeTypeFullNameList(type);
|
||||
String last = fullName.getLast();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : fullName) {
|
||||
sb.append(s);
|
||||
if (s != last) {
|
||||
sb.append('.');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static LinkedList<String> computeTypeFullNameList(JetType type) {
|
||||
if (type instanceof DeferredType) {
|
||||
type = ((DeferredType)type).getActualType();
|
||||
}
|
||||
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
|
||||
LinkedList<String> fullName = Lists.newLinkedList();
|
||||
while (declarationDescriptor != null) {
|
||||
fullName.addFirst(declarationDescriptor.getName());
|
||||
declarationDescriptor = declarationDescriptor.getContainingDeclaration();
|
||||
}
|
||||
assert fullName.size() > 0;
|
||||
if (JavaDescriptorResolver.JAVA_ROOT.equals(fullName.getFirst())) {
|
||||
fullName.removeFirst();
|
||||
}
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public static boolean checkTypeIsStandard(JetType type, Project project) {
|
||||
LinkedList<String> fullName = computeTypeFullNameList(type);
|
||||
if (fullName.size() == 3 && fullName.getFirst().equals("java") && fullName.get(1).equals("lang")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getJetStandardLibrary(project);
|
||||
JetScope libraryScope = standardLibrary.getLibraryScope();
|
||||
|
||||
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
||||
if (declaration instanceof JavaClassDescriptor) {
|
||||
return false;
|
||||
}
|
||||
while (!(declaration instanceof NamespaceDescriptor)) {
|
||||
declaration = declaration.getContainingDeclaration();
|
||||
assert declaration != null;
|
||||
}
|
||||
return libraryScope == ((NamespaceDescriptor) declaration).getMemberScope();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.AnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.JetHighlighter;
|
||||
import org.jetbrains.jet.plugin.quickfix.IntentionActionFactory;
|
||||
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory;
|
||||
import org.jetbrains.jet.plugin.quickfix.QuickFixes;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -90,8 +90,8 @@ public class JetPsiChecker implements Annotator {
|
||||
DiagnosticWithPsiElement diagnosticWithPsiElement = (DiagnosticWithPsiElement) diagnostic;
|
||||
if (diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
|
||||
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
|
||||
Collection<IntentionActionFactory> intentionActionFactories = QuickFixes.get(factory);
|
||||
for (IntentionActionFactory intentionActionFactory : intentionActionFactories) {
|
||||
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.get(factory);
|
||||
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
|
||||
IntentionAction action = null;
|
||||
if (intentionActionFactory != null) {
|
||||
action = intentionActionFactory.createAction(diagnosticWithPsiElement);
|
||||
|
||||
@@ -8,12 +8,11 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class AddFunctionBodyFix extends IntentionActionForPsiElement<JetFunctionOrPropertyAccessor> {
|
||||
public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> {
|
||||
public AddFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) {
|
||||
super(element);
|
||||
}
|
||||
@@ -49,10 +48,10 @@ public class AddFunctionBodyFix extends IntentionActionForPsiElement<JetFunction
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
|
||||
return new IntentionActionFactory<JetFunctionOrPropertyAccessor>() {
|
||||
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
|
||||
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor;
|
||||
return new AddFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement());
|
||||
}
|
||||
|
||||
@@ -97,17 +97,17 @@ public class AddModifierFix extends ModifierFix {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier, final JetToken[] modifiersThatCanBeReplaced, final JetToken[] conflictedModifiers) {
|
||||
return new IntentionActionFactory<JetModifierListOwner>() {
|
||||
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier, final JetToken[] modifiersThatCanBeReplaced, final JetToken[] conflictedModifiers) {
|
||||
return new JetIntentionActionFactory<JetModifierListOwner>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
|
||||
return new AddModifierFix((JetModifierListOwner) diagnostic.getPsiElement(), modifier, modifiersThatCanBeReplaced, conflictedModifiers);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
|
||||
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
|
||||
return createFactory(modifier, new JetToken[0], new JetToken[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ 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.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithAdditionalInfo;
|
||||
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.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
@@ -17,7 +19,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ChangeAccessorTypeFix extends IntentionActionForPsiElement<JetPropertyAccessor> {
|
||||
public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccessor> {
|
||||
private final JetType type;
|
||||
|
||||
public ChangeAccessorTypeFix(@NotNull JetPropertyAccessor element, JetType type) {
|
||||
@@ -58,14 +60,14 @@ public class ChangeAccessorTypeFix extends IntentionActionForPsiElement<JetPrope
|
||||
}
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetPropertyAccessor> createFactory() {
|
||||
return new IntentionActionFactory<JetPropertyAccessor>() {
|
||||
public static JetIntentionActionFactory<JetPropertyAccessor> createFactory() {
|
||||
return new JetIntentionActionFactory<JetPropertyAccessor>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic instanceof DiagnosticWithAdditionalInfo;
|
||||
public JetIntentionAction<JetPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetPropertyAccessor;
|
||||
assert ((DiagnosticWithAdditionalInfo) diagnostic).getInfo() instanceof JetType;
|
||||
return new ChangeAccessorTypeFix((JetPropertyAccessor) diagnostic.getPsiElement(), (JetType) ((DiagnosticWithAdditionalInfo) diagnostic).getInfo());
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
|
||||
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
|
||||
return new ChangeAccessorTypeFix((JetPropertyAccessor) diagnostic.getPsiElement(), type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ChangeVariableMutabilityFix extends IntentionActionForPsiElement<JetProperty> {
|
||||
public class ChangeVariableMutabilityFix extends JetIntentionAction<JetProperty> {
|
||||
public ChangeVariableMutabilityFix(@NotNull JetProperty element) {
|
||||
super(element);
|
||||
}
|
||||
@@ -52,10 +52,10 @@ public class ChangeVariableMutabilityFix extends IntentionActionForPsiElement<Je
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetProperty> createFactory() {
|
||||
return new IntentionActionFactory<JetProperty>() {
|
||||
public static JetIntentionActionFactory<JetProperty> createFactory() {
|
||||
return new JetIntentionActionFactory<JetProperty>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetProperty;
|
||||
return new ChangeVariableMutabilityFix((JetProperty) diagnostic.getPsiElement());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ImportClassHelper {
|
||||
public static void perform(@NotNull JetType type, @NotNull PsiElement element, @NotNull PsiElement newElement) {
|
||||
PsiElement parent = element;
|
||||
while (!(parent instanceof JetNamespace)) {
|
||||
parent = parent.getParent();
|
||||
assert parent != null;
|
||||
}
|
||||
JetNamespace namespace = (JetNamespace) parent;
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
if (JetPluginUtil.checkTypeIsStandard(type, element.getProject())) {
|
||||
element.replace(newElement);
|
||||
return;
|
||||
}
|
||||
|
||||
String typeFullName = JetPluginUtil.computeTypeFullName(type);
|
||||
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(element.getProject(), typeFullName);
|
||||
|
||||
if (!importDirectives.isEmpty()) {
|
||||
boolean isPresent = false;
|
||||
for (JetImportDirective directive : importDirectives) {
|
||||
if (directive.getText().endsWith(typeFullName) ||
|
||||
directive.getText().endsWith(typeFullName + ";")) {
|
||||
isPresent = true;
|
||||
}
|
||||
}
|
||||
if (!isPresent) {
|
||||
JetImportDirective lastDirective = importDirectives.get(importDirectives.size() - 1);
|
||||
lastDirective.getParent().addAfter(newDirective, lastDirective);
|
||||
lastDirective.getParent().addAfter(JetPsiFactory.createWhiteSpace(element.getProject(), "\n"), lastDirective);
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<JetDeclaration> declarations = namespace.getDeclarations();
|
||||
assert !declarations.isEmpty();
|
||||
JetDeclaration firstDeclaration = declarations.iterator().next();
|
||||
firstDeclaration.getParent().addBefore(newDirective, firstDeclaration);
|
||||
firstDeclaration.getParent().addBefore(JetPsiFactory.createWhiteSpace(element.getProject(), "\n\n"), firstDeclaration);
|
||||
}
|
||||
element.replace(newElement);
|
||||
parent.replace(namespace);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class IntentionActionForPsiElement<T extends PsiElement> implements IntentionAction {
|
||||
protected @NotNull T element;
|
||||
|
||||
public IntentionActionForPsiElement(@NotNull T element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return element.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class JetIntentionAction<T extends PsiElement> implements IntentionAction {
|
||||
protected @NotNull T element;
|
||||
|
||||
public JetIntentionAction(@NotNull T element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return element.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static DiagnosticWithParameters<PsiElement> assertAndCastToDiagnosticWithParameters(Diagnostic diagnostic, DiagnosticParameter... parameters) {
|
||||
assert diagnostic instanceof DiagnosticWithParameters :
|
||||
"For this type of quick fix diagnostic with additional " +
|
||||
(parameters.length == 1 ? "parameter '" + parameters[0] + "'" : "parameters " + Arrays.asList(parameters)) + " is expected";
|
||||
|
||||
for (DiagnosticParameter parameter : parameters) {
|
||||
assert ((DiagnosticWithParameters) diagnostic).hasParameter(parameter) :
|
||||
"For this type of quick fix diagnostic with additional parameter '" + parameter + "' is expected";
|
||||
}
|
||||
return (DiagnosticWithParameters<PsiElement>) diagnostic;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -6,8 +6,8 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface IntentionActionFactory<T extends PsiElement> {
|
||||
public interface JetIntentionActionFactory<T extends PsiElement> {
|
||||
|
||||
IntentionActionForPsiElement<T> createAction(DiagnosticWithPsiElement diagnostic);
|
||||
JetIntentionAction<T> createAction(DiagnosticWithPsiElement diagnostic);
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class ModifierFix extends IntentionActionForPsiElement<JetModifierListOwner> {
|
||||
public abstract class ModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
protected final JetKeywordToken modifier;
|
||||
|
||||
protected ModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithAdditionalInfo;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElementImpl;
|
||||
|
||||
@@ -11,20 +12,13 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElementImpl;
|
||||
public class QuickFixUtil {
|
||||
private QuickFixUtil() {}
|
||||
|
||||
public static <T extends PsiElement> IntentionActionFactory<T> createFactoryRedirectingAdditionalInfoToAnotherFactory(final IntentionActionFactory<T> factory) {
|
||||
return new IntentionActionFactory<T>() {
|
||||
public static <T extends PsiElement> JetIntentionActionFactory<T> createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<T> parameter) {
|
||||
return new JetIntentionActionFactory<T>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<T> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
//no type check; should be followed manually
|
||||
assert diagnostic instanceof DiagnosticWithAdditionalInfo;
|
||||
Object info = ((DiagnosticWithAdditionalInfo) diagnostic).getInfo();
|
||||
T element = null;
|
||||
try {
|
||||
element = (T) info;
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
assert false : ex;
|
||||
}
|
||||
public JetIntentionAction<T> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, parameter);
|
||||
T element = diagnosticWithParameters.getParameter(parameter);
|
||||
return factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionOrPropertyAccessor;
|
||||
@@ -18,26 +19,26 @@ import java.util.Collection;
|
||||
* @author svtk
|
||||
*/
|
||||
public class QuickFixes {
|
||||
private static final Multimap<PsiElementOnlyDiagnosticFactory, IntentionActionFactory> actionMap = HashMultimap.create();
|
||||
private static final Multimap<PsiElementOnlyDiagnosticFactory, JetIntentionActionFactory> actionMap = HashMultimap.create();
|
||||
|
||||
public static Collection<IntentionActionFactory> get(PsiElementOnlyDiagnosticFactory diagnosticFactory) {
|
||||
public static Collection<JetIntentionActionFactory> get(PsiElementOnlyDiagnosticFactory diagnosticFactory) {
|
||||
return actionMap.get(diagnosticFactory);
|
||||
}
|
||||
|
||||
private QuickFixes() {}
|
||||
|
||||
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, IntentionActionFactory<T> actionFactory) {
|
||||
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, JetIntentionActionFactory<T> actionFactory) {
|
||||
actionMap.put(diagnosticFactory, actionFactory);
|
||||
}
|
||||
|
||||
static {
|
||||
IntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD);
|
||||
IntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD}, new JetToken[] {JetTokens.FINAL_KEYWORD});
|
||||
JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD);
|
||||
JetIntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD}, new JetToken[] {JetTokens.FINAL_KEYWORD});
|
||||
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
|
||||
add(Errors.ABSTRACT_PROPERTY_NOT_IN_CLASS, removeAbstractModifierFactory);
|
||||
|
||||
IntentionActionFactory<JetProperty> removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
|
||||
JetIntentionActionFactory<JetProperty> removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
|
||||
add(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removeAbstractModifierFactory);
|
||||
add(Errors.ABSTRACT_PROPERTY_WITH_INITIALIZER, removePartsFromPropertyFactory);
|
||||
|
||||
@@ -47,21 +48,23 @@ public class QuickFixes {
|
||||
add(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removeAbstractModifierFactory);
|
||||
add(Errors.ABSTRACT_PROPERTY_WITH_SETTER, removePartsFromPropertyFactory);
|
||||
|
||||
add(Errors.PROPERTY_INITIALIZER_IN_TRAIT, removePartsFromPropertyFactory);
|
||||
|
||||
add(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
|
||||
add(Errors.REDUNDANT_ABSTRACT, removeAbstractModifierFactory);
|
||||
|
||||
IntentionActionFactory<JetModifierListOwner> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory);
|
||||
JetIntentionActionFactory<JetModifierListOwner> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.CLASS);
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
|
||||
|
||||
IntentionActionFactory<JetFunctionOrPropertyAccessor> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
|
||||
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> 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);
|
||||
|
||||
IntentionActionFactory<JetFunctionOrPropertyAccessor> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
|
||||
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
|
||||
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
|
||||
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
@@ -77,7 +80,7 @@ public class QuickFixes {
|
||||
add(Errors.USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
|
||||
add(Errors.USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
|
||||
|
||||
IntentionActionFactory<JetPropertyAccessor> changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
|
||||
JetIntentionActionFactory<JetPropertyAccessor> changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
|
||||
add(Errors.WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
|
||||
add(Errors.WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
|
||||
|
||||
|
||||
@@ -9,12 +9,11 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class RemoveFunctionBodyFix extends IntentionActionForPsiElement<JetFunctionOrPropertyAccessor> {
|
||||
public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> {
|
||||
|
||||
public RemoveFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) {
|
||||
super(element);
|
||||
@@ -52,10 +51,10 @@ public class RemoveFunctionBodyFix extends IntentionActionForPsiElement<JetFunct
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
|
||||
return new IntentionActionFactory<JetFunctionOrPropertyAccessor>() {
|
||||
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() {
|
||||
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor;
|
||||
return new RemoveFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement());
|
||||
}
|
||||
|
||||
@@ -86,10 +86,10 @@ public class RemoveModifierFix extends ModifierFix {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
|
||||
return new IntentionActionFactory<JetModifierListOwner>() {
|
||||
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) {
|
||||
return new JetIntentionActionFactory<JetModifierListOwner>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
|
||||
return new RemoveModifierFix((JetModifierListOwner) diagnostic.getPsiElement(), modifier);
|
||||
}
|
||||
|
||||
@@ -6,21 +6,28 @@ 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.DiagnosticWithAdditionalInfo;
|
||||
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.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class RemovePartsFromPropertyFix extends IntentionActionForPsiElement<JetProperty> {
|
||||
public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty> {
|
||||
private final JetType type;
|
||||
private final String partsToRemove;
|
||||
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, JetType type) {
|
||||
super(element);
|
||||
this.type = type;
|
||||
if (type instanceof DeferredType) {
|
||||
this.type = ((DeferredType) type).getActualType();
|
||||
}
|
||||
else {
|
||||
this.type = type;
|
||||
}
|
||||
partsToRemove = partsToRemove(element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
||||
element.getSetter() != null && element.getSetter().getBodyExpression() != null,
|
||||
element.getInitializer() != null);
|
||||
@@ -78,6 +85,7 @@ public class RemovePartsFromPropertyFix extends IntentionActionForPsiElement<Jet
|
||||
newElement.deleteChildInternal(setter.getNode());
|
||||
}
|
||||
JetExpression initializer = newElement.getInitializer();
|
||||
boolean needImport = false;
|
||||
if (initializer != null) {
|
||||
PsiElement nameIdentifier = newElement.getNameIdentifier();
|
||||
assert nameIdentifier != null;
|
||||
@@ -87,9 +95,14 @@ public class RemovePartsFromPropertyFix extends IntentionActionForPsiElement<Jet
|
||||
|
||||
if (newElement.getPropertyTypeRef() == null) {
|
||||
newElement = addPropertyType(project, newElement, type);
|
||||
needImport = true;
|
||||
}
|
||||
}
|
||||
element.replace(newElement);
|
||||
if (needImport) {
|
||||
ImportClassHelper.perform(type, element, newElement);
|
||||
} else {
|
||||
element.replace(newElement);
|
||||
}
|
||||
}
|
||||
|
||||
public static JetProperty addPropertyType(Project project, JetProperty property, JetType type) {
|
||||
@@ -105,16 +118,14 @@ public class RemovePartsFromPropertyFix extends IntentionActionForPsiElement<Jet
|
||||
return newProperty;
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetProperty> createFactory() {
|
||||
return new IntentionActionFactory<JetProperty>() {
|
||||
public static JetIntentionActionFactory<JetProperty> createFactory() {
|
||||
return new JetIntentionActionFactory<JetProperty>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetProperty;
|
||||
assert diagnostic instanceof DiagnosticWithAdditionalInfo;
|
||||
|
||||
Object info = ((DiagnosticWithAdditionalInfo) diagnostic).getInfo();
|
||||
assert info instanceof JetType;
|
||||
return new RemovePartsFromPropertyFix((JetProperty) diagnostic.getPsiElement(), (JetType) info);
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.TYPE);
|
||||
JetType type = diagnosticWithParameters.getParameter(DiagnosticParameters.TYPE);
|
||||
return new RemovePartsFromPropertyFix((JetProperty) diagnostic.getPsiElement(), type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ 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.DiagnosticWithAdditionalInfo;
|
||||
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;
|
||||
@@ -13,7 +15,7 @@ import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class RemoveRedundantModifierFix extends IntentionActionForPsiElement<JetModifierList> {
|
||||
public class RemoveRedundantModifierFix extends JetIntentionAction<JetModifierList> {
|
||||
private JetKeywordToken redundantModifier;
|
||||
public RemoveRedundantModifierFix(@NotNull JetModifierList element, @NotNull JetKeywordToken redundantModifier) {
|
||||
super(element);
|
||||
@@ -38,15 +40,14 @@ public class RemoveRedundantModifierFix extends IntentionActionForPsiElement<Jet
|
||||
element.replace(RemoveModifierFix.removeModifierFromList(newElement, redundantModifier));
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetModifierList> createFactory() {
|
||||
return new IntentionActionFactory<JetModifierList>() {
|
||||
public static JetIntentionActionFactory<JetModifierList> createFactory() {
|
||||
return new JetIntentionActionFactory<JetModifierList>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetModifierList;
|
||||
assert diagnostic instanceof DiagnosticWithAdditionalInfo;
|
||||
Object info = ((DiagnosticWithAdditionalInfo) diagnostic).getInfo();
|
||||
assert info instanceof JetKeywordToken;
|
||||
return new RemoveRedundantModifierFix((JetModifierList) diagnostic.getPsiElement(), (JetKeywordToken) info);
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
|
||||
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
|
||||
return new RemoveRedundantModifierFix((JetModifierList) diagnostic.getPsiElement(), modifier);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+7
-7
@@ -13,7 +13,7 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> extends IntentionActionForPsiElement<T> {
|
||||
public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
|
||||
public RemoveRightPartOfBinaryExpressionFix(@NotNull T element) {
|
||||
super(element);
|
||||
}
|
||||
@@ -36,10 +36,10 @@ public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpressi
|
||||
}
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetBinaryExpressionWithTypeRHS> createRemoveCastFactory() {
|
||||
return new IntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
|
||||
public static JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS> createRemoveCastFactory() {
|
||||
return new JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetBinaryExpressionWithTypeRHS;
|
||||
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement()) {
|
||||
@NotNull
|
||||
@@ -52,10 +52,10 @@ public abstract class RemoveRightPartOfBinaryExpressionFix<T extends JetExpressi
|
||||
};
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetBinaryExpression> createRemoveElvisOperatorFactory() {
|
||||
return new IntentionActionFactory<JetBinaryExpression>() {
|
||||
public static JetIntentionActionFactory<JetBinaryExpression> createRemoveElvisOperatorFactory() {
|
||||
return new JetIntentionActionFactory<JetBinaryExpression>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetBinaryExpression> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetBinaryExpression> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetBinaryExpression;
|
||||
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpression>((JetBinaryExpression) diagnostic.getPsiElement()) {
|
||||
@NotNull
|
||||
|
||||
+4
-4
@@ -14,7 +14,7 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpression> extends IntentionActionForPsiElement<T> {
|
||||
public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpression> extends JetIntentionAction<T> {
|
||||
private final String expressionWithNecessaryOperation;
|
||||
public ReplaceOperationInBinaryExpressionFix(@NotNull T element, String expressionWithNecessaryOperation) {
|
||||
super(element);
|
||||
@@ -39,10 +39,10 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
|
||||
}
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetBinaryExpressionWithTypeRHS> createChangeCastToStaticAssertFactory() {
|
||||
return new IntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
|
||||
public static JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS> createChangeCastToStaticAssertFactory() {
|
||||
return new JetIntentionActionFactory<JetBinaryExpressionWithTypeRHS>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetBinaryExpressionWithTypeRHS;
|
||||
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>((JetBinaryExpressionWithTypeRHS) diagnostic.getPsiElement(), "2 : Int") {
|
||||
@NotNull
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ReplaceSafeCallToDotCall extends IntentionActionForPsiElement<JetElement> {
|
||||
public class ReplaceSafeCallToDotCall extends JetIntentionAction<JetElement> {
|
||||
|
||||
public ReplaceSafeCallToDotCall(@NotNull JetElement element) {
|
||||
super(element);
|
||||
@@ -36,6 +36,7 @@ public class ReplaceSafeCallToDotCall extends IntentionActionForPsiElement<JetEl
|
||||
JetSafeQualifiedExpression safeQualifiedExpression = (JetSafeQualifiedExpression) element;
|
||||
JetDotQualifiedExpression newElement = (JetDotQualifiedExpression) JetPsiFactory.createExpression(project, "x.foo");
|
||||
|
||||
//TODO check for null
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode());
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode());
|
||||
|
||||
@@ -50,10 +51,10 @@ public class ReplaceSafeCallToDotCall extends IntentionActionForPsiElement<JetEl
|
||||
}
|
||||
}
|
||||
|
||||
public static IntentionActionFactory<JetElement> createFactory() {
|
||||
return new IntentionActionFactory<JetElement>() {
|
||||
public static JetIntentionActionFactory<JetElement> createFactory() {
|
||||
return new JetIntentionActionFactory<JetElement>() {
|
||||
@Override
|
||||
public IntentionActionForPsiElement<JetElement> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<JetElement> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetElement;
|
||||
return new ReplaceSafeCallToDotCall((JetElement) diagnostic.getPsiElement());
|
||||
}
|
||||
|
||||
@@ -349,59 +349,52 @@ public class JetDefaultModalityModifiersTest extends LightDaemonAnalyzerTestCase
|
||||
tc.testPropertyAccessorModalityInClass("class A : C { final override val a: Int = 0 }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("class A : C { final override val a: Int = 0; get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("class A : C { final override val a: Int = 0; final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("class A : C { final override val a: Int = 0; override get() = 2 }", Modality.OPEN);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0; get }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0; open get }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0; final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0; override get() = 2 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { override val a: Int = 0; final override get() = 2 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; get }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; open get }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; override get() = 2 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { open override val a: Int = 0; final override get() = 2 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0 }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; override get() = 2 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("open class A : C { final override val a: Int = 0; final override get() = 2 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { abstract override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { override val a: Int override get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { override val a: Int open override get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { override val a: Int final override get() = 10 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open abstract override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int override get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int open override get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A : C { open override val a: Int final override get() = 10 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int = 0; get }", Modality.OPEN);
|
||||
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { abstract override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { abstract override val a: Int get }", Modality.ABSTRACT);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { abstract override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { abstract override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { abstract override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { abstract override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { override val a: Int get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { override val a: Int open get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { override val a: Int final get() = 10 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open abstract override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open abstract override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open abstract override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open abstract override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open override val a: Int get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open override val a: Int open get() = 10 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInClass("abstract class A { open override val a: Int final get() = 10 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int open get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A { override val a: Int final get() = 1 }", Modality.FINAL);
|
||||
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int open get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInTrait("abstract trait A { override val a: Int final get() = 1 }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int override get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int abstract get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int open get }", Modality.ABSTRACT);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int open override get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int override get() = 1 }", Modality.OPEN);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int final get }", Modality.FINAL);
|
||||
tc.testPropertyAccessorModalityInTrait("trait A : C { override val a: Int final override get() = 1 }", Modality.FINAL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user