public List<JavaPackage> getPackagesForModule(Pom module) { List<JavaPackage> packages = new ArrayList<JavaPackage>(); for (JavaType type : getTypesForModule(module)) { if (!packages.contains(type.getPackage())) { packages.add(type.getPackage()); } } return packages; }
@Override public JavaPackage getCompilationUnitPackage() { return cid.getName().getPackage(); }
public void setTypeNotVerified(JavaType javaType) { Validate.notNull(javaType, "JavaType required"); if (javaType.getPackage().getFullyQualifiedPackageName().startsWith("java.")) { return; } registerListener(); this.javaTypeNotVerified = javaType; javaPackageNotVerified = javaType.getPackage(); this.isVerified = false; module = null; }
public void setType(final JavaType javaType) { Validate.notNull(javaType, "JavaType required"); if (javaType.getPackage().getFullyQualifiedPackageName().startsWith("java.")) { return; } module = null; this.javaType = javaType; javaPackage = javaType.getPackage(); setPromptPath(javaType.getFullyQualifiedTypeName()); }
@Override public Set<ImportMetadata> getImports() { Set<ImportMetadata> imports = new HashSet<ImportMetadata>(); for (final Entry<JavaType, Boolean> entry : registeredImports.entrySet()) { JavaType registeredImport = entry.getKey(); boolean asStatic = entry.getValue(); imports.add(new ImportMetadataBuilder(getDeclaredByMetadataId(), Modifier.PUBLIC, registeredImport.getPackage(), registeredImport, asStatic, false).build()); } return imports; } }
/** * Constructor * * @param declaredByMetadataId * @param governor (required) * @param aspect (required) * @param privilegedAspect */ public ItdTypeDetailsBuilder(final String declaredByMetadataId, final ClassOrInterfaceTypeDetails governor, final JavaType aspect, final boolean privilegedAspect) { super(declaredByMetadataId); Validate.notNull(governor, "Name (to receive the introductions) required"); Validate.notNull(aspect, "Aspect required"); this.aspect = aspect; this.governor = governor; importRegistrationResolver = new ImportRegistrationResolverImpl(aspect.getPackage()); this.privilegedAspect = privilegedAspect; this.declarePrecedence = new LinkedHashSet<JavaType>(); }
protected JavaType getCustomRepositoryJavaTypeFor(JavaType repositoryType) { String javaTypeName = repositoryType.getPackage().getFullyQualifiedPackageName().concat(".") .concat(repositoryType.getSimpleTypeName()).concat("Custom"); return new JavaType(javaTypeName, repositoryType.getModule()); }
public void setTypeNotVerified(JavaType javaType, Pom module) { if (javaType == null) { Validate.notNull(module, "ERROR: javaType and module cannot be both null"); javaPackageNotVerified = projectOperations.getTopLevelPackage(module.getModuleName()); } else { if (javaType.getPackage().getFullyQualifiedPackageName().startsWith("java.")) { return; } javaPackageNotVerified = javaType.getPackage(); } registerListener(); this.moduleNotVerified = module; this.javaTypeNotVerified = javaType; this.isVerified = false; }
/** * Return QueryDSL Q JavaType for an entity JavaType * * @param entity * @return */ private JavaType getQJavaTypeFor(JavaType entity) { return new JavaType(entity.getPackage().getFullyQualifiedPackageName().concat(".Q") .concat(entity.getSimpleTypeName())); }
/** * Builds an import of the given {@link JavaType} for use by the given * caller. * * @param callerMID the metadata ID of the compilation unit to receive the * import (required) * @param typeToImport the type to import (required) * @return a non-<code>null</code>, non-static, non-wildcard import * @since 1.2.0 */ public static ImportMetadata getImport(final String callerMID, final JavaType typeToImport) { return new ImportMetadataBuilder(callerMID, 0, typeToImport.getPackage(), typeToImport, false, false).build(); }
public void setType(final JavaType javaType, final Pom module) { if (javaType == null) { Validate.notNull(module, "ERROR: javaType and module cannot be both null"); javaPackage = projectOperations.getTopLevelPackage(module.getModuleName()); } else { if (javaType.getPackage().getFullyQualifiedPackageName().startsWith("java.")) { return; } javaPackage = javaType.getPackage(); } this.module = module; this.javaType = javaType; this.isVerified = true; setPromptPath(javaType.getFullyQualifiedTypeName()); }
private void prependCompilationUnitDetails() { final StringBuilder topOfFile = new StringBuilder(); topOfFile.append("// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.") .append(NEW_LINE); topOfFile .append( "// You may push code into the target .java compilation unit if you wish to edit any member(s).") .append(NEW_LINE).append(NEW_LINE); // Note we're directly interacting with the top of file string builder if (!aspect.isDefaultPackage()) { topOfFile.append("package ").append(aspect.getPackage().getFullyQualifiedPackageName()) .append(";").append(NEW_LINE); topOfFile.append(NEW_LINE); } // Ordered to ensure consistency of output final SortedMap<JavaType, Boolean> types = new TreeMap<JavaType, Boolean>(); types.putAll(resolver.getRegisteredImports()); if (!types.isEmpty()) { // First of all include the static imports writeStaticImports(topOfFile, types); // After static imports, include the other ones writeImports(topOfFile, types); topOfFile.append(NEW_LINE); } // Now append the normal file to the bottom topOfFile.append(pw.toString()); // Replace the old writer with out new writer pw = topOfFile; }
/** * @return the package name (never null) */ public JavaPackage getPackage() { if (isDefaultPackage() && !Character.isUpperCase(fullyQualifiedTypeName.charAt(0))) { return new JavaPackage("", module); } if (enclosingType != null) { final String enclosingTypeFullyQualifiedTypeName = enclosingType.getFullyQualifiedTypeName(); final int offset = enclosingTypeFullyQualifiedTypeName.lastIndexOf("."); // Handle case where the package name after the last period starts // with a capital letter. if (offset > -1 && Character.isUpperCase(enclosingTypeFullyQualifiedTypeName.charAt(offset + 1))) { return new JavaPackage(enclosingTypeFullyQualifiedTypeName, module); } return enclosingType.getPackage(); } final int offset = fullyQualifiedTypeName.lastIndexOf("."); return offset == -1 ? new JavaPackage("") : new JavaPackage(fullyQualifiedTypeName.substring(0, offset), module); }
private void appendTypeDeclaration() { Validate.isTrue(introductionTo.getPackage().equals(aspect.getPackage()), "Aspect and introduction must be in identical packages"); appendIndent(); if (itdTypeDetails.isPrivilegedAspect()) { append("privileged "); } append("aspect " + aspect.getSimpleTypeName() + " {"); this.newLine(false); indent(); this.newLine(); // Set to false, as it was set true during the above operations content = false; }
private JavaType filterControllerByPackageAndPrefix( Collection<ClassOrInterfaceTypeDetails> itemControllers, JavaPackage controllerPackage, String pathPrefix) { for (ClassOrInterfaceTypeDetails controller : itemControllers) { ControllerAnnotationValues values = new ControllerAnnotationValues(controller); if (controllerPackage.equals(controller.getType().getPackage()) && (StringUtils.isBlank(pathPrefix) && StringUtils.isBlank(values.getPathPrefix()) || StringUtils .equals(pathPrefix, values.getPathPrefix()))) { return controller.getType(); } } return null; }
public boolean isFullyQualifiedFormRequired(final JavaType javaType) { Validate.notNull(javaType, "Java type required"); if (javaType.getDataType() == DataType.PRIMITIVE || javaType.getDataType() == DataType.VARIABLE) { // Primitives and type variables do not need to be used in // fully-qualified form return false; } if (registeredImports.get(javaType) != null) { // Already know about this one return false; } if (compilationUnitPackage.equals(javaType.getPackage())) { // No need for an explicit registration, given it's in the same // package return false; } if (JdkJavaType.isPartOfJavaLang(javaType)) { return false; } // To get this far, it must need a fully-qualified name return true; }
@Override public JavaType createDataOnDemand(JavaType entity) { Validate.notNull(entity, "Entity to produce a data on demand provider for is required"); JavaType dodClass = getDataOnDemand(entity); if (dodClass != null) { return dodClass; } // Add plugin to generate test jar addMavenJarPlugin(entity.getModule()); // Create the JavaType for DoD class JavaType name = new JavaType(entity.getPackage().getFullyQualifiedPackageName().concat(".dod.") .concat(entity.getSimpleTypeName()).concat("DataOnDemand"), entity.getModule()); // Obatain test path for the module of the new class final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, name.getModule()); Validate.notNull(path, "Location of the new data on demand provider is required"); // Create DoD configuration class createDataOnDemandConfiguration(entity.getModule()); // Create entity factories for the given entity and its related entities createEntityFactory(entity); // Create data on demand class return newDataOnDemandClass(entity, name); }
/** * Constructor based on an existing ITD * * @param existing (required) */ public ItdTypeDetailsBuilder(final ItdTypeDetails existing) { super(existing.getDeclaredByMetadataId(), existing); aspect = existing.getAspect(); governor = existing.getGovernor(); importRegistrationResolver = new ImportRegistrationResolverImpl(aspect.getPackage()); privilegedAspect = existing.isPrivilegedAspect(); declarePrecedence = existing.getDeclarePrecedence(); }
@Override 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(); }
responseType.getAnnotation()); for (ClassOrInterfaceTypeDetails existingController : detailControllers) { if (existingController.getType().getPackage().equals(controllerPackage)) { ControllerAnnotationValues values = new ControllerAnnotationValues(existingController); AnnotationAttributeValue<String> relationFieldAttr =