コード例 #1
0
 protected void validateTranslatableString(Element element, Attr attr, boolean shouldTranslate) {
   if (!shouldTranslate) return;
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED);
   if (severity == CompilerFlags.IGNORE) return;
   String value = attr.getValue();
   if (!value.startsWith("%")) { // $NON-NLS-1$
     report(
         NLS.bind(MDECoreMessages.Builders_Manifest_non_ext_attribute, attr.getName()),
         getLine(element, attr.getName()),
         severity,
         MDEMarkerFactory.P_UNTRANSLATED_NODE,
         element,
         attr.getName(),
         MDEMarkerFactory.CAT_NLS);
   } else if (fModel instanceof AbstractNLModel) {
     NLResourceHelper helper = ((AbstractNLModel) fModel).getNLResourceHelper();
     if (helper == null || !helper.resourceExists(value)) {
       report(
           NLS.bind(MDECoreMessages.Builders_Manifest_key_not_found, value.substring(1)),
           getLine(element, attr.getName()),
           severity,
           MDEMarkerFactory.CAT_NLS);
     }
   }
 }
コード例 #2
0
 protected void validateResourceAttribute(Element element, Attr attr) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
   if (severity != CompilerFlags.IGNORE && !resourceExists(attr.getValue())) {
     report(
         NLS.bind(
             MDECoreMessages.Builders_Manifest_resource,
             (new String[] {attr.getValue(), attr.getName()})),
         getLine(element, attr.getName()),
         severity,
         MDEMarkerFactory.CAT_OTHER);
   }
 }
コード例 #3
0
 private void validateExistingExtensionAttributes(
     Element element, NamedNodeMap attrs, ISchemaElement schemaElement) {
   for (int i = 0; i < attrs.getLength(); i++) {
     Attr attr = (Attr) attrs.item(i);
     ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName());
     if (attInfo == null) {
       HashSet allowedElements = new HashSet();
       computeAllowedElements(schemaElement.getType(), allowedElements);
       if (allowedElements.contains(attr.getName())) {
         validateJavaAttribute(element, attr);
       } else {
         int flag = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
         if (flag != CompilerFlags.IGNORE) reportUnknownAttribute(element, attr.getName(), flag);
       }
     } else {
       validateExtensionAttribute(element, attr, attInfo);
     }
   }
 }
コード例 #4
0
 private void validateIdentifierAttribute(Element element, Attr attr, ISchemaAttribute attInfo) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_IDENTIFIER);
   if (severity != CompilerFlags.IGNORE) {
     String value = attr.getValue();
     String basedOn = attInfo.getBasedOn();
     // only validate if we have a valid value and basedOn value
     if (value != null && basedOn != null && value.length() > 0 && basedOn.length() > 0) {
       Map attributes = PDESchemaHelper.getValidAttributes(attInfo);
       if (!attributes.containsKey(value)) { // report error if we are missing something
         report(
             NLS.bind(
                 MDECoreMessages.ExtensionsErrorReporter_unknownIdentifier,
                 (new String[] {attr.getValue(), attr.getName()})),
             getLine(element, attr.getName()),
             severity,
             MDEMarkerFactory.CAT_OTHER);
       }
     }
   }
 }
コード例 #5
0
  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);
      }
    }
  }
コード例 #6
0
 protected void validateRestrictionAttribute(
     Element element, Attr attr, ISchemaRestriction restriction) {
   Object[] children = restriction.getChildren();
   String value = attr.getValue();
   for (int i = 0; i < children.length; i++) {
     Object child = children[i];
     if (child instanceof ISchemaEnumeration) {
       ISchemaEnumeration enumeration = (ISchemaEnumeration) child;
       if (enumeration.getName().equals(value)) {
         return;
       }
     }
   }
   reportIllegalAttributeValue(element, attr);
 }
コード例 #7
0
  protected void validateExtensionPoint(Element element) {
    if (assertAttributeDefined(element, "id", CompilerFlags.ERROR)) { // $NON-NLS-1$
      Attr idAttr = element.getAttributeNode("id"); // $NON-NLS-1$
      double schemaVersion = getSchemaVersion();
      String message = null;
      if (schemaVersion < 3.2 && !IdUtil.isValidSimpleID(idAttr.getValue()))
        message = NLS.bind(MDECoreMessages.Builders_Manifest_simpleID, idAttr.getValue());
      else if (schemaVersion >= 3.2) {
        if (!IdUtil.isValidCompositeID(idAttr.getValue())) {
          message = NLS.bind(MDECoreMessages.Builders_Manifest_compositeID, idAttr.getValue());
        }
      }

      if (message != null)
        report(
            message,
            getLine(element, idAttr.getName()),
            CompilerFlags.WARNING,
            MDEMarkerFactory.CAT_OTHER);
    }

    assertAttributeDefined(element, "name", CompilerFlags.ERROR); // $NON-NLS-1$

    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Attr attr = (Attr) attrs.item(i);
      String name = attr.getName();
      if ("name".equals(name)) { // $NON-NLS-1$
        validateTranslatableString(element, attr, true);
      } else if (!"id".equals(name)
          && !"schema".equals(name)
          && severity != CompilerFlags.IGNORE) { // $NON-NLS-1$ //$NON-NLS-2$
        reportUnknownAttribute(element, name, severity);
      }
    }

    severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
    if (severity != CompilerFlags.IGNORE) {
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++)
        reportIllegalElement((Element) children.item(i), severity);
    }

    // Validate the "schema" attribute of the extension point
    Attr attr = element.getAttributeNode(IMonitorExtensionPoint.P_SCHEMA);
    // Only validate the attribute if it was defined
    if (attr != null) {
      String schemaValue = attr.getValue();
      IResource res = getFile().getProject().findMember(schemaValue);
      String errorMessage = null;
      // Check to see if the value specified is an extension point schema and it exists
      if (!(res instanceof IFile
          && (res.getName().endsWith(".exsd")
              || //$NON-NLS-1$
              res.getName().endsWith(".mxsd")))) // $NON-NLS-1$
      errorMessage = MDECoreMessages.ExtensionsErrorReporter_InvalidSchema;
      // Report an error if one was found
      if (errorMessage != null) {
        severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
        if (severity != CompilerFlags.IGNORE)
          report(
              NLS.bind(errorMessage, schemaValue),
              getLine(element),
              severity,
              MDEMarkerFactory.CAT_OTHER);
      }
    }
  }