/plugins/OpenIt/tags/release_1_5_2/src/org/etheridge/common/utility/JavaUtilities.java

# · Java · 82 lines · 38 code · 16 blank · 28 comment · 6 complexity · 04ea77d9db1c1d877db802f44cc6d224 MD5 · raw file

  1. /*
  2. * LazyImporter jEdit Plugin (JavaUtilities.java)
  3. *
  4. * Copyright (C) 2003 Matt Etheridge (matt@etheridge.org)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. package org.etheridge.common.utility;
  21. import java.io.File;
  22. public class JavaUtilities {
  23. public static String removeStringLiterals(String text) {
  24. StringBuffer buffer = new StringBuffer(text);
  25. // iterate through buffer, replacing string literals with spaces
  26. int position = 0;
  27. while (position < buffer.length()) {
  28. if (buffer.charAt(position) == '"') {
  29. int stringLiteralStart = position + 1;
  30. position++;
  31. while (buffer.charAt(position) != '"') {
  32. position++;
  33. }
  34. buffer.replace(stringLiteralStart, position, createEmptyString(position - stringLiteralStart));
  35. }
  36. position++;
  37. }
  38. return buffer.toString();
  39. }
  40. /**
  41. * Converts a / separated package name to a . separated package name
  42. */
  43. public static String convertPathPackageToDotPackage(String pathPackage) {
  44. char pathSeparatorChar = File.separatorChar;
  45. String dotPackage = pathPackage.replace(pathSeparatorChar, '.');
  46. // remove a dot at the beginning if there is one
  47. if (dotPackage.endsWith(".")) {
  48. dotPackage = dotPackage.substring(0, dotPackage.length() - 1);
  49. }
  50. // remove dot at the END if there is one
  51. if (dotPackage.startsWith(".")) {
  52. return dotPackage.substring(1);
  53. }
  54. return dotPackage;
  55. }
  56. //
  57. // Private Helper Methods
  58. //
  59. private static String createEmptyString(int size) {
  60. StringBuffer stringBuffer = new StringBuffer();
  61. for (int i = 0; i < size; i++) {
  62. stringBuffer.append(' ');
  63. }
  64. return stringBuffer.toString();
  65. }
  66. }