diff options
author | Jesse Wilson <jessewilson@google.com> | 2009-06-01 17:59:44 -0700 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2009-07-21 11:06:25 -0700 |
commit | 5e0dd414ff2ee5dfe69dec1f03bf584f0b223533 (patch) | |
tree | cff92c205329cd5084f013542b8914ec28cb7650 /tools/apicheck/src/com/android | |
parent | 3c3fae144e5ac97f094d53d6d4e758c2fd468c7d (diff) | |
download | build-5e0dd414ff2ee5dfe69dec1f03bf584f0b223533.zip build-5e0dd414ff2ee5dfe69dec1f03bf584f0b223533.tar.gz build-5e0dd414ff2ee5dfe69dec1f03bf584f0b223533.tar.bz2 |
Adding version information to DroidDoc. Rather than pulling the version from
@since tags in the code, it's pulled from the API XML files also used by
apicheck.
The code now reads the apicheck XML, and applies it's versions to the DroidDoc
class models. The models output the version to HDF, and that's picked up by
the CS templates.
The clearsilver templates will be changed to be pretty in a follow up change.
Diffstat (limited to 'tools/apicheck/src/com/android')
4 files changed, 76 insertions, 68 deletions
diff --git a/tools/apicheck/src/com/android/apicheck/ApiCheck.java b/tools/apicheck/src/com/android/apicheck/ApiCheck.java index f78117c..20a98ce 100644 --- a/tools/apicheck/src/com/android/apicheck/ApiCheck.java +++ b/tools/apicheck/src/com/android/apicheck/ApiCheck.java @@ -20,7 +20,6 @@ import org.xml.sax.*; import org.xml.sax.helpers.*; import java.io.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.Stack; public class ApiCheck { @@ -83,62 +82,62 @@ public class ApiCheck { } } - String xmlFileName = args.get(0); - String xmlFileNameNew = args.get(1); - XMLReader xmlreader = null; - try { - // parse the XML files into our data structures - xmlreader = XMLReaderFactory.createXMLReader(); - ApiCheck acheck = new ApiCheck(); - MakeHandler handler = acheck.new MakeHandler(); - xmlreader.setContentHandler(handler); - xmlreader.setErrorHandler(handler); - FileReader filereader = new FileReader(xmlFileName); - xmlreader.parse(new InputSource(filereader)); - FileReader filereaderNew = new FileReader(xmlFileNameNew); - xmlreader.parse(new InputSource(filereaderNew)); + ApiCheck acheck = new ApiCheck(); - // establish the superclass relationships - handler.getOldApi().resolveSuperclasses(); - handler.getNewApi().resolveSuperclasses(); - - // finally, run the consistency check - handler.getOldApi().isConsistent(handler.getNewApi()); + ApiInfo oldApi = acheck.parseApi(args.get(0)); + ApiInfo newApi = acheck.parseApi(args.get(1)); - } catch (SAXParseException e) { - Errors.error(Errors.PARSE_ERROR, - new SourcePositionInfo(xmlFileName, e.getLineNumber(), 0), - e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - Errors.error(Errors.PARSE_ERROR, - new SourcePositionInfo(xmlFileName, 0, 0), - e.getMessage()); - } + // only run the consistency check if we haven't had XML parse errors + if (!Errors.hadError) { + oldApi.isConsistent(newApi); + } Errors.printErrors(); System.exit(Errors.hadError ? 1 : 0); } - private class MakeHandler extends DefaultHandler { + public ApiInfo parseApi(String xmlFile) { + FileReader fileReader = null; + try { + XMLReader xmlreader = XMLReaderFactory.createXMLReader(); + MakeHandler handler = new MakeHandler(); + xmlreader.setContentHandler(handler); + xmlreader.setErrorHandler(handler); + fileReader = new FileReader(xmlFile); + xmlreader.parse(new InputSource(fileReader)); + ApiInfo apiInfo = handler.getApi(); + apiInfo.resolveSuperclasses(); + return apiInfo; + } catch (SAXParseException e) { + Errors.error(Errors.PARSE_ERROR, + new SourcePositionInfo(xmlFile, e.getLineNumber(), 0), + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + Errors.error(Errors.PARSE_ERROR, + new SourcePositionInfo(xmlFile, 0, 0), e.getMessage()); + } finally { + if (fileReader != null) { + try { + fileReader.close(); + } catch (IOException ignored) {} + } + } + return null; + } + + private static class MakeHandler extends DefaultHandler { - private Integer mWarningCount; - private ApiInfo mOriginalApi; - private ApiInfo mNewApi; - private boolean mOldApi; + private ApiInfo mApi; private PackageInfo mCurrentPackage; private ClassInfo mCurrentClass; private AbstractMethodInfo mCurrentMethod; - private ConstructorInfo mCurrentConstructor; private Stack<ClassInfo> mClassScope = new Stack<ClassInfo>(); - - + + public MakeHandler() { super(); - mOriginalApi = new ApiInfo(); - mNewApi = new ApiInfo(); - mOldApi = true; - + mApi = new ApiInfo(); } public void startElement(String uri, String localName, String qName, @@ -229,25 +228,11 @@ public class ApiCheck { mCurrentPackage.addClass(mCurrentClass); mCurrentClass = mClassScope.pop(); } else if (qName.equals("package")){ - if (mOldApi) { - mOriginalApi.addPackage(mCurrentPackage); - } else { - mNewApi.addPackage(mCurrentPackage); - } + mApi.addPackage(mCurrentPackage); } } - public void endDocument() { - mOldApi = !mOldApi; - } - - public ApiInfo getOldApi() { - return mOriginalApi; - } - - public ApiInfo getNewApi() { - return mNewApi; - } - - + public ApiInfo getApi() { + return mApi; } + } } diff --git a/tools/apicheck/src/com/android/apicheck/ClassInfo.java b/tools/apicheck/src/com/android/apicheck/ClassInfo.java index 4bbf78b..5405ad2 100644 --- a/tools/apicheck/src/com/android/apicheck/ClassInfo.java +++ b/tools/apicheck/src/com/android/apicheck/ClassInfo.java @@ -187,8 +187,8 @@ public class ClassInfo { } for (FieldInfo mInfo : mFields.values()) { - if (cl.mFields.containsKey(mInfo.qualifiedName())) { - if (!mInfo.isConsistent(cl.mFields.get(mInfo.qualifiedName()))) { + if (cl.mFields.containsKey(mInfo.name())) { + if (!mInfo.isConsistent(cl.mFields.get(mInfo.name()))) { consistent = false; } } else { @@ -267,7 +267,7 @@ public class ClassInfo { } public void addField(FieldInfo fInfo) { - mFields.put(fInfo.qualifiedName(), fInfo); + mFields.put(fInfo.name(), fInfo); } @@ -279,4 +279,26 @@ public class ClassInfo { return mExistsInBoth; } + public Map<String, ConstructorInfo> allConstructors() { + return mConstructors; + } + + public Map<String, FieldInfo> allFields() { + return mFields; + } + + public Map<String, MethodInfo> allMethods() { + return mMethods; + } + + /** + * Returns the class hierarchy for this class, starting with this class. + */ + public Iterable<ClassInfo> hierarchy() { + List<ClassInfo> result = new ArrayList<ClassInfo>(4); + for (ClassInfo c = this; c != null; c = c.mSuperClass) { + result.add(c); + } + return result; + } } diff --git a/tools/apicheck/src/com/android/apicheck/ConstructorInfo.java b/tools/apicheck/src/com/android/apicheck/ConstructorInfo.java index 57d7617..f36c7cd 100644 --- a/tools/apicheck/src/com/android/apicheck/ConstructorInfo.java +++ b/tools/apicheck/src/com/android/apicheck/ConstructorInfo.java @@ -55,11 +55,12 @@ public class ConstructorInfo implements AbstractMethodInfo { } public String getHashableName() { - String returnString = qualifiedName(); + StringBuilder result = new StringBuilder(); + result.append(name()); for (ParameterInfo pInfo : mParameters) { - returnString += ":" + pInfo.getType(); + result.append(":").append(pInfo.getType()); } - return returnString; + return result.toString(); } public boolean isInBoth() { diff --git a/tools/apicheck/src/com/android/apicheck/MethodInfo.java b/tools/apicheck/src/com/android/apicheck/MethodInfo.java index 86e20de..e4e4537 100644 --- a/tools/apicheck/src/com/android/apicheck/MethodInfo.java +++ b/tools/apicheck/src/com/android/apicheck/MethodInfo.java @@ -195,7 +195,7 @@ public class MethodInfo implements AbstractMethodInfo { } public String getHashableName() { - return qualifiedName() + getParameterHash(); + return name() + getParameterHash(); } public String getSignature() { |