From abeca4e54ab0a989189b973ae4023d9a35b401ff Mon Sep 17 00:00:00 2001 From: Michael Glavassevich Date: Tue, 5 Nov 2024 13:40:30 -0500 Subject: [PATCH 1/2] Use a collector to build the list of accessor names. Move string literals for the prefixes into a constant list. Signed-off-by: Michael Glavassevich --- .../tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java index 0b6138b4a..6160e392d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java @@ -28,11 +28,15 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class JDTUtils { // Percent encoding obtained from: https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters private static final String LEVEL1_URI_REGEX = "(?:\\/(?:(?:\\{(\\w|-|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+\\})|(?:(\\w|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+)))*\\/?"; + // Unmodifiable list of accessor prefixes + private static final List ACCESSOR_PREFIXES = List.of("get", "set", "is"); + /** * Check if a URI starts with a leading slash. * @@ -66,11 +70,8 @@ public static boolean isValidLevel1URI(String uriString) { public static List getFieldAccessors(PsiJavaFile unit, PsiField field) { List accessors = new ArrayList(); String fieldName = field.getName(); - fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - List accessorNames = new ArrayList(); - accessorNames.add("get" + fieldName); - accessorNames.add("set" + fieldName); - accessorNames.add("is" + fieldName); + String accessorSuffix = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + List accessorNames = ACCESSOR_PREFIXES.stream().map(s -> s + accessorSuffix).collect(Collectors.toList()); for (PsiClass type : unit.getClasses()) { for (PsiMethod method : type.getMethods()) { From efc840f9e18e36e24ddf27fd47179e43cf1a2b2f Mon Sep 17 00:00:00 2001 From: Michael Glavassevich Date: Tue, 5 Nov 2024 13:42:58 -0500 Subject: [PATCH 2/2] Updating the copyright. Signed-off-by: Michael Glavassevich --- .../openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java index 6160e392d..38299f4f1 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/JDTUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016-2017 Red Hat, Inc. + * Copyright (c) 2016, 2024 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at