Merge branch 'master' of github.com:JetBrains/kotlin
This commit is contained in:
@@ -23,13 +23,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public abstract class AbstractDiagnostic<P extends PsiElement> implements Diagnostic<P> {
|
||||
private final P psiElement;
|
||||
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
|
||||
private final E psiElement;
|
||||
private final String message;
|
||||
private final AbstractDiagnosticFactory factory;
|
||||
private final Severity severity;
|
||||
|
||||
public AbstractDiagnostic(@NotNull P psiElement, @NotNull AbstractDiagnosticFactory factory, @NotNull Severity severity, @NotNull String message) {
|
||||
public AbstractDiagnostic(@NotNull E psiElement, @NotNull AbstractDiagnosticFactory factory, @NotNull Severity severity, @NotNull String message) {
|
||||
this.psiElement = psiElement;
|
||||
this.factory = factory;
|
||||
this.severity = severity;
|
||||
@@ -63,7 +63,7 @@ public abstract class AbstractDiagnostic<P extends PsiElement> implements Diagno
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public P getPsiElement() {
|
||||
public E getPsiElement() {
|
||||
return psiElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface Diagnostic<E extends PsiElement> {//todo
|
||||
public interface Diagnostic {
|
||||
|
||||
@NotNull
|
||||
AbstractDiagnosticFactory getFactory();
|
||||
@@ -38,7 +38,7 @@ public interface Diagnostic<E extends PsiElement> {//todo
|
||||
Severity getSeverity();
|
||||
|
||||
@NotNull
|
||||
E getPsiElement();
|
||||
PsiElement getPsiElement();
|
||||
|
||||
@NotNull
|
||||
List<TextRange> getTextRanges();
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticFactory<P extends PsiElement> extends DiagnosticFactoryWithPsiElement<P> {
|
||||
public class DiagnosticFactory<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> {
|
||||
protected final String message;
|
||||
|
||||
protected DiagnosticFactory(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy) {
|
||||
protected DiagnosticFactory(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy) {
|
||||
super(severity, positioningStrategy);
|
||||
this.message = message;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class DiagnosticFactory<P extends PsiElement> extends DiagnosticFactoryWi
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic<P> on(@NotNull P element) {
|
||||
return new DiagnosticWithPsiElement<P>(element, this, severity, message);
|
||||
public ParametrizedDiagnostic<E> on(@NotNull E element) {
|
||||
return new DiagnosticWithPsiElement<E>(element, this, severity, message);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticFactory1<P extends PsiElement, A> extends DiagnosticFactoryWithMessageFormat<P> {
|
||||
public class DiagnosticFactory1<E extends PsiElement, A> extends DiagnosticFactoryWithMessageFormat<E> {
|
||||
private final Renderer<? super A> renderer;
|
||||
|
||||
protected String makeMessage(@NotNull A argument) {
|
||||
@@ -34,11 +34,11 @@ public class DiagnosticFactory1<P extends PsiElement, A> extends DiagnosticFacto
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DiagnosticWithPsiElement<P> on(@NotNull P element, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(argument));
|
||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(argument));
|
||||
}
|
||||
|
||||
protected DiagnosticFactory1(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> renderer) {
|
||||
protected DiagnosticFactory1(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> renderer) {
|
||||
super(severity, message, positioningStrategy);
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DiagnosticFactory2<P extends PsiElement, A, B> extends DiagnosticFactoryWithMessageFormat<P> {
|
||||
public class DiagnosticFactory2<E extends PsiElement, A, B> extends DiagnosticFactoryWithMessageFormat<E> {
|
||||
private final Renderer<? super A> rendererForA;
|
||||
private final Renderer<? super B> rendererForB;
|
||||
|
||||
@@ -39,12 +39,12 @@ public class DiagnosticFactory2<P extends PsiElement, A, B> extends DiagnosticFa
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic<P> on(@NotNull P element, @NotNull A a, @NotNull B b) {
|
||||
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(a, b));
|
||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b) {
|
||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(a, b));
|
||||
}
|
||||
|
||||
|
||||
private DiagnosticFactory2(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
|
||||
private DiagnosticFactory2(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB) {
|
||||
super(severity, message, positioningStrategy);
|
||||
this.rendererForA = rendererForA;
|
||||
this.rendererForB = rendererForB;
|
||||
|
||||
@@ -22,12 +22,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticFactory3<P extends PsiElement, A, B, C> extends DiagnosticFactoryWithMessageFormat<P> {
|
||||
public class DiagnosticFactory3<E extends PsiElement, A, B, C> extends DiagnosticFactoryWithMessageFormat<E> {
|
||||
private final Renderer<? super A> rendererForA;
|
||||
private final Renderer<? super B> rendererForB;
|
||||
private final Renderer<? super C> rendererForC;
|
||||
|
||||
protected DiagnosticFactory3(Severity severity, String messageStub, PositioningStrategy<? super P> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
|
||||
protected DiagnosticFactory3(Severity severity, String messageStub, PositioningStrategy<? super E> positioningStrategy, Renderer<? super A> rendererForA, Renderer<? super B> rendererForB, Renderer<? super C> rendererForC) {
|
||||
super(severity, messageStub, positioningStrategy);
|
||||
this.rendererForA = rendererForA;
|
||||
this.rendererForB = rendererForB;
|
||||
@@ -66,7 +66,7 @@ public class DiagnosticFactory3<P extends PsiElement, A, B, C> extends Diagnosti
|
||||
return rendererForC.render(c);
|
||||
}
|
||||
@NotNull
|
||||
public DiagnosticWithPsiElement<P> on(@NotNull P element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return new DiagnosticWithPsiElement<P>(element, this, severity, makeMessage(a, b, c));
|
||||
public ParametrizedDiagnostic<E> on(@NotNull E element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return new DiagnosticWithPsiElement<E>(element, this, severity, makeMessage(a, b, c));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,14 +23,14 @@ import java.text.MessageFormat;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class DiagnosticFactoryWithMessageFormat<P extends PsiElement> extends DiagnosticFactoryWithPsiElement<P> {
|
||||
public abstract class DiagnosticFactoryWithMessageFormat<E extends PsiElement> extends DiagnosticFactoryWithPsiElement<E> {
|
||||
protected final MessageFormat messageFormat;
|
||||
|
||||
public DiagnosticFactoryWithMessageFormat(Severity severity, String message) {
|
||||
this(severity, message, PositioningStrategies.DEFAULT);
|
||||
}
|
||||
|
||||
public DiagnosticFactoryWithMessageFormat(Severity severity, String message, PositioningStrategy<? super P> positioningStrategy) {
|
||||
public DiagnosticFactoryWithMessageFormat(Severity severity, String message, PositioningStrategy<? super E> positioningStrategy) {
|
||||
super(severity, positioningStrategy);
|
||||
this.messageFormat = new MessageFormat(message);
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,16 +24,16 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class DiagnosticFactoryWithPsiElement<P extends PsiElement> extends AbstractDiagnosticFactory {
|
||||
public abstract class DiagnosticFactoryWithPsiElement<E extends PsiElement> extends AbstractDiagnosticFactory {
|
||||
protected final Severity severity;
|
||||
protected final PositioningStrategy<? super P> positioningStrategy;
|
||||
protected final PositioningStrategy<? super E> positioningStrategy;
|
||||
|
||||
public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super P> positioningStrategy) {
|
||||
public DiagnosticFactoryWithPsiElement(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
|
||||
this.severity = severity;
|
||||
this.positioningStrategy = positioningStrategy;
|
||||
}
|
||||
|
||||
protected List<TextRange> getTextRanges(Diagnostic<P> diagnostic) {
|
||||
protected List<TextRange> getTextRanges(ParametrizedDiagnostic<E> diagnostic) {
|
||||
return positioningStrategy.mark(diagnostic.getPsiElement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DiagnosticUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LineAndColumn getLineAndColumn(@NotNull Diagnostic<? extends PsiElement> diagnostic) {
|
||||
public static LineAndColumn getLineAndColumn(@NotNull Diagnostic diagnostic) {
|
||||
PsiFile file = diagnostic.getPsiFile();
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
TextRange firstRange = diagnostic.getTextRanges().iterator().next();
|
||||
|
||||
+4
-4
@@ -25,15 +25,15 @@ import java.util.List;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithPsiElement<P extends PsiElement> extends AbstractDiagnostic<P> {
|
||||
public DiagnosticWithPsiElement(@NotNull P psiElement, @NotNull DiagnosticFactoryWithPsiElement<P> factory, @NotNull Severity severity, @NotNull String message) {
|
||||
public class DiagnosticWithPsiElement<E extends PsiElement> extends AbstractDiagnostic<E> {
|
||||
public DiagnosticWithPsiElement(@NotNull E psiElement, @NotNull DiagnosticFactoryWithPsiElement<E> factory, @NotNull Severity severity, @NotNull String message) {
|
||||
super(psiElement, factory, severity, message);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DiagnosticFactoryWithPsiElement<P> getFactory() {
|
||||
return (DiagnosticFactoryWithPsiElement<P>)super.getFactory();
|
||||
public DiagnosticFactoryWithPsiElement<E> getFactory() {
|
||||
return (DiagnosticFactoryWithPsiElement<E>)super.getFactory();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public interface ParametrizedDiagnostic<E extends PsiElement> extends Diagnostic {
|
||||
@NotNull
|
||||
@Override
|
||||
E getPsiElement();
|
||||
}
|
||||
@@ -27,9 +27,9 @@ import java.util.List;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class PositioningStrategy<P extends PsiElement> {
|
||||
public class PositioningStrategy<E extends PsiElement> {
|
||||
@NotNull
|
||||
public List<TextRange> mark(@NotNull P element) {
|
||||
public List<TextRange> mark(@NotNull E element) {
|
||||
return markElement(element);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface RedeclarationDiagnostic extends Diagnostic<PsiElement> {
|
||||
public interface RedeclarationDiagnostic extends Diagnostic {
|
||||
class SimpleRedeclarationDiagnostic extends AbstractDiagnostic<PsiElement> implements RedeclarationDiagnostic {
|
||||
|
||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name, RedeclarationDiagnosticFactory factory) {
|
||||
|
||||
@@ -257,7 +257,7 @@ public class BodyResolver {
|
||||
private void resolveAnonymousInitializers(JetClassOrObject jetClassOrObject, MutableClassDescriptor classDescriptor) {
|
||||
if (!context.completeAnalysisNeeded(jetClassOrObject)) return;
|
||||
List<JetClassInitializer> anonymousInitializers = jetClassOrObject.getAnonymousInitializers();
|
||||
if (jetClassOrObject.hasPrimaryConstructor()) {
|
||||
if (classDescriptor.getUnsubstitutedPrimaryConstructor() != null) {
|
||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
assert primaryConstructor != null;
|
||||
final JetScope scopeForInitializers = classDescriptor.getScopeForInitializers();
|
||||
|
||||
@@ -155,11 +155,6 @@ public class DeclarationsChecker {
|
||||
}
|
||||
if ((memberDescriptor.getVisibility() == Visibility.PUBLIC || memberDescriptor.getVisibility() == Visibility.PROTECTED) &&
|
||||
hasDeferredType && nameIdentifier != null) {
|
||||
|
||||
JetType returnType = memberDescriptor.getReturnType();
|
||||
if (returnType instanceof DeferredType) {
|
||||
returnType = ((DeferredType) returnType).getActualType();
|
||||
}
|
||||
context.getTrace().report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(nameIdentifier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class NoC {
|
||||
trait NoC {
|
||||
<!ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR!>{
|
||||
|
||||
}<!>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
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;
|
||||
@@ -23,16 +24,19 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
@@ -40,7 +44,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
private final JetKeywordToken modifier;
|
||||
private final JetToken[] modifiersThanCanBeReplaced;
|
||||
|
||||
private AddModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier, JetToken[] modifiersThanCanBeReplaced) {
|
||||
private AddModifierFix(@NotNull JetModifierListOwner element, @NotNull JetKeywordToken modifier, @Nullable JetToken[] modifiersThanCanBeReplaced) {
|
||||
super(element);
|
||||
this.modifier = modifier;
|
||||
this.modifiersThanCanBeReplaced = modifiersThanCanBeReplaced;
|
||||
@@ -67,7 +71,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
|
||||
if (modifier == ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
|
||||
return JetBundle.message("make.element.modifier", getElementName(element), modifier.getValue());
|
||||
}
|
||||
return JetBundle.message("add.modifier", modifier.getValue());
|
||||
@@ -85,7 +89,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetModifierListOwner addModifier(@NotNull PsiElement element, @NotNull JetKeywordToken modifier, JetToken[] modifiersThanCanBeReplaced, @NotNull Project project) {
|
||||
private static JetModifierListOwner addModifier(@NotNull PsiElement element, @NotNull JetKeywordToken modifier, @Nullable JetToken[] modifiersThanCanBeReplaced, @NotNull Project project) {
|
||||
JetModifierListOwner newElement = (JetModifierListOwner) (element.copy());
|
||||
|
||||
JetModifierList modifierList = newElement.getModifierList();
|
||||
@@ -98,12 +102,14 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
}
|
||||
else {
|
||||
boolean replaced = false;
|
||||
for (JetToken modifierThanCanBeReplaced : modifiersThanCanBeReplaced) {
|
||||
if (modifierList.hasModifier(modifierThanCanBeReplaced)) {
|
||||
PsiElement openModifierPsi = modifierList.getModifierNode(modifierThanCanBeReplaced).getPsi();
|
||||
assert openModifierPsi != null;
|
||||
openModifierPsi.replace(listWithModifier.getFirstChild());
|
||||
replaced = true;
|
||||
if (modifiersThanCanBeReplaced != null) {
|
||||
for (JetToken modifierThanCanBeReplaced : modifiersThanCanBeReplaced) {
|
||||
if (modifierList.hasModifier(modifierThanCanBeReplaced)) {
|
||||
PsiElement openModifierPsi = modifierList.getModifierNode(modifierThanCanBeReplaced).getPsi();
|
||||
assert openModifierPsi != null;
|
||||
openModifierPsi.replace(listWithModifier.getFirstChild());
|
||||
replaced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!replaced) {
|
||||
@@ -120,14 +126,25 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final JetToken[] modifiersThatCanBeReplaced) {
|
||||
public static <T extends JetModifierListOwner> JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class<T> modifierOwnerClass) {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, JetModifierListOwner.class);
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, modifierOwnerClass);
|
||||
if (modifierListOwner == null) return null;
|
||||
return new AddModifierFix(modifierListOwner, modifier, modifiersThatCanBeReplaced);
|
||||
return new AddModifierFix(modifierListOwner, modifier, MODIFIERS_THAT_CAN_BE_REPLACED.get(modifier));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory(final JetKeywordToken modifier) {
|
||||
return createFactory(modifier, JetModifierListOwner.class);
|
||||
}
|
||||
|
||||
private static Map<JetToken, JetToken[]> MODIFIERS_THAT_CAN_BE_REPLACED = new HashMap<JetToken, JetToken[]>();
|
||||
static {
|
||||
MODIFIERS_THAT_CAN_BE_REPLACED.put(ABSTRACT_KEYWORD, new JetToken[]{OPEN_KEYWORD, FINAL_KEYWORD});
|
||||
MODIFIERS_THAT_CAN_BE_REPLACED.put(OVERRIDE_KEYWORD, new JetToken[]{OPEN_KEYWORD});
|
||||
MODIFIERS_THAT_CAN_BE_REPLACED.put(OPEN_KEYWORD, new JetToken[]{FINAL_KEYWORD});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class FakeDiagnosticForQuickFixes implements Diagnostic {
|
||||
private final PsiElement element;
|
||||
|
||||
public FakeDiagnosticForQuickFixes(PsiElement element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AbstractDiagnosticFactory getFactory() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getMessage() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Severity getSeverity() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getPsiElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TextRange> getTextRanges() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiFile getPsiFile() {
|
||||
return element.getContainingFile();
|
||||
}
|
||||
}
|
||||
@@ -40,16 +40,6 @@ public class QuickFixUtil {
|
||||
private QuickFixUtil() {
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> JetIntentionActionFactory createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory factory, final Class<T> aClass) {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
T element = getParentElementOfType(diagnostic, aClass);
|
||||
return factory.createAction(new FakeDiagnosticForQuickFixes(element));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean removePossiblyWhiteSpace(ASTDelegatePsiElement element, PsiElement possiblyWhiteSpace) {
|
||||
if (possiblyWhiteSpace instanceof PsiWhiteSpace) {
|
||||
element.deleteChildInternal(possiblyWhiteSpace.getNode());
|
||||
|
||||
@@ -19,15 +19,15 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
@@ -47,8 +47,8 @@ public class QuickFixes {
|
||||
private QuickFixes() {}
|
||||
|
||||
static {
|
||||
JetIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD);
|
||||
JetIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD});
|
||||
JetIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD);
|
||||
JetIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD);
|
||||
|
||||
factories.put(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
|
||||
factories.put(Errors.ABSTRACT_PROPERTY_NOT_IN_CLASS, removeAbstractModifierFactory);
|
||||
@@ -67,7 +67,7 @@ public class QuickFixes {
|
||||
|
||||
factories.put(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
|
||||
|
||||
JetIntentionActionFactory addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, JetClass.class);
|
||||
JetIntentionActionFactory addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, JetClass.class);
|
||||
factories.put(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
factories.put(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
|
||||
|
||||
@@ -85,8 +85,8 @@ public class QuickFixes {
|
||||
factories.put(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory);
|
||||
factories.put(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
factories.put(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OVERRIDE_KEYWORD));
|
||||
factories.put(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
|
||||
factories.put(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OVERRIDE_KEYWORD));
|
||||
factories.put(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(OVERRIDE_KEYWORD));
|
||||
|
||||
factories.put(Errors.USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
|
||||
factories.put(Errors.USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
|
||||
@@ -99,13 +99,12 @@ public class QuickFixes {
|
||||
|
||||
JetIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
|
||||
factories.put(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
|
||||
factories.put(Errors.ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD, true));
|
||||
factories.put(Errors.OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD, true));
|
||||
factories.put(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
|
||||
factories.put(Errors.ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD, true));
|
||||
factories.put(Errors.OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD, true));
|
||||
factories.put(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD));
|
||||
|
||||
JetIntentionActionFactory addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
|
||||
JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
|
||||
factories.put(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, JetClass.class));
|
||||
JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD);
|
||||
factories.put(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, AddModifierFix.createFactory(OPEN_KEYWORD, JetClass.class));
|
||||
factories.put(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
|
||||
|
||||
JetIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class NoC {
|
||||
trait NoC {
|
||||
<error>{
|
||||
|
||||
}</error>
|
||||
|
||||
Reference in New Issue
Block a user