diff --git a/plugins/devkit/src/dom/impl/I18nReferenceContributor.java b/plugins/devkit/src/dom/impl/I18nReferenceContributor.java index 468fdfb38858..8c16c0dabfd5 100644 --- a/plugins/devkit/src/dom/impl/I18nReferenceContributor.java +++ b/plugins/devkit/src/dom/impl/I18nReferenceContributor.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.idea.devkit.dom.impl; @@ -122,15 +110,13 @@ public class I18nReferenceContributor extends PsiReferenceContributor { final Project project = myElement.getProject(); PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(project); final List variants = new ArrayList<>(); - referenceManager.processPropertiesFiles(GlobalSearchScopesCore.projectProductionScope(project), new PropertiesFileProcessor() { - public boolean process(String baseName, PropertiesFile propertiesFile) { - final Icon icon = propertiesFile.getContainingFile().getIcon(Iconable.ICON_FLAG_READ_STATUS); - final String relativePath = ProjectUtil.calcRelativeToProjectPath(propertiesFile.getVirtualFile(), project); - variants.add(LookupElementBuilder.create(propertiesFile, baseName) - .withIcon(icon) - .withTailText(" (" + relativePath + ")", true)); - return true; - } + referenceManager.processPropertiesFiles(GlobalSearchScopesCore.projectProductionScope(project), (baseName, propertiesFile) -> { + final Icon icon = propertiesFile.getContainingFile().getIcon(Iconable.ICON_FLAG_READ_STATUS); + final String relativePath = ProjectUtil.calcRelativeToProjectPath(propertiesFile.getVirtualFile(), project); + variants.add(LookupElementBuilder.create(propertiesFile, baseName) + .withIcon(icon) + .withTailText(" (" + relativePath + ")", true)); + return true; }, this); return variants.toArray(new LookupElement[variants.size()]); } diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaI18nUtil.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaI18nUtil.java index 91ed561746e1..0d71b09eafa5 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaI18nUtil.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaI18nUtil.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.codeInspection.i18n; import com.intellij.codeInsight.AnnotationUtil; @@ -220,21 +222,18 @@ public class JavaI18nUtil extends I18nUtil { @Nullable private static ResourceBundle resolveResourceBundleByKey(@NotNull final String key, @NotNull final Project project) { final Ref bundleRef = Ref.create(); - final boolean r = PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles(new PropertiesFileProcessor() { - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { - if (propertiesFile.findPropertyByKey(key) != null) { - if (bundleRef.get() == null) { - bundleRef.set(propertiesFile.getResourceBundle()); - } - else { - if (!bundleRef.get().equals(propertiesFile.getResourceBundle())) { - return false; - } + final boolean r = PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles((baseName, propertiesFile) -> { + if (propertiesFile.findPropertyByKey(key) != null) { + if (bundleRef.get() == null) { + bundleRef.set(propertiesFile.getResourceBundle()); + } + else { + if (!bundleRef.get().equals(propertiesFile.getResourceBundle())) { + return false; } } - return true; } + return true; }); return r ? bundleRef.get() : null; } diff --git a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesFileProcessor.java b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesFileProcessor.java index c10152842007..72e3285c6bb7 100644 --- a/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesFileProcessor.java +++ b/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/PropertiesFileProcessor.java @@ -1,22 +1,11 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.lang.properties; import com.intellij.lang.properties.psi.PropertiesFile; +@FunctionalInterface public interface PropertiesFileProcessor { boolean process(String baseName, PropertiesFile propertiesFile); } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/PropertiesReferenceManager.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/PropertiesReferenceManager.java index c043844f61a5..7d0ce70308c6 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/PropertiesReferenceManager.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/PropertiesReferenceManager.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.lang.properties; @@ -74,13 +62,11 @@ public class PropertiesReferenceManager { final ArrayList result = new ArrayList<>(); - processPropertiesFiles(searchScope, new PropertiesFileProcessor() { - public boolean process(String baseName, PropertiesFile propertiesFile) { - if (baseName.equals(bundleName)) { - result.add(propertiesFile); - } - return true; + processPropertiesFiles(searchScope, (baseName, propertiesFile) -> { + if (baseName.equals(bundleName)) { + result.add(propertiesFile); } + return true; }, bundleNameEvaluator); return result; } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java index 7422775498a5..0bd2b8d71621 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java @@ -1,6 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.lang.properties.references; import com.intellij.lang.injection.InjectedLanguageManager; @@ -78,20 +78,16 @@ public class I18nUtil { final List paths = new ArrayList<>(); final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles(new PropertiesFileProcessor() { - - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { - if (propertiesFile instanceof XmlPropertiesFile) { - return true; - } - VirtualFile virtualFile = propertiesFile.getVirtualFile(); - if (projectFileIndex.isInContent(virtualFile)) { - String path = FileUtil.toSystemDependentName(virtualFile.getPath()); - paths.add(path); - } + PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles((baseName, propertiesFile) -> { + if (propertiesFile instanceof XmlPropertiesFile) { return true; } + VirtualFile virtualFile = propertiesFile.getVirtualFile(); + if (projectFileIndex.isInContent(virtualFile)) { + String path = FileUtil.toSystemDependentName(virtualFile.getPath()); + paths.add(path); + } + return true; }); return paths; } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/PropertiesPsiCompletionUtil.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/PropertiesPsiCompletionUtil.java index ca039613f862..d3c8ea3cc66b 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/PropertiesPsiCompletionUtil.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/PropertiesPsiCompletionUtil.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.lang.properties.references; @@ -59,13 +47,10 @@ public class PropertiesPsiCompletionUtil { List propertiesFileList = propertyReference.getPropertiesFiles(); if (propertiesFileList == null) { PropertiesReferenceManager - .getInstance(propertyReference.getElement().getProject()).processAllPropertiesFiles(new PropertiesFileProcessor() { - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { + .getInstance(propertyReference.getElement().getProject()).processAllPropertiesFiles((baseName, propertiesFile) -> { addVariantsFromFile(propertyReference, propertiesFile, variants); return true; - } - }); + }); } else { for (PropertiesFile propFile : propertiesFileList) { diff --git a/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java b/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java index 79e1641c0e6e..0c18edaf9291 100644 --- a/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java +++ b/plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.lang.properties; @@ -127,18 +115,15 @@ public class ResourceBundleReference extends PsiReferenceBase final Set bundleNames = new HashSet<>(); final List variants = new SmartList<>(); - PropertiesFileProcessor processor = new PropertiesFileProcessor() { - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { - if (!bundleNames.add(baseName)) return true; + PropertiesFileProcessor processor = (baseName, propertiesFile) -> { + if (!bundleNames.add(baseName)) return true; - final LookupElementBuilder builder = - LookupElementBuilder.create(baseName) - .withIcon(AllIcons.Nodes.ResourceBundle); - boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile()); - variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder); - return true; - } + final LookupElementBuilder builder = + LookupElementBuilder.create(baseName) + .withIcon(AllIcons.Nodes.ResourceBundle); + boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile()); + variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder); + return true; }; referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this); diff --git a/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java b/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java index c95fd1ec7f53..c27ffdc4878c 100644 --- a/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java +++ b/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.lang.properties.create; @@ -423,16 +423,14 @@ public class CreateResourceBundleDialogComponent { private MyExistLocalesListModel() { myLocales = new ArrayList<>(); myLocales.add(PropertiesUtil.DEFAULT_LOCALE); - PropertiesReferenceManager.getInstance(myProject).processPropertiesFiles(GlobalSearchScope.projectScope(myProject), new PropertiesFileProcessor() { - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { - final Locale locale = propertiesFile.getLocale(); - if (locale != PropertiesUtil.DEFAULT_LOCALE && !myLocales.contains(locale)) { - myLocales.add(locale); - } - return true; - } - }, BundleNameEvaluator.DEFAULT); + PropertiesReferenceManager.getInstance(myProject).processPropertiesFiles(GlobalSearchScope.projectScope(myProject), + (baseName, propertiesFile) -> { + final Locale locale = propertiesFile.getLocale(); + if (locale != PropertiesUtil.DEFAULT_LOCALE && !myLocales.contains(locale)) { + myLocales.add(locale); + } + return true; + }, BundleNameEvaluator.DEFAULT); Collections.sort(myLocales, LOCALE_COMPARATOR); } diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesCopyHandler.java b/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesCopyHandler.java index 26d1e7a55fcc..aedb1020b4bf 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesCopyHandler.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/PropertiesCopyHandler.java @@ -228,12 +228,9 @@ public class PropertiesCopyHandler extends CopyHandlerDelegateBase { PropertiesReferenceManager .getInstance(myProject) .processPropertiesFiles(searchScope, - new PropertiesFileProcessor() { - @Override - public boolean process(String baseName, PropertiesFile propertiesFile) { - propertiesFiles.add(propertiesFile); - return true; - } + (baseName, propertiesFile) -> { + propertiesFiles.add(propertiesFile); + return true; }, BundleNameEvaluator.BASE_NAME); final List resourceBundlesAsFileSystemItems = propertiesFiles