Package japa.parser.ast

Examples of japa.parser.ast.CompilationUnit


    public final String getCompilationUnitContents(
            final ClassOrInterfaceTypeDetails cid) {
        Validate.notNull(cid, "Class or interface type details are required");
        // Create a compilation unit to store the type to be created
        final CompilationUnit compilationUnit = new CompilationUnit();

        // NB: this import list is replaced at the end of this method by a
        // sorted version
        compilationUnit.setImports(new ArrayList<ImportDeclaration>());

        if (!cid.getName().isDefaultPackage()) {
            compilationUnit.setPackage(new PackageDeclaration(ASTHelper
                    .createNameExpr(cid.getName().getPackage()
                            .getFullyQualifiedPackageName())));
        }

        // Add the class of interface declaration to the compilation unit
        final List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
        compilationUnit.setTypes(types);

        updateOutput(compilationUnit, null, cid, null);

        return compilationUnit.toString();
    }
View Full Code Here


        Validate.notBlank(declaredByMetadataId,
                "Declaring metadata ID required");
        Validate.notNull(typeName, "Java type to locate required");
        try {
            final CompilationUnit compilationUnit = JavaParser
                    .parse(new ByteArrayInputStream(fileContents.getBytes()));
            final TypeDeclaration typeDeclaration = JavaParserUtils
                    .locateTypeDeclaration(compilationUnit, typeName);
            if (typeDeclaration == null) {
                return null;
View Full Code Here

            catch (IOException ignored) {
            }
            if (StringUtils.isBlank(typeContents)) {
                return null;
            }
            final CompilationUnit compilationUnit = JavaParser
                    .parse(new ByteArrayInputStream(typeContents.getBytes()));
            final String typeName = fileIdentifier.substring(
                    fileIdentifier.lastIndexOf(File.separator) + 1,
                    fileIdentifier.lastIndexOf("."));
            for (final TypeDeclaration typeDeclaration : compilationUnit
                    .getTypes()) {
                if (typeName.equals(typeDeclaration.getName())) {
                    return new JavaType(compilationUnit.getPackage().getName()
                            .getName()
                            + "." + typeDeclaration.getName());
                }
            }
            return null;
View Full Code Here

            catch (final IOException ignored) {
            }
            if (StringUtils.isBlank(typeContents)) {
                return null;
            }
            final CompilationUnit compilationUnit = JavaParser
                    .parse(new ByteArrayInputStream(typeContents.getBytes()));
            if (compilationUnit == null || compilationUnit.getPackage() == null) {
                return null;
            }
            return new JavaPackage(compilationUnit.getPackage().getName()
                    .toString());
        }
        catch (final ParseException e) {
            throw new IllegalStateException("Failed to parse " + fileIdentifier
                    + " : " + e.getMessage());
View Full Code Here

                    + field.getFieldName() + " = "
                    + field.getFieldInitializer() + ";\n");
            sb.append("}\n");
            final ByteArrayInputStream bais = new ByteArrayInputStream(sb
                    .toString().getBytes());
            CompilationUnit ci;
            try {
                ci = JavaParser.parse(bais);
            }
            catch (final ParseException pe) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not parse correctly", pe);
            }
            final List<TypeDeclaration> types = ci.getTypes();
            if (types == null || types.size() != 1) {
                throw new IllegalArgumentException("Field member invalid");
            }
            final TypeDeclaration td = types.get(0);
            final List<BodyDeclaration> bodyDeclarations = td.getMembers();
View Full Code Here

            sb.append("\n");
            sb.append("  }\n");
            sb.append("}\n");
            final ByteArrayInputStream bais = new ByteArrayInputStream(sb
                    .toString().getBytes());
            CompilationUnit ci;
            try {
                ci = JavaParser.parse(bais);
            }
            catch (final ParseException pe) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not parse correctly", pe);
            }
            final List<TypeDeclaration> types = ci.getTypes();
            if (types == null || types.size() != 1) {
                throw new IllegalArgumentException("Method body invalid");
            }
            final TypeDeclaration td = types.get(0);
            final List<BodyDeclaration> bodyDeclarations = td.getMembers();
View Full Code Here

            sb.append("\n");
            sb.append("  }\n");
            sb.append("}\n");
            final ByteArrayInputStream bais = new ByteArrayInputStream(sb
                    .toString().getBytes());
            CompilationUnit ci;
            try {
                ci = JavaParser.parse(bais);
            }
            catch (final ParseException pe) {
                throw new IllegalStateException(
                        "Illegal state: JavaParser did not parse correctly", pe);
            }
            final List<TypeDeclaration> types = ci.getTypes();
            if (types == null || types.size() != 1) {
                throw new IllegalArgumentException("Method body invalid");
            }
            final TypeDeclaration td = types.get(0);
            final List<BodyDeclaration> bodyDeclarations = td.getMembers();
View Full Code Here

  public String getLotusMethodText(String methodName) {
    String retVal_ = "";
    try {
      InputStream in = Utils.class.getResourceAsStream((String) ExtLibUtil.resolveVariable(FacesContext
          .getCurrentInstance(), "lotusClassName"));
      CompilationUnit cu;
      cu = JavaParser.parse(in);
      // visit and print the methods names
      ExtendedDumpVisitor dv = new ExtendedDumpVisitor();
      dv.setSearchMethodName(methodName);
      dv.visit(cu, null);
View Full Code Here

  public String getOurMethodText(String methodName) {
    String retVal_ = "";
    try {
      InputStream in = Utils.class.getResourceAsStream((String) ExtLibUtil.resolveVariable(FacesContext
          .getCurrentInstance(), "ourClassName"));
      CompilationUnit cu;
      cu = JavaParser.parse(in);
      // visit and print the methods names
      ExtendedDumpVisitor dv = new ExtendedDumpVisitor();
      dv.setSearchMethodName(methodName);
      dv.visit(cu, null);
View Full Code Here

    if (is == null) {
      return;
    }

    CompilationUnit cu;
    try {
      // parse the file
      cu = JavaParser.parse(is);
    } finally {
      is.close();
    }

    MethodParametersVisitor visitor = new MethodParametersVisitor();

    cu.accept(visitor, cache);

  }
View Full Code Here

TOP

Related Classes of japa.parser.ast.CompilationUnit

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.