1 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 20 public class Php { 21 22 23 public Php() { 24 } 25 26 public static String functionName(SyntaxContext context) { 27 ASTPath path = context.getASTPath(); 28 ASTNode n = (ASTNode) path.getLeaf(); 29 String name = null; 30 ASTNode nameNode = n.getNode("FunctionName"); 31 32 if (nameNode != null) { 33 name = nameNode.getAsText(); 34 } 35 36 String 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 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 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 name = nameNode.getAsText(); 69 70 return name.substring(1, name.length() - 1); 71 } 72 73 return "?"; 74 } 75 76 private static String getAsText (ASTNode n) { 77 if (n == null) return ""; 78 return n.getAsText (); 79 } 80 81 } 82 | Popular Tags |