protected void acceptSiblings(GroovySourceAST t) { if (t != null) { GroovySourceAST sibling = (GroovySourceAST) t.getNextSibling(); while (sibling != null) { accept(sibling); sibling = (GroovySourceAST) sibling.getNextSibling(); } } }
private String getIdentPlusTypeArgsFor(GroovySourceAST gpn) { GroovySourceAST groovySourceAST = gpn.childOfType(IDENT); StringBuilder ident = new StringBuilder(); ident.append(groovySourceAST.getText()); GroovySourceAST typeParams = (GroovySourceAST) groovySourceAST.getNextSibling(); getTypeParameters(typeParams, ident, "def"); return ident.toString(); } }
public void visitEnumConstantDef(GroovySourceAST t,int visit) { GroovySourceAST sibling = (GroovySourceAST)t.getNextSibling(); if (sibling != null && sibling.getType() == GroovyTokenTypes.ENUM_CONSTANT_DEF) { print(t,visit,null,null,", "); } }
/** * traverse an AST node * @param t the AST node to traverse */ private void traverse(GroovySourceAST t) { if (t == null) { return; } if (unvisitedNodes != null) { unvisitedNodes.add(t); } GroovySourceAST child = (GroovySourceAST)t.getFirstChild(); if (child != null) { traverse(child); } GroovySourceAST sibling = (GroovySourceAST)t.getNextSibling(); if (sibling != null) { traverse(sibling); } }
protected void accept_FirstSecondAndThirdChild_v_v_ForthChild(GroovySourceAST t) { GroovySourceAST child1 = (GroovySourceAST) t.getFirstChild(); if (child1 != null) { accept(child1); GroovySourceAST child2 = (GroovySourceAST) child1.getNextSibling(); if (child2 != null) { accept(child2); GroovySourceAST child3 = (GroovySourceAST) child2.getNextSibling(); if (child3 != null) { accept(child3); openingVisit(t); GroovySourceAST child4 = (GroovySourceAST) child3.getNextSibling(); if (child4 != null) { subsequentVisit(t); accept(child4); } } } } }
private void getTypeArguments(GroovySourceAST child, StringBuilder result, String defaultText) { if (child != null && child.getType() == TYPE_ARGUMENTS && child.getNumberOfChildren() > 0) { result.append("<"); GroovySourceAST typeArgumentsNext = (GroovySourceAST) child.getFirstChild(); List<String> typeArgumentParts = new ArrayList<String>(); while (typeArgumentsNext != null) { if (typeArgumentsNext.getType() == TYPE_ARGUMENT && typeArgumentsNext.getNumberOfChildren() > 0) { typeArgumentParts.add(getTypeNodeAsText((GroovySourceAST) typeArgumentsNext.getFirstChild(), defaultText)); } typeArgumentsNext = (GroovySourceAST) typeArgumentsNext.getNextSibling(); } result.append(DefaultGroovyMethods.join(typeArgumentParts, ", ")); result.append(">"); } }
private void getTypeParameters(GroovySourceAST child, StringBuilder result, String defaultText) { if (child != null && child.getType() == TYPE_PARAMETERS && child.getNumberOfChildren() > 0) { result.append("<"); GroovySourceAST typeParametersNext = (GroovySourceAST) child.getFirstChild(); List<String> typeParameterParts = new ArrayList<String>(); while (typeParametersNext != null) { if (typeParametersNext.getType() == TYPE_PARAMETER && typeParametersNext.getNumberOfChildren() > 0) { typeParameterParts.add(getTypeNodeAsText((GroovySourceAST) typeParametersNext.getFirstChild(), defaultText)); } typeParametersNext = (GroovySourceAST) typeParametersNext.getNextSibling(); } result.append(DefaultGroovyMethods.join(typeParameterParts, ", ")); result.append(">"); } }
protected void accept_v_FirstChild_v_SecondChild_v___LastChild_v(GroovySourceAST t) { openingVisit(t); GroovySourceAST child = (GroovySourceAST) t.getFirstChild(); if (child != null) { accept(child); GroovySourceAST sibling = (GroovySourceAST) child.getNextSibling(); while (sibling != null) { subsequentVisit(t); accept(sibling); sibling = (GroovySourceAST) sibling.getNextSibling(); } } closingVisit(t); }
protected void accept_v_FirstChild_2ndv_SecondChild_v___LastChild_v(GroovySourceAST t) { openingVisit(t); GroovySourceAST child = (GroovySourceAST) t.getFirstChild(); if (child != null) { accept(child); GroovySourceAST sibling = (GroovySourceAST) child.getNextSibling(); if (sibling != null) { secondVisit(t); accept(sibling); sibling = (GroovySourceAST) sibling.getNextSibling(); while (sibling != null) { subsequentVisit(t); accept(sibling); sibling = (GroovySourceAST) sibling.getNextSibling(); } } } closingVisit(t); }
@Override public void visitImport(GroovySourceAST t, int visit) { if (visit == OPENING_VISIT) { String importTextWithSlashesInsteadOfDots = extractImportPath(t); GroovySourceAST child = t.childOfType(LITERAL_as); if (child != null) { String alias = child.childOfType(DOT).getNextSibling().getText(); child = child.childOfType(DOT); importTextWithSlashesInsteadOfDots = recurseDownImportBranch(child); aliases.put(alias, importTextWithSlashesInsteadOfDots); } importedClassesAndPackages.add(importTextWithSlashesInsteadOfDots); } }
protected void accept_v_FirstChildsFirstChild_v_Child2_Child3_v_Child4_v___v_LastChild(GroovySourceAST t) { openingVisit(t); GroovySourceAST expr2 = t.childAt(0); skip(expr2); accept(expr2.childAt(0)); closingVisit(t); GroovySourceAST sibling = (GroovySourceAST) expr2.getNextSibling(); boolean firstSList = true; while (sibling != null) { if (!firstSList) { subsequentVisit(t); } firstSList = false; accept(sibling); sibling = (GroovySourceAST) sibling.getNextSibling(); } }
protected void accept_FirstChild_v_RestOfTheChildren_v_LastChild(GroovySourceAST t) { int count = 0; accept(t.childAt(0)); count++; openingVisit(t); if (t.childAt(0) != null) { GroovySourceAST sibling = (GroovySourceAST) t.childAt(0).getNextSibling(); while (sibling != null) { if (count == t.getNumberOfChildren() - 1) { closingVisit(t); } accept(sibling); count++; sibling = (GroovySourceAST) sibling.getNextSibling(); } } }
private String buildName(GroovySourceAST t) { if (t != null) { if (t.getType() == DOT) { GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild(); GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling(); return (buildName(firstChild) + "/" + buildName(secondChild)); } if (t.getType() == IDENT) { return t.getText(); } } return ""; }
private void handleDefaultValue(GroovySourceAST currentNode, SimpleGroovyParameter parameter) { GroovySourceAST paramPart = (GroovySourceAST) currentNode.getFirstChild(); for (int i = 1; i < currentNode.getNumberOfChildren(); i++) { paramPart = (GroovySourceAST) paramPart.getNextSibling(); } GroovySourceAST nodeToProcess = paramPart; if (paramPart.getNumberOfChildren() > 0) { nodeToProcess = (GroovySourceAST) paramPart.getFirstChild(); } // hack warning! // TODO handle , and ) when they occur within Strings parameter.setDefaultValue(getChildTextFromSource(nodeToProcess, ",)")); }
private String getDefaultValue(GroovySourceAST t) { GroovySourceAST child = (GroovySourceAST) t.getFirstChild(); if (t.getNumberOfChildren() != 4) return null; for (int i = 1; i < t.getNumberOfChildren(); i++) { child = (GroovySourceAST) child.getNextSibling(); } GroovySourceAST nodeToProcess = child; if (child.getType() != ANNOTATION_ARRAY_INIT && child.getNumberOfChildren() > 0) { nodeToProcess = (GroovySourceAST) child.getFirstChild(); } return getChildTextFromSource(nodeToProcess, ";"); }
GroovySourceAST b = (GroovySourceAST) a.getNextSibling();
private String recurseDownImportBranch(GroovySourceAST t) { if (t != null) { if (t.getType() == DOT) { GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild(); GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling(); return (recurseDownImportBranch(firstChild) + "/" + recurseDownImportBranch(secondChild)); } if (t.getType() == IDENT) { return t.getText(); } if (t.getType() == STAR) { return t.getText(); } } return ""; }
t = (GroovySourceAST)t.getNextSibling();
private String getTypeNodeAsText(GroovySourceAST typeNode, String defaultText) { // TODO refactor to retain richer type information rather than converting to String if (typeNode == null) { return defaultText; } if (typeNode.getType() == TYPE) { return getAsText(typeNode, defaultText); } else if (typeNode.getType() == TYPE_ARGUMENT) { return getTypeNodeAsText((GroovySourceAST) typeNode.getFirstChild(), defaultText); } else if (typeNode.getType() == WILDCARD_TYPE) { AST next = typeNode.getNextSibling(); if (next == null && typeNode.getFirstChild() != null) { // Java2Groovy produces a slightly different tree structure (TODO fix converter or java.g instead?) next = typeNode.getFirstChild(); } if (next == null) return "?"; String boundType = getTypeNodeAsText((GroovySourceAST) next.getFirstChild(), defaultText); if (next.getType() == TYPE_UPPER_BOUNDS) return "? extends " + boundType; if (next.getType() == TYPE_LOWER_BOUNDS) return "? super " + boundType; } else if (typeNode.getType() == IDENT) { return getAsTextCurrent(typeNode, defaultText); } return defaultText; }
private void addParametersTo(GroovySourceAST t, SimpleGroovyExecutableMemberDoc executableMemberDoc) { // parameters GroovySourceAST parametersNode = t.childOfType(PARAMETERS); if (parametersNode != null && parametersNode.getNumberOfChildren() > 0) { GroovySourceAST currentNode = (GroovySourceAST) parametersNode.getFirstChild(); while (currentNode != null) { String parameterTypeName = getTypeOrDefault(currentNode); String parameterName = getText(currentNode.childOfType(IDENT)); SimpleGroovyParameter parameter = new SimpleGroovyParameter(parameterName); parameter.setVararg(currentNode.getType() == VARIABLE_PARAMETER_DEF); parameter.setTypeName(parameterTypeName); GroovySourceAST modifiers = currentNode.childOfType(MODIFIERS); if (modifiers != null) { List<GroovySourceAST> annotations = modifiers.childrenOfType(ANNOTATION); for (GroovySourceAST a : annotations) { addAnnotationRef(parameter, a); } } executableMemberDoc.add(parameter); if (currentNode.getNumberOfChildren() == 4) { handleDefaultValue(currentNode, parameter); } currentNode = (GroovySourceAST) currentNode.getNextSibling(); } } }