Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2013-12-30 16:32:08 +01:00
25 changed files with 239 additions and 92 deletions
@@ -184,8 +184,13 @@ public class MainWatchPanel extends WatchPanel implements DataProvider {
}
TextWithImports text = comboBox.getText();
WatchDebuggerTree.setWatchNodeText(node, text);
comboBox.addRecent(text);
if (!text.isEmpty()) {
WatchDebuggerTree.setWatchNodeText(node, text);
comboBox.addRecent(text);
}
else {
getWatchTree().removeWatch(node);
}
try {
super.doOKAction();
}
@@ -196,6 +201,9 @@ public class MainWatchPanel extends WatchPanel implements DataProvider {
public void cancelEditing() {
comboBox.setPopupVisible(false);
if (((WatchItemDescriptor)node.getDescriptor()).getEvaluationText().isEmpty()) {
getWatchTree().removeWatch(node);
}
try {
super.cancelEditing();
@@ -25,8 +25,7 @@ import com.intellij.psi.stubs.StubElement;
import com.intellij.util.cls.ClsFormatException;
import com.intellij.util.indexing.FileContent;
import java.util.Arrays;
import java.util.Comparator;
import java.util.*;
/**
* @author max
@@ -73,8 +72,9 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
@Override
public int getStubVersion() {
int version = STUB_VERSION;
final ClsStubBuilderFactory[] factories = Extensions.getExtensions(ClsStubBuilderFactory.EP_NAME);
Arrays.sort(factories, new Comparator<ClsStubBuilderFactory>() { // stable order
List<ClsStubBuilderFactory> factories = new ArrayList<ClsStubBuilderFactory>(Arrays.asList(
Extensions.getExtensions(ClsStubBuilderFactory.EP_NAME)));
Collections.sort(factories, new Comparator<ClsStubBuilderFactory>() { // stable order in copy
@Override
public int compare(ClsStubBuilderFactory o1, ClsStubBuilderFactory o2) {
return o1.getClass().getName().compareTo(o2.getClass().getName());
@@ -83,6 +83,10 @@ public final class Urls {
@Nullable
public static Url parse(@NotNull String url, boolean asLocalIfNoScheme) {
if (url.isEmpty()) {
return null;
}
if (asLocalIfNoScheme && !URLUtil.containsScheme(url)) {
// nodejs debug — files only in local filesystem
return new LocalFileUrl(url);
@@ -101,7 +105,7 @@ public final class Urls {
return toUriWithoutParameters(asUrl);
}
catch (Exception e) {
LOG.info("Can't parse " + url, e);
LOG.info("Cannot parse url " + url, e);
return null;
}
}
@@ -70,6 +70,14 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti
if (!loggingMethodNames.contains(name)) {
return;
}
final PsiMethod method = expression.resolveMethod();
if (method == null) {
return;
}
final PsiClass aClass = method.getContainingClass();
if (!InheritanceUtil.isInheritor(aClass, "org.slf4j.Logger")) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 0) {
@@ -76,4 +76,15 @@ public class PlaceholderCountMatchesArgumentCountInspectionTest extends LightIns
" public static class SecondException extends Exception { }\n" +
"}");
}
public void testNoSlf4j() {
doTest("class FalsePositiveSLF4J {\n" +
" public void method( DefinitelyNotSLF4J definitelyNotSLF4J ) {\n" +
" definitelyNotSLF4J.trace( \"not a trace message\", \"not a trace parameter\" );\n" +
" }\n" +
" public interface DefinitelyNotSLF4J {\n" +
" void trace( String firstParameter, Object secondParameter );\n" +
" }\n" +
"}");
}
}
@@ -45,7 +45,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -204,9 +203,12 @@ public class GradleExecutionHelper {
@NotNull GradleExecutionSettings settings,
@NotNull ExternalSystemTaskNotificationListener listener) {
// use it only for customized wrapper
// TODO works correctly only or root project
if (settings.getDistributionType() != DistributionType.WRAPPED) return;
if (!settings.getDistributionType().isWrapped()) return;
if (settings.getDistributionType() == DistributionType.DEFAULT_WRAPPED &&
GradleUtil.findDefaultWrapperPropertiesFile(projectPath) != null) {
return;
}
ProjectConnection connection = getConnection(projectPath, settings);
try {
@@ -73,9 +73,9 @@ public class GradleTaskManager extends AbstractExternalSystemTaskManager<GradleE
@Nullable final String debuggerSetup,
@NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
if (settings != null) {
myHelper.ensureInstalledWrapper(id, projectPath, settings, listener);
}
// if (settings != null) {
// myHelper.ensureInstalledWrapper(id, projectPath, settings, listener);
// }
// TODO add support for external process mode
if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
@@ -107,4 +107,6 @@ target.0.does.not.exist=Target ''{0}'' does not exist
target.annotation.is.unused=@Target is unused
change.lvalue.type=Change variable ''{0}'' type to ''{1}''
replace.qualified.name.with.import=Replace qualified name with import
highlight.assignments.from.void=Highlight assignments from void type
highlight.assignments.from.void=Highlight assignments from void type
comments.count.as.content=Comments count as content
ignore.when.catch.parameter.is.named.ignore.or.ignored=Ignore when catch parameter is named ignore or ignored
@@ -18,16 +18,26 @@ package org.jetbrains.plugins.groovy.codeInspection.exception;
import com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import javax.swing.*;
public class GroovyEmptyCatchBlockInspection extends BaseInspection {
public boolean myIgnore = true;
public boolean myCountCommentsAsContent = true;
@Nls
@NotNull
@@ -41,11 +51,21 @@ public class GroovyEmptyCatchBlockInspection extends BaseInspection {
return "Empty 'catch' block";
}
@NotNull
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private static class Visitor extends BaseInspectionVisitor {
@Nullable
@Override
public JComponent createOptionsPanel() {
MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
panel.addCheckbox(GroovyInspectionBundle.message("comments.count.as.content"), "myCountCommentsAsContent");
panel.addCheckbox(GroovyInspectionBundle.message("ignore.when.catch.parameter.is.named.ignore.or.ignored"), "myIgnore");
return panel;
}
private class Visitor extends BaseInspectionVisitor {
public void visitCatchClause(GrCatchClause catchClause) {
super.visitCatchClause(catchClause);
@@ -56,15 +76,29 @@ public class GroovyEmptyCatchBlockInspection extends BaseInspection {
final GrParameter parameter = catchClause.getParameter();
if (parameter == null) return;
if (GrExceptionUtil.ignore(parameter)) return;
if (myIgnore && GrExceptionUtil.ignore(parameter)) return;
final LocalQuickFix[] fixes = {new RenameElementFix(parameter, "ignored")};
final LocalQuickFix[] fixes = myIgnore
? new RenameElementFix[]{new RenameElementFix(parameter, "ignored")}
: LocalQuickFix.EMPTY_ARRAY;
registerError(catchClause.getFirstChild(), "Empty '#ref' block #loc", fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
private static boolean isEmpty(@NotNull GrOpenBlock body) {
private boolean isEmpty(@NotNull GrOpenBlock body) {
final GrStatement[] statements = body.getStatements();
return statements.length == 0;
if (statements.length != 0) return false;
if (myCountCommentsAsContent) {
final PsiElement brace = body.getLBrace();
if (brace != null) {
final PsiElement next = PsiUtil.skipWhitespaces(brace.getNextSibling(), true);
if (next instanceof PsiComment) {
return false;
}
}
}
return true;
}
}
}
@@ -55,6 +55,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrPropertySelection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
@@ -1270,6 +1271,13 @@ public class ExpressionGenerator extends Generator {
builder.append(')');
}
@Override
public void visitPropertySelection(GrPropertySelection expression) {
expression.getQualifier().accept(this);
builder.append('.');
builder.append(expression.getReferenceNameElement().getText());
}
@Override
public void visitIndexProperty(GrIndexProperty expression) {
final GrExpression selectedExpression = expression.getInvokedExpression();
@@ -23,6 +23,7 @@ import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspec
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryContinueInspection
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryReturnInspection
import org.jetbrains.plugins.groovy.codeInspection.declaration.GrMethodMayBeStaticInspection
import org.jetbrains.plugins.groovy.codeInspection.exception.GroovyEmptyCatchBlockInspection
import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection
import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection
import org.jetbrains.plugins.groovy.codeInspection.threading.GroovyUnconditionalWaitInspection
@@ -316,4 +317,34 @@ for(i in []) {
''', GroovyUnnecessaryContinueInspection)
}
void testEmptyCatchBlock1() {
testHighlighting('''
try{} <warning descr="Empty 'catch' block">catch</warning>(IOException e) {}
try{} catch(IOException ignored) {}
try{} catch(IOException ignore) {}
try{} catch(IOException e) {/*comment*/}
''', GroovyEmptyCatchBlockInspection)
}
void testEmptyCatchBlock2() {
GroovyEmptyCatchBlockInspection inspection = new GroovyEmptyCatchBlockInspection()
inspection.myIgnore = false
myFixture.enableInspections(inspection)
testHighlighting('try{} <warning descr="Empty \'catch\' block">catch</warning>(IOException ignored) {}')
}
void testEmptyCatchBlock3() {
GroovyEmptyCatchBlockInspection inspection = new GroovyEmptyCatchBlockInspection()
inspection.myIgnore = false
myFixture.enableInspections(inspection)
testHighlighting('try{} <warning descr="Empty \'catch\' block">catch</warning>(IOException ignored) {}')
}
void testEmptyCatchBlock4() {
GroovyEmptyCatchBlockInspection inspection = new GroovyEmptyCatchBlockInspection()
inspection.myCountCommentsAsContent = false
myFixture.enableInspections(inspection)
testHighlighting('try{} <warning descr="Empty \'catch\' block">catch</warning>(IOException e) {/*comment*/}')
}
}
@@ -198,4 +198,6 @@ public final class Matcher {
void testInWitchClassCheck() { doTest() }
void testSwitch() { doTest() }
void testPropSelection() { doTest() }
}
@@ -0,0 +1 @@
print p."a$c"
@@ -0,0 +1 @@
print(this.getBinding().getProperty("p")."a$c");
@@ -22,8 +22,10 @@ import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiFile;
import com.intellij.util.SmartList;
import gnu.trove.THashMap;
@@ -40,49 +42,54 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
myProject = project;
}
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> children, ViewSettings settings) {
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parent instanceof ResourceBundleNode) return children;
Map<ResourceBundle,Collection<PropertiesFile>> childBundles = new THashMap<ResourceBundle, Collection<PropertiesFile>>();
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
Collection<PropertiesFile> files = childBundles.get(bundle);
if (files == null) {
files = new SmartList<PropertiesFile>();
childBundles.put(bundle, files);
}
files.add(propertiesFile);
}
}
}
List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : childBundles.entrySet()) {
ResourceBundle resourceBundle = entry.getKey();
Collection<PropertiesFile> files = entry.getValue();
if (files.size() != 1) {
result.add(new ResourceBundleNode(myProject, resourceBundle, settings));
}
}
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
if (childBundles.get(bundle).size() != 1) {
continue;
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<AbstractTreeNode>>() {
@Override
public Collection<AbstractTreeNode> compute() {
Map<ResourceBundle,Collection<PropertiesFile>> childBundles = new THashMap<ResourceBundle, Collection<PropertiesFile>>();
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
Collection<PropertiesFile> files = childBundles.get(bundle);
if (files == null) {
files = new SmartList<PropertiesFile>();
childBundles.put(bundle, files);
}
files.add(propertiesFile);
}
}
}
}
result.add(child);
}
return result;
List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : childBundles.entrySet()) {
ResourceBundle resourceBundle = entry.getKey();
Collection<PropertiesFile> files = entry.getValue();
if (files.size() != 1) {
result.add(new ResourceBundleNode(myProject, resourceBundle, settings));
}
}
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
if (childBundles.get(bundle).size() != 1) {
continue;
}
}
}
result.add(child);
}
return result;
}
});
}
public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
@@ -32,10 +32,9 @@ import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.IncorrectOperationException;
import com.intellij.reference.SoftLazyValue;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.text.CharArrayUtil;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -82,14 +81,7 @@ public class XmlPropertiesFile implements PropertiesFile {
new CachedValueProvider<PropertiesFile>() {
@Override
public Result<PropertiesFile> compute() {
CharSequence contents = file.getViewProvider().getContents();
PropertiesFile value = null;
if (CharArrayUtil.indexOf(contents, XmlPropertiesIndex.HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD, 0) != -1 &&
XmlPropertiesIndex.isAccepted(contents)
) {
value = new XmlPropertiesFile(file);
}
PropertiesFile value = XmlPropertiesIndex.isPropertiesFile(file) ? new XmlPropertiesFile(file) : null;
return Result.create(value, file);
}
}, false);
@@ -2,12 +2,18 @@ package com.intellij.lang.properties.xml;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.EverythingGlobalScope;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.Consumer;
import com.intellij.util.indexing.*;
import com.intellij.util.io.*;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.EnumeratorStringDescriptor;
import com.intellij.util.io.IOUtil;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.util.xml.NanoXmlUtil;
import net.n3.nanoxml.StdXMLReader;
@@ -31,7 +37,7 @@ public class XmlPropertiesIndex extends FileBasedIndexExtension<XmlPropertiesInd
public static final ID<Key,String> NAME = ID.create("xmlProperties");
private static final EnumeratorStringDescriptor ENUMERATOR_STRING_DESCRIPTOR = new EnumeratorStringDescriptor();
public static final String HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD = "http://java.sun.com/dtd/properties.dtd";
private static final String HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD = "http://java.sun.com/dtd/properties.dtd";
@NotNull
@Override
@@ -94,6 +100,20 @@ public class XmlPropertiesIndex extends FileBasedIndexExtension<XmlPropertiesInd
return map;
}
static boolean isPropertiesFile(XmlFile file) {
if (DumbService.isDumb(file.getProject())) {
CharSequence contents = file.getViewProvider().getContents();
return CharArrayUtil.indexOf(contents, HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD, 0) != -1 &&
isAccepted(contents);
}
return !FileBasedIndex.getInstance().processValues(NAME, MARKER_KEY, file.getVirtualFile(), new FileBasedIndex.ValueProcessor<String>() {
@Override
public boolean process(VirtualFile file, String value) {
return false;
}
}, new EverythingGlobalScope());
}
static boolean isAccepted(CharSequence bytes) {
MyIXMLBuilderAdapter builder = parse(bytes, true);
return builder != null && builder.accepted;
@@ -25,7 +25,11 @@ import com.intellij.psi.filters.getters.HtmlAttributeValueGetter;
import com.intellij.psi.filters.getters.XmlAttributeValueGetter;
import com.intellij.psi.filters.position.XmlTokenTypeFilter;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.*;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlToken;
import com.intellij.psi.xml.XmlTokenType;
import com.intellij.xml.util.HtmlUtil;
import org.jetbrains.annotations.NonNls;
/**
@@ -36,7 +40,6 @@ public class HtmlCompletionData extends XmlCompletionData {
private boolean myCaseInsensitive;
private static final @NonNls String JAVASCRIPT_LANGUAGE_ID = "JavaScript";
private static final @NonNls String STYLE_TAG = "style";
private static final @NonNls String SCRIPT_TAG = "script";
public HtmlCompletionData() {
this(true);
@@ -46,6 +49,7 @@ public class HtmlCompletionData extends XmlCompletionData {
myCaseInsensitive = _caseInsensitive;
}
@Override
protected ElementFilter createXmlEntityCompletionFilter() {
if (isCaseInsensitive()) {
return new AndFilter(
@@ -77,12 +81,15 @@ public class HtmlCompletionData extends XmlCompletionData {
myCaseInsensitive = caseInsensitive;
}
@Override
protected XmlAttributeValueGetter getAttributeValueGetter() {
return new HtmlAttributeValueGetter(!isCaseInsensitive());
}
@Override
protected ElementFilter createTagCompletionFilter() {
return new ElementFilter() {
@Override
public boolean isAcceptable(Object element, PsiElement context) {
String name = ((XmlTag)context).getName();
@@ -92,7 +99,7 @@ public class HtmlCompletionData extends XmlCompletionData {
}
if (equalNames(name, STYLE_TAG) ||
equalNames(name,SCRIPT_TAG)) {
equalNames(name, HtmlUtil.SCRIPT_TAG_NAME)) {
return false;
}
@@ -100,33 +107,40 @@ public class HtmlCompletionData extends XmlCompletionData {
return true;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
};
}
@Override
protected ElementFilter createAttributeCompletionFilter() {
return new ElementFilter() {
@Override
public boolean isAcceptable(Object element, PsiElement context) {
if (isStyleAttributeContext(context)) return false;
return true;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
};
}
@Override
protected ElementFilter createAttributeValueCompletionFilter() {
return new ElementFilter() {
@Override
public boolean isAcceptable(Object element, PsiElement context) {
if (isStyleAttributeContext(context)) return false;
if ( isScriptContext((PsiElement)element) ) return false;
return true;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
@@ -151,11 +165,13 @@ public class HtmlCompletionData extends XmlCompletionData {
return false;
}
@Override
public void registerVariant(CompletionVariant variant) {
super.registerVariant(variant);
if (isCaseInsensitive()) variant.setCaseInsensitive(true);
}
@Override
public String findPrefix(PsiElement insertedElement, int offset) {
String prefix = super.findPrefix(insertedElement, offset);
@@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.impl.source.xml.TagNameVariantCollector;
import com.intellij.psi.impl.source.xml.XmlDocumentImpl;
import com.intellij.psi.util.PsiTreeUtil;
@@ -34,6 +33,7 @@ import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlText;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.util.HtmlUtil;
import org.jetbrains.annotations.NotNull;
class XmlMover extends LineMover {
@@ -62,11 +62,7 @@ class XmlMover extends LineMover {
if (checkInjections(movedEndElement, movedStartElement)) return false;
XmlTag nearestTag = PsiTreeUtil.getParentOfType(movedStartElement, XmlTag.class);
if (nearestTag != null &&
( "script".equals(nearestTag.getLocalName()) ||
(nearestTag instanceof HtmlTag && "script".equalsIgnoreCase(nearestTag.getLocalName()))
)
) {
if (nearestTag != null && HtmlUtil.isScriptTag(nearestTag)) {
return false;
}
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xml.util.HtmlUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -69,7 +70,7 @@ class HtmlTagTreeElement extends PsiTreeElementBase<XmlTag> implements LocationP
return null;
}
if (tag.getName().equalsIgnoreCase("img") || tag.getName().equalsIgnoreCase("script")) {
if (tag.getName().equalsIgnoreCase("img") || HtmlUtil.isScriptTag(tag)) {
return getPathDescription(tag.getAttributeValue("src"));
}
else if (tag.getName().equalsIgnoreCase("link")) {
@@ -39,7 +39,7 @@ public class HtmlScriptLanguageInjector implements MultiHostInjector {
return;
}
XmlTag scriptTag = ((XmlText)host).getParentTag();
if (scriptTag == null || !"script".equalsIgnoreCase(scriptTag.getLocalName())) {
if (scriptTag == null || !HtmlUtil.isScriptTag(scriptTag)) {
return;
}
String mimeType = scriptTag.getAttributeValue("type");
@@ -44,8 +44,7 @@ import java.util.Set;
*/
public class CheckEmptyTagInspection extends XmlSuppressableInspectionTool {
private static final Logger LOG = Logger.getInstance("#com.intellij.xml.util.CheckEmptyTagInspection");
@NonNls private static final String SCRIPT_TAG_NAME = "script";
@NonNls private static final Set<String> ourTagsWithEmptyEndsNotAllowed = new THashSet<String>(Arrays.asList(SCRIPT_TAG_NAME, "div", "iframe"));
@NonNls private static final Set<String> ourTagsWithEmptyEndsNotAllowed = new THashSet<String>(Arrays.asList(HtmlUtil.SCRIPT_TAG_NAME, "div", "iframe"));
@Override
public boolean isEnabledByDefault() {
@@ -41,8 +41,6 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
protected static final String AMP_ENTITY_REFERENCE = "&amp;";
@NonNls
protected static final String LT_ENTITY_REFERENCE = "&lt;";
@NonNls
private static final String SCRIPT_TAG_NAME = "script";
private Lexer myXmlLexer;
@Override
@@ -57,8 +55,8 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
@Override public void visitXmlTag(final XmlTag tag) {
if (HtmlUtil.isHtmlTag(tag)) return;
if (SCRIPT_TAG_NAME.equals(tag.getName()) ||
tag instanceof HtmlTag && SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
if (HtmlUtil.SCRIPT_TAG_NAME.equals(tag.getName()) ||
tag instanceof HtmlTag && HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
final PsiFile psiFile = tag.getContainingFile();
final FileType fileType = psiFile.getFileType();
@@ -28,8 +28,8 @@ import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.xml.*;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.util.HtmlPsiUtil;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlPsiUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -41,7 +41,6 @@ import java.util.List;
public class ScriptSupportUtil {
private static final Key<CachedValue<XmlTag[]>> CachedScriptTagsKey = Key.create("script tags");
private static final ThreadLocal<String> ProcessingDeclarationsFlag = new ThreadLocal<String>();
@NonNls private static final String SCRIPT_TAG = "script";
private ScriptSupportUtil() {
}
@@ -66,13 +65,14 @@ public class ScriptSupportUtil {
if (document != null) {
PsiElementProcessor psiElementProcessor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof XmlTag) {
final XmlTag tag = (XmlTag)element;
if (SCRIPT_TAG.equalsIgnoreCase(tag.getName())) {
if (HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
final XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor != null && SCRIPT_TAG.equals(descriptor.getName())) {
if (descriptor != null && HtmlUtil.SCRIPT_TAG_NAME.equals(descriptor.getName())) {
scriptTags.add(tag);
}
}
@@ -70,6 +70,8 @@ public class HtmlUtil {
@NonNls private static final String CHARSET_PREFIX = CHARSET+"=";
@NonNls private static final String HTML5_DATA_ATTR_PREFIX = "data-";
public static final String SCRIPT_TAG_NAME = "script";
public static final String[] CONTENT_TYPES =
{"application/activemessage", "application/andrew-inset", "application/applefile", "application/atomicmail", "application/dca-rft",
"application/dec-dx", "application/mac-binhex40"
@@ -488,7 +490,7 @@ public class HtmlUtil {
public void endTag(final CharSequence localName, final String namespace, final int startoffset, final int endoffset) {
@NonNls final String name = localName.toString().toLowerCase();
if ("meta".equals(name) && (metHttpEquiv || metHttml5Charset) && contentAttributeValue != null) {
String charsetName = null;
String charsetName;
if (metHttpEquiv) {
int start = contentAttributeValue.indexOf(CHARSET_PREFIX);
if (start == -1) return;
@@ -606,4 +608,8 @@ public class HtmlUtil {
}
return false;
}
public static boolean isScriptTag(@NotNull XmlTag tag) {
return tag.getLocalName().equalsIgnoreCase(SCRIPT_TAG_NAME);
}
}