Properties API further extraction

This commit is contained in:
Anna Bulenkova
2014-03-24 12:59:50 +01:00
parent 45d0dcf6df
commit 3c94abe286
59 changed files with 557 additions and 277 deletions
+1
View File
@@ -31,6 +31,7 @@
<orderEntry type="module" module-name="external-system-impl" scope="RUNTIME" />
<orderEntry type="module" module-name="junit_rt" scope="TEST" />
<orderEntry type="module" module-name="xml-psi-impl" scope="TEST" />
<orderEntry type="module" module-name="properties-psi-api" scope="TEST" />
</component>
</module>
+1
View File
@@ -27,6 +27,7 @@
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="ant-jps-plugin" />
<orderEntry type="module" module-name="dom-impl" />
<orderEntry type="module" module-name="properties-psi-api" />
</component>
<component name="copyright">
<Base>
+1
View File
@@ -40,6 +40,7 @@
</orderEntry>
<orderEntry type="module" module-name="spellchecker" />
<orderEntry type="module" module-name="dom-tests" scope="TEST" />
<orderEntry type="module" module-name="properties-psi-api" />
</component>
</module>
+1
View File
@@ -20,6 +20,7 @@
<orderEntry type="module" module-name="jsp-openapi" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
<orderEntry type="module" module-name="properties-psi-api" />
<orderEntry type="module" module-name="properties-psi-impl" />
</component>
</module>
@@ -18,7 +18,7 @@ package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.template.macro.MacroUtil;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.PropertyCreationHandler;
import com.intellij.lang.properties.references.I18nUtil;
@@ -252,7 +252,7 @@ public class JavaI18nUtil extends I18nUtil {
public static boolean isPropertyRef(final PsiLiteralExpression expression, final String key, final String resourceBundleName) {
if (resourceBundleName == null) {
return !PropertiesUtil.findPropertiesByKey(expression.getProject(), key).isEmpty();
return !PropertiesImplUtil.findPropertiesByKey(expression.getProject(), key).isEmpty();
}
else {
final List<PropertiesFile> propertiesFiles = propertiesFilesByBundleName(resourceBundleName, expression);
@@ -11,6 +11,9 @@
<orderEntry type="module" module-name="core-api" />
<orderEntry type="module" module-name="editor-ui-api" />
<orderEntry type="module" module-name="analysis-api" />
<orderEntry type="module" module-name="indexing-api" />
<orderEntry type="module" module-name="xml-psi-api" />
<orderEntry type="module" module-name="projectModel-api" />
</component>
</module>
@@ -0,0 +1,57 @@
/*
* 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.
* 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 com.intellij.lang.properties;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
/**
* @author Anna Bulenkova
*/
public class EmptyResourceBundle {
private EmptyResourceBundle() {}
private static class Holder {
private static final ResourceBundle NULL = new ResourceBundle() {
@NotNull
public List<PropertiesFile> getPropertiesFiles(final Project project) {
return Collections.emptyList();
}
@NotNull
public PropertiesFile getDefaultPropertiesFile(final Project project) {
throw new IllegalStateException();
}
@NotNull
public String getBaseName() {
return "";
}
@NotNull
public VirtualFile getBaseDirectory() {
throw new IllegalStateException();
}
};
}
public static ResourceBundle getInstance() {
return Holder.NULL;
}
}
@@ -1,3 +1,18 @@
/*
* 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.
* 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 com.intellij.lang.properties;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -16,70 +16,26 @@
package com.intellij.lang.properties;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.PropertyKeyIndex;
import com.intellij.lang.properties.xml.XmlPropertiesFile;
import com.intellij.lang.properties.xml.XmlPropertiesIndex;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.SmartList;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
/**
* @author cdr
*/
public class PropertiesUtil {
private PropertiesUtil() {
}
public static boolean isPropertiesFile(VirtualFile file, Project project) {
return getPropertiesFile(PsiManager.getInstance(project).findFile(file)) != null;
}
public static boolean isPropertiesFile(PsiFile file) {
return getPropertiesFile(file) != null;
}
@Nullable
public static PropertiesFile getPropertiesFile(@Nullable PsiFile file) {
if (file == null) return null;
return file instanceof PropertiesFile ? (PropertiesFile)file : XmlPropertiesFile.getPropertiesFile(file);
}
@NotNull
public static List<IProperty> findPropertiesByKey(final Project project, final String key) {
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final ArrayList<IProperty> properties =
new ArrayList<IProperty>(PropertyKeyIndex.getInstance().get(key, project, scope));
final Set<VirtualFile> files = new HashSet<VirtualFile>();
FileBasedIndex.getInstance().processValues(XmlPropertiesIndex.NAME, new XmlPropertiesIndex.Key(key), null, new FileBasedIndex.ValueProcessor<String>() {
@Override
public boolean process(VirtualFile file, String value) {
if (files.add(file)) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
PropertiesFile propertiesFile = XmlPropertiesFile.getPropertiesFile(psiFile);
if (propertiesFile != null) {
properties.addAll(propertiesFile.findPropertiesByKey(key));
}
}
return false;
}
}, scope);
return properties;
}
public static boolean isPropertyComplete(final Project project, ResourceBundle resourceBundle, String propertyName) {
List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles(project);
@@ -195,31 +151,8 @@ public class PropertiesUtil {
return result;
}
@Nullable
public static PropertiesFile getPropertiesFile(@NotNull String bundleName,
@NotNull Module searchFromModule,
@Nullable Locale locale) {
PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(searchFromModule.getProject());
return manager.findPropertiesFile(searchFromModule, bundleName, locale);
}
@Nullable
public static String getPackageQualifiedName(@NotNull PsiDirectory directory) {
return ProjectRootManager.getInstance(directory.getProject()).getFileIndex().getPackageNameByDirectory(directory.getVirtualFile());
}
public static ResourceBundle getResourceBundle(final PsiFile containingFile) {
VirtualFile virtualFile = containingFile.getVirtualFile();
if (!containingFile.isValid() || virtualFile == null) {
return ResourceBundleImpl.NULL;
}
String baseName = getBaseName(virtualFile);
PsiDirectory directory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() {
@Nullable
public PsiDirectory compute() {
return containingFile.getContainingDirectory();
}});
if (directory == null) return ResourceBundleImpl.NULL;
return new ResourceBundleImpl(directory.getVirtualFile(), baseName);
}
}
@@ -30,18 +30,18 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface ResourceBundle {
DataKey<ResourceBundle[]> ARRAY_DATA_KEY = DataKey.create("resource.bundle.array");
public abstract class ResourceBundle {
public static final DataKey<ResourceBundle[]> ARRAY_DATA_KEY = DataKey.create("resource.bundle.array");
@NotNull
List<PropertiesFile> getPropertiesFiles(final Project project);
public abstract List<PropertiesFile> getPropertiesFiles(final Project project);
@NotNull
PropertiesFile getDefaultPropertiesFile(final Project project);
public abstract PropertiesFile getDefaultPropertiesFile(final Project project);
@NotNull
String getBaseName();
public abstract String getBaseName();
@NotNull
VirtualFile getBaseDirectory();
public abstract VirtualFile getBaseDirectory();
}
@@ -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.
@@ -17,8 +17,7 @@
package com.intellij.lang.properties.psi;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.editor.ResourceBundleUtil;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.lang.properties.PropertiesFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.UserDataCache;
import com.intellij.openapi.util.text.StringUtil;
@@ -50,9 +49,9 @@ public class PropertiesElementFactory {
@NotNull
public static PropertiesFile createPropertiesFile(@NotNull Project project, @NonNls @NotNull String text) {
@NonNls String filename = "dummy." + StdFileTypes.PROPERTIES.getDefaultExtension();
@NonNls String filename = "dummy." + PropertiesFileType.INSTANCE.getDefaultExtension();
return (PropertiesFile)PsiFileFactory.getInstance(project)
.createFileFromText(filename, StdFileTypes.PROPERTIES, text);
.createFileFromText(filename, PropertiesFileType.INSTANCE, text);
}
@NotNull
@@ -64,9 +63,9 @@ public class PropertiesElementFactory {
catch (IOException e) {
throw new RuntimeException(e);
}
@NonNls String filename = fileName + "." + StdFileTypes.PROPERTIES.getDefaultExtension();
@NonNls String filename = fileName + "." + PropertiesFileType.INSTANCE.getDefaultExtension();
return (PropertiesFile)PsiFileFactory.getInstance(project)
.createFileFromText(filename, StdFileTypes.PROPERTIES, stream.toString());
.createFileFromText(filename, PropertiesFileType.INSTANCE, stream.toString());
}
@NotNull
@@ -103,6 +102,7 @@ public class PropertiesElementFactory {
}
public static String escapeValue(String value) {
return ResourceBundleUtil.fromValueEditorToPropertyValue(value);
return PropertiesResourceBundleUtil.fromValueEditorToPropertyValue(value);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -106,4 +106,4 @@ public interface PropertiesFile {
Project getProject();
String getText();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -22,4 +22,4 @@ package com.intellij.lang.properties.psi;
import com.intellij.psi.StubBasedPsiElement;
public interface PropertiesList extends StubBasedPsiElement<PropertiesListStub> {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -22,4 +22,4 @@ package com.intellij.lang.properties.psi;
import com.intellij.psi.stubs.StubElement;
public interface PropertiesListStub extends StubElement<PropertiesList> {
}
}
@@ -0,0 +1,89 @@
/*
* 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.
* 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 com.intellij.lang.properties.psi;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
/**
* @author Konstantin Bulenkov
*/
public class PropertiesResourceBundleUtil {
private static final TIntHashSet SYMBOLS_TO_ESCAPE = new TIntHashSet(new int[]{'#', '!', '=', ':'});
private static final char ESCAPE_SYMBOL = '\\';
/**
* Allows to map given 'raw' property value text to the 'user-friendly' text to show at the resource bundle editor.
* <p/>
* <b>Note:</b> please refer to {@link java.util.Properties#store(java.io.Writer, String)} contract for the property value escape rules.
*
* @param text 'raw' property value text
* @return 'user-friendly' text to show at the resource bundle editor
*/
@SuppressWarnings("AssignmentToForLoopParameter")
@NotNull
public static String fromPropertyValueToValueEditor(@NotNull String text) {
StringBuilder buffer = new StringBuilder();
boolean escaped = false;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == ESCAPE_SYMBOL && !escaped && (i == text.length() - 1 || (text.charAt(i + 1) != 'u' && text.charAt(i + 1) != 'U'))) {
escaped = true;
continue;
}
if (escaped && c == 'n') {
buffer.append(ESCAPE_SYMBOL);
}
buffer.append(c);
escaped = false;
}
return buffer.toString();
}
/**
* Perform reverse operation to {@link #fromPropertyValueToValueEditor(String)}.
*
* @param text 'user-friendly' text shown to the user at the resource bundle editor
* @return 'raw' value to store at the *.properties file
*/
@NotNull
public static String fromValueEditorToPropertyValue(@NotNull String text) {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if ((i == 0 && (c == ' ' || c == '\t')) // Leading white space
|| c == '\n' // Multi-line value
|| SYMBOLS_TO_ESCAPE.contains(c)) // Special symbol
{
buffer.append(ESCAPE_SYMBOL);
}
else if (c == ESCAPE_SYMBOL) { // Escaped 'escape' symbol)
if (text.length() > i + 1) {
final char nextChar = text.charAt(i + 1);
if (nextChar != 'n' && nextChar != 'u' && nextChar != 'U') {
buffer.append(ESCAPE_SYMBOL);
}
} else {
buffer.append(ESCAPE_SYMBOL);
}
}
buffer.append(c);
}
return buffer.toString();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -36,4 +36,4 @@ public class PropertyKeyIndex extends StringStubIndexExtension<Property> {
public StubIndexKey<String, Property> getKey() {
return KEY;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -23,4 +23,4 @@ import com.intellij.psi.stubs.StubElement;
public interface PropertyStub extends StubElement<Property> {
String getKey();
}
}
@@ -0,0 +1,24 @@
/*
* 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.
* 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 com.intellij.lang.properties.xml;
import com.intellij.lang.properties.psi.PropertiesFile;
/**
* @author Anna Bulenkova
*/
public abstract class XmlPropertiesFile implements PropertiesFile {
}
@@ -11,6 +11,9 @@
<orderEntry type="module" module-name="core-impl" />
<orderEntry type="module" module-name="editor-ui-api" />
<orderEntry type="module" module-name="analysis-api" />
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="xml-psi-api" />
<orderEntry type="module" module-name="xml-psi-impl" />
</component>
</module>
@@ -0,0 +1,97 @@
/*
* 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.
* 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 com.intellij.lang.properties;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.PropertyKeyIndex;
import com.intellij.lang.properties.xml.XmlPropertiesFileImpl;
import com.intellij.lang.properties.xml.XmlPropertiesIndex;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Konstantin Bulenkov
*/
public class PropertiesImplUtil extends PropertiesUtil {
public static ResourceBundle getResourceBundle(final PsiFile containingFile) {
VirtualFile virtualFile = containingFile.getVirtualFile();
if (!containingFile.isValid() || virtualFile == null) {
return EmptyResourceBundle.getInstance();
}
String baseName = getBaseName(virtualFile);
PsiDirectory directory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() {
@Nullable
public PsiDirectory compute() {
return containingFile.getContainingDirectory();
}});
if (directory == null) return EmptyResourceBundle.getInstance();
return new ResourceBundleImpl(directory.getVirtualFile(), baseName);
}
public static boolean isPropertiesFile(VirtualFile file, Project project) {
return getPropertiesFile(PsiManager.getInstance(project).findFile(file)) != null;
}
public static boolean isPropertiesFile(PsiFile file) {
return getPropertiesFile(file) != null;
}
@Nullable
public static PropertiesFile getPropertiesFile(@Nullable PsiFile file) {
if (file == null) return null;
return file instanceof PropertiesFile ? (PropertiesFile)file : XmlPropertiesFileImpl.getPropertiesFile(file);
}
@NotNull
public static List<IProperty> findPropertiesByKey(final Project project, final String key) {
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final ArrayList<IProperty> properties =
new ArrayList<IProperty>(PropertyKeyIndex.getInstance().get(key, project, scope));
final Set<VirtualFile> files = new HashSet<VirtualFile>();
FileBasedIndex.getInstance().processValues(XmlPropertiesIndex.NAME, new XmlPropertiesIndex.Key(key), null, new FileBasedIndex.ValueProcessor<String>() {
@Override
public boolean process(VirtualFile file, String value) {
if (files.add(file)) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
PropertiesFile propertiesFile = XmlPropertiesFileImpl.getPropertiesFile(psiFile);
if (propertiesFile != null) {
properties.addAll(propertiesFile.findPropertiesByKey(key));
}
}
return false;
}
}, scope);
return properties;
}
}
@@ -31,42 +31,19 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ResourceBundleImpl implements ResourceBundle {
@NotNull private final VirtualFile myBaseDirectory;
@NotNull private final String myBaseName;
public class ResourceBundleImpl extends ResourceBundle {
@NonNls private static final String RESOURCE_BUNDLE_PREFIX = "resourceBundle:";
@NotNull protected final VirtualFile myBaseDirectory;
@NotNull protected final String myBaseName;
public ResourceBundleImpl(@NotNull VirtualFile baseDirectory, @NotNull String baseName) {
myBaseDirectory = baseDirectory;
myBaseName = baseName;
}
public static final ResourceBundle NULL = new ResourceBundle() {
@NotNull
public List<PropertiesFile> getPropertiesFiles(final Project project) {
return Collections.emptyList();
}
@NotNull
public PropertiesFile getDefaultPropertiesFile(final Project project) {
throw new IllegalStateException();
}
@NotNull
public String getBaseName() {
return "";
}
@NotNull
public VirtualFile getBaseDirectory() {
throw new IllegalStateException();
}
};
@NotNull
public List<PropertiesFile> getPropertiesFiles(final Project project) {
VirtualFile[] children = myBaseDirectory.getChildren();
@@ -75,7 +52,7 @@ public class ResourceBundleImpl implements ResourceBundle {
for (VirtualFile file : children) {
if (!file.isValid()) continue;
if (Comparing.strEqual(PropertiesUtil.getBaseName(file), myBaseName)) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiManager.findFile(file));
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiManager.findFile(file));
if (propertiesFile != null) {
result.add(propertiesFile);
}
@@ -143,4 +120,5 @@ public class ResourceBundleImpl implements ResourceBundle {
public VirtualFile getBaseDirectory() {
return myBaseDirectory;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -58,4 +58,4 @@ public class Parsing {
LOG.assertTrue(builder.getTokenType() == PropertiesTokenTypes.KEY_CHARACTERS);
builder.advanceLexer();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.lang.properties.parsing;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
@@ -25,12 +24,12 @@ import com.intellij.lang.properties.psi.impl.PropertyImpl;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
/**
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -56,4 +56,4 @@ public class PropertyListStubElementType extends IStubElementType<PropertiesList
public void indexStub(@NotNull final PropertiesListStub stub, @NotNull final IndexSink sink) {
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -61,4 +61,4 @@ public class PropertyStubElementType extends IStubElementType<PropertyStub, Prop
public void indexStub(@NotNull final PropertyStub stub, @NotNull final IndexSink sink) {
sink.occurrence(PropertyKeyIndex.KEY, PropertyImpl.unescape(stub.getKey()));
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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,16 +18,13 @@ package com.intellij.lang.properties.psi.impl;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.ASTNode;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesLanguage;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.*;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.parsing.PropertiesElementTypes;
import com.intellij.lang.properties.psi.PropertiesElementFactory;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.TokenType;
@@ -58,7 +55,7 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
@Override
@NotNull
public FileType getFileType() {
return StdFileTypes.PROPERTIES;
return PropertiesFileType.INSTANCE;
}
@NonNls
@@ -117,7 +114,7 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
@Override
@NotNull
public ResourceBundle getResourceBundle() {
return PropertiesUtil.getResourceBundle(getContainingFile());
return PropertiesImplUtil.getResourceBundle(getContainingFile());
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -29,4 +29,4 @@ public class PropertiesListStubImpl extends StubBase<PropertiesList> implements
public PropertiesListStubImpl(final StubElement parent) {
super(parent, PropertiesElementTypes.PROPERTIES_LIST);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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.
@@ -22,7 +22,7 @@ package com.intellij.lang.properties.psi.impl;
import com.intellij.extapi.psi.StubBasedPsiElementBase;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.lang.properties.PropertiesLanguage;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
@@ -38,6 +38,6 @@ public class PropertiesStubElementImpl <T extends StubElement> extends StubBased
@NotNull
public Language getLanguage() {
return StdFileTypes.PROPERTIES.getLanguage();
return PropertiesLanguage.INSTANCE;
}
}
@@ -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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 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,8 +15,8 @@
*/
package com.intellij.lang.properties.xml;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -46,7 +46,7 @@ import java.util.*;
* @author Dmitry Avdeev
* Date: 7/26/11
*/
public class XmlPropertiesFile implements PropertiesFile {
public class XmlPropertiesFileImpl extends XmlPropertiesFile {
private static final Key<CachedValue<PropertiesFile>> KEY = Key.create("xml properties file");
private final XmlFile myFile;
@@ -63,31 +63,14 @@ public class XmlPropertiesFile implements PropertiesFile {
MultiMap<String, IProperty> map = new MultiMap<String, IProperty>();
for (XmlTag entry : entries) {
XmlProperty property = new XmlProperty(entry, XmlPropertiesFile.this);
XmlProperty property = new XmlProperty(entry, XmlPropertiesFileImpl.this);
map.putValue(property.getKey(), property);
}
return map;
}
};
@Nullable
public static PropertiesFile getPropertiesFile(final PsiFile file) {
return file instanceof XmlFile && file.getFileType() == XmlFileType.INSTANCE ? getPropertiesFile((XmlFile)file) : null;
}
public static PropertiesFile getPropertiesFile(final XmlFile file) {
CachedValuesManager manager = CachedValuesManager.getManager(file.getProject());
return manager.getCachedValue(file, KEY,
new CachedValueProvider<PropertiesFile>() {
@Override
public Result<PropertiesFile> compute() {
PropertiesFile value = XmlPropertiesIndex.isPropertiesFile(file) ? new XmlPropertiesFile(file) : null;
return Result.create(value, file);
}
}, false);
}
private XmlPropertiesFile(XmlFile file) {
private XmlPropertiesFileImpl(XmlFile file) {
myFile = file;
}
@@ -118,7 +101,7 @@ public class XmlPropertiesFile implements PropertiesFile {
@NotNull
@Override
public ResourceBundle getResourceBundle() {
return PropertiesUtil.getResourceBundle(getContainingFile());
return PropertiesImplUtil.getResourceBundle(getContainingFile());
}
@NotNull
@@ -147,6 +130,26 @@ public class XmlPropertiesFile implements PropertiesFile {
return new XmlProperty(entry, this);
}
public static PropertiesFile getPropertiesFile(final PsiFile file) {
CachedValuesManager manager = CachedValuesManager.getManager(file.getProject());
if (file instanceof XmlFile) {
return manager.getCachedValue(file, KEY,
new CachedValueProvider<PropertiesFile>() {
@Override
public Result<PropertiesFile> compute() {
PropertiesFile value =
XmlPropertiesIndex.isPropertiesFile((XmlFile)file)
? new XmlPropertiesFileImpl((XmlFile)file)
: null;
return Result.create(value, file);
}
}, false
);
}
return null;
}
@NotNull
@Override
public Map<String, String> getNamesMap() {
@@ -187,7 +190,7 @@ public class XmlPropertiesFile implements PropertiesFile {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
XmlPropertiesFile that = (XmlPropertiesFile)o;
XmlPropertiesFileImpl that = (XmlPropertiesFileImpl)o;
if (!myFile.equals(that.myFile)) return false;
@@ -22,9 +22,9 @@ public class XmlProperty implements IProperty, PomRenameableTarget, PsiTarget {
@NotNull
private final XmlTag myTag;
private final XmlPropertiesFile myPropertiesFile;
private final XmlPropertiesFileImpl myPropertiesFile;
public XmlProperty(@NotNull XmlTag tag, XmlPropertiesFile xmlPropertiesFile) {
public XmlProperty(@NotNull XmlTag tag, XmlPropertiesFileImpl xmlPropertiesFile) {
myTag = tag;
myPropertiesFile = xmlPropertiesFile;
}
@@ -2,7 +2,11 @@ package com.intellij.properties;
import com.intellij.core.CoreApplicationEnvironment;
import com.intellij.core.CoreProjectEnvironment;
import com.intellij.lang.LanguageParserDefinitions;
import com.intellij.lang.properties.PropertiesFileType;
import com.intellij.lang.properties.PropertiesLanguage;
import com.intellij.lang.properties.parsing.PropertiesParserDefinition;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
/**
* @author Anna Bulenkova
@@ -11,6 +15,8 @@ public class PropertiesCoreEnvironment {
public static class ApplicationEnvironment {
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) {
appEnvironment.registerFileType(PropertiesFileType.INSTANCE, "properties");
SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(PropertiesLanguage.INSTANCE, new PropertiesSyntaxHighlighterFactory());
appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesParserDefinition());
}
}
@@ -0,0 +1,32 @@
/*
* 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.
* 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 com.intellij.properties;
import com.intellij.lang.properties.PropertiesHighlighter;
import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import org.jetbrains.annotations.NotNull;
/**
* @author Anna Bulenkova
*/
public class PropertiesSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory {
@NotNull
@Override
protected SyntaxHighlighter createHighlighter() {
return new PropertiesHighlighter();
}
}
@@ -0,0 +1,65 @@
/*
* Copyright 2000-2009 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.
*/
/*
* @author max
*/
package com.intellij.properties;
import com.intellij.lang.properties.parsing.PropertiesElementTypes;
import com.intellij.lang.properties.psi.Property;
import com.intellij.lang.properties.psi.PropertyKeyIndex;
import com.intellij.lang.properties.psi.PropertyStub;
import com.intellij.lang.properties.psi.impl.PropertyImpl;
import com.intellij.lang.properties.psi.impl.PropertyStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class PropertyStubElementType extends IStubElementType<PropertyStub, Property> {
public PropertyStubElementType() {
super("PROPERTY", PropertiesElementTypes.LANG);
}
public Property createPsi(@NotNull final PropertyStub stub) {
return new PropertyImpl(stub, this);
}
public PropertyStub createStub(@NotNull final Property psi, final StubElement parentStub) {
return new PropertyStubImpl(parentStub, psi.getKey());
}
@NotNull
public String getExternalId() {
return "properties.prop";
}
public void serialize(@NotNull final PropertyStub stub, @NotNull final StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getKey());
}
@NotNull
public PropertyStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
final StringRef ref = dataStream.readName();
return new PropertyStubImpl(parentStub, ref.getString());
}
public void indexStub(@NotNull final PropertyStub stub, @NotNull final IndexSink sink) {
sink.occurrence(PropertyKeyIndex.KEY, PropertyImpl.unescape(stub.getKey()));
}
}
@@ -139,7 +139,7 @@ public class PropertiesReferenceManager {
private boolean processFile(VirtualFile file, BundleNameEvaluator evaluator, PropertiesFileProcessor processor) {
final PsiFile psiFile = myPsiManager.findFile(file);
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiFile);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
if (propertiesFile != null) {
final String qName = evaluator.evaluateBundleName(psiFile);
if (qName != null) {
@@ -0,0 +1,38 @@
/*
* 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.
* 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 com.intellij.lang.properties;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.module.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
/**
* @author Anna Bulenkova
*/
public class PropertiesUtilBase {
private PropertiesUtilBase() {}
@Nullable
public static PropertiesFile getPropertiesFile(@NotNull String bundleName,
@NotNull Module searchFromModule,
@Nullable Locale locale) {
PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(searchFromModule.getProject());
return manager.findPropertiesFile(searchFromModule, bundleName, locale);
}
}
@@ -28,9 +28,11 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.ide.util.treeView.AbstractTreeUi;
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.PropertiesResourceBundleUtil;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
@@ -373,7 +375,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
myVfsListener = new VirtualFileAdapter() {
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
if (PropertiesUtil.isPropertiesFile(event.getFile(), myProject)) {
if (PropertiesImplUtil.isPropertiesFile(event.getFile(), myProject)) {
recreateEditorsPanel();
}
}
@@ -390,7 +392,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
@Override
public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
if (PropertiesUtil.isPropertiesFile(event.getFile(), myProject)) {
if (PropertiesImplUtil.isPropertiesFile(event.getFile(), myProject)) {
if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
recreateEditorsPanel();
}
@@ -426,7 +428,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
@Override
public void childrenChanged(@NotNull PsiTreeChangeEvent event) {
final PsiFile file = event.getFile();
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(file);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile == null) return;
if (!propertiesFile.getResourceBundle().equals(myResourceBundle)) return;
updateEditorsFromProperties();
@@ -474,7 +476,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
}
else {
String rawValue = property.getValue();
value = rawValue == null ? "" : ResourceBundleUtil.fromPropertyValueToValueEditor(rawValue);
value = rawValue == null ? "" : PropertiesResourceBundleUtil.fromPropertyValueToValueEditor(rawValue);
}
final Document document = editor.getDocument();
CommandProcessor.getInstance().executeCommand(null, new Runnable() {
@@ -15,7 +15,7 @@
*/
package com.intellij.lang.properties.editor;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.fileEditor.FileEditor;
@@ -41,7 +41,7 @@ public class ResourceBundleEditorProvider extends FileTypeFactory implements Fil
if (file instanceof ResourceBundleAsVirtualFile) return true;
if (!file.isValid()) return false;
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiFile);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
return propertiesFile != null && propertiesFile.getResourceBundle().getPropertiesFiles(project).size() > 1;
}
@@ -57,7 +57,7 @@ public class ResourceBundleEditorProvider extends FileTypeFactory implements Fil
if (psiFile == null) {
throw new IllegalArgumentException("psifile cannot be null");
}
resourceBundle = PropertiesUtil.getPropertiesFile(psiFile).getResourceBundle();
resourceBundle = PropertiesImplUtil.getPropertiesFile(psiFile).getResourceBundle();
}
return new ResourceBundleEditor(project, resourceBundle);
@@ -27,22 +27,15 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Writer;
import java.util.Properties;
/**
* @author Denis Zhdanov
* @since 10/5/11 2:35 PM
*/
public class ResourceBundleUtil {
private static final TIntHashSet SYMBOLS_TO_ESCAPE = new TIntHashSet(new int[]{'#', '!', '=', ':'});
private static final char ESCAPE_SYMBOL = '\\';
private ResourceBundleUtil() {
}
@@ -101,64 +94,4 @@ public class ResourceBundleUtil {
return (ResourceBundleEditor)editors[0];
}
/**
* Allows to map given 'raw' property value text to the 'user-friendly' text to show at the resource bundle editor.
* <p/>
* <b>Note:</b> please refer to {@link Properties#store(Writer, String)} contract for the property value escape rules.
*
* @param text 'raw' property value text
* @return 'user-friendly' text to show at the resource bundle editor
*/
@SuppressWarnings("AssignmentToForLoopParameter")
@NotNull
public static String fromPropertyValueToValueEditor(@NotNull String text) {
StringBuilder buffer = new StringBuilder();
boolean escaped = false;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == ESCAPE_SYMBOL && !escaped && (i == text.length() - 1 || (text.charAt(i + 1) != 'u' && text.charAt(i + 1) != 'U'))) {
escaped = true;
continue;
}
if (escaped && c == 'n') {
buffer.append(ESCAPE_SYMBOL);
}
buffer.append(c);
escaped = false;
}
return buffer.toString();
}
/**
* Perform reverse operation to {@link #fromPropertyValueToValueEditor(String)}.
*
* @param text 'user-friendly' text shown to the user at the resource bundle editor
* @return 'raw' value to store at the *.properties file
*/
@NotNull
public static String fromValueEditorToPropertyValue(@NotNull String text) {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if ((i == 0 && (c == ' ' || c == '\t')) // Leading white space
|| c == '\n' // Multi-line value
|| SYMBOLS_TO_ESCAPE.contains(c)) // Special symbol
{
buffer.append(ESCAPE_SYMBOL);
}
else if (c == ESCAPE_SYMBOL) { // Escaped 'escape' symbol)
if (text.length() > i + 1) {
final char nextChar = text.charAt(i + 1);
if (nextChar != 'n' && nextChar != 'u' && nextChar != 'U') {
buffer.append(ESCAPE_SYMBOL);
}
} else {
buffer.append(ESCAPE_SYMBOL);
}
}
buffer.append(c);
}
return buffer.toString();
}
}
@@ -18,7 +18,7 @@ package com.intellij.lang.properties.projectView;
import com.intellij.ide.projectView.TreeStructureProvider;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
@@ -54,7 +54,7 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
Collection<PropertiesFile> files = childBundles.get(bundle);
@@ -78,7 +78,7 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile((PsiFile)f);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile((PsiFile)f);
if (propertiesFile != null) {
ResourceBundle bundle = propertiesFile.getResourceBundle();
if (childBundles.get(bundle).size() != 1) {
@@ -26,7 +26,7 @@ import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.lang.properties.PropertiesBundle;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -62,7 +62,7 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle>{
public boolean contains(@NotNull VirtualFile file) {
if (!file.isValid()) return false;
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiFile);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
return propertiesFile != null && getValue().getPropertiesFiles(myProject).contains(propertiesFile);
}
@@ -59,7 +59,7 @@ public abstract class PropertyReferenceBase implements PsiPolyVariantReference,
PropertiesFile propertiesFile = property.getPropertiesFile();
ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
String value = property.getValue();
boolean hasBundle = resourceBundle != ResourceBundleImpl.NULL;
boolean hasBundle = resourceBundle != EmptyResourceBundle.getInstance();
if (hasBundle) {
PropertiesFile defaultPropertiesFile = resourceBundle.getDefaultPropertiesFile(propertiesFile.getProject());
IProperty defaultProperty = defaultPropertiesFile.findPropertyByKey(key);
@@ -203,7 +203,7 @@ public abstract class PropertyReferenceBase implements PsiPolyVariantReference,
List<IProperty> properties;
final List<PropertiesFile> propertiesFiles = getPropertiesFiles();
if (propertiesFiles == null) {
properties = PropertiesUtil.findPropertiesByKey(getElement().getProject(), key);
properties = PropertiesImplUtil.findPropertiesByKey(getElement().getProject(), key);
}
else {
properties = new ArrayList<IProperty>();
@@ -2,6 +2,7 @@ package com.intellij.lang.properties.xml;
import com.intellij.ide.IconProvider;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlFile;
import icons.PropertiesIcons;
@@ -19,6 +20,6 @@ public class XmlPropertiesIconProvider extends IconProvider {
public Icon getIcon(@NotNull PsiElement element, int flags) {
return element instanceof XmlFile &&
((XmlFile)element).getFileType() == XmlFileType.INSTANCE &&
XmlPropertiesFile.getPropertiesFile((XmlFile)element) != null ? PropertiesIcons.XmlProperties : null;
PropertiesImplUtil.getPropertiesFile((XmlFile)element) != null ? PropertiesIcons.XmlProperties : null;
}
}
@@ -15,7 +15,7 @@
*/
package com.intellij.lang.properties.xml;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.patterns.XmlPatterns;
import com.intellij.pom.references.PomService;
@@ -37,9 +37,9 @@ public class XmlPropertiesReferenceContributor extends PsiReferenceContributor {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(element.getContainingFile());
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(element.getContainingFile());
if (propertiesFile == null) return PsiReference.EMPTY_ARRAY;
XmlProperty property = new XmlProperty(PsiTreeUtil.getParentOfType(element, XmlTag.class), (XmlPropertiesFile)propertiesFile);
XmlProperty property = new XmlProperty(PsiTreeUtil.getParentOfType(element, XmlTag.class), (XmlPropertiesFileImpl)propertiesFile);
return new PsiReference[] { new PsiReferenceBase.Immediate<PsiElement>(element, PomService.convertToPsi(property))};
}
});
@@ -15,8 +15,7 @@
*/
package com.intellij.lang.properties.editor;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
import com.intellij.lang.properties.psi.PropertiesResourceBundleUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -65,12 +64,12 @@ public class ResourceBundleUtilTest {
assertEquals(
"Expected property value differs from the one converted from value editor text",
entry[0],
ResourceBundleUtil.fromValueEditorToPropertyValue(entry[1])
PropertiesResourceBundleUtil.fromValueEditorToPropertyValue(entry[1])
);
assertEquals(
"Expected value editor text differs from the one converted from property value",
entry[1],
ResourceBundleUtil.fromPropertyValueToValueEditor(entry[0])
PropertiesResourceBundleUtil.fromPropertyValueToValueEditor(entry[0])
);
}
}
@@ -1,8 +1,8 @@
package com.intellij.lang.properties.xml;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesImplUtil;
import com.intellij.lang.properties.PropertiesReferenceManager;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.psi.PsiFile;
@@ -24,13 +24,13 @@ public class XmlPropertiesTest extends LightPlatformCodeInsightFixtureTestCase {
PropertiesFile file = files.get(0);
assertEquals(1, file.findPropertiesByKey("foo").size());
List<IProperty> properties = PropertiesUtil.findPropertiesByKey(getProject(), "foo");
List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(getProject(), "foo");
assertEquals(1, properties.size());
}
public void testWrongFile() throws Exception {
PsiFile psiFile = myFixture.configureByFile("wrong.xml");
PropertiesFile file = PropertiesUtil.getPropertiesFile(psiFile);
PropertiesFile file = PropertiesImplUtil.getPropertiesFile(psiFile);
assertNull(file);
}
@@ -18,7 +18,7 @@ package com.intellij.uiDesigner;
import com.intellij.ProjectTopics;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesUtilBase;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleServiceManager;
@@ -96,7 +96,7 @@ public class StringDescriptorManager {
propertiesFile = myPropertiesFileCache.get(cacheKey);
}
if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
propertiesFile = PropertiesUtil.getPropertiesFile(propFileName, myModule, locale);
propertiesFile = PropertiesUtilBase.getPropertiesFile(propFileName, myModule, locale);
synchronized (myPropertiesFileCache) {
myPropertiesFileCache.put(cacheKey, propertiesFile);
}
@@ -15,8 +15,9 @@
*/
package com.intellij.uiDesigner.binding;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesFileType;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesUtilBase;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
@@ -53,7 +54,7 @@ public final class ResourceBundleFileReference extends ReferenceInForm {
if (module == null) {
return null;
}
PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(getRangeText(), module, null);
PropertiesFile propertiesFile = PropertiesUtilBase.getPropertiesFile(getRangeText(), module, null);
return propertiesFile == null ? null : propertiesFile.getContainingFile();
}
@@ -17,6 +17,7 @@ package com.intellij.uiDesigner.binding;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesUtilBase;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
@@ -52,7 +53,7 @@ public final class ResourceBundleKeyReference extends ReferenceInForm {
if (module == null) {
return null;
}
final PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(myBundleName, module, null);
final PropertiesFile propertiesFile = PropertiesUtilBase.getPropertiesFile(myBundleName, module, null);
if (propertiesFile == null) {
return null;
}
@@ -20,7 +20,7 @@ import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.ide.util.TreeFileChooser;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesReferenceManager;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.PropertiesUtilBase;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.Property;
import com.intellij.openapi.application.ApplicationManager;
@@ -375,7 +375,7 @@ public final class StringEditorDialog extends DialogWrapper{
public void actionPerformed(final ActionEvent e) {
Project project = myEditor.getProject();
final String bundleNameText = myTfBundleName.getText().replace('/', '.');
PropertiesFile file = PropertiesUtil.getPropertiesFile(bundleNameText, myEditor.getModule(), myLocale);
PropertiesFile file = PropertiesUtilBase.getPropertiesFile(bundleNameText, myEditor.getModule(), myLocale);
PsiFile initialPropertiesFile = file == null ? null : file.getContainingFile();
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesScope(myEditor.getModule());
TreeFileChooser fileChooser = TreeClassChooserFactory.getInstance(project).createFileChooser(UIDesignerBundle.message("title.choose.properties.file"), initialPropertiesFile,