Package japa.parser.ast.expr

Examples of japa.parser.ast.expr.NameExpr


            final FieldAccessExpr field = (FieldAccessExpr) expression;
            final String fieldName = field.getField();

            // Determine the type
            final Expression scope = field.getScope();
            NameExpr nameToFind = null;
            if (scope instanceof FieldAccessExpr) {
                final FieldAccessExpr fScope = (FieldAccessExpr) scope;
                nameToFind = JavaParserUtils.getNameExpr(fScope.toString());
            }
            else if (scope instanceof NameExpr) {
                nameToFind = (NameExpr) scope;
            }
            else {
                throw new UnsupportedOperationException(
                        "A FieldAccessExpr for '"
                                + field.getScope()
                                + "' should return a NameExpr or FieldAccessExpr (was "
                                + field.getScope().getClass().getName() + ")");
            }
            final JavaType fieldType = JavaParserUtils.getJavaType(
                    compilationUnitServices, nameToFind, null);

            final EnumDetails enumDetails = new EnumDetails(fieldType,
                    new JavaSymbolName(fieldName));
            return new EnumAttributeValue(annotationName, enumDetails);
        }

        if (expression instanceof NameExpr) {
            final NameExpr field = (NameExpr) expression;
            final String name = field.getName();
            // As we have no way of finding out the real type
            final JavaType fieldType = new JavaType("unknown.Object");
            final EnumDetails enumDetails = new EnumDetails(fieldType,
                    new JavaSymbolName(name));
            return new EnumAttributeValue(annotationName, enumDetails);
View Full Code Here


      }

      if (n.getThrows() != null) {
        printer.print(" throws ");
        for (Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext();) {
          NameExpr name = i.next();
          name.accept(this, arg);
          if (i.hasNext()) {
            printer.print(", ");
          }
        }
      }
View Full Code Here

     *            qualified name
     * @return instanceof {@link NameExpr}
     */
    public static NameExpr createNameExpr(String qualifiedName) {
        String[] split = qualifiedName.split("\\.");
        NameExpr ret = new NameExpr(split[0]);
        for (int i = 1; i < split.length; i++) {
            ret = new QualifiedNameExpr(ret, split[i]);
        }
        return ret;
    }
View Full Code Here

        //add a body to the method
        BlockStmt block = new BlockStmt();
        method.setBody(block);

        //add a statement do the method body
        NameExpr clazz = new NameExpr("System");
        FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
        MethodCallExpr call = new MethodCallExpr(field, "println");
        ASTHelper.addArgument(call, new StringLiteralExpr("Hello World"));
        ASTHelper.addStmt(block, call);
View Full Code Here

    public static String getTestPackageNameFrom(PackageDeclaration packageDeclaration) {
        if (null == packageDeclaration) {
            return Consts.TEST_PACKAGE;
        } else {
            NameExpr packageNameExpr = packageDeclaration.getName();
            String packageName = packageNameExpr.toString();
            return packageName + "." + Consts.TEST_PACKAGE;
        }
    }
View Full Code Here

        return this;
    }

    public CompilationUnitBuilder buildImports(String[] imports) {

        ImportDeclaration importDeclaration = new ImportDeclaration(new NameExpr("org.testng.annotations.Test"),
                false, false);
        if (null != cu.getImports()) {
            cu.getImports().add(importDeclaration);
        } else {
            cu.setImports(Arrays.asList(importDeclaration));
View Full Code Here

    public ClassTypeBuilder buildMethod(String methodName, MethodDeclaration method, String... params) {

        method.setName(methodName);
//        MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr(new NameExpr("Test"));
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
        memberValuePairs.add(new MemberValuePair("description", new NameExpr("\"申艳超的测试用例\"")));
        NormalAnnotationExpr normalAnnotationExpr = new NormalAnnotationExpr(new NameExpr("Test"), memberValuePairs);
        List<AnnotationExpr> annotationExprList = new ArrayList<AnnotationExpr>();
//        annotationExprList.add(markerAnnotationExpr);
        annotationExprList.add(normalAnnotationExpr);
        if (null != method.getParameters()) {
            method.getParameters().clear();
View Full Code Here

        return Boolean.TRUE;
    }

    public Boolean visit(NameExpr n1, Node arg) {
        NameExpr n2 = (NameExpr) arg;

        if (!objEquals(n1.getName(), n2.getName())) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }
View Full Code Here

        printer.print(")");

        if (n.getThrows() != null) {
            printer.print(" throws ");
            for (Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext();) {
                NameExpr name = i.next();
                name.accept(this, arg);
                if (i.hasNext()) {
                    printer.print(", ");
                }
            }
        }
View Full Code Here

        }

        if (n.getThrows() != null) {
            printer.print(" throws ");
            for (Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext();) {
                NameExpr name = i.next();
                name.accept(this, arg);
                if (i.hasNext()) {
                    printer.print(", ");
                }
            }
        }
View Full Code Here

TOP

Related Classes of japa.parser.ast.expr.NameExpr

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.