mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved to xml-analysis
This commit is contained in:
+11
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -18,12 +18,10 @@ package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.XmlErrorMessages;
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -39,20 +37,20 @@ import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.XmlExtension;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 18-Nov-2005
|
||||
*/
|
||||
public class InsertRequiredAttributeFix implements IntentionAction, LocalQuickFix, HighPriorityAction {
|
||||
private final XmlTag myTag;
|
||||
public class InsertRequiredAttributeFix extends LocalQuickFixAndIntentionActionOnPsiElement implements HighPriorityAction {
|
||||
private final String myAttrName;
|
||||
private final String[] myValues;
|
||||
@NonNls
|
||||
private static final String NAME_TEMPLATE_VARIABLE = "name";
|
||||
|
||||
public InsertRequiredAttributeFix(@NotNull XmlTag tag, @NotNull String attrName,@NotNull String... values) {
|
||||
myTag = tag;
|
||||
super(tag);
|
||||
myAttrName = attrName;
|
||||
myValues = values;
|
||||
}
|
||||
@@ -63,12 +61,6 @@ public class InsertRequiredAttributeFix implements IntentionAction, LocalQuickFi
|
||||
return XmlErrorMessages.message("insert.required.attribute.quickfix.text", myAttrName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -76,18 +68,13 @@ public class InsertRequiredAttributeFix implements IntentionAction, LocalQuickFi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
invoke(project, null, myTag.getContainingFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return myTag.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) {
|
||||
public void invoke(@NotNull final Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable("is null when called from inspection") final Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
|
||||
XmlTag myTag = (XmlTag)startElement;
|
||||
ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(myTag);
|
||||
|
||||
final XmlElementDescriptor descriptor = myTag.getDescriptor();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -17,7 +17,6 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.CreateNSDeclarationIntentionFix;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.InsertRequiredAttributeFix;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.psi.xml.XmlToken;
|
||||
@@ -27,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class XmlQuickFixFactoryImpl extends XmlQuickFixFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public IntentionAction insertRequiredAttributeFix(@NotNull XmlTag tag, @NotNull String attrName, @NotNull String... values) {
|
||||
public LocalQuickFixAndIntentionActionOnPsiElement insertRequiredAttributeFix(@NotNull XmlTag tag, @NotNull String attrName, @NotNull String... values) {
|
||||
return new InsertRequiredAttributeFix(tag, attrName, values);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="lang-api" />
|
||||
<orderEntry type="module" module-name="xml-psi-api" exported="" />
|
||||
<orderEntry type="module" module-name="xml-analysis-api" exported="" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
@@ -29,7 +28,7 @@ public abstract class XmlQuickFixFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract IntentionAction insertRequiredAttributeFix(@NotNull XmlTag tag, @NotNull String attrName,@NotNull String... values);
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement insertRequiredAttributeFix(@NotNull XmlTag tag, @NotNull String attrName,@NotNull String... values);
|
||||
|
||||
@NotNull
|
||||
public abstract LocalQuickFix createNSDeclarationIntentionFix(@NotNull final PsiElement element,
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -30,7 +30,7 @@ public abstract class XmlTagRuleProvider {
|
||||
|
||||
public static final Rule[] EMPTY_ARRAY = new Rule[0];
|
||||
|
||||
public void annotate(@NotNull XmlTag tag, ProblemsHolder holder) {
|
||||
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.intellij.xml.util;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.InsertRequiredAttributeFix;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.XmlQuickFixFactory;
|
||||
import com.intellij.codeInspection.htmlInspections.RemoveAttributeIntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
@@ -117,7 +117,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
// ---=== Classes ===---
|
||||
|
||||
public abstract static class Effect {
|
||||
public abstract void annotate(@NotNull XmlTag tag, ProblemsHolder holder);
|
||||
public abstract void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder);
|
||||
}
|
||||
|
||||
public static class InvalidAttrEffect extends Effect {
|
||||
@@ -132,7 +132,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull XmlTag tag, ProblemsHolder holder) {
|
||||
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
|
||||
XmlAttribute attribute = tag.getAttribute(myAttrName);
|
||||
if (attribute != null) {
|
||||
PsiElement attributeNameElement = getAttributeNameElement(attribute);
|
||||
@@ -155,7 +155,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull XmlTag tag, ProblemsHolder holder) {
|
||||
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
|
||||
for (XmlAttribute xmlAttribute : tag.getAttributes()) {
|
||||
String attrName = xmlAttribute.getName();
|
||||
if (!ArrayUtil.contains(attrName, myAttrNames)) {
|
||||
@@ -178,7 +178,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull XmlTag tag, ProblemsHolder holder) {
|
||||
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
|
||||
if (myCondition.value(tag)) {
|
||||
for (Effect effect : myEffect) {
|
||||
effect.annotate(tag, holder);
|
||||
@@ -214,7 +214,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull XmlTag tag, ProblemsHolder holder) {
|
||||
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
|
||||
for (String attributeName : myAttributeNames) {
|
||||
if (tag.getAttribute(attributeName) != null) {
|
||||
return;
|
||||
@@ -228,7 +228,7 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
|
||||
|
||||
LocalQuickFix[] fixes = new LocalQuickFix[myAttributeNames.length];
|
||||
for (int i = 0; i < myAttributeNames.length; i++) {
|
||||
fixes[i] = new InsertRequiredAttributeFix(tag, myAttributeNames[i]);
|
||||
fixes[i] = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, myAttributeNames[i]);
|
||||
}
|
||||
|
||||
holder.registerProblem(tagNameElement, "Tag should have one of following attributes: " + StringUtil.join(myAttributeNames, ", "),
|
||||
Reference in New Issue
Block a user