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, String filename, PHPIdentifierLocation location) {
21 FileReader phpFileReader;
22 hoverInfoBuffer.append(location.toString());
23 hoverInfoBuffer.append(" - \n");
25 hoverInfoBuffer.append( getUsage(filename, location) );
26 hoverInfoBuffer.append('\n');
28 // read the phpdoc for the function
29 if (location.getPHPDocOffset() >= 0) {
30 phpFileReader = new FileReader(filename);
31 char[] phpDocDeclarationCharArray = new char[location.getPHPDocLength()];
32 phpFileReader.skip(location.getPHPDocOffset());
33 phpFileReader.read(phpDocDeclarationCharArray, 0, location.getPHPDocLength());
34 PHPDocCharArrayCommentReader phpdocConverter = new PHPDocCharArrayCommentReader(phpDocDeclarationCharArray);
35 hoverInfoBuffer.append(phpdocConverter.getString());
36 hoverInfoBuffer.append('\n');
37 phpFileReader.close();
40 } catch (IOException e) {
45 public static String getUsage(String filename, PHPIdentifierLocation location) {
46 FileReader phpFileReader;
47 String usage = location.getUsage();
54 phpFileReader = new FileReader(filename);
55 // read the function declaration
56 if (location.getOffset() >= 0 && (location.isMethod() || location.isConstructor() || location.isFunction() || location.isDefine())) {
57 char[] functionDeclarationCharArray = new char[256];
58 int offset = location.getOffset();
59 phpFileReader.skip(offset);
60 int length = phpFileReader.read(functionDeclarationCharArray, 0, 256);
64 for (int i = 0; i < length; i++) {
65 if (functionDeclarationCharArray[i] == ')') {
69 if (functionDeclarationCharArray[i] == '{' || functionDeclarationCharArray[i] == '}') {
74 usage = new String(functionDeclarationCharArray, 0, length);
76 phpFileReader.close();
77 } catch (IOException e) {
80 // cache the usage string:
81 location.setUsage(usage);