root = Util.parseDocument(xml); } catch (CoreException ce) { abort("Failed to parse API description xml file", ce); //$NON-NLS-1$ abort(ScannerMessages.ComponentXMLScanner_0, null); String name = type.getAttribute(IApiXmlConstants.ATTR_NAME); if (name.length() == 0) { abort("Missing type name", null); //$NON-NLS-1$ annotateDescriptor(project, settings, typedesc, type, earlierversion); annotateMethodSettings(project, settings, typedesc, type, earlierversion); annotateFieldSettings(project, settings, typedesc, type, earlierversion);
/** * Annotates the backing {@link IApiDescription} from the given * {@link Element}, by adding the visibility and restriction attributes to * the specified {@link IElementDescriptor} * * @param settings the settings to annotate * @param descriptor the current descriptor context * @param element the current element to annotate from * @param earlierversion if the version read from XML is older than the * current tooling version */ private static void annotateDescriptor(IJavaProject project, IApiDescription settings, IElementDescriptor descriptor, Element element, boolean earlierversion) { int typeVis = getVisibility(element); if (typeVis != -1) { settings.setVisibility(descriptor, typeVis); } settings.setRestrictions(descriptor, getRestrictions(project, element, descriptor, earlierversion)); }
name = method.getAttribute(IApiXmlConstants.ATTR_NAME); if (name == null) { abort(ScannerMessages.ComponentXMLScanner_2, null); abort(ScannerMessages.ComponentXMLScanner_3, null); annotateDescriptor(project, settings, methoddesc, method, earlierversion);
try { HashMap map = new HashMap(); ApiDescriptionProcessor.collectTagUpdates(project, cxml, map); IFile file = null; TextFileChange change = null;
/** * This method updates the javadoc for members of the specified java source * files with information retrieved from the the specified component.xml * file. * * @param project the java project to update * @param componentxml the component.xml file to update from * @param collector * @throws CoreException * @throws IOException */ public static void collectTagUpdates(IJavaProject project, File componentxml, Map<IFile, Set<TextEdit>> collector) throws CoreException, IOException { IApiDescription description = new ApiDescription(null); annotateApiSettings(project, description, serializeComponentXml(componentxml)); // visit the types DescriptionVisitor visitor = new DescriptionVisitor(project, description, collector); description.accept(visitor, null); IStatus status = visitor.getStatus(); if (!status.isOK()) { throw new CoreException(status); } }
switch (descriptor.getElementType()) { case IElementDescriptor.FIELD: { res = annotateRestriction(element, IApiXmlConstants.ATTR_REFERENCE, RestrictionModifiers.NO_REFERENCE, res); break; res = annotateRestriction(element, IApiXmlConstants.ATTR_REFERENCE, RestrictionModifiers.NO_REFERENCE, res); if (!method.isConstructor()) { res = annotateRestriction(element, IApiXmlConstants.ATTR_OVERRIDE, RestrictionModifiers.NO_OVERRIDE, res); res = annotateRestriction(element, IApiXmlConstants.ATTR_IMPLEMENT, RestrictionModifiers.NO_IMPLEMENT, res); if (earlierversion && RestrictionModifiers.isImplementRestriction(res)) { res |= RestrictionModifiers.NO_EXTEND; res = annotateRestriction(element, IApiXmlConstants.ATTR_EXTEND, RestrictionModifiers.NO_EXTEND, res); if (!RestrictionModifiers.isExtendRestriction(res)) { res = annotateRestriction(element, IApiXmlConstants.ATTR_SUBCLASS, RestrictionModifiers.NO_EXTEND, res); res = annotateRestriction(element, IApiXmlConstants.ATTR_INSTANTIATE, RestrictionModifiers.NO_INSTANTIATE, res); IType type = null; if (project != null) {
@Override public void endVisitElement(IElementDescriptor element, IApiAnnotations description) { if (element.getElementType() == IElementDescriptor.TYPE) { IReferenceTypeDescriptor refType = (IReferenceTypeDescriptor) element; try { IReferenceTypeDescriptor topLevelType = refType.getEnclosingType(); while (topLevelType != null) { refType = topLevelType; topLevelType = refType.getEnclosingType(); } IType type = project.findType(refType.getQualifiedName(), new NullProgressMonitor()); IType typeInProject = Util.getTypeInSameJavaProject(type, refType.getQualifiedName(), project); if (typeInProject != null) { type = typeInProject; } if (type != null) { processTagUpdates(type, refType, apiDescription, members, fCollector); } } catch (CoreException e) { addStatus(e.getStatus()); } catch (BadLocationException e) { addStatus(new Status(IStatus.ERROR, ApiPlugin.PLUGIN_ID, ScannerMessages.ComponentXMLScanner_0 + element.toString(), e)); } members.clear(); } }
/** * Creates and returns this component's API description based on packages * supplied by this component, exported packages, and associated directives. * * @return API description * @throws CoreException if unable to initialize */ protected IApiDescription createLocalApiDescription() throws CoreException { IApiDescription apiDesc = new ApiDescription(getSymbolicName()); // first mark all packages as internal initializeApiDescription(apiDesc, getBundleDescription(), getLocalPackageNames()); try { String xml = loadApiDescription(new File(fLocation)); setHasApiDescription(xml != null); if (xml != null) { ApiDescriptionProcessor.annotateApiSettings(null, apiDesc, xml); } } catch (IOException e) { abort("Unable to load .api_description file ", e); //$NON-NLS-1$ } return apiDesc; }
/** * Annotates the supplied {@link IApiDescription} from all of the field * elements that are direct children of the specified {@link Element}. * {@link IFieldDescriptor}s are created as needed and added as children of * the specified {@link IReferenceTypeDescriptor}. * * @param settings the {@link IApiDescription} to add the new * {@link IFieldDescriptor} to * @param typedesc the containing type descriptor for this field * @param type the parent {@link Element} * @param earlierversion if the version read from XML is older than the * current tooling version * @throws CoreException */ private static void annotateFieldSettings(IJavaProject project, IApiDescription settings, IReferenceTypeDescriptor typedesc, Element type, boolean earlierversion) throws CoreException { NodeList fields = type.getElementsByTagName(IApiXmlConstants.ELEMENT_FIELD); Element field = null; IFieldDescriptor fielddesc = null; String name = null; for (int i = 0; i < fields.getLength(); i++) { field = (Element) fields.item(i); name = field.getAttribute(IApiXmlConstants.ATTR_NAME); if (name == null) { abort(ScannerMessages.ComponentXMLScanner_1, null); } fielddesc = typedesc.getField(name); annotateDescriptor(project, settings, fielddesc, field, earlierversion); } }
try { HashMap<IFile, Set<TextEdit>> map = new HashMap<>(); ApiDescriptionProcessor.collectTagUpdates(project, cxml, map); IFile file = null; TextFileChange change = null;