1- /*******************************************************************************
1+ /*******************************************************************************
22 * Copyright (c) 2018 Microsoft Corporation and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
1818import java .util .regex .Matcher ;
1919import java .util .regex .Pattern ;
2020
21- import org .apache .commons .lang3 .StringUtils ;
2221import org .eclipse .core .runtime .IProgressMonitor ;
2322import org .eclipse .jdt .core .IMethod ;
2423import org .eclipse .jdt .core .IPackageFragmentRoot ;
@@ -225,18 +224,6 @@ public static void resolveSingleType(IJavaProject javaProject, String typeName,
225224 }
226225 }
227226
228- /**
229- * Helper method to check if a string is not empty (null or zero-length).
230- * Note: This does NOT trim or check for whitespace-only strings.
231- * Use this instead of StringUtils.isNotBlank() when you want to preserve whitespace.
232- *
233- * @param str the string to check
234- * @return true if the string is not null and not empty
235- */
236- private static boolean isNotEmpty (String str ) {
237- return str != null && !str .isEmpty ();
238- }
239-
240227 /**
241228 * Check if a type belongs to a common JDK package that should be skipped.
242229 * Uses package-level matching for efficient filtering.
@@ -245,7 +232,7 @@ private static boolean isNotEmpty(String str) {
245232 * @return true if the type is from a common JDK package
246233 */
247234 private static boolean isCommonJdkType (String typeName ) {
248- if (StringUtils . isBlank ( typeName )) {
235+ if (typeName == null || typeName . isEmpty ( )) {
249236 return false ;
250237 }
251238
@@ -672,7 +659,7 @@ private static String extractBriefJavaDoc(org.eclipse.jdt.core.IType type) {
672659
673660 try {
674661 String javadoc = type .getAttachedJavadoc (null );
675- if (! isNotEmpty ( javadoc )) {
662+ if (javadoc == null || javadoc . isEmpty ( )) {
676663 return null ;
677664 }
678665 return getFirstSentenceOrLimit (javadoc , 120 );
@@ -802,7 +789,7 @@ public static String generateClassDescription(org.eclipse.jdt.core.IType type, S
802789 description .append ("Signature: " ).append (signature ).append ("\n \n " );
803790
804791 // === 2. JavaDoc (inserted after signature) ===
805- if (StringUtils . isNotBlank (javadoc )) {
792+ if (isNotEmpty (javadoc )) {
806793 description .append ("JavaDoc:\n " ).append (javadoc ).append ("\n \n " );
807794 }
808795
@@ -924,7 +911,7 @@ private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType t
924911
925912 // === High Priority: Extract class description text (first paragraph) ===
926913 String description = extractClassDescription (cleanedJavadoc );
927- if (StringUtils . isNotBlank (description )) {
914+ if (isNotEmpty (description )) {
928915 result .append ("Description:\n " ).append (description ).append ("\n \n " );
929916 }
930917
@@ -933,7 +920,7 @@ private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType t
933920 Matcher markdownMatcher = MARKDOWN_CODE_PATTERN .matcher (rawJavadoc );
934921 while (markdownMatcher .find ()) {
935922 String code = markdownMatcher .group (1 ).trim ();
936- if (StringUtils . isNotBlank (code ) && seenCodeSnippets .add (code )) {
923+ if (isNotEmpty (code ) && seenCodeSnippets .add (code )) {
937924 result .append ("```java\n " ).append (code ).append ("\n ```\n \n " );
938925 }
939926 }
@@ -943,7 +930,7 @@ private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType t
943930 Matcher preMatcher = HTML_PRE_PATTERN .matcher (cleanedJavadoc );
944931 while (preMatcher .find ()) {
945932 String code = preMatcher .group (1 ).replaceAll ("(?i)<code[^>]*>" , "" ).replaceAll ("(?i)</code>" , "" ).trim ();
946- if (StringUtils . isNotBlank (code ) && seenCodeSnippets .add (code )) {
933+ if (isNotEmpty (code ) && seenCodeSnippets .add (code )) {
947934 result .append ("```java\n " ).append (code ).append ("\n ```\n \n " );
948935 }
949936 }
@@ -953,7 +940,7 @@ private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType t
953940 while (codeMatcher .find ()) {
954941 String code = codeMatcher .group (1 ).trim ();
955942 // Use HashSet for O(1) duplicate checking
956- if (StringUtils . isNotBlank (code ) && seenCodeSnippets .add (code )) {
943+ if (isNotEmpty (code ) && seenCodeSnippets .add (code )) {
957944 result .append ("```java\n " ).append (code ).append ("\n ```\n \n " );
958945 }
959946 }
@@ -971,7 +958,7 @@ private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType t
971958 * Returns the first paragraph of descriptive text, limited to reasonable length.
972959 */
973960 private static String extractClassDescription (String cleanedJavadoc ) {
974- if (! isNotEmpty ( cleanedJavadoc )) {
961+ if (cleanedJavadoc == null || cleanedJavadoc . isEmpty ( )) {
975962 return "" ;
976963 }
977964
@@ -1002,7 +989,7 @@ private static String extractClassDescription(String cleanedJavadoc) {
1002989 * Clean up raw JavaDoc comment by removing comment markers and asterisks
1003990 */
1004991 private static String cleanJavadocComment (String rawJavadoc ) {
1005- if (! isNotEmpty ( rawJavadoc )) {
992+ if (rawJavadoc == null || rawJavadoc . isEmpty ( )) {
1006993 return "" ;
1007994 }
1008995
@@ -1042,7 +1029,7 @@ private static String cleanJavadocComment(String rawJavadoc) {
10421029 * Convert HTML entities to their plain text equivalents
10431030 */
10441031 private static String convertHtmlEntities (String text ) {
1045- if (! isNotEmpty ( text )) {
1032+ if (text == null || text . isEmpty ( )) {
10461033 return text ;
10471034 }
10481035 return text .replace (" " , " " )
@@ -1061,7 +1048,7 @@ private static String convertHtmlEntities(String text) {
10611048 * Preserves line breaks for block-level tags like <p>, <br>, <div>.
10621049 */
10631050 private static String removeHtmlTags (String text ) {
1064- if (! isNotEmpty ( text )) {
1051+ if (text == null || text . isEmpty ( )) {
10651052 return text ;
10661053 }
10671054
@@ -1111,7 +1098,7 @@ private static String extractMethodJavaDocSummary(IMethod method) {
11111098 * Extract the main description part from JavaDoc (before @tags)
11121099 */
11131100 private static String extractJavadocDescription (String cleanedJavadoc ) {
1114- if (! isNotEmpty ( cleanedJavadoc )) {
1101+ if (cleanedJavadoc == null || cleanedJavadoc . isEmpty ( )) {
11151102 return "" ;
11161103 }
11171104
@@ -1144,7 +1131,7 @@ private static String extractJavadocDescription(String cleanedJavadoc) {
11441131 * Get the first sentence or limit the text to maxLength characters
11451132 */
11461133 private static String getFirstSentenceOrLimit (String text , int maxLength ) {
1147- if (! isNotEmpty ( text )) {
1134+ if (text == null || text . isEmpty ( )) {
11481135 return "" ;
11491136 }
11501137
@@ -1246,7 +1233,7 @@ public static String generateFieldSignature(org.eclipse.jdt.core.IField field) {
12461233 * Convert JDT type signature to human-readable format
12471234 */
12481235 public static String convertTypeSignature (String jdtSignature ) {
1249- if (! isNotEmpty ( jdtSignature )) {
1236+ if (jdtSignature == null || jdtSignature . isEmpty ( )) {
12501237 return "void" ;
12511238 }
12521239
@@ -1452,7 +1439,7 @@ private static String generateMethodSignatureInternal(IMethod method, boolean si
14521439 // Add JavaDoc if requested
14531440 if (includeJavadoc ) {
14541441 String javadocSummary = extractMethodJavaDocSummary (method );
1455- if (StringUtils . isNotBlank ( javadocSummary )) {
1442+ if (javadocSummary != null && ! javadocSummary . isEmpty ( )) {
14561443 return "// " + javadocSummary + "\n " + sb .toString ();
14571444 }
14581445 }
@@ -1507,7 +1494,7 @@ private static String generateFieldSignatureInternal(org.eclipse.jdt.core.IField
15071494 // Add JavaDoc if not simplified
15081495 if (!simplified ) {
15091496 String javadocSummary = extractFieldJavaDocSummary (field );
1510- if (StringUtils . isNotBlank ( javadocSummary )) {
1497+ if (javadocSummary != null && ! javadocSummary . isEmpty ( )) {
15111498 return "// " + javadocSummary + "\n " + sb .toString ();
15121499 }
15131500 }
@@ -1518,4 +1505,10 @@ private static String generateFieldSignatureInternal(org.eclipse.jdt.core.IField
15181505 }
15191506 }
15201507
1508+ /**
1509+ * Utility method to check if a string is not empty or null
1510+ */
1511+ private static boolean isNotEmpty (String value ) {
1512+ return value != null && !value .isEmpty ();
1513+ }
15211514}
0 commit comments