langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
changeset 8631 664f84942e74
parent 7681 1f0819a3341f
child 9303 eae35c201e19
equal deleted inserted replaced
8630:cd9eefe597f6 8631:664f84942e74
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   380             } finally {
   380             } finally {
   381                 in.close();
   381                 in.close();
   382                 out.close();
   382                 out.close();
   383             }
   383             }
   384         } catch (IOException ie) {
   384         } catch (IOException ie) {
   385             ie.printStackTrace();
   385             ie.printStackTrace(System.err);
   386             throw new DocletAbortException();
   386             throw new DocletAbortException();
   387         }
   387         }
   388     }
   388     }
   389 
   389 
   390     /**
   390     /**
   397             PackageDoc pkgDoc){
   397             PackageDoc pkgDoc){
   398         try{
   398         try{
   399             String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
   399             String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
   400             String completePath = new SourcePath(configuration.sourcepath).
   400             String completePath = new SourcePath(configuration.sourcepath).
   401                 getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR;
   401                 getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR;
   402             //Make sure that both paths are using the same seperators.
   402             //Make sure that both paths are using the same separators.
   403             completePath = Util.replaceText(completePath, File.separator,
   403             completePath = Util.replaceText(completePath, File.separator,
   404                     DirectoryManager.URL_FILE_SEPARATOR);
   404                     DirectoryManager.URL_FILE_SEPARATOR);
   405             pkgPath = Util.replaceText(pkgPath, File.separator,
   405             pkgPath = Util.replaceText(pkgPath, File.separator,
   406                     DirectoryManager.URL_FILE_SEPARATOR);
   406                     DirectoryManager.URL_FILE_SEPARATOR);
   407             return completePath.substring(0, completePath.indexOf(pkgPath));
   407             return completePath.substring(0, completePath.lastIndexOf(pkgPath));
   408         } catch (Exception e){
   408         } catch (Exception e){
   409             return "";
   409             return "";
   410         }
   410         }
   411     }
   411     }
   412 
   412 
   534             findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
   534             findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
   535         else
   535         else
   536             findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
   536             findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
   537     }
   537     }
   538 
   538 
   539 
       
   540     public static <T extends ProgramElementDoc> List<T> asList(T[] members) {
       
   541         List<T> list = new ArrayList<T>();
       
   542         for (int i = 0; i < members.length; i++) {
       
   543             list.add(members[i]);
       
   544         }
       
   545         return list;
       
   546     }
       
   547 
       
   548     /**
   539     /**
   549      * Enclose in quotes, used for paths and filenames that contains spaces
   540      * Enclose in quotes, used for paths and filenames that contains spaces
   550      */
   541      */
   551     public static String quote(String filepath) {
   542     public static String quote(String filepath) {
   552         return ("\"" + filepath + "\"");
   543         return ("\"" + filepath + "\"");
   581     public static String replaceText(String originalStr, String oldStr,
   572     public static String replaceText(String originalStr, String oldStr,
   582             String newStr) {
   573             String newStr) {
   583         if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
   574         if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
   584             return originalStr;
   575             return originalStr;
   585         }
   576         }
   586         StringBuffer result = new StringBuffer(originalStr);
   577         return originalStr.replace(oldStr, newStr);
   587         int startIndex = 0;
       
   588         while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
       
   589             result = result.replace(startIndex, startIndex + oldStr.length(),
       
   590                     newStr);
       
   591             startIndex += newStr.length();
       
   592         }
       
   593         return result.toString();
       
   594     }
   578     }
   595 
   579 
   596     /**
   580     /**
   597      * Given a string, escape all special html characters and
   581      * Given a string, escape all special html characters and
   598      * return the result.
   582      * return the result.
   831      * Given a string, replace all tabs with the appropriate
   815      * Given a string, replace all tabs with the appropriate
   832      * number of spaces.
   816      * number of spaces.
   833      * @param tabLength the length of each tab.
   817      * @param tabLength the length of each tab.
   834      * @param s the String to scan.
   818      * @param s the String to scan.
   835      */
   819      */
   836     public static void replaceTabs(int tabLength, StringBuffer s) {
   820     public static void replaceTabs(int tabLength, StringBuilder s) {
   837         int index, col;
   821         if (whitespace == null || whitespace.length() < tabLength)
   838         StringBuffer whitespace;
   822             whitespace = String.format("%" + tabLength + "s", " ");
   839         while ((index = s.indexOf("\t")) != -1) {
   823         int index = 0;
   840             whitespace = new StringBuffer();
   824         while ((index = s.indexOf("\t", index)) != -1) {
   841             col = index;
   825             int spaceCount = tabLength - index % tabLength;
   842             do {
   826             s.replace(index, index+1, whitespace.substring(0, spaceCount));
   843                 whitespace.append(" ");
   827             index += spaceCount;
   844                 col++;
   828         }
   845             } while ((col%tabLength) != 0);
   829     }
   846             s.replace(index, index+1, whitespace.toString());
   830     private static String whitespace;
   847         }
       
   848     }
       
   849 
   831 
   850     /**
   832     /**
   851      * The documentation for values() and valueOf() in Enums are set by the
   833      * The documentation for values() and valueOf() in Enums are set by the
   852      * doclet.
   834      * doclet.
   853      */
   835      */