diff --git a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml index feb2f144ec77..ba5998920e23 100644 --- a/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml +++ b/java/java-analysis-impl/src/META-INF/JavaAnalysisPlugin.xml @@ -35,6 +35,7 @@ + diff --git a/java/java-analysis-impl/src/com/intellij/psi/util/DefaultPropertyAccessorDetector.java b/java/java-analysis-impl/src/com/intellij/psi/util/DefaultPropertyAccessorDetector.java new file mode 100644 index 000000000000..a3a48e2beef8 --- /dev/null +++ b/java/java-analysis-impl/src/com/intellij/psi/util/DefaultPropertyAccessorDetector.java @@ -0,0 +1,24 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.psi.util; + +import com.intellij.lang.java.beans.PropertyKind; +import com.intellij.psi.PsiMethod; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class DefaultPropertyAccessorDetector { + + public static @Nullable PropertyAccessorDetector.PropertyAccessorInfo getDefaultAccessorInfo(@NotNull PsiMethod method) { + if (PropertyUtilBase.isSimplePropertyGetter(method)) { + return new PropertyAccessorDetector.PropertyAccessorInfo(PropertyUtilBase.getPropertyNameByGetter(method), + method.getReturnType(), + PropertyKind.GETTER); + } + else if (PropertyUtilBase.isSimplePropertySetter(method)) { + return new PropertyAccessorDetector.PropertyAccessorInfo(PropertyUtilBase.getPropertyNameBySetter(method), + method.getParameterList().getParameters()[0].getType(), + PropertyKind.SETTER); + } + return null; + } +} diff --git a/java/java-analysis-impl/src/com/intellij/psi/util/PropertyAccessorDetector.java b/java/java-analysis-impl/src/com/intellij/psi/util/PropertyAccessorDetector.java new file mode 100644 index 000000000000..ee97fafed0ac --- /dev/null +++ b/java/java-analysis-impl/src/com/intellij/psi/util/PropertyAccessorDetector.java @@ -0,0 +1,34 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.psi.util; + +import com.intellij.lang.java.beans.PropertyKind; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface PropertyAccessorDetector { + ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.propertyAccessorDetector"); + + static @Nullable PropertyAccessorInfo detectFrom(@NotNull PsiMethod method) { + for (PropertyAccessorDetector detector : EP_NAME.getExtensions()) { + PropertyAccessorInfo accessorInfo = detector.detectPropertyAccessor(method); + if (accessorInfo != null) { + return accessorInfo; + } + } + return DefaultPropertyAccessorDetector.getDefaultAccessorInfo(method); + } + + /** + * Detects property access information if any, or results to null + */ + @Nullable PropertyAccessorInfo detectPropertyAccessor(@NotNull PsiMethod method); + + record PropertyAccessorInfo(@NotNull String propertyName, @NotNull PsiType propertyType, @NotNull PropertyKind kind) { + public boolean isKindOf(PropertyKind other) { + return this.kind == other; + } + } +} \ No newline at end of file diff --git a/java/java-psi-api/src/com/intellij/psi/util/PropertyAccessorDetector.java b/java/java-psi-api/src/com/intellij/psi/util/PropertyAccessorDetector.java deleted file mode 100644 index b22efa3ff5dd..000000000000 --- a/java/java-psi-api/src/com/intellij/psi/util/PropertyAccessorDetector.java +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.psi.util; - -import com.intellij.lang.java.beans.PropertyKind; -import com.intellij.openapi.extensions.ExtensionPointName; -import com.intellij.psi.PsiMethod; -import com.intellij.psi.PsiType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface PropertyAccessorDetector { - ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.propertyAccessorDetector"); - - static @Nullable PropertyAccessorInfo detectFrom(@NotNull PsiMethod method) { - for (PropertyAccessorDetector detector : EP_NAME.getExtensions()) { - PropertyAccessorInfo accessorInfo = detector.detectPropertyAccessor(method); - if (accessorInfo != null) { - return accessorInfo; - } - } - return getDefaultAccessorInfo(method); - } - - @Nullable - static PropertyAccessorInfo getDefaultAccessorInfo(@NotNull PsiMethod method) { - if (PropertyUtilBase.isSimplePropertyGetter(method)) { - return new PropertyAccessorInfo(PropertyUtilBase.getPropertyNameByGetter(method), - method.getReturnType(), - PropertyKind.GETTER); - } - else if (PropertyUtilBase.isSimplePropertySetter(method)) { - return new PropertyAccessorInfo(PropertyUtilBase.getPropertyNameBySetter(method), - method.getParameterList().getParameters()[0].getType(), - PropertyKind.SETTER); - } - return null; - } - - /** - * Detects property access information if any, or results to null - */ - @Nullable PropertyAccessorInfo detectPropertyAccessor(@NotNull PsiMethod method); - - class PropertyAccessorInfo { - private final @NotNull String propertyName; - private final @NotNull PsiType propertyType; - private final @NotNull PropertyKind kind; - - public PropertyAccessorInfo(@NotNull String propertyName, @NotNull PsiType propertyType, @NotNull PropertyKind kind) { - this.propertyName = propertyName; - this.propertyType = propertyType; - this.kind = kind; - } - - public @NotNull String getPropertyName() { - return propertyName; - } - - public @NotNull PsiType getPropertyType() { - return propertyType; - } - - public @NotNull PropertyKind getKind() { - return kind; - } - - public boolean isKindOf(PropertyKind other) { - return this.kind == other; - } - } -} \ No newline at end of file diff --git a/java/java-psi-impl/src/META-INF/JavaPsiPlugin.xml b/java/java-psi-impl/src/META-INF/JavaPsiPlugin.xml index 858ef44bdb28..6eec44669025 100644 --- a/java/java-psi-impl/src/META-INF/JavaPsiPlugin.xml +++ b/java/java-psi-impl/src/META-INF/JavaPsiPlugin.xml @@ -28,7 +28,6 @@ - diff --git a/java/java-structure-view/intellij.java.structureView.iml b/java/java-structure-view/intellij.java.structureView.iml index 8f0338e01890..4ac4895efae8 100644 --- a/java/java-structure-view/intellij.java.structureView.iml +++ b/java/java-structure-view/intellij.java.structureView.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PropertyGroup.java b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PropertyGroup.java index 65bfbe38c292..5ff2da591282 100644 --- a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PropertyGroup.java +++ b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PropertyGroup.java @@ -62,7 +62,7 @@ public final class PropertyGroup implements Group, ColoredItemPresentation, Acce if (null != accessorInfo && (accessorInfo.isKindOf(PropertyKind.GETTER) || accessorInfo.isKindOf(PropertyKind.SETTER))) { - PropertyGroup group = new PropertyGroup(accessorInfo.getPropertyName(), accessorInfo.getPropertyType(), + PropertyGroup group = new PropertyGroup(accessorInfo.propertyName(), accessorInfo.propertyType(), method.hasModifierProperty(PsiModifier.STATIC), method.getProject()); if (accessorInfo.isKindOf(PropertyKind.GETTER)) { group.setGetter(method);