示例#1
0
 @Override
 public ExtensionValueReturn execute() {
   List<Element> resultQuery = (List<Element>) getParam(0);
   Element e = resultQuery.get(0);
   if (e instanceof Node) {
     Node node = (Node) e;
     Leaf fileNameLeaf = node.getLeaf("filename", 0);
     if (fileNameLeaf != null) {
       String value = fileNameLeaf.getValue();
       int index = value.indexOf(".");
       if (index > 0) {
         return returnString(value.substring(0, index));
       }
     }
   }
   return returnString(null);
 }
  /**
   * Creates a root CST node which contains the particular CST for the file and its name and path.
   *
   * @param child
   * @param sourceFilePath
   * @return
   */
  protected Node createRootNode(Element child, String sourceFilePath) {
    Node specficidNode = (Node) child;

    // The node to be returned
    Node file = CSTFactory.eINSTANCE.createNode();
    file.setKind("file");

    Leaf pathLeaf = CSTFactory.eINSTANCE.createLeaf();
    pathLeaf.setKind("path");
    pathLeaf.setValue(sourceFilePath);

    Leaf pathFileName = CSTFactory.eINSTANCE.createLeaf();
    pathFileName.setKind("filename");
    pathFileName.setValue(extractFileName(sourceFilePath));

    file.getChildren().add(pathLeaf);
    file.getChildren().add(pathFileName);
    file.getChildren().add(specficidNode);

    return file;
  }