Пример #1
0
    protected void printFeatures(FSTNode node, boolean start) {

      if (node.getType().equals("CompilationUnit") || !coveredByParent(node, node.getParent())) {
        if (start) printToken(startIfdef(FeatureExpressions.get(node)));
        else printToken(endIfdef(FeatureExpressions.get(node)));
      }
    }
  /**
   * recursively searches the tree for `Func` nodes and records meta data for discovered ones.
   *
   * @param n FSTNode to be searched for `Func` nodes
   */
  public void discoverFuncIntroductions(FSTNode n) {
    if (n.getType().equals("Func")) {
      String funcName = getMethodName(n);
      putMapping(funcName, getFeatureName(n), funcName);
      return;
    }

    if (n instanceof FSTNonTerminal) {
      FSTNonTerminal nt = (FSTNonTerminal) n;
      for (FSTNode child : nt.getChildren()) {
        discoverFuncIntroductions(child);
      }
    }
  }
  /**
   * extracts the method name (function name for C) from the node
   *
   * <p>this assumes the node is a `Func` node.
   *
   * @param node a `Func` node.
   * @return the method name e.g. "main"
   */
  public String getMethodName(FSTNode node) {
    String methodName = node.getName();

    StringTokenizer st = new StringTokenizer(methodName, "(");
    if (st.hasMoreTokens()) {
      methodName = st.nextToken();
    }
    st = new StringTokenizer(methodName, " ");

    while (st.hasMoreTokens()) {
      methodName = st.nextToken();
    }

    return methodName;
  }
 /**
  * extracts the feature name
  *
  * @param node `Feature` node or descendant of a `Feature` node.
  * @return name of the feature this node is a descendant of, e.g. "Base".
  */
 public String getFeatureName(FSTNode node) {
   if (node.getType().equals("Feature")) return node.getName();
   else return getFeatureName(node.getParent());
 }
Пример #5
0
 private static String getFeatureName(FSTNode node) {
   if (node.getType().equals("Feature"))
     return node.getName().toLowerCase() + (FSTGenComposerExtension.key ? "" : "()");
   else return getFeatureName(node.getParent());
 }
Пример #6
0
 private boolean coveredByParent(FSTNode node, FSTNode parent) {
   if (GuidslFileLoader.featureModel.checkCondition(
       new Implies(FeatureExpressions.get(parent), FeatureExpressions.get(node)))) return true;
   if (parent.getParent() != null) return coveredByParent(node, parent.getParent());
   return false;
 }
Пример #7
0
 public boolean visit(FSTNonTerminal nonTerminal) {
   if (nonTerminal.getType().equals("CompilationUnit")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "LayerDeclaration");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "PackageDeclaration");
       if (v != null) {
         v.accept(this);
       }
     }
     for (FSTNode v : getChildren(nonTerminal, "ImportDeclaration")) {
       v.accept(this);
     }
     for (FSTNode v : getChildren(nonTerminal, "TypeDeclaration")) {
       v.accept(this);
     }
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("AnnotationTypeDeclaration")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("@");
     printToken("interface");
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     for (FSTNode v : getChildren(nonTerminal, "AnnotationTypeMemberDeclaration")) {
       v.accept(this);
     }
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("ClassDeclaration")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ClassOrInterface");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "TypeParameters");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ExtendsList");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     hintIncIndent();
     hintNewLine();
     for (FSTNode v : getChildren(nonTerminal, "ClassOrInterfaceBodyDeclaration")) {
       v.accept(this);
       hintNewLine();
       hintNewLine();
     }
     hintDecIndent();
     hintNewLine();
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("EnumDecl")) {
     printFeatures(nonTerminal, true);
     Iterator<FSTNode> listElements = getChildren(nonTerminal, "EnumConstant").iterator();
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("enum");
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     if (listElements.hasNext()) {
       listElements.next().accept(this);
     }
     while (listElements.hasNext()) {
       printToken(",");
       listElements.next().accept(this);
     }
     {
       FSTNode v = getChild(nonTerminal, "EnumBodyInternal");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("EnumBodyInternal")) {
     printFeatures(nonTerminal, true);
     printToken(";");
     for (FSTNode v : getChildren(nonTerminal, "ClassOrInterfaceBodyDeclaration")) {
       v.accept(this);
     }
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("InnerClassDecl")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ClassOrInterface");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "TypeParameters");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ExtendsList");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     hintIncIndent();
     hintNewLine();
     for (FSTNode v : getChildren(nonTerminal, "ClassOrInterfaceBodyDeclaration")) {
       v.accept(this);
       hintNewLine();
       hintNewLine();
     }
     hintDecIndent();
     hintNewLine();
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("InnerEnumDecl")) {
     printFeatures(nonTerminal, true);
     Iterator<FSTNode> listElements = getChildren(nonTerminal, "EnumConstant").iterator();
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("enum");
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     if (listElements.hasNext()) {
       listElements.next().accept(this);
     }
     while (listElements.hasNext()) {
       printToken(",");
       listElements.next().accept(this);
     }
     {
       FSTNode v = getChild(nonTerminal, "EnumBodyInternal");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("AnnotationInnerAnnotation")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("@");
     printToken("interface");
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     for (FSTNode v : getChildren(nonTerminal, "AnnotationTypeMemberDeclaration")) {
       v.accept(this);
     }
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("AnnotationInnerClass")) {
     printFeatures(nonTerminal, true);
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ClassOrInterface");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "TypeParameters");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ExtendsList");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     hintIncIndent();
     hintNewLine();
     for (FSTNode v : getChildren(nonTerminal, "ClassOrInterfaceBodyDeclaration")) {
       v.accept(this);
       hintNewLine();
       hintNewLine();
     }
     hintDecIndent();
     hintNewLine();
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   if (nonTerminal.getType().equals("AnnotationInnerEnum")) {
     printFeatures(nonTerminal, true);
     Iterator<FSTNode> listElements = getChildren(nonTerminal, "EnumConstant").iterator();
     {
       FSTNode v = getChild(nonTerminal, "Modifiers");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("enum");
     {
       FSTNode v = getChild(nonTerminal, "Id");
       if (v != null) {
         v.accept(this);
       }
     }
     {
       FSTNode v = getChild(nonTerminal, "ImplementsList");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("{");
     if (listElements.hasNext()) {
       listElements.next().accept(this);
     }
     while (listElements.hasNext()) {
       printToken(",");
       listElements.next().accept(this);
     }
     {
       FSTNode v = getChild(nonTerminal, "EnumBodyInternal");
       if (v != null) {
         v.accept(this);
       }
     }
     printToken("}");
     printFeatures(nonTerminal, false);
     return false;
   }
   throw new RuntimeException("Unknown Non Terminal in FST " + nonTerminal);
 }