1 package net.sourceforge.phpdt.internal.corext.phpdoc;
3 import java.io.FileReader;
4 import java.io.IOException;
6 import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
9 * Utility class for static PHPdoc helper mehods
11 public class PHPDocUtil {
14 * Generate a PHPDoc hover text if possible
16 * @param hoverInfoBuffer
20 public static void appendPHPDoc(StringBuffer hoverInfoBuffer,
21 String filename, PHPIdentifierLocation location) {
22 FileReader phpFileReader;
23 hoverInfoBuffer.append(location.toString());
24 hoverInfoBuffer.append(" - <b>");
26 hoverInfoBuffer.append(getUsage(filename, location));
27 hoverInfoBuffer.append("</b><br>");
29 // read the phpdoc for the function
30 if (location.getPHPDocOffset() >= 0) {
31 phpFileReader = new FileReader(filename);
32 char[] phpDocDeclarationCharArray = new char[location
34 phpFileReader.skip(location.getPHPDocOffset());
35 phpFileReader.read(phpDocDeclarationCharArray, 0, location
37 PHPDocCharArrayCommentReader phpdocConverter = new PHPDocCharArrayCommentReader(
38 phpDocDeclarationCharArray);
39 hoverInfoBuffer.append(phpdocConverter.getString());
40 // hoverInfoBuffer.append("<br><br>");
41 phpFileReader.close();
44 } catch (IOException e) {
49 public static String getUsage(String filename,
50 PHPIdentifierLocation location) {
51 FileReader phpFileReader;
52 String usage = location.getUsage();
59 phpFileReader = new FileReader(filename);
60 // read the function declaration
61 if (location.getOffset() >= 0
62 && (location.isMethod() || location.isConstructor()
63 || location.isFunction() || location.isDefine())) {
64 char[] functionDeclarationCharArray = new char[256];
65 int offset = location.getOffset();
66 phpFileReader.skip(offset);
67 int length = phpFileReader.read(functionDeclarationCharArray,
72 for (int i = 0; i < length; i++) {
73 if (functionDeclarationCharArray[i] == ')') {
77 if (functionDeclarationCharArray[i] == '{'
78 || functionDeclarationCharArray[i] == '}') {
83 usage = new String(functionDeclarationCharArray, 0, length);
85 phpFileReader.close();
86 } catch (IOException e) {
89 // cache the usage string:
90 location.setUsage(usage);