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<String> 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); } } }
protected void validateTranslatableElementContent(Element element) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED); if (severity == CompilerFlags.IGNORE) return; String value = getTextContent(element); if (value == null) return; if (!value.startsWith("%")) { //$NON-NLS-1$ report(NLS.bind(PDECoreMessages.Builders_Manifest_non_ext_element, element.getNodeName()), getLine(element), severity, PDEMarkerFactory.P_UNTRANSLATED_NODE, element, null, PDEMarkerFactory.CAT_NLS); } else if (fModel instanceof AbstractNLModel) { NLResourceHelper helper = ((AbstractNLModel) fModel).getNLResourceHelper(); if (helper == null || !helper.resourceExists(value)) { report(NLS.bind(PDECoreMessages.Builders_Manifest_key_not_found, value.substring(1), PDEManager.getBundleLocalization(fModel).concat(".properties")), getLine(element), severity, PDEMarkerFactory.CAT_NLS); //$NON-NLS-1$ } } }
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(PDECoreMessages.Builders_Manifest_resource, (new String[] {attr.getValue(), attr.getName()})), getLine(element, attr.getName()), severity, PDEMarkerFactory.CAT_OTHER); } }
validateMaxElementMult(element, schemaElement); validateMinElementMult(element, schemaElement); reportIllegalElement(element, severity); return; if (severity != CompilerFlags.IGNORE) { HashSet<String> allowedElements = new HashSet<>(); computeAllowedElements(parentSchema.getType(), allowedElements); if (!allowedElements.contains(elementName)) { reportIllegalElement(element, severity); return; if (attr != null && attr.getKind() == IMetaAttribute.JAVA) { if (attr.isDeprecated()) reportDeprecatedAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$ validateJavaAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$ validateRequiredExtensionAttributes(element, schemaElement); validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement); validateInternalExtensionAttribute(element, schemaElement); if (schemaElement.isDeprecated()) { if (schemaElement instanceof ISchemaRootElement) reportDeprecatedRootElement(element, ((ISchemaRootElement) schemaElement).getDeprecatedSuggestion()); else reportDeprecatedElement(element); validateTranslatableElementContent(element);
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())) report(message, getLine(element, idAttr.getName()), CompilerFlags.WARNING, PDEMarkerFactory.CAT_OTHER); assertAttributeDefined(element, "name", CompilerFlags.ERROR); //$NON-NLS-1$ 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); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) reportIllegalElement((Element) children.item(i), severity); IResource res = getFile().getProject().findMember(schemaValue); String errorMessage = null; severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE); if (severity != CompilerFlags.IGNORE) report(NLS.bind(errorMessage, schemaValue), getLine(element), severity, PDEMarkerFactory.CAT_OTHER);
public void validateContent(IProgressMonitor monitor) { Element element = getDocumentRoot(); if (element == null) return; String elementName = element.getNodeName(); if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$ reportIllegalElement(element, CompilerFlags.ERROR); } else { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity); String name = child.getNodeName(); if (name.equals("extension")) { //$NON-NLS-1$ validateExtension(child); } else if (name.equals("extension-point")) { //$NON-NLS-1$ validateExtensionPoint(child); } else { if (!name.equals("runtime") && !name.equals("requires")) { //$NON-NLS-1$ //$NON-NLS-2$ severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity); } else { severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity);
private void validateExtensionAttribute(Element element, Attr attr, ISchemaAttribute attInfo) { ISchemaSimpleType type = attInfo.getType(); int kind = attInfo.getKind(); if (kind == IMetaAttribute.JAVA) { validateJavaAttribute(element, attr); } else if (kind == IMetaAttribute.RESOURCE) { validateResourceAttribute(element, attr); } else if (kind == IMetaAttribute.IDENTIFIER) { validateIdentifierAttribute(element, attr, attInfo); } else if (kind == IMetaAttribute.STRING) { ISchemaRestriction restriction = type.getRestriction(); if (restriction != null) { validateRestrictionAttribute(element, attr, restriction); } } else if (type.getName().equals("boolean")) { //$NON-NLS-1$ validateBoolean(element, attr); } validateTranslatableString(element, attr, attInfo.isTranslatable()); if (attInfo.isDeprecated()) { reportDeprecatedAttribute(element, attr); } }
protected void validateExtension(Element element) { if (!assertAttributeDefined(element, "point", CompilerFlags.ERROR)) //$NON-NLS-1$ return; String pointID = element.getAttribute("point"); //$NON-NLS-1$ IPluginExtensionPoint point = PDEStateHelper.findExtensionPoint(pointID); if (point == null) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_EX_POINTS); if (severity != CompilerFlags.IGNORE) { report(NLS.bind(PDECoreMessages.Builders_Manifest_ex_point, pointID), getLine(element, "point"), severity, PDEMarkerFactory.CAT_OTHER); //$NON-NLS-1$ } } else { SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry(); ISchema schema = registry.getSchema(pointID); if (schema != null) { validateElement(element, schema, true); } } }
private void computeAllowedElements(ISchemaCompositor compositor, HashSet<String> elementSet) { ISchemaObject[] children = compositor.getChildren(); for (int i = 0; i < children.length; i++) { ISchemaObject child = children[i]; if (child instanceof ISchemaObjectReference) { ISchemaObjectReference ref = (ISchemaObjectReference) child; ISchemaElement refElement = (ISchemaElement) ref.getReferencedObject(); if (refElement != null) elementSet.add(refElement.getName()); } else if (child instanceof ISchemaCompositor) { computeAllowedElements((ISchemaCompositor) child, elementSet); } } }
if (bundleManifest.exists()) { if ((type & EXTENSIONS) != 0) reporter = new ExtensionsErrorReporter(file); if ((type & MANIFEST) != 0) bundleReporter = new BundleErrorReporter(bundleManifest);
validateMaxElementMult(element, schemaElement); validateMinElementMult(element, schemaElement); reportIllegalElement(element, severity); return; if (severity != CompilerFlags.IGNORE) { HashSet allowedElements = new HashSet(); computeAllowedElements(parentSchema.getType(), allowedElements); if (!allowedElements.contains(elementName)) { reportIllegalElement(element, severity); return; if (attr != null && attr.getKind() == IMetaAttribute.JAVA) { if (attr.isDeprecated()) reportDeprecatedAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$ validateJavaAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$ validateRequiredExtensionAttributes(element, schemaElement); validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement); if (schemaElement.isDeprecated()) { if (schemaElement instanceof ISchemaRootElement) reportDeprecatedRootElement(element, ((ISchemaRootElement)schemaElement).getDeprecatedSuggestion()); else reportDeprecatedElement(element); validateTranslatableElementContent(element);
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())) report(message, getLine(element, idAttr.getName()), CompilerFlags.WARNING, PDEMarkerFactory.CAT_OTHER); assertAttributeDefined(element, "name", CompilerFlags.ERROR); //$NON-NLS-1$ 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); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) reportIllegalElement((Element)children.item(i), severity); IResource res = getFile().getProject().findMember(schemaValue); String errorMessage = null; severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE); if (severity != CompilerFlags.IGNORE) report(NLS.bind(errorMessage, schemaValue), getLine(element), severity, PDEMarkerFactory.CAT_OTHER);
@Override public void validateContent(IProgressMonitor monitor) { Element element = getDocumentRoot(); if (element == null) return; String elementName = element.getNodeName(); if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$ reportIllegalElement(element, CompilerFlags.ERROR); } else { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity); String name = child.getNodeName(); if (name.equals("extension")) { //$NON-NLS-1$ validateExtension(child); } else if (name.equals("extension-point")) { //$NON-NLS-1$ validateExtensionPoint(child); } else { if (!name.equals("runtime") && !name.equals("requires")) { //$NON-NLS-1$ //$NON-NLS-2$ severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity); } else { severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity);
private void validateExtensionAttribute(Element element, Attr attr, ISchemaAttribute attInfo) { ISchemaSimpleType type = attInfo.getType(); ISchemaRestriction restriction = type.getRestriction(); if (restriction != null) { validateRestrictionAttribute(element, attr, restriction); } int kind = attInfo.getKind(); if (kind == IMetaAttribute.JAVA) { validateJavaAttribute(element, attr); } else if (kind == IMetaAttribute.RESOURCE) { validateResourceAttribute(element, attr); } else if (type.getName().equals("boolean")) { //$NON-NLS-1$ validateBoolean(element, attr); } validateTranslatableString(element, attr, attInfo.isTranslatable()); if (attInfo.isDeprecated()) { reportDeprecatedAttribute(element, attr); } }
protected void validateExtension(Element element) { if (!assertAttributeDefined(element, "point", CompilerFlags.ERROR)) //$NON-NLS-1$ return; String pointID = element.getAttribute("point"); //$NON-NLS-1$ if (!PDECore.getDefault().getExtensionsRegistry().hasExtensionPoint(pointID)) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_EX_POINTS); if (severity != CompilerFlags.IGNORE) { report(NLS.bind(PDECoreMessages.Builders_Manifest_ex_point, pointID), getLine(element, "point"), severity, PDEMarkerFactory.CAT_OTHER); //$NON-NLS-1$ } } else { SchemaRegistry reg = PDECore.getDefault().getSchemaRegistry(); ISchema schema = reg.getSchema(pointID); if (schema != null) { validateElement(element, schema, true); } } }
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(PDECoreMessages.Builders_Manifest_resource, (new String[] { attr.getValue(), attr.getName() })), getLine(element, attr.getName()), severity, PDEMarkerFactory.CAT_OTHER); } }
private void computeAllowedElements(ISchemaCompositor compositor, HashSet elementSet) { ISchemaObject[] children = compositor.getChildren(); for (int i = 0; i < children.length; i++) { ISchemaObject child = children[i]; if (child instanceof ISchemaObjectReference) { ISchemaObjectReference ref = (ISchemaObjectReference) child; ISchemaElement refElement = (ISchemaElement) ref .getReferencedObject(); if (refElement != null) elementSet.add(refElement.getName()); } else if (child instanceof ISchemaCompositor) { computeAllowedElements((ISchemaCompositor) child, elementSet); } } }
if (bundleManifest.exists()) { if ((type & EXTENSIONS) != 0) reporter = new ExtensionsErrorReporter(file); if ((type & MANIFEST) != 0) bundleReporter = new BundleErrorReporter(bundleManifest);