mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Javafx: Minor refactoring in JavaFxPsiUtil - code duplication removed, better names for methods (IDEA-165983)
This commit is contained in:
@@ -863,7 +863,7 @@ public class JavaFxPsiUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<String, PsiMember> collectReadableProperties(@Nullable PsiClass psiClass) {
|
||||
public static Map<String, PsiMember> getReadableProperties(@Nullable PsiClass psiClass) {
|
||||
if (psiClass != null) {
|
||||
return CachedValuesManager.getCachedValue(psiClass, () ->
|
||||
CachedValueProvider.Result.create(prepareReadableProperties(psiClass), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT));
|
||||
@@ -871,7 +871,6 @@ public class JavaFxPsiUtil {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private static Map<String, PsiMember> prepareReadableProperties(@NotNull PsiClass psiClass) {
|
||||
final Map<String, PsiMember> acceptableMembers = new THashMap<>();
|
||||
@@ -887,7 +886,7 @@ public class JavaFxPsiUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<String, PsiMember> collectWritableProperties(@Nullable PsiClass psiClass) {
|
||||
public static Map<String, PsiMember> getWritableProperties(@Nullable PsiClass psiClass) {
|
||||
if (psiClass != null) {
|
||||
return CachedValuesManager.getCachedValue(psiClass, () ->
|
||||
CachedValueProvider.Result.create(prepareWritableProperties(psiClass), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT));
|
||||
@@ -899,16 +898,11 @@ public class JavaFxPsiUtil {
|
||||
private static Map<String, PsiMember> prepareWritableProperties(@NotNull PsiClass psiClass) {
|
||||
// todo search for setter in corresponding builder class, e.g. MyDataBuilder.setText() + MyData.getText(), reuse logic from hasBuilder()
|
||||
final Map<String, PsiMember> acceptableMembers = new THashMap<>();
|
||||
for (PsiMethod constructor : psiClass.getConstructors()) {
|
||||
if (!constructor.hasModifierProperty(PsiModifier.PUBLIC)) continue;
|
||||
final PsiParameter[] parameters = constructor.getParameterList().getParameters();
|
||||
for (PsiParameter parameter : parameters) {
|
||||
final String propertyName = getPropertyNameFromNamedArgAnnotation(parameter);
|
||||
if (!StringUtil.isEmpty(propertyName) && !acceptableMembers.containsKey(propertyName)) {
|
||||
final PsiField field = psiClass.findFieldByName(propertyName, true);
|
||||
if (field != null && !field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
acceptableMembers.put(propertyName, field);
|
||||
}
|
||||
for (String propertyName : prepareConstructorNamedArgProperties(psiClass)) {
|
||||
if (!acceptableMembers.containsKey(propertyName)) {
|
||||
final PsiField field = psiClass.findFieldByName(propertyName, true);
|
||||
if (field != null && !field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
acceptableMembers.put(propertyName, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -978,6 +972,7 @@ public class JavaFxPsiUtil {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<String> prepareConstructorNamedArgProperties(@NotNull PsiClass psiClass) {
|
||||
final Set<String> properties = new THashSet<>();
|
||||
for (PsiMethod constructor : psiClass.getConstructors()) {
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class JavaFxColorRgbInspection extends XmlSuppressableInspectionTool {
|
||||
@NotNull String propertyName,
|
||||
@NotNull String propertyValue,
|
||||
@NotNull PsiElement location) {
|
||||
final PsiMember declaration = JavaFxPsiUtil.collectWritableProperties(psiClass).get(propertyName);
|
||||
final PsiMember declaration = JavaFxPsiUtil.getWritableProperties(psiClass).get(propertyName);
|
||||
final String boxedQName = JavaFxPsiUtil.getBoxedPropertyType(psiClass, declaration);
|
||||
if (CommonClassNames.JAVA_LANG_FLOAT.equals(boxedQName) || CommonClassNames.JAVA_LANG_DOUBLE.equals(boxedQName)) {
|
||||
try {
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class JavaFxDefaultTagInspection extends XmlSuppressableInspectionTool{
|
||||
if (subTags.length != 0) {
|
||||
final PsiClass tagValueClass = JavaFxPsiUtil.getTagValueClass(subTags[subTags.length - 1]);
|
||||
if (JavaFxPsiUtil.isObservableCollection(tagValueClass)) {
|
||||
final PsiMember property = JavaFxPsiUtil.collectWritableProperties(parentTagClass).get(propertyName);
|
||||
final PsiMember property = JavaFxPsiUtil.getWritableProperties(parentTagClass).get(propertyName);
|
||||
if (property != null) {
|
||||
final PsiType propertyType = JavaFxPsiUtil.getWritablePropertyType(parentTagClass, property);
|
||||
final PsiClass propertyClass = PsiUtil.resolveClassInClassTypeOnly(propertyType);
|
||||
|
||||
+5
-5
@@ -165,7 +165,7 @@ public abstract class JavaFxClassTagDescriptorBase implements XmlElementDescript
|
||||
final String parentTagName = contextTag.getName();
|
||||
if (!FxmlConstants.FX_DEFINE.equals(parentTagName)) {
|
||||
if (FxmlConstants.FX_ROOT.equals(parentTagName)) {
|
||||
final Map<String, PsiMember> properties = JavaFxPsiUtil.collectWritableProperties(psiClass);
|
||||
final Map<String, PsiMember> properties = JavaFxPsiUtil.getWritableProperties(psiClass);
|
||||
if (properties.get(name) != null) {
|
||||
return new JavaFxPropertyTagDescriptor(psiClass, name, false);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public abstract class JavaFxClassTagDescriptorBase implements XmlElementDescript
|
||||
}
|
||||
}
|
||||
}
|
||||
final Map<String, PsiMember> properties = JavaFxPsiUtil.collectWritableProperties(psiClass);
|
||||
final Map<String, PsiMember> properties = JavaFxPsiUtil.getWritableProperties(psiClass);
|
||||
if (properties.get(name) != null) {
|
||||
return new JavaFxPropertyTagDescriptor(psiClass, name, false);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public abstract class JavaFxClassTagDescriptorBase implements XmlElementDescript
|
||||
|
||||
@NotNull
|
||||
private <T> Set<String> collectWritableProperties(final List<T> children, final Function<PsiMember, T> factory) {
|
||||
final Map<String, PsiMember> fieldList = JavaFxPsiUtil.collectWritableProperties(getPsiClass());
|
||||
final Map<String, PsiMember> fieldList = JavaFxPsiUtil.getWritableProperties(getPsiClass());
|
||||
for (PsiMember field : fieldList.values()) {
|
||||
children.add(factory.fun(field));
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public abstract class JavaFxClassTagDescriptorBase implements XmlElementDescript
|
||||
if (propertySetter != null) {
|
||||
return new JavaFxStaticSetterAttributeDescriptor(propertySetter, attributeName);
|
||||
}
|
||||
final PsiMember psiMember = JavaFxPsiUtil.collectWritableProperties(psiClass).get(attributeName);
|
||||
final PsiMember psiMember = JavaFxPsiUtil.getWritableProperties(psiClass).get(attributeName);
|
||||
if (psiMember != null) {
|
||||
return new JavaFxPropertyAttributeDescriptor(attributeName, psiClass);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ public abstract class JavaFxClassTagDescriptorBase implements XmlElementDescript
|
||||
public boolean isReadOnlyAttribute(String attributeName) {
|
||||
final PsiClass psiClass = getPsiClass();
|
||||
return psiClass != null &&
|
||||
!JavaFxPsiUtil.collectWritableProperties(psiClass).containsKey(attributeName) &&
|
||||
!JavaFxPsiUtil.getWritableProperties(psiClass).containsKey(attributeName) &&
|
||||
!JavaFxPsiUtil.getConstructorNamedArgProperties(psiClass).contains(attributeName);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -190,7 +190,7 @@ public class JavaFxPropertyAttributeDescriptor extends BasicXmlAttributeDescript
|
||||
final List<String> remainingPropertyNames = propertyNames.subList(1, propertyNames.size());
|
||||
for (String propertyName : remainingPropertyNames) {
|
||||
if (aClass == null) break;
|
||||
final PsiMember member = JavaFxPsiUtil.collectReadableProperties(aClass).get(propertyName);
|
||||
final PsiMember member = JavaFxPsiUtil.getReadableProperties(aClass).get(propertyName);
|
||||
aClass = JavaFxPsiUtil.getPropertyClass(JavaFxPsiUtil.getReadablePropertyType(member), xmlAttributeValue);
|
||||
}
|
||||
if (aClass != null && !InheritanceUtil.isInheritorOrSelf(aClass, targetPropertyClass, true)) {
|
||||
@@ -273,7 +273,7 @@ public class JavaFxPropertyAttributeDescriptor extends BasicXmlAttributeDescript
|
||||
}
|
||||
|
||||
private PsiMember getDeclarationMember() {
|
||||
return JavaFxPsiUtil.collectWritableProperties(myPsiClass).get(myName);
|
||||
return JavaFxPsiUtil.getWritableProperties(myPsiClass).get(myName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ public class JavaFxPropertyTagDescriptor implements XmlElementDescriptor {
|
||||
public PsiElement getDeclaration() {
|
||||
if (myPsiClass == null) return null;
|
||||
if (myStatic) return JavaFxPsiUtil.findStaticPropertySetter(myName, myPsiClass);
|
||||
return JavaFxPsiUtil.collectWritableProperties(myPsiClass).get(myName);
|
||||
return JavaFxPsiUtil.getWritableProperties(myPsiClass).get(myName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -250,7 +250,7 @@ public class JavaFxComponentIdReferenceProvider extends PsiReferenceProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
return JavaFxPsiUtil.collectReadableProperties(myPsiClass).get(myFieldName);
|
||||
return JavaFxPsiUtil.getReadableProperties(myPsiClass).get(myFieldName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -268,7 +268,7 @@ public class JavaFxComponentIdReferenceProvider extends PsiReferenceProvider {
|
||||
private Object[] collectProperties(@NotNull PsiType propertyType, @NotNull Project project) {
|
||||
final PsiType resolvedType = JavaFxPsiUtil.getWritablePropertyType(propertyType, project);
|
||||
final List<LookupElement> objs = new ArrayList<>();
|
||||
final Collection<PsiMember> readableProperties = JavaFxPsiUtil.collectReadableProperties(myPsiClass).values();
|
||||
final Collection<PsiMember> readableProperties = JavaFxPsiUtil.getReadableProperties(myPsiClass).values();
|
||||
for (PsiMember readableMember : readableProperties) {
|
||||
final PsiType readableType = JavaFxPsiUtil.getReadablePropertyType(readableMember);
|
||||
if (readableType == null) continue;
|
||||
|
||||
Reference in New Issue
Block a user