From 21bb50227360f2e5ceeda2d4110596f7a12f0f08 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 5 Feb 2019 09:36:01 +0100 Subject: [PATCH] use extensionList --- .../com/intellij/uast/UastMetaLanguage.java | 14 +++++++---- ...nMethodIsAlwaysInvertedInspectionTest.java | 5 +--- .../org/jetbrains/uast/UastLanguagePlugin.kt | 25 ++++--------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/java/java-analysis-api/src/com/intellij/uast/UastMetaLanguage.java b/java/java-analysis-api/src/com/intellij/uast/UastMetaLanguage.java index 66aea1626805..62c827b47584 100644 --- a/java/java-analysis-api/src/com/intellij/uast/UastMetaLanguage.java +++ b/java/java-analysis-api/src/com/intellij/uast/UastMetaLanguage.java @@ -1,24 +1,28 @@ -// 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. +// Copyright 2000-2019 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.uast; import com.intellij.lang.Language; import com.intellij.lang.MetaLanguage; +import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.uast.UastLanguagePlugin; import java.util.Collection; -import java.util.HashSet; +import java.util.Collections; import java.util.Set; /** * @author yole */ public class UastMetaLanguage extends MetaLanguage { - private final Set myLanguages = new HashSet<>(); + private final Set myLanguages; protected UastMetaLanguage() { super("UAST"); - for (UastLanguagePlugin plugin: UastLanguagePlugin.Companion.getInstances()) { + + Collection languagePlugins = UastLanguagePlugin.Companion.getInstances(); + myLanguages = new THashSet<>(languagePlugins.size()); + for (UastLanguagePlugin plugin: languagePlugins) { myLanguages.add(plugin.getLanguage()); } } @@ -31,6 +35,6 @@ public class UastMetaLanguage extends MetaLanguage { @NotNull @Override public Collection getMatchingLanguages() { - return myLanguages; + return Collections.unmodifiableSet(myLanguages); } } diff --git a/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodIsAlwaysInvertedInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodIsAlwaysInvertedInspectionTest.java index 81e174f55d7b..f395a169f38f 100644 --- a/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodIsAlwaysInvertedInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodIsAlwaysInvertedInspectionTest.java @@ -1,6 +1,4 @@ -// 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-2019 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; import com.intellij.codeInspection.booleanIsAlwaysInverted.BooleanMethodIsAlwaysInvertedInspection; @@ -9,7 +7,6 @@ import com.intellij.testFramework.IdeaTestUtil; import com.siyeh.ig.IGInspectionTestCase; public class BooleanMethodIsAlwaysInvertedInspectionTest extends IGInspectionTestCase { - public void testUnusedMethod() { doTest(); } diff --git a/uast/uast-common/src/org/jetbrains/uast/UastLanguagePlugin.kt b/uast/uast-common/src/org/jetbrains/uast/UastLanguagePlugin.kt index 529f393c65c9..61eb6fef1555 100644 --- a/uast/uast-common/src/org/jetbrains/uast/UastLanguagePlugin.kt +++ b/uast/uast-common/src/org/jetbrains/uast/UastLanguagePlugin.kt @@ -1,18 +1,4 @@ -/* - * 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-2019 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.uast import com.intellij.lang.Language @@ -21,13 +7,12 @@ import com.intellij.psi.* interface UastLanguagePlugin { companion object { - val extensionPointName: ExtensionPointName = - ExtensionPointName.create("org.jetbrains.uast.uastLanguagePlugin") - private val extensionArray: Array by lazy(LazyThreadSafetyMode.PUBLICATION) { extensionPointName.extensions } + val extensionPointName = ExtensionPointName("org.jetbrains.uast.uastLanguagePlugin") + private val extensions by lazy(LazyThreadSafetyMode.PUBLICATION) { extensionPointName.extensionList } - fun getInstances(): Collection = extensionArray.toList() + fun getInstances(): Collection = extensions - fun byLanguage(language: Language): UastLanguagePlugin? = extensionArray.firstOrNull { it.language === language } + fun byLanguage(language: Language): UastLanguagePlugin? = extensions.firstOrNull { it.language === language } } data class ResolvedMethod(val call: UCallExpression, val method: PsiMethod)