KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > php > Php


1 /*
2  * PHP.java
3  *
4  * Created on February 22, 2007, 3:43 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.languages.php;
11
12 import org.netbeans.api.languages.ASTNode;
13 import org.netbeans.api.languages.ASTPath;
14 import org.netbeans.api.languages.SyntaxContext;
15
16 /**
17  *
18  * @author marcow
19  */

20 public class Php {
21     
22     /** Creates a new instance of PHP */
23     public Php() {
24     }
25     
26     public static String JavaDoc functionName(SyntaxContext context) {
27         ASTPath path = context.getASTPath();
28         ASTNode n = (ASTNode) path.getLeaf();
29         String JavaDoc name = null;
30         ASTNode nameNode = n.getNode("FunctionName");
31         
32         if (nameNode != null) {
33             name = nameNode.getAsText();
34         }
35         
36         String JavaDoc parameters = "";
37         ASTNode parametersNode = n.getNode("FormalParameterList");
38         
39         if (parametersNode != null) {
40             parameters = parametersNode.getAsText();
41         }
42         
43         if (name != null) {
44             return name + "(" + parameters + ")";
45         }
46
47         return "?";
48     }
49     
50     public static String JavaDoc className(SyntaxContext context) {
51         ASTPath path = context.getASTPath();
52         ASTNode n = (ASTNode) path.getLeaf();
53         ASTNode nameNode = n.getNode("ClassName");
54
55         if (nameNode != null) {
56             return nameNode.getAsText();
57         }
58         
59         return "?";
60     }
61     
62     public static String JavaDoc constantName(SyntaxContext context) {
63         ASTPath path = context.getASTPath();
64         ASTNode n = (ASTNode) path.getLeaf();
65         ASTNode nameNode = n.getNode("ConstantName");
66
67         if (nameNode != null) {
68             String JavaDoc name = nameNode.getAsText();
69             
70             return name.substring(1, name.length() - 1);
71         }
72         
73         return "?";
74     }
75     
76     private static String JavaDoc getAsText (ASTNode n) {
77         if (n == null) return "";
78         return n.getAsText ();
79     }
80     
81 }
82
Popular Tags