removed core-impl dependency on properties files

This commit is contained in:
Alexey Kudravtsev
2016-02-29 13:56:59 +03:00
parent 88e1356e78
commit fdd0f11743
8 changed files with 42 additions and 30 deletions
-1
View File
@@ -16,7 +16,6 @@
<sourceFolder url="file://$MODULE_DIR$/../../plugins/generate-tostring/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../plugins/generate-tostring/resources" type="java-resource" />
</content>
<orderEntry type="module" module-name="boot" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
-1
View File
@@ -9,7 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="core-api" exported="" />
<orderEntry type="library" name="picocontainer" level="project" />
<orderEntry type="module" module-name="boot" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.openapi.fileEditor.impl;
import com.intellij.lang.properties.charset.Native2AsciiCharset;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationUtil;
@@ -119,33 +118,29 @@ public final class LoadTextUtil {
}
@NotNull
public static Charset detectCharset(@NotNull VirtualFile virtualFile, @NotNull byte[] content, @NotNull FileType fileType) {
private static Charset detectCharset(@NotNull VirtualFile virtualFile, @NotNull byte[] content, @NotNull FileType fileType) {
Charset charset = null;
String charsetName = fileType.getCharset(virtualFile, content);
Trinity<Charset,CharsetToolkit.GuessedEncoding, byte[]> guessed = guessFromContent(virtualFile, content, content.length);
if (guessed != null && guessed.first != null) {
charset = guessed.first;
Charset hardCodedCharset = guessed == null ? null : guessed.first;
if (charsetName != null) {
charset = CharsetToolkit.forName(charsetName);
}
else if (hardCodedCharset == null) {
Charset specifiedExplicitly = EncodingRegistry.getInstance().getEncoding(virtualFile, true);
if (specifiedExplicitly != null) {
charset = specifiedExplicitly;
}
}
else {
String charsetName = fileType.getCharset(virtualFile, content);
if (charsetName == null) {
Charset specifiedExplicitly = EncodingRegistry.getInstance().getEncoding(virtualFile, true);
if (specifiedExplicitly != null) {
charset = specifiedExplicitly;
}
}
else {
charset = CharsetToolkit.forName(charsetName);
}
charset = hardCodedCharset;
}
if (charset == null) {
charset = EncodingRegistry.getInstance().getDefaultCharset();
}
if (fileType.getName().equals("Properties") && EncodingRegistry.getInstance().isNative2Ascii(virtualFile)) {
charset = Native2AsciiCharset.wrap(charset);
}
virtualFile.setCharset(charset);
return charset;
}
@@ -17,5 +17,6 @@
<orderEntry type="module" module-name="projectModel-api" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="boot" />
</component>
</module>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -16,7 +16,10 @@
package com.intellij.lang.properties;
import com.intellij.icons.AllIcons;
import com.intellij.lang.properties.charset.Native2AsciiCharset;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingRegistry;
@@ -63,10 +66,14 @@ public class PropertiesFileType extends LanguageFileType {
@Override
public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
Charset charset = EncodingRegistry.getInstance().getDefaultCharsetForPropertiesFiles(file);
Trinity<Charset, CharsetToolkit.GuessedEncoding, byte[]> guessed = LoadTextUtil.guessFromContent(file, content, content.length);
Charset charset = guessed == null || guessed.first == null ? EncodingRegistry.getInstance().getDefaultCharsetForPropertiesFiles(file) : guessed.first;
if (charset == null) {
charset = CharsetToolkit.getDefaultSystemCharset();
}
if (EncodingRegistry.getInstance().isNative2Ascii(file)) {
charset = Native2AsciiCharset.wrap(charset);
}
return charset.name();
}
}
+1 -3
View File
@@ -6,7 +6,6 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="module" module-name="boot" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="lang-api" />
@@ -22,5 +21,4 @@
<orderEntry type="module" module-name="properties-psi-impl" exported="" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
</component>
</module>
</module>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -19,7 +19,9 @@ import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeBundle;
import com.intellij.lang.Language;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.text.XmlCharsetDetector;
@@ -70,7 +72,12 @@ public class HtmlFileType extends XmlLikeFileType {
@Override
public String getCharset(@NotNull final VirtualFile file, @NotNull final byte[] content) {
String charset = XmlCharsetDetector.extractXmlEncodingFromProlog(content);
Trinity<Charset, CharsetToolkit.GuessedEncoding, byte[]> guessed = LoadTextUtil.guessFromContent(file, content, content.length);
String charset =
guessed != null && guessed.first != null
? guessed.first.name()
: XmlCharsetDetector.extractXmlEncodingFromProlog(content);
if (charset != null) return charset;
@NonNls String strContent;
try {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -16,8 +16,10 @@
package com.intellij.ide.highlighter;
import com.intellij.lang.Language;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.text.XmlCharsetDetector;
@@ -32,7 +34,11 @@ public abstract class XmlLikeFileType extends LanguageFileType {
}
@Override
public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
String charset = XmlCharsetDetector.extractXmlEncodingFromProlog(content);
Trinity<Charset, CharsetToolkit.GuessedEncoding, byte[]> guessed = LoadTextUtil.guessFromContent(file, content, content.length);
String charset =
guessed != null && guessed.first != null
? guessed.first.name()
: XmlCharsetDetector.extractXmlEncodingFromProlog(content);
return charset == null ? CharsetToolkit.UTF8 : charset;
}