private void updateTypeCache() { if (getTypeCache().getAllTypeIdentifiers().isEmpty()) { initTypeMap(); } discoverTypes(); // Update the type cache for (final String change : dirtyFiles) { cacheType(change); } dirtyFiles.clear(); }
private void cacheType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); if (doesPathIndicateJavaType(fileCanonicalPath)) { final String id = getPhysicalTypeIdentifier(fileCanonicalPath); if (id != null && PhysicalTypeIdentifier.isValid(id)) { // Change to Java, so drop the cache final ClassOrInterfaceTypeDetails cid = lookupClassOrInterfaceTypeDetails(id); if (cid == null) { if (!getFileManager().exists(fileCanonicalPath)) { getTypeCache().removeType(id); final JavaType type = getTypeCache().getTypeDetails(id).getName(); updateChanges(type.getFullyQualifiedTypeName(), true); } return; } getTypeCache().cacheType(fileCanonicalPath, cid); updateAttributeCache(cid); updateChanges(cid.getName().getFullyQualifiedTypeName(), false); } } }
public Set<JavaType> findTypesWithAnnotation(final JavaType... annotationsToDetect) { return findTypesWithAnnotation(Arrays.asList(annotationsToDetect)); }
public void addDependencies(ModuleFeatureName moduleFeatureName, final Collection<? extends Dependency> newDependencies) { for (String moduleName : getModuleNames(moduleFeatureName)) { getProjectOperations().addDependencies(moduleName, newDependencies); } }
private Set<String> discoverTypes() { // Retrieve a list of paths that have been discovered or modified since // the last invocation by this class for (final String change : getFileMonitorService().getDirtyFiles( TypeLocationServiceImpl.class.getName())) { if (doesPathIndicateJavaType(change)) { discoveredTypes.add(change); dirtyFiles.add(change); } } return discoveredTypes; }
public String getPhysicalTypeIdentifier(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); if (!doesPathIndicateJavaType(fileCanonicalPath)) { return null; String physicalTypeIdentifier = getTypeCache().getTypeIdFromTypeFilePath(fileCanonicalPath); if (physicalTypeIdentifier != null) { return physicalTypeIdentifier; StringUtils.replace(fileCanonicalPath, typeDirectory + File.separator, "", 1).replace( ".java", ""); final JavaPackage javaPackage = getTypeResolutionService().getPackage(fileCanonicalPath); if (javaPackage == null) { return null; final Pom module = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); Validate.notNull(module, "The module for the file '" + fileCanonicalPath + "' could not be located"); new JavaType(javaPackage.getFullyQualifiedPackageName() + "." + simpleTypeName, module.getModuleName()); getTypeCache().cacheTypeAgainstModule(module, javaType); getTypeCache().cacheFilePathAgainstTypeIdentifier(fileCanonicalPath, physicalTypeIdentifier);
public String getPhysicalTypeCanonicalPath(final String physicalTypeId) { final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(physicalTypeId); final JavaType javaType = PhysicalTypeIdentifier.getJavaType(physicalTypeId); final Pom pom = getProjectOperations().getPomFromModuleName(logicalPath.getModule()); final String canonicalFilePath = pom.getPathLocation(logicalPath.getPath()) + javaType.getRelativeFileName(); if (getFileManager().exists(canonicalFilePath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); getTypeCache().cacheFilePathAgainstTypeIdentifier(canonicalFilePath, physicalTypeId); } return canonicalFilePath; }
private void initTypeMap() { for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath path : pom.getPhysicalPaths()) { if (path.isSource()) { final String allJavaFiles = FileUtils.ensureTrailingSeparator(path.getLocationPath()) + JAVA_FILES_ANT_PATH; for (final FileDetails file : getFileManager().findMatchingAntPath(allJavaFiles)) { cacheType(file.getCanonicalPath()); } } } } }
public ClassOrInterfaceTypeDetails getTypeDetails(final String physicalTypeId) { if (StringUtils.isBlank(physicalTypeId)) { return null; } Validate.isTrue(PhysicalTypeIdentifier.isValid(physicalTypeId), "Metadata id '%s' is not a valid physical type id", physicalTypeId); updateTypeCache(); final ClassOrInterfaceTypeDetails cachedDetails = getTypeCache().getTypeDetails(physicalTypeId); if (cachedDetails != null) { return cachedDetails; } final PhysicalTypeMetadata physicalTypeMetadata = (PhysicalTypeMetadata) getMetadataService().get(physicalTypeId); if (physicalTypeMetadata == null) { return null; } return physicalTypeMetadata.getMemberHoldingTypeDetails(); }
/** * Builds a map of a module's packages and all types anywhere within them, * e.g. if there's two types com.foo.bar.A and com.foo.baz.B, the map will * look like this: "com": {"com.foo.bar.A", "com.foo.baz.B"} "com.foo": * {"com.foo.bar.A", "com.foo.baz.B"}, "com.foo.bar": {"com.foo.bar.A"}, * "com.foo.baz": {"com.foo.baz.B"} All packages that directly contain a * type are added to the given set. * * @param typesInModule the Java types within the module in question * @param typePackages the set to which to add each type's package * @return a non-<code>null</code> map laid out as above */ @SuppressWarnings("unused") private Map<String, Collection<String>> getTypesByPackage(final Iterable<String> typesInModule, final Set<String> typePackages) { final Map<String, Collection<String>> typesByPackage = new HashMap<String, Collection<String>>(); for (final String typeName : typesInModule) { final String typePackage = getPackageFromType(typeName); typePackages.add(typePackage); for (final String discoveredPackage : getAllPackages(typePackage)) { if (typesByPackage.get(discoveredPackage) == null) { typesByPackage.put(discoveredPackage, new HashSet<String>()); } typesByPackage.get(discoveredPackage).add(typeName); } } return typesByPackage; }
@Override public Collection<String> getModuleNames(ModuleFeatureName moduleFeatureName) { Validate.notNull(moduleFeatureName, "Module featured required"); List<String> moduleNames = new ArrayList<String>(); ModuleFeature moduleFeature = getModuleFeature(moduleFeatureName); if (moduleFeature != null) { moduleNames = moduleFeature.getModuleNames(); } return moduleNames; }
private String getParentPath(final JavaType javaType) { final String relativePath = javaType.getRelativeFileName(); for (final String typePath : discoverTypes()) { if (typePath.endsWith(relativePath)) { return StringUtils.removeEnd(typePath, relativePath); } } return null; }
/** * Obtains the a fresh copy of the {@link ClassOrInterfaceTypeDetails} for * the given physical type. * * @param physicalTypeIdentifier to lookup (required) * @return the requested details (or <code>null</code> if unavailable) */ private ClassOrInterfaceTypeDetails lookupClassOrInterfaceTypeDetails( final String physicalTypeIdentifier) { final PhysicalTypeMetadata physicalTypeMetadata = (PhysicalTypeMetadata) getMetadataService().evictAndGet(physicalTypeIdentifier); if (physicalTypeMetadata == null) { return null; } return physicalTypeMetadata.getMemberHoldingTypeDetails(); }
public String getPhysicalTypeIdentifier(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); if (!doesPathIndicateJavaType(fileCanonicalPath)) { return null; String physicalTypeIdentifier = getTypeCache().getTypeIdFromTypeFilePath(fileCanonicalPath); if (physicalTypeIdentifier != null) { return physicalTypeIdentifier; StringUtils.replace(fileCanonicalPath, typeDirectory + File.separator, "", 1).replace( ".java", ""); final JavaPackage javaPackage = getTypeResolutionService().getPackage(fileCanonicalPath); if (javaPackage == null) { return null; final Pom module = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); Validate.notNull(module, "The module for the file '" + fileCanonicalPath + "' could not be located"); new JavaType(javaPackage.getFullyQualifiedPackageName() + "." + simpleTypeName, module.getModuleName()); getTypeCache().cacheTypeAgainstModule(module, javaType); getTypeCache().cacheFilePathAgainstTypeIdentifier(fileCanonicalPath, physicalTypeIdentifier);
public String getPhysicalTypeCanonicalPath(final String physicalTypeId) { final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(physicalTypeId); final JavaType javaType = PhysicalTypeIdentifier.getJavaType(physicalTypeId); final Pom pom = getProjectOperations().getPomFromModuleName(logicalPath.getModule()); final String canonicalFilePath = pom.getPathLocation(logicalPath.getPath()) + javaType.getRelativeFileName(); if (getFileManager().exists(canonicalFilePath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); getTypeCache().cacheFilePathAgainstTypeIdentifier(canonicalFilePath, physicalTypeId); } return canonicalFilePath; }
private void initTypeMap() { for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath path : pom.getPhysicalPaths()) { if (path.isSource()) { final String allJavaFiles = FileUtils.ensureTrailingSeparator(path.getLocationPath()) + JAVA_FILES_ANT_PATH; for (final FileDetails file : getFileManager().findMatchingAntPath(allJavaFiles)) { cacheType(file.getCanonicalPath()); } } } } }
public ClassOrInterfaceTypeDetails getTypeDetails(final String physicalTypeId) { if (StringUtils.isBlank(physicalTypeId)) { return null; } Validate.isTrue(PhysicalTypeIdentifier.isValid(physicalTypeId), "Metadata id '%s' is not a valid physical type id", physicalTypeId); updateTypeCache(); final ClassOrInterfaceTypeDetails cachedDetails = getTypeCache().getTypeDetails(physicalTypeId); if (cachedDetails != null) { return cachedDetails; } final PhysicalTypeMetadata physicalTypeMetadata = (PhysicalTypeMetadata) getMetadataService().get(physicalTypeId); if (physicalTypeMetadata == null) { return null; } return physicalTypeMetadata.getMemberHoldingTypeDetails(); }
public void removeDependencies(ModuleFeatureName moduleFeatureName, final Collection<? extends Dependency> newDependencies) { for (String moduleName : getModuleNames(moduleFeatureName)) { getProjectOperations().removeDependencies(moduleName, newDependencies); } }
private Set<String> discoverTypes() { // Retrieve a list of paths that have been discovered or modified since // the last invocation by this class for (final String change : getFileMonitorService().getDirtyFiles( TypeLocationServiceImpl.class.getName())) { if (doesPathIndicateJavaType(change)) { discoveredTypes.add(change); dirtyFiles.add(change); } } return discoveredTypes; }
/** * Builds a map of a module's packages and all types anywhere within them, * e.g. if there's two types com.foo.bar.A and com.foo.baz.B, the map will * look like this: "com": {"com.foo.bar.A", "com.foo.baz.B"} "com.foo": * {"com.foo.bar.A", "com.foo.baz.B"}, "com.foo.bar": {"com.foo.bar.A"}, * "com.foo.baz": {"com.foo.baz.B"} All packages that directly contain a * type are added to the given set. * * @param typesInModule the Java types within the module in question * @param typePackages the set to which to add each type's package * @return a non-<code>null</code> map laid out as above */ @SuppressWarnings("unused") private Map<String, Collection<String>> getTypesByPackage(final Iterable<String> typesInModule, final Set<String> typePackages) { final Map<String, Collection<String>> typesByPackage = new HashMap<String, Collection<String>>(); for (final String typeName : typesInModule) { final String typePackage = getPackageFromType(typeName); typePackages.add(typePackage); for (final String discoveredPackage : getAllPackages(typePackage)) { if (typesByPackage.get(discoveredPackage) == null) { typesByPackage.put(discoveredPackage, new HashSet<String>()); } typesByPackage.get(discoveredPackage).add(typeName); } } return typesByPackage; }