Examples of QualifiedNameExpr


Examples of com.github.antlrjavaparser.api.expr.QualifiedNameExpr

            ImportDeclaration importDeclaration;

            if (!importType.isAsterisk()) {
                NameExpr typeToImportExpr;
                if (importType.getImportType().getEnclosingType() == null) {
                    typeToImportExpr = new QualifiedNameExpr(new NameExpr(
                            importType.getImportType().getPackage()
                                    .getFullyQualifiedPackageName()),
                            importType.getImportType().getSimpleTypeName());
                }
                else {
                    typeToImportExpr = new QualifiedNameExpr(new NameExpr(
                            importType.getImportType().getEnclosingType()
                                    .getFullyQualifiedTypeName()), importType
                            .getImportType().getSimpleTypeName());
                }
View Full Code Here

Examples of com.github.antlrjavaparser.api.expr.QualifiedNameExpr

     */
    public static ClassOrInterfaceType getClassOrInterfaceType(
            final NameExpr nameExpr) {
        Validate.notNull(nameExpr, "Java type required");
        if (nameExpr instanceof QualifiedNameExpr) {
            final QualifiedNameExpr qne = (QualifiedNameExpr) nameExpr;
            if (StringUtils.isNotBlank(qne.getQualifier().getName())) {
                return new ClassOrInterfaceType(qne.getQualifier().getName()
                        + "." + qne.getName());
            }
            return new ClassOrInterfaceType(qne.getName());
        }
        return new ClassOrInterfaceType(nameExpr.getName());
    }
View Full Code Here

Examples of com.github.antlrjavaparser.api.expr.QualifiedNameExpr

        final JavaPackage compilationUnitPackage = compilationUnitServices
                .getCompilationUnitPackage();

        if (nameToFind instanceof QualifiedNameExpr) {
            final QualifiedNameExpr qne = (QualifiedNameExpr) nameToFind;

            // Handle qualified name expressions that are related to inner types
            // (eg Foo.Bar)
            final NameExpr qneQualifier = qne.getQualifier();
            final NameExpr enclosedBy = getNameExpr(compilationUnitServices
                    .getEnclosingTypeName().getSimpleTypeName());
            if (isEqual(qneQualifier, enclosedBy)) {
                // This qualified name expression is simply an inner type
                // reference
                final String name = compilationUnitServices
                        .getEnclosingTypeName().getFullyQualifiedTypeName()
                        + "." + nameToFind.getName();
                return new JavaType(name,
                        compilationUnitServices.getEnclosingTypeName());
            }

            // Refers to a different enclosing type, so calculate the package
            // name based on convention of an uppercase letter denotes same
            // package (ROO-1210)
            if (qne.toString().length() > 1
                    && Character.isUpperCase(qne.toString().charAt(0))) {
                // First letter is uppercase, so this likely requires prepending
                // of some package name
                final ImportDeclaration importDeclaration = getImportDeclarationFor(
                        compilationUnitServices, qne.getQualifier());
                if (importDeclaration == null) {
                    if (!compilationUnitPackage.getFullyQualifiedPackageName()
                            .equals("")) {
                        // It was not imported, so let's assume it's in the same
                        // package
                        return new JavaType(compilationUnitServices
                                .getCompilationUnitPackage()
                                .getFullyQualifiedPackageName()
                                + "." + qne.toString());
                    }
                }
                else {
                    return new JavaType(importDeclaration.getName() + "."
                            + qne.getName());
                }

                // This name expression (which contains a dot) had its qualifier
                // imported, so let's use the import
            }
            else {
                // First letter is lowercase, so the reference already includes
                // a package
                return new JavaType(qne.toString());
            }
        }

        if ("?".equals(nameToFind.getName())) {
            return new JavaType(OBJECT.getFullyQualifiedTypeName(), 0,
View Full Code Here

Examples of com.github.antlrjavaparser.api.expr.QualifiedNameExpr

        Validate.notBlank(className, "Class name required");
        if (className.contains(".")) {
            final int offset = className.lastIndexOf(".");
            final String packageName = className.substring(0, offset);
            final String typeName = className.substring(offset + 1);
            return new QualifiedNameExpr(new NameExpr(packageName), typeName);
        }
        return new NameExpr(className);
    }
View Full Code Here

Examples of com.github.antlrjavaparser.api.expr.QualifiedNameExpr

            return new NameExpr(typeToImport.getSimpleTypeName());
        }

        NameExpr typeToImportExpr;
        if (typeToImport.getEnclosingType() == null) {
            typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport
                    .getPackage().getFullyQualifiedPackageName()),
                    typeToImport.getSimpleTypeName());
        }
        else {
            typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport
                    .getEnclosingType().getFullyQualifiedTypeName()),
                    typeToImport.getSimpleTypeName());
        }

        final ImportDeclaration newImport = new ImportDeclaration(
                typeToImportExpr, false, false);

        boolean addImport = true;
        boolean useSimpleTypeName = false;
        for (final ImportDeclaration existingImport : imports) {
            if (existingImport.getName().getName()
                    .equals(newImport.getName().getName())) {
                // Do not import, as there is already an import with the simple
                // type name
                addImport = false;

                // If this is a complete match, it indicates we can use the
                // simple type name
                if (isEqual(existingImport.getName(), newImport.getName())) {
                    useSimpleTypeName = true;
                    break;
                }
            }
        }

        if (addImport
                && JdkJavaType.isPartOfJavaLang(typeToImport
                        .getSimpleTypeName())) {
            // This simple type name would be part of java.lang if left as the
            // simple name. We want a fully-qualified name.
            addImport = false;
            useSimpleTypeName = false;
        }

        if (JdkJavaType.isPartOfJavaLang(typeToImport)) {
            // So we would have imported, but we don't need to
            addImport = false;

            // The fact we could have imported means there was no other
            // conflicting simple type names
            useSimpleTypeName = true;
        }

        if (addImport
                && typeToImport.getPackage().equals(compilationUnitPackage)) {
            // It is not theoretically necessary to add an import for something
            // in the same package,
            // but we elect to explicitly perform an import so future
            // conflicting types are not imported
            // addImport = true;
            // useSimpleTypeName = false;
        }

        if (addImport
                && targetType.getSimpleTypeName().equals(
                        typeToImport.getSimpleTypeName())) {
            // So we would have imported it, but then it would conflict with the
            // simple name of the type
            addImport = false;
            useSimpleTypeName = false;
        }

        if (addImport) {
            imports.add(newImport);
            useSimpleTypeName = true;
        }

        // This is pretty crude, but at least it emits source code for people
        // (forget imports, though!)
        if (typeToImport.getArgName() != null) {
            return new NameExpr(typeToImport.toString());
        }

        if (useSimpleTypeName) {
            return new NameExpr(typeToImport.getSimpleTypeName());
        }
        return new QualifiedNameExpr(new NameExpr(typeToImport.getPackage()
                .getFullyQualifiedPackageName()),
                typeToImport.getSimpleTypeName());
    }
View Full Code Here

Examples of japa.parser.ast.expr.QualifiedNameExpr

                        + cid.getName() + "'");
        for (final ImportMetadata importType : cid.getRegisteredImports()) {
            if (!importType.isAsterisk()) {
                NameExpr typeToImportExpr;
                if (importType.getImportType().getEnclosingType() == null) {
                    typeToImportExpr = new QualifiedNameExpr(new NameExpr(
                            importType.getImportType().getPackage()
                                    .getFullyQualifiedPackageName()),
                            importType.getImportType().getSimpleTypeName());
                }
                else {
                    typeToImportExpr = new QualifiedNameExpr(new NameExpr(
                            importType.getImportType().getEnclosingType()
                                    .getFullyQualifiedTypeName()), importType
                            .getImportType().getSimpleTypeName());
                }
                compilationUnit.getImports().add(
View Full Code Here

Examples of japa.parser.ast.expr.QualifiedNameExpr

     */
    public static ClassOrInterfaceType getClassOrInterfaceType(
            final NameExpr nameExpr) {
        Validate.notNull(nameExpr, "Java type required");
        if (nameExpr instanceof QualifiedNameExpr) {
            final QualifiedNameExpr qne = (QualifiedNameExpr) nameExpr;
            if (StringUtils.isNotBlank(qne.getQualifier().getName())) {
                return new ClassOrInterfaceType(qne.getQualifier().getName()
                        + "." + qne.getName());
            }
            return new ClassOrInterfaceType(qne.getName());
        }
        return new ClassOrInterfaceType(nameExpr.getName());
    }
View Full Code Here

Examples of japa.parser.ast.expr.QualifiedNameExpr

        final JavaPackage compilationUnitPackage = compilationUnitServices
                .getCompilationUnitPackage();

        if (nameToFind instanceof QualifiedNameExpr) {
            final QualifiedNameExpr qne = (QualifiedNameExpr) nameToFind;

            // Handle qualified name expressions that are related to inner types
            // (eg Foo.Bar)
            final NameExpr qneQualifier = qne.getQualifier();
            final NameExpr enclosedBy = getNameExpr(compilationUnitServices
                    .getEnclosingTypeName().getSimpleTypeName());
            if (isEqual(qneQualifier, enclosedBy)) {
                // This qualified name expression is simply an inner type
                // reference
                final String name = compilationUnitServices
                        .getEnclosingTypeName().getFullyQualifiedTypeName()
                        + "." + nameToFind.getName();
                return new JavaType(name,
                        compilationUnitServices.getEnclosingTypeName());
            }

            // Refers to a different enclosing type, so calculate the package
            // name based on convention of an uppercase letter denotes same
            // package (ROO-1210)
            if (qne.toString().length() > 1
                    && Character.isUpperCase(qne.toString().charAt(0))) {
                // First letter is uppercase, so this likely requires prepending
                // of some package name
                final ImportDeclaration importDeclaration = getImportDeclarationFor(
                        compilationUnitServices, qne.getQualifier());
                if (importDeclaration == null) {
                    if (!compilationUnitPackage.getFullyQualifiedPackageName()
                            .equals("")) {
                        // It was not imported, so let's assume it's in the same
                        // package
                        return new JavaType(compilationUnitServices
                                .getCompilationUnitPackage()
                                .getFullyQualifiedPackageName()
                                + "." + qne.toString());
                    }
                }
                else {
                    return new JavaType(importDeclaration.getName() + "."
                            + qne.getName());
                }

                // This name expression (which contains a dot) had its qualifier
                // imported, so let's use the import
            }
            else {
                // First letter is lowercase, so the reference already includes
                // a package
                return new JavaType(qne.toString());
            }
        }

        if ("?".equals(nameToFind.getName())) {
            return new JavaType(OBJECT.getFullyQualifiedTypeName(), 0,
View Full Code Here

Examples of japa.parser.ast.expr.QualifiedNameExpr

        Validate.notBlank(className, "Class name required");
        if (className.contains(".")) {
            final int offset = className.lastIndexOf(".");
            final String packageName = className.substring(0, offset);
            final String typeName = className.substring(offset + 1);
            return new QualifiedNameExpr(new NameExpr(packageName), typeName);
        }
        return new NameExpr(className);
    }
View Full Code Here

Examples of japa.parser.ast.expr.QualifiedNameExpr

            return new NameExpr(typeToImport.getSimpleTypeName());
        }

        NameExpr typeToImportExpr;
        if (typeToImport.getEnclosingType() == null) {
            typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport
                    .getPackage().getFullyQualifiedPackageName()),
                    typeToImport.getSimpleTypeName());
        }
        else {
            typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport
                    .getEnclosingType().getFullyQualifiedTypeName()),
                    typeToImport.getSimpleTypeName());
        }

        final ImportDeclaration newImport = new ImportDeclaration(
                typeToImportExpr, false, false);

        boolean addImport = true;
        boolean useSimpleTypeName = false;
        for (final ImportDeclaration existingImport : imports) {
            if (existingImport.getName().getName()
                    .equals(newImport.getName().getName())) {
                // Do not import, as there is already an import with the simple
                // type name
                addImport = false;

                // If this is a complete match, it indicates we can use the
                // simple type name
                if (isEqual(existingImport.getName(), newImport.getName())) {
                    useSimpleTypeName = true;
                    break;
                }
            }
        }

        if (addImport
                && JdkJavaType.isPartOfJavaLang(typeToImport
                        .getSimpleTypeName())) {
            // This simple type name would be part of java.lang if left as the
            // simple name. We want a fully-qualified name.
            addImport = false;
            useSimpleTypeName = false;
        }

        if (JdkJavaType.isPartOfJavaLang(typeToImport)) {
            // So we would have imported, but we don't need to
            addImport = false;

            // The fact we could have imported means there was no other
            // conflicting simple type names
            useSimpleTypeName = true;
        }

        if (addImport
                && typeToImport.getPackage().equals(compilationUnitPackage)) {
            // It is not theoretically necessary to add an import for something
            // in the same package,
            // but we elect to explicitly perform an import so future
            // conflicting types are not imported
            // addImport = true;
            // useSimpleTypeName = false;
        }

        if (addImport
                && targetType.getSimpleTypeName().equals(
                        typeToImport.getSimpleTypeName())) {
            // So we would have imported it, but then it would conflict with the
            // simple name of the type
            addImport = false;
            useSimpleTypeName = false;
        }

        if (addImport) {
            imports.add(newImport);
            useSimpleTypeName = true;
        }

        // This is pretty crude, but at least it emits source code for people
        // (forget imports, though!)
        if (typeToImport.getArgName() != null) {
            return new NameExpr(typeToImport.toString());
        }

        if (useSimpleTypeName) {
            return new NameExpr(typeToImport.getSimpleTypeName());
        }
        return new QualifiedNameExpr(new NameExpr(typeToImport.getPackage()
                .getFullyQualifiedPackageName()),
                typeToImport.getSimpleTypeName());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.