Diagnostic parameter types added; opportunity to import class of known type added

This commit is contained in:
svtk
2011-09-27 16:25:17 +04:00
parent 87b22e810f
commit fdac4c7ef4
39 changed files with 489 additions and 253 deletions
@@ -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));
@@ -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);
}
}
@@ -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;
}
}
@@ -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");
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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);
}
@@ -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();
}
}
}
@@ -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");