public static String nameToPath(final String s) { return toValidName(s).replace('.', File.separatorChar); }
/** * Returns the directory name that correspond to the package name of the given * fully qualified name. * * @param fullyQualifiedName a fully qualified name * @return the directory name that correspond to the package name of the given * fully qualified name. */ public static String fullyQualifiedNameToDirName( final String fullyQualifiedName) { final String packageName = getPackageName(toValidName(fullyQualifiedName)); if (packageName == null) return "/"; return packageNameToDirName(packageName); }
/** * Split the given fully-qualified name in an array of the identifiers that it * is made of. * * @param name a valid fully-qualified name (see {@link #isValid(String)}). * @return an array of the identifiers that compose the given fully qualified * name. */ public static final String[] splitName(final String name) { if (!isValid(name)) throw new IllegalArgumentException("Name \"" + name + "\" is not a valid name."); return name.split("\\."); }
public static String toCName(final String s) { return toValidName(s).replace('.', '_'); }
/** * Returns the package name part of the given fully-qualified name. If the * given fully-qualified name does not contain a package name, this method * returns <code>null</code>. * * @param name a valid fully-qualified name (see {@link #isValid(String)}). * @return the package name part of the given fully-qualified name. */ public static final String getPackageName(final String name) { if (!isValid(name)) throw new IllegalArgumentException("Name \"" + name + "\" is not a valid name."); final int i = name.lastIndexOf('.'); return i == -1 ? null : name.substring(0, i); }
/** * Returns the absolute path corresponding to the given fully qualified name * followed by the given suffix. * * @param fullyQualifiedName a fully qualified name * @param suffix a suffix to add to the fully qualified name.May be * <code>null</code> * @param extension the file extension to add at the end of the returned path. * May be <code>null</code> * @return the absolute path corresponding to the given fully qualified name. */ public static String fullyQualifiedNameToPath( final String fullyQualifiedName, final String suffix, final String extension) { String path = "/" + toValidName(fullyQualifiedName).replace('.', '/'); if (suffix != null) { path += suffix; } if (extension != null) { if (!extension.startsWith(".")) path += "."; path += extension; } return path; } }
public static final String toValidName(String name) { int i = name.indexOf('<'); if (i >= 0) { // name contains template parameter final String tmplValues = name.substring(i); final String defName = name.substring(0, i); if (!isValid(defName)) throw new IllegalArgumentException("Name \"" + defName + "\" is not a valid name."); return defName + "_tmpl_" + Integer.toHexString(tmplValues.hashCode()); } i = name.indexOf('$'); if (i >= 0) { // name references an anonymous definition name = name.replace("$", "_anon_"); } if (!isValid(name)) throw new IllegalArgumentException("Name \"" + name + "\" is not a valid name."); return name; } }
/** * A static method that returns the name of the file that is generated by this * component for the given {@link InstancesDescriptor}; * * @param instanceDesc an {@link InstancesDescriptor} node. * @return the name of the file that is generated by this component for the * given {@link Definition}; */ public static String getInstancesFileName( final InstancesDescriptor instanceDesc) { String outputFileName = toValidName(instanceDesc.topLevelDefinition .getName()); outputFileName += "_" + toValidName(instanceDesc.instanceDefinition.getName()).replace('.', '_') + "_instances"; outputFileName = fullyQualifiedNameToPath(outputFileName, FILE_EXT); return outputFileName; }
final String previousName = (String) map.put(toValidName(name), name); if (previousName != null && !previousName.equals(name)) { throw new CompilerError(GenericErrors.INTERNAL_ERROR,