Example #1
0
  /**
   * Creates a default package name based on the name of the project. If the project name is not a
   * valid java identifier, this method will return the given class name converted to lower case.
   *
   * @param project the project to generate the package name from
   * @param className class name to use as package name if project name fails
   */
  public static String createDefaultPackageName(IProject project, String className) {
    String id = project.getName().toLowerCase(Locale.ENGLISH);
    IStatus status =
        JavaConventions.validatePackageName(
            id,
            PDEJavaHelper.getJavaSourceLevel(project),
            PDEJavaHelper.getJavaComplianceLevel(project));
    if (status.getSeverity() == IStatus.ERROR) return className.toLowerCase(Locale.ENGLISH);

    return id;
  }
  protected void validateJavaAttribute(Element element, Attr attr) {
    String value = attr.getValue();
    IJavaProject javaProject = JavaCore.create(fFile.getProject());

    // be careful: people have the option to use the format:
    // fullqualifiedName:staticMethod
    int index = value.indexOf(":"); // $NON-NLS-1$
    if (index != -1) value = value.substring(0, index);

    // assume we're on the classpath already
    boolean onClasspath = true;
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_CLASS);
    if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) {
      onClasspath = PDEJavaHelper.isOnClasspath(value, javaProject);
      if (!onClasspath) {
        report(
            NLS.bind(
                MDECoreMessages.Builders_Manifest_class, (new String[] {value, attr.getName()})),
            getLine(element, attr.getName()),
            severity,
            MDEMarkerFactory.P_UNKNOWN_CLASS,
            element,
            attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(),
            MDEMarkerFactory.CAT_FATAL);
      }
    }

    severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DISCOURAGED_CLASS);
    if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) {
      BundleDescription desc = fModel.getBundleDescription();
      if (desc == null) return;
      // only check if we're discouraged if there is something on the classpath
      if (onClasspath && PDEJavaHelper.isDiscouraged(value, javaProject, desc)) {
        report(
            NLS.bind(
                MDECoreMessages.Builders_Manifest_discouragedClass,
                (new String[] {value, attr.getName()})),
            getLine(element, attr.getName()),
            severity,
            MDEMarkerFactory.M_DISCOURAGED_CLASS,
            element,
            attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(),
            MDEMarkerFactory.CAT_OTHER);
      }
    }
  }