Package com.bacoder.parser.java.api

Examples of com.bacoder.parser.java.api.TryStatement


    return throwStatement;
  }

  protected TryStatement processTryStatement(StatementContext context) {
    TryStatement tryStatement = createNode(context, TryStatement.class);

    ResourceSpecificationContext resourceSpecificationContext =
        getChild(context, ResourceSpecificationContext.class);
    if (resourceSpecificationContext != null) {
      ResourcesContext resourcesContext =
          getChild(resourceSpecificationContext, ResourcesContext.class);
      if (resourcesContext != null) {
        tryStatement.setResources(transform(resourcesContext, ResourceContext.class,
            new Function<ResourceContext, Resource>() {
              @Override
              public Resource apply(ResourceContext context) {
                Resource resource = createNode(context, Resource.class);

                setModifiers(context, resource);

                ClassOrInterfaceTypeContext classOrInterfaceTypeContext =
                    getChild(context, ClassOrInterfaceTypeContext.class);
                if (classOrInterfaceTypeContext != null) {
                  resource.setType(
                      getAdapter(ClassOrInterfaceTypeAdapter.class).adapt(
                          classOrInterfaceTypeContext));
                }

                VariableDeclaratorIdContext variableDeclaratorIdContext =
                    getChild(context, VariableDeclaratorIdContext.class);
                if (variableDeclaratorIdContext != null) {
                  TerminalNode identifierNode =
                      getTerminalNode(variableDeclaratorIdContext, JavaParser.Identifier);
                  if (identifierNode != null) {
                    resource.setName(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
                  }

                  resource.setDimensions(
                      getAdapter(ArrayDimensionsAdapter.class).adapt(variableDeclaratorIdContext));
                }

                ExpressionContext expressionContext = getChild(context, ExpressionContext.class);
                if (expressionContext != null) {
                  resource.setInitializer(
                      getAdapter(ExpressionAdapter.class).adapt(expressionContext));
                }

                return resource;
              }
            }));
      }
    }

    BlockContext blockContext = getChild(context, BlockContext.class);
    if (blockContext != null) {
      tryStatement.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
    }

    tryStatement.setCatchClauses(transform(context, CatchClauseContext.class,
        new Function<CatchClauseContext, CatchClause>() {
          @Override
          public CatchClause apply(CatchClauseContext context) {
            CatchClause catchClause = createNode(context, CatchClause.class);

            setModifiers(context, catchClause);

            CatchTypeContext catchTypeContext = getChild(context, CatchTypeContext.class);
            if (catchTypeContext != null) {
              catchClause.setExceptions(transform(catchTypeContext, QualifiedNameContext.class,
                  new Function<QualifiedNameContext, QualifiedName>() {
                    @Override
                    public QualifiedName apply(QualifiedNameContext context) {
                      return getAdapter(QualifiedNameAdapter.class).adapt(context);
                    }
                  }));
            }

            TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
            if (identifierNode != null) {
              catchClause.setVariable(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
            }

            BlockContext blockContext = getChild(context, BlockContext.class);
            if (blockContext != null) {
              catchClause.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
            }

            return catchClause;
          }
        }));

    FinallyBlockContext finallyBlockContext = getChild(context, FinallyBlockContext.class);
    if (finallyBlockContext != null) {
      BlockContext finallyBodyContext = getChild(finallyBlockContext, BlockContext.class);
      if (finallyBodyContext != null) {
        tryStatement.setFinallyBlock(getAdapter(BlockAdapter.class).adapt(finallyBodyContext));
      }
    }

    return tryStatement;
  }
View Full Code Here

TOP

Related Classes of com.bacoder.parser.java.api.TryStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.