Autoformat the api-checker tool source Review at http://gwt-code-reviews.appspot.com/1405801 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10003 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java index 00fc0bc..6bd042b 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java
@@ -28,8 +28,7 @@ /** * abstract super-class for ApiMethod and ApiConstructor. */ -abstract class ApiAbstractMethod implements Comparable<ApiAbstractMethod>, - ApiElement { +abstract class ApiAbstractMethod implements Comparable<ApiAbstractMethod>, ApiElement { static String computeApiSignature(JAbstractMethod method) { String className = method.getEnclosingType().getQualifiedSourceName(); @@ -117,8 +116,8 @@ return false; } for (int i = 0; i < length; i++) { - if (!ApiDiffGenerator.isFirstTypeAssignableToSecond( - method.getParameters()[i].getType(), parametersInNew[i].getType())) { + if (!ApiDiffGenerator.isFirstTypeAssignableToSecond(method.getParameters()[i].getType(), + parametersInNew[i].getType())) { return false; } } @@ -144,11 +143,11 @@ apiChanges.add(returnApiChange); return apiChanges; } - + abstract ApiChange checkReturnTypeCompatibility(ApiAbstractMethod newMethod); abstract List<ApiChange> getAllChangesInApi(ApiAbstractMethod newMethod); - + String getApiSignature() { if (apiSignature == null) { apiSignature = computeApiSignature(method); @@ -162,7 +161,7 @@ * <p> * Useful to determine the method overloading because a null could be passed * for a primitive type. - * <p> + * <p> * Not sure if the implementation is sufficient. If need be, look at the * implementation below. * @@ -187,7 +186,7 @@ * return returnStr.toString(); * } * </pre> - * + * * @return the coarse signature as a String */ String getCoarseSignature() { @@ -237,8 +236,7 @@ for (JType newException : newMethod.getMethod().getThrows()) { boolean isSubclass = false; for (JType legalType : legalTypes) { - if (ApiDiffGenerator.isFirstTypeAssignableToSecond(newException, - legalType)) { + if (ApiDiffGenerator.isFirstTypeAssignableToSecond(newException, legalType)) { isSubclass = true; break; } @@ -259,11 +257,10 @@ + "::" + signature + " defined in " - + (enclosingType == null ? "null enclosing type " - : enclosingType.getQualifiedSourceName()); + + (enclosingType == null ? "null enclosing type " : enclosingType + .getQualifiedSourceName()); } - return apiClass.getClassObject().getQualifiedSourceName() + "::" - + signature; + return apiClass.getClassObject().getQualifiedSourceName() + "::" + signature; } }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiChange.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiChange.java index ec37077..1aae13c 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiChange.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiChange.java
@@ -100,7 +100,7 @@ public int compareTo(ApiChange arg0) { return this.toString().compareTo(arg0.toString()); } - + @Override public boolean equals(Object o) { if (!(o instanceof ApiChange)) { @@ -108,7 +108,7 @@ } return this.toString().equals(o.toString()); } - + public ApiElement getApiElement() { return element; } @@ -123,8 +123,8 @@ public String getStringRepresentationWithoutMessage() { if (stringRepresentationWithoutMessage == null) { - stringRepresentationWithoutMessage = element.getRelativeSignature() - + ApiDiffGenerator.DELIMITER + status.name(); + stringRepresentationWithoutMessage = + element.getRelativeSignature() + ApiDiffGenerator.DELIMITER + status.name(); } return stringRepresentationWithoutMessage; } @@ -142,8 +142,9 @@ @Override public String toString() { if (stringRepresentation == null) { - stringRepresentation = getStringRepresentationWithoutMessage() - + (message == null ? "" : (ApiDiffGenerator.DELIMITER + message)); + stringRepresentation = + getStringRepresentationWithoutMessage() + + (message == null ? "" : (ApiDiffGenerator.DELIMITER + message)); } return stringRepresentation; }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClass.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClass.java index ff62d3c..ef714ce 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClass.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClass.java
@@ -84,7 +84,7 @@ public int compareTo(ApiClass other) { return getName().compareTo(other.getName()); } - + @Override public boolean equals(Object o) { if (!(o instanceof ApiClass)) { @@ -92,7 +92,7 @@ } return this.getName().equals(((ApiClass) o).getName()); } - + public String getRelativeSignature() { return classType.getQualifiedSourceName(); } @@ -111,22 +111,20 @@ StringBuffer sb = new StringBuffer(); sb.append("\t" + getName() + "\n"); if (apiFields != null) { - ArrayList<ApiField> apiFieldsList = new ArrayList<ApiField>( - apiFields.values()); + ArrayList<ApiField> apiFieldsList = new ArrayList<ApiField>(apiFields.values()); Collections.sort(apiFieldsList); for (ApiField apiField : apiFieldsList) { sb.append("\t\t" + apiField.getRelativeSignature() + "\n"); } } - if (apiMembersByName != null - && apiMembersByName.get(MethodType.METHOD) != null) { + if (apiMembersByName != null && apiMembersByName.get(MethodType.METHOD) != null) { for (MethodType method : MethodType.values()) { HashSet<ApiAbstractMethod> apiMethodsSet = new HashSet<ApiAbstractMethod>(); for (Set<ApiAbstractMethod> methodsSets : apiMembersByName.get(method).values()) { apiMethodsSet.addAll(methodsSets); } - ArrayList<ApiAbstractMethod> apiMethodsList = new ArrayList<ApiAbstractMethod>( - apiMethodsSet); + ArrayList<ApiAbstractMethod> apiMethodsList = + new ArrayList<ApiAbstractMethod>(apiMethodsSet); Collections.sort(apiMethodsList); for (ApiAbstractMethod apiMethod : apiMethodsList) { sb.append("\t\t" + apiMethod.getRelativeSignature() + "\n"); @@ -162,8 +160,7 @@ return new HashSet<String>(apiMembersByName.get(type).keySet()); } - Set<ApiAbstractMethod> getApiMembersBySet(Set<String> methodNames, - MethodType type) { + Set<ApiAbstractMethod> getApiMembersBySet(Set<String> methodNames, MethodType type) { Map<String, Set<ApiAbstractMethod>> current = apiMembersByName.get(type); Set<ApiAbstractMethod> tempMethods = new HashSet<ApiAbstractMethod>(); for (String methodName : methodNames) { @@ -295,8 +292,7 @@ JMethod existing = methodsBySignature.put(signature, method); if (existing != null) { // decide which implementation to keep - if (existing.getEnclosingType().isAssignableTo( - method.getEnclosingType())) { + if (existing.getEnclosingType().isAssignableTo(method.getEnclosingType())) { methodsBySignature.put(signature, existing); } } @@ -321,11 +317,10 @@ } private void initializeApiConstructorsAndMethods() { - apiMembersByName = new EnumMap<MethodType, Map<String, Set<ApiAbstractMethod>>>( - MethodType.class); + apiMembersByName = + new EnumMap<MethodType, Map<String, Set<ApiAbstractMethod>>>(MethodType.class); for (MethodType method : MethodType.values()) { - apiMembersByName.put(method, - new HashMap<String, Set<ApiAbstractMethod>>()); + apiMembersByName.put(method, new HashMap<String, Set<ApiAbstractMethod>>()); Map<String, Set<ApiAbstractMethod>> pointer = apiMembersByName.get(method); List<String> notAddedMembers = new ArrayList<String>(); JAbstractMethod jams[] = getAccessibleMethods(method); @@ -352,9 +347,8 @@ } } if (notAddedMembers.size() > 0) { - logger.log(TreeLogger.SPAM, "class " + getName() + ", removing " - + notAddedMembers.size() + " nonApi members: " + notAddedMembers, - null); + logger.log(TreeLogger.SPAM, "class " + getName() + ", removing " + notAddedMembers.size() + + " nonApi members: " + notAddedMembers, null); } } }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java index 80288a6..f9460a8 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java
@@ -33,8 +33,7 @@ */ final class ApiClassDiffGenerator implements Comparable<ApiClassDiffGenerator> { - static final Collection<ApiChange> EMPTY_COLLECTION = new ArrayList<ApiChange>( - 0); + static final Collection<ApiChange> EMPTY_COLLECTION = new ArrayList<ApiChange>(0); static String printSetWithHashCode(Set<?> set, String identifier) { StringBuffer sb = new StringBuffer(); @@ -66,27 +65,24 @@ private final ApiClass oldClass; - ApiClassDiffGenerator(String className, - ApiPackageDiffGenerator apiPackageDiffGenerator) throws NotFoundException { + ApiClassDiffGenerator(String className, ApiPackageDiffGenerator apiPackageDiffGenerator) + throws NotFoundException { this.className = className; apiDiffGenerator = apiPackageDiffGenerator.getApiDiffGenerator(); - this.newClass = apiPackageDiffGenerator.getNewApiPackage().getApiClass( - className); - this.oldClass = apiPackageDiffGenerator.getOldApiPackage().getApiClass( - className); + this.newClass = apiPackageDiffGenerator.getNewApiPackage().getApiClass(className); + this.oldClass = apiPackageDiffGenerator.getOldApiPackage().getApiClass(className); if (newClass == null || oldClass == null) { - throw new NotFoundException("for class " + className - + ", one of the class objects is null"); + throw new NotFoundException("for class " + className + ", one of the class objects is null"); } intersectingFields = new HashMap<ApiField, Set<ApiChange>>(); - intersectingMethods = new EnumMap<ApiClass.MethodType, Map<ApiAbstractMethod, Set<ApiChange>>>( - ApiClass.MethodType.class); - missingMethods = new EnumMap<ApiClass.MethodType, Set<ApiAbstractMethod>>( - ApiClass.MethodType.class); + intersectingMethods = + new EnumMap<ApiClass.MethodType, Map<ApiAbstractMethod, Set<ApiChange>>>( + ApiClass.MethodType.class); + missingMethods = + new EnumMap<ApiClass.MethodType, Set<ApiAbstractMethod>>(ApiClass.MethodType.class); for (ApiClass.MethodType methodType : ApiClass.MethodType.values()) { - intersectingMethods.put(methodType, - new HashMap<ApiAbstractMethod, Set<ApiChange>>()); + intersectingMethods.put(methodType, new HashMap<ApiAbstractMethod, Set<ApiChange>>()); } } @@ -98,7 +94,7 @@ public int compareTo(ApiClassDiffGenerator other) { return getName().compareTo(other.getName()); } - + @Override public boolean equals(Object o) { if (!(o instanceof ApiClassDiffGenerator)) { @@ -116,18 +112,15 @@ void computeApiDiff() { Set<String> newFieldNames = newClass.getApiFieldNames(); Set<String> oldFieldNames = oldClass.getApiFieldNames(); - Set<String> intersection = ApiDiffGenerator.removeIntersection( - newFieldNames, oldFieldNames); + Set<String> intersection = ApiDiffGenerator.removeIntersection(newFieldNames, oldFieldNames); missingFields = oldClass.getApiFieldsBySet(oldFieldNames); processFieldsInIntersection(intersection); for (ApiClass.MethodType methodType : ApiClass.MethodType.values()) { Set<String> newMethodNames = newClass.getApiMemberNames(methodType); Set<String> oldMethodNames = oldClass.getApiMemberNames(methodType); - intersection = ApiDiffGenerator.removeIntersection(newMethodNames, - oldMethodNames); - missingMethods.put(methodType, oldClass.getApiMembersBySet( - oldMethodNames, methodType)); + intersection = ApiDiffGenerator.removeIntersection(newMethodNames, oldMethodNames); + missingMethods.put(methodType, oldClass.getApiMembersBySet(oldMethodNames, methodType)); processElementsInIntersection(intersection, methodType); } } @@ -158,8 +151,7 @@ * Even though the method name is contained in the "property" parameter, the * type information is lost. TODO (amitmanjhi): fix this issue later. */ - private <T> void addProperty(Map<T, Set<ApiChange>> hashMap, T key, - ApiChange property) { + private <T> void addProperty(Map<T, Set<ApiChange>> hashMap, T key, ApiChange property) { Set<ApiChange> value = hashMap.get(key); if (value == null) { value = new HashSet<ApiChange>(); @@ -170,8 +162,7 @@ private Collection<ApiChange> getIntersectingFields() { Collection<ApiChange> collection = new ArrayList<ApiChange>(); - List<ApiField> intersectingFieldsList = new ArrayList<ApiField>( - intersectingFields.keySet()); + List<ApiField> intersectingFieldsList = new ArrayList<ApiField>(intersectingFields.keySet()); Collections.sort(intersectingFieldsList); for (ApiField apiField : intersectingFieldsList) { for (ApiChange apiChange : intersectingFields.get(apiField)) { @@ -181,11 +172,10 @@ return collection; } - private Collection<ApiChange> getIntersectingMethods( - ApiClass.MethodType methodType) { + private Collection<ApiChange> getIntersectingMethods(ApiClass.MethodType methodType) { Collection<ApiChange> collection = new ArrayList<ApiChange>(); - List<ApiAbstractMethod> apiMethodsList = new ArrayList<ApiAbstractMethod>( - intersectingMethods.get(methodType).keySet()); + List<ApiAbstractMethod> apiMethodsList = + new ArrayList<ApiAbstractMethod>(intersectingMethods.get(methodType).keySet()); Collections.sort(apiMethodsList); for (ApiAbstractMethod apiMethod : apiMethodsList) { collection.addAll(intersectingMethods.get(methodType).get(apiMethod)); @@ -195,8 +185,8 @@ private Collection<ApiChange> getMissingMethods(ApiClass.MethodType methodType) { Collection<ApiChange> collection = new ArrayList<ApiChange>(); - List<ApiAbstractMethod> apiMethodsList = new ArrayList<ApiAbstractMethod>( - missingMethods.get(methodType)); + List<ApiAbstractMethod> apiMethodsList = + new ArrayList<ApiAbstractMethod>(missingMethods.get(methodType)); Collections.sort(apiMethodsList); for (ApiAbstractMethod apiMethod : apiMethodsList) { collection.add(new ApiChange(apiMethod, ApiChange.Status.MISSING)); @@ -214,10 +204,9 @@ * @return the possible incompatibilities due to method overloading. */ private Map<ApiAbstractMethod, ApiChange> getOverloadedMethodIncompatibility( - Set<ApiAbstractMethod> methodsInNew, - Set<ApiAbstractMethod> methodsInExisting) { - if (!ApiCompatibilityChecker.API_SOURCE_COMPATIBILITY - || methodsInExisting.size() != 1 || methodsInNew.size() <= 1) { + Set<ApiAbstractMethod> methodsInNew, Set<ApiAbstractMethod> methodsInExisting) { + if (!ApiCompatibilityChecker.API_SOURCE_COMPATIBILITY || methodsInExisting.size() != 1 + || methodsInNew.size() <= 1) { return Collections.emptyMap(); } ApiAbstractMethod existingMethod = methodsInExisting.toArray(new ApiAbstractMethod[0])[0]; @@ -231,11 +220,12 @@ if (isPairwiseCompatible(matchingMethods)) { return Collections.emptyMap(); } - Map<ApiAbstractMethod, ApiChange> incompatibilities = new HashMap<ApiAbstractMethod, ApiChange>(); + Map<ApiAbstractMethod, ApiChange> incompatibilities = + new HashMap<ApiAbstractMethod, ApiChange>(); incompatibilities.put(existingMethod, new ApiChange(existingMethod, ApiChange.Status.OVERLOADED_METHOD_CALL, - "Many methods in the new API with similar signatures. Methods = " - + methodsInNew + " This might break API source compatibility")); + "Many methods in the new API with similar signatures. Methods = " + methodsInNew + + " This might break API source compatibility")); return incompatibilities; } @@ -248,8 +238,7 @@ for (int j = i + 1; j < length; j++) { ApiAbstractMethod firstMethod = methods.get(i); ApiAbstractMethod secondMethod = methods.get(j); - if (!firstMethod.isCompatible(secondMethod) - && !secondMethod.isCompatible(firstMethod)) { + if (!firstMethod.isCompatible(secondMethod) && !secondMethod.isCompatible(firstMethod)) { return false; } } @@ -267,23 +256,22 @@ ApiClass.MethodType methodType) { Set<ApiAbstractMethod> missingElements = missingMethods.get(methodType); - Map<ApiAbstractMethod, Set<ApiChange>> intersectingElements = intersectingMethods.get(methodType); + Map<ApiAbstractMethod, Set<ApiChange>> intersectingElements = + intersectingMethods.get(methodType); Set<ApiAbstractMethod> onlyInExisting = new HashSet<ApiAbstractMethod>(); Set<ApiAbstractMethod> onlyInNew = new HashSet<ApiAbstractMethod>(); Set<String> commonSignature = new HashSet<String>(); for (String elementName : intersection) { - Set<ApiAbstractMethod> methodsInNew = newClass.getApiMethodsByName( - elementName, methodType); - Set<ApiAbstractMethod> methodsInExisting = oldClass.getApiMethodsByName( - elementName, methodType); + Set<ApiAbstractMethod> methodsInNew = newClass.getApiMethodsByName(elementName, methodType); + Set<ApiAbstractMethod> methodsInExisting = + oldClass.getApiMethodsByName(elementName, methodType); onlyInNew.addAll(methodsInNew); onlyInExisting.addAll(methodsInExisting); - Map<ApiAbstractMethod, ApiChange> incompatibilityMap = getOverloadedMethodIncompatibility( - methodsInNew, methodsInExisting); - for (Map.Entry<ApiAbstractMethod, ApiChange> entry - : incompatibilityMap.entrySet()) { + Map<ApiAbstractMethod, ApiChange> incompatibilityMap = + getOverloadedMethodIncompatibility(methodsInNew, methodsInExisting); + for (Map.Entry<ApiAbstractMethod, ApiChange> entry : incompatibilityMap.entrySet()) { addProperty(intersectingElements, entry.getKey(), entry.getValue()); } @@ -314,15 +302,12 @@ for (ApiChange.Status status : methodInExisting.getModifierChanges(methodInNew)) { currentApiChange.add(new ApiChange(methodInExisting, status)); } - if (methodInNew.getInternalSignature().equals( - methodInExisting.getInternalSignature())) { - currentApiChange.add(new ApiChange(methodInExisting, - ApiChange.Status.COMPATIBLE)); + if (methodInNew.getInternalSignature().equals(methodInExisting.getInternalSignature())) { + currentApiChange.add(new ApiChange(methodInExisting, ApiChange.Status.COMPATIBLE)); hasSameSignature = true; } else { currentApiChange.add(new ApiChange(methodInExisting, - ApiChange.Status.COMPATIBLE_WITH, - methodInNew.getApiSignature())); + ApiChange.Status.COMPATIBLE_WITH, methodInNew.getApiSignature())); } } @@ -370,8 +355,7 @@ for (ApiAbstractMethod methodInNew : methodsInNew) { ApiAbstractMethod sameSignatureMethod = null; for (ApiAbstractMethod methodInExisting : methodsInExisting) { - if (methodInNew.getInternalSignature().equals( - methodInExisting.getInternalSignature())) { + if (methodInNew.getInternalSignature().equals(methodInExisting.getInternalSignature())) { sameSignatureMethod = methodInExisting; break; }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java index 61c3b5b..14805d1 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java
@@ -126,8 +126,7 @@ try { return new FileInputStream(file); } catch (FileNotFoundException e) { - throw new RuntimeException("Unable to open file '" - + file.getAbsolutePath() + "'", e); + throw new RuntimeException("Unable to open file '" + file.getAbsolutePath() + "'", e); } } @@ -187,8 +186,8 @@ private final JarFile jarFiles[]; private Set<Resource> resources = null; - JarFileResources(JarFile[] jarFiles, Set<String> includedPaths, - Set<String> excludedPaths, TreeLogger logger) { + JarFileResources(JarFile[] jarFiles, Set<String> includedPaths, Set<String> excludedPaths, + TreeLogger logger) { super(logger); this.jarFiles = jarFiles; this.includedPaths = includedPaths; @@ -220,8 +219,7 @@ if (fileName.endsWith(".java") && isIncluded(fileName)) { // add this compilation unit String fileContent = getFileContentsFromJar(jarFile, jarEntry); - String packageName = extractPackageName(new StringReader( - fileContent)); + String packageName = extractPackageName(new StringReader(fileContent)); if (packageName == null) { logger.log(TreeLogger.WARN, "Not adding file = " + fileName + ", because packageName = null", null); @@ -232,13 +230,12 @@ if (lastModified < 0) { lastModified = System.currentTimeMillis(); } - resources.add(new StaticResource(packageName + "." - + getClassName(fileName), fileContent, lastModified)); - logger.log(TreeLogger.DEBUG, "adding pkgName = " + packageName - + ", file = " + fileName, null); + resources.add(new StaticResource(packageName + "." + getClassName(fileName), + fileContent, lastModified)); + logger.log(TreeLogger.DEBUG, "adding pkgName = " + packageName + ", file = " + + fileName, null); } else { - logger.log(TreeLogger.SPAM, " not adding file " + fileName, - null); + logger.log(TreeLogger.SPAM, " not adding file " + fileName, null); } } } @@ -247,8 +244,7 @@ return resources; } - String getFileContentsFromJar(JarFile jarFile, JarEntry jarEntry) - throws IOException { + String getFileContentsFromJar(JarFile jarFile, JarEntry jarEntry) throws IOException { StringBuffer fileContent = new StringBuffer(); InputStream is = jarFile.getInputStream(jarEntry); BufferedInputStream bis = new BufferedInputStream(is); @@ -280,8 +276,8 @@ } for (String includedPath : includedPaths) { if (fileName.startsWith(includedPath)) { - logger.log(TreeLogger.SPAM, fileName - + " is not excluded, and is included by " + includedPath); + logger.log(TreeLogger.SPAM, fileName + " is not excluded, and is included by " + + includedPath); return true; } } @@ -299,8 +295,8 @@ this.logger = logger; } - public abstract Set<Resource> getResources() throws NotFoundException, - IOException, UnableToCompleteException; + public abstract Set<Resource> getResources() throws NotFoundException, IOException, + UnableToCompleteException; // TODO (amitmanjhi): remove this code. use TypeOracle functionality // instead. @@ -319,8 +315,7 @@ return null; } - protected File getFileFromName(String tag, String pathName) - throws FileNotFoundException { + protected File getFileFromName(String tag, String pathName) throws FileNotFoundException { File file = new File(pathName); if (!file.exists()) { throw new FileNotFoundException(tag + "file " + pathName + " not found"); @@ -331,8 +326,8 @@ // TODO (amitmanjhi): remove this code. use TypeOracle functionality // instead. protected boolean isValidPackage(String packageName, String filePath) { - logger.log(TreeLogger.SPAM, "packageName = " + packageName - + ", filePath = " + filePath, null); + logger + .log(TreeLogger.SPAM, "packageName = " + packageName + ", filePath = " + filePath, null); if (packageName == null) { return false; } @@ -342,8 +337,8 @@ } String dirPath = filePath.substring(0, lastSlashPosition); String packageNameAsPath = packageName.replace('.', '/'); - logger.log(TreeLogger.SPAM, "packageNameAsPath " + packageNameAsPath - + ", dirPath = " + dirPath, null); + logger.log(TreeLogger.SPAM, "packageNameAsPath " + packageNameAsPath + ", dirPath = " + + dirPath, null); return dirPath.endsWith(packageNameAsPath); } } @@ -358,16 +353,15 @@ private Set<Resource> units = null; SourceFileResources(String dirRoot, Set<String> includedPathsAsString, - Set<String> excludedPathsAsString, TreeLogger logger) - throws FileNotFoundException, IOException { + Set<String> excludedPathsAsString, TreeLogger logger) throws FileNotFoundException, + IOException { super(logger); if (dirRoot == null) { dirRoot = ""; } includedPaths = new HashSet<File>(); for (String includedPath : includedPathsAsString) { - includedPaths.add(getFileFromName("source file: ", dirRoot - + includedPath)); + includedPaths.add(getFileFromName("source file: ", dirRoot + includedPath)); } String fullExcludedPaths[] = new String[excludedPathsAsString.size()]; @@ -409,10 +403,10 @@ return excludeScanner.match(fileName); } - private void updateCompilationUnitsInPath(File sourcePathEntry) - throws NotFoundException, IOException, UnableToCompleteException { - logger.log(TreeLogger.SPAM, "entering addCompilationUnitsInPath, file = " - + sourcePathEntry, null); + private void updateCompilationUnitsInPath(File sourcePathEntry) throws NotFoundException, + IOException, UnableToCompleteException { + logger.log(TreeLogger.SPAM, "entering addCompilationUnitsInPath, file = " + sourcePathEntry, + null); File[] files = sourcePathEntry.listFiles(); if (files == null) { // No files found. return; @@ -427,31 +421,26 @@ } if (isExcludedFile(file.getAbsolutePath())) { // do not process the subtree - logger.log(TreeLogger.DEBUG, - "not traversing " + file.toURI().toURL(), null); + logger.log(TreeLogger.DEBUG, "not traversing " + file.toURI().toURL(), null); continue; } if (file.isFile()) { String fileName = file.getName(); if (file.getName().endsWith("java")) { - String className = file.getName().substring(0, - fileName.length() - 5); + String className = file.getName().substring(0, fileName.length() - 5); String pkgName = extractPackageName(new FileReader(file)); if (pkgName == null) { - logger.log(TreeLogger.WARN, - "Not adding file = " + file.toString() - + ", because packageName = null", null); + logger.log(TreeLogger.WARN, "Not adding file = " + file.toString() + + ", because packageName = null", null); } else { - if (isValidPackage(pkgName, - sourcePathEntry.toURI().toURL().toString())) { + if (isValidPackage(pkgName, sourcePathEntry.toURI().toURL().toString())) { // Add if the package and fileNames are okay String typeName = Shared.makeTypeName(pkgName, className); units.add(new FileResource(file, Shared.toPath(typeName))); - logger.log(TreeLogger.DEBUG, "adding pkgName = " + pkgName - + ", file = " + file.toString(), null); + logger.log(TreeLogger.DEBUG, "adding pkgName = " + pkgName + ", file = " + + file.toString(), null); } else { - logger.log(TreeLogger.SPAM, " not adding file " - + file.toURI().toURL(), null); + logger.log(TreeLogger.SPAM, " not adding file " + file.toURI().toURL(), null); } } } @@ -503,8 +492,8 @@ public static final boolean REMOVE_NON_SUBCLASSABLE_ABSTRACT_CLASS_FROM_API = true; // remove duplicates by default - public static Collection<ApiChange> getApiDiff(ApiContainer newApi, - ApiContainer existingApi, Set<String> whiteList) throws NotFoundException { + public static Collection<ApiChange> getApiDiff(ApiContainer newApi, ApiContainer existingApi, + Set<String> whiteList) throws NotFoundException { ApiDiffGenerator apiDiff = new ApiDiffGenerator(newApi, existingApi); return getApiDiff(apiDiff, whiteList, FILTER_DUPLICATES); } @@ -521,25 +510,21 @@ AbstractTreeLogger logger = new PrintWriterTreeLogger(); logger.setMaxDetail(checker.type); - logger.log( - TreeLogger.INFO, - "gwtDevJar = " + checker.gwtDevJar + ", userJar = " - + checker.gwtUserJar + ", refjars = " - + Arrays.toString(checker.refJars) + ", logLevel = " - + checker.type + ", printAllApi = " + checker.printAllApi, null); + logger.log(TreeLogger.INFO, "gwtDevJar = " + checker.gwtDevJar + ", userJar = " + + checker.gwtUserJar + ", refjars = " + Arrays.toString(checker.refJars) + + ", logLevel = " + checker.type + ", printAllApi = " + checker.printAllApi, null); Set<String> excludedPackages = checker.getSetOfExcludedPackages(checker.configProperties); if (PROCESS_NEW_API) { Set<Resource> resources = new HashSet<Resource>(); - resources.addAll(new SourceFileResources( - checker.configProperties.getProperty("dirRoot_new"), - checker.getConfigPropertyAsSet("sourceFiles_new"), - checker.getConfigPropertyAsSet("excludedFiles_new"), logger).getResources()); + resources.addAll(new SourceFileResources(checker.configProperties + .getProperty("dirRoot_new"), checker.getConfigPropertyAsSet("sourceFiles_new"), checker + .getConfigPropertyAsSet("excludedFiles_new"), logger).getResources()); resources.addAll(checker.getJavaxValidationCompilationUnits(logger)); resources.addAll(checker.getGwtCompilationUnits(logger)); - newApi = new ApiContainer( - checker.configProperties.getProperty("name_new"), resources, - excludedPackages, logger); + newApi = + new ApiContainer(checker.configProperties.getProperty("name_new"), resources, + excludedPackages, logger); if (checker.printAllApi) { logger.log(TreeLogger.INFO, newApi.getApiAsString()); } @@ -547,28 +532,26 @@ if (PROCESS_EXISTING_API) { Set<Resource> resources = new HashSet<Resource>(); if (checker.refJars == null) { - resources.addAll(new SourceFileResources( - checker.configProperties.getProperty("dirRoot_old"), - checker.getConfigPropertyAsSet("sourceFiles_old"), + resources.addAll(new SourceFileResources(checker.configProperties + .getProperty("dirRoot_old"), checker.getConfigPropertyAsSet("sourceFiles_old"), checker.getConfigPropertyAsSet("excludedFiles_old"), logger).getResources()); } else { - resources.addAll(new JarFileResources(checker.refJars, - checker.getConfigPropertyAsSet("sourceFiles_old"), - checker.getConfigPropertyAsSet("excludedFiles_old"), logger).getResources()); + resources.addAll(new JarFileResources(checker.refJars, checker + .getConfigPropertyAsSet("sourceFiles_old"), checker + .getConfigPropertyAsSet("excludedFiles_old"), logger).getResources()); } resources.addAll(checker.getJavaxValidationCompilationUnits(logger)); resources.addAll(checker.getGwtCompilationUnits(logger)); - existingApi = new ApiContainer( - checker.configProperties.getProperty("name_old"), resources, - excludedPackages, logger); + existingApi = + new ApiContainer(checker.configProperties.getProperty("name_old"), resources, + excludedPackages, logger); if (checker.printAllApi) { logger.log(TreeLogger.INFO, existingApi.getApiAsString()); } } if (PROCESS_NEW_API && PROCESS_EXISTING_API) { - Collection<ApiChange> apiDifferences = getApiDiff(newApi, existingApi, - checker.whiteList); + Collection<ApiChange> apiDifferences = getApiDiff(newApi, existingApi, checker.whiteList); for (ApiChange apiChange : apiDifferences) { System.out.println(apiChange); } @@ -585,7 +568,8 @@ // that the build breaks. try { t.printStackTrace(); - System.err.println("To view the help for this tool, execute this tool without any arguments"); + System.err + .println("To view the help for this tool, execute this tool without any arguments"); } finally { System.exit(-1); } @@ -593,8 +577,8 @@ } // interface for testing, since do not want to build ApiDiff frequently - static Collection<ApiChange> getApiDiff(ApiDiffGenerator apiDiff, - Set<String> whiteList, boolean removeDuplicates) throws NotFoundException { + static Collection<ApiChange> getApiDiff(ApiDiffGenerator apiDiff, Set<String> whiteList, + boolean removeDuplicates) throws NotFoundException { Collection<ApiChange> collection = apiDiff.getApiDiff(); if (removeDuplicates) { collection = apiDiff.removeDuplicates(collection); @@ -610,12 +594,10 @@ continue; } // check for Status.Compatible and Status.Compatible_with - if (!PRINT_COMPATIBLE - && apiChange.getStatus().equals(ApiChange.Status.COMPATIBLE)) { + if (!PRINT_COMPATIBLE && apiChange.getStatus().equals(ApiChange.Status.COMPATIBLE)) { continue; } - if (!PRINT_COMPATIBLE_WITH - && apiChange.getStatus().equals(ApiChange.Status.COMPATIBLE_WITH)) { + if (!PRINT_COMPATIBLE_WITH && apiChange.getStatus().equals(ApiChange.Status.COMPATIBLE_WITH)) { continue; } prunedCollection.add(apiChange); @@ -896,14 +878,13 @@ try { return new JarFile(str); } catch (IOException ex) { - System.err.println("exception in getting jar from fileName: " + str - + ", message: " + ex.getMessage()); + System.err.println("exception in getting jar from fileName: " + str + ", message: " + + ex.getMessage()); return null; } } - protected void setPropertiesAndWhitelist(String fileName) - throws IllegalArgumentException { + protected void setPropertiesAndWhitelist(String fileName) throws IllegalArgumentException { try { // load config properties FileInputStream fis = new FileInputStream(fileName); @@ -934,9 +915,8 @@ return set; } - private Set<Resource> getGwtCompilationUnits(TreeLogger logger) - throws FileNotFoundException, IOException, NotFoundException, - UnableToCompleteException { + private Set<Resource> getGwtCompilationUnits(TreeLogger logger) throws FileNotFoundException, + IOException, NotFoundException, UnableToCompleteException { Set<Resource> resources = new HashSet<Resource>(); if (gwtDevJar == null || gwtUserJar == null) { if (gwtDevJar != null) { @@ -948,29 +928,32 @@ return resources; } // gwt-user.jar - Set<String> gwtIncludedPaths = new HashSet<String>( - Arrays.asList(new String[] {"com/google/gwt"})); - Set<String> gwtExcludedPaths = new HashSet<String>( - Arrays.asList(new String[] { - "com/google/gwt/benchmarks", - "com/google/gwt/i18n/rebind", - "com/google/gwt/i18n/tools", - "com/google/gwt/json", - "com/google/gwt/junit", - "com/google/gwt/user/client/rpc/core/java/util/LinkedHashMap_CustomFieldSerializer.java", - "com/google/gwt/user/rebind", "com/google/gwt/user/server", - "com/google/gwt/user/tools",})); - Resources cu = new JarFileResources(new JarFile[] {gwtUserJar}, - gwtIncludedPaths, gwtExcludedPaths, logger); + Set<String> gwtIncludedPaths = + new HashSet<String>(Arrays.asList(new String[] {"com/google/gwt"})); + Set<String> gwtExcludedPaths = + new HashSet<String>( + Arrays + .asList(new String[] { + "com/google/gwt/benchmarks", + "com/google/gwt/i18n/rebind", + "com/google/gwt/i18n/tools", + "com/google/gwt/json", + "com/google/gwt/junit", + "com/google/gwt/user/client/rpc/core/java/util/LinkedHashMap_CustomFieldSerializer.java", + "com/google/gwt/user/rebind", "com/google/gwt/user/server", + "com/google/gwt/user/tools",})); + Resources cu = + new JarFileResources(new JarFile[] {gwtUserJar}, gwtIncludedPaths, gwtExcludedPaths, logger); resources.addAll(cu.getResources()); // gwt-dev-*.jar - gwtIncludedPaths = new HashSet<String>(Arrays.asList(new String[] { - "com/google/gwt/core/client", - "com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang", - "com/google/gwt/lang",})); - cu = new JarFileResources(new JarFile[] {gwtDevJar}, gwtIncludedPaths, - new HashSet<String>(), logger); + gwtIncludedPaths = + new HashSet<String>(Arrays.asList(new String[] { + "com/google/gwt/core/client", "com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang", + "com/google/gwt/lang",})); + cu = + new JarFileResources(new JarFile[] {gwtDevJar}, gwtIncludedPaths, new HashSet<String>(), + logger); resources.addAll(cu.getResources()); return resources; } @@ -983,10 +966,10 @@ throws UnableToCompleteException, NotFoundException, IOException { Set<Resource> resources = new HashSet<Resource>(); if (extraSourceJars != null) { - Resources extra = new JarFileResources(extraSourceJars, - Collections.singleton(""), new HashSet<String>(Arrays.asList( - "javax/validation/Validation.java", - "javax/validation/constraints/Pattern.java")), logger); + Resources extra = + new JarFileResources(extraSourceJars, Collections.singleton(""), new HashSet<String>( + Arrays.asList("javax/validation/Validation.java", + "javax/validation/constraints/Pattern.java")), logger); Set<Resource> loaded = extra.getResources(); System.out.println("Found " + loaded.size() + " new resources"); resources.addAll(loaded);
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java index e7cbb5e..057c5e5 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java
@@ -63,13 +63,11 @@ * @throws IllegalArgumentException if one of the arguments is illegal * @throws UnableToCompleteException if there is a TypeOracle exception */ - ApiContainer(String name, Set<Resource> resources, - Set<String> excludedPackages, TreeLogger logger) + ApiContainer(String name, Set<Resource> resources, Set<String> excludedPackages, TreeLogger logger) throws UnableToCompleteException { this.name = name; this.logger = logger; - logger.log(TreeLogger.INFO, "name = " + name + ", builders.size = " - + resources.size(), null); + logger.log(TreeLogger.INFO, "name = " + name + ", builders.size = " + resources.size(), null); this.typeOracle = createTypeOracle(resources); this.excludedPackages = excludedPackages; initializeApiPackages(); @@ -83,8 +81,7 @@ public String getApiAsString() { StringBuffer sb = new StringBuffer(); sb.append("Api: " + name + ", size = " + apiPackages.size() + "\n\n"); - List<ApiPackage> sortedApiPackages = new ArrayList<ApiPackage>( - apiPackages.values()); + List<ApiPackage> sortedApiPackages = new ArrayList<ApiPackage>(apiPackages.values()); Collections.sort(sortedApiPackages); for (ApiPackage apiPackage : sortedApiPackages) { sb.append(apiPackage.getApiAsString()); @@ -181,8 +178,7 @@ return false; } - private TypeOracle createTypeOracle(Set<Resource> resources) - throws UnableToCompleteException { + private TypeOracle createTypeOracle(Set<Resource> resources) throws UnableToCompleteException { List<CompilationUnitBuilder> builders = new ArrayList<CompilationUnitBuilder>(); for (Resource resource : resources) { CompilationUnitBuilder builder = CompilationUnitBuilder.create(resource); @@ -190,23 +186,20 @@ } List<CompilationUnit> units = JdtCompiler.compile(builders); boolean anyError = false; - TreeLogger branch = logger.branch(TreeLogger.TRACE, - "Checking for compile errors"); + TreeLogger branch = logger.branch(TreeLogger.TRACE, "Checking for compile errors"); for (CompilationUnit unit : units) { CompilationProblemReporter.reportErrors(branch, unit, false); anyError |= unit.isError(); } if (anyError) { - logger.log(TreeLogger.ERROR, "Unable to build typeOracle for " - + getName()); + logger.log(TreeLogger.ERROR, "Unable to build typeOracle for " + getName()); throw new UnableToCompleteException(); } TypeOracleMediatorFromSource mediator = new TypeOracleMediatorFromSource(); mediator.addNewUnits(logger, units); - logger.log(TreeLogger.INFO, "API " + name - + ", Finished with building typeOracle, added " + units.size() - + " files", null); + logger.log(TreeLogger.INFO, "API " + name + ", Finished with building typeOracle, added " + + units.size() + " files", null); return mediator.getTypeOracle(); } @@ -224,8 +217,7 @@ * Purge non API packages. */ private void initializeApiPackages() { - Set<JPackage> allPackages = new HashSet<JPackage>( - Arrays.asList(typeOracle.getPackages())); + Set<JPackage> allPackages = new HashSet<JPackage>(Arrays.asList(typeOracle.getPackages())); Set<String> packagesNotAdded = new HashSet<String>(); for (JPackage packageObject : allPackages) { if (isApiPackage(packageObject)) { @@ -236,12 +228,12 @@ } } if (packagesNotAdded.size() > 0) { - logger.log(TreeLogger.DEBUG, "API " + name + ": not added " - + packagesNotAdded.size() + " packages: " + packagesNotAdded, null); + logger.log(TreeLogger.DEBUG, "API " + name + ": not added " + packagesNotAdded.size() + + " packages: " + packagesNotAdded, null); } if (apiPackages.size() > 0) { - logger.log(TreeLogger.INFO, "API " + name + " " + apiPackages.size() - + " Api packages: " + apiPackages.keySet(), null); + logger.log(TreeLogger.INFO, "API " + name + " " + apiPackages.size() + " Api packages: " + + apiPackages.keySet(), null); } }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiDiffGenerator.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiDiffGenerator.java index a47eb32..737044a 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiDiffGenerator.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiDiffGenerator.java
@@ -76,7 +76,8 @@ return intersection; } - Map<String, ApiPackageDiffGenerator> intersectingPackages = new HashMap<String, ApiPackageDiffGenerator>(); + Map<String, ApiPackageDiffGenerator> intersectingPackages = + new HashMap<String, ApiPackageDiffGenerator>(); Set<String> missingPackageNames; final ApiContainer newApi; @@ -101,8 +102,7 @@ } else { i = -1; } - ApiClassDiffGenerator result = findApiClassDiffGenerator(pkgName, - typeName); + ApiClassDiffGenerator result = findApiClassDiffGenerator(pkgName, typeName); if (result != null) { return result; } @@ -118,12 +118,10 @@ * * @return <code>null</code> if the type is not found */ - ApiClassDiffGenerator findApiClassDiffGenerator(String pkgName, - String typeName) { + ApiClassDiffGenerator findApiClassDiffGenerator(String pkgName, String typeName) { ApiPackageDiffGenerator pkg = findApiPackageDiffGenerator(pkgName); if (pkg != null) { - ApiClassDiffGenerator type = pkg.findApiClassDiffGenerator(pkgName + "." - + typeName); + ApiClassDiffGenerator type = pkg.findApiClassDiffGenerator(pkgName + "." + typeName); if (type != null) { return type; } @@ -166,36 +164,37 @@ * @param originalCollection collection with duplicates. * @return collection minus duplicates. */ - Collection<ApiChange> removeDuplicates( - Collection<ApiChange> originalCollection) { + Collection<ApiChange> removeDuplicates(Collection<ApiChange> originalCollection) { /* * Map from the hashCode of an apiChange to the list of ApiChanges. There * can be multiple ApiChanges that have the same hashCode, but neither is a * subset of another. Example: if B and C both extend A, and there is an * ApiChange in B and C due to an api element of A. */ - Map<Integer, Collection<ApiChange>> apiChangeMap = new HashMap<Integer, Collection<ApiChange>>(); + Map<Integer, Collection<ApiChange>> apiChangeMap = + new HashMap<Integer, Collection<ApiChange>>(); for (ApiChange apiChange : originalCollection) { String apiChangeStr = apiChange.getApiElement().getRelativeSignature(); - Collection<ApiChange> apiChangesSameHashCode = apiChangeMap.get(apiChange.hashCodeForDuplication()); + Collection<ApiChange> apiChangesSameHashCode = + apiChangeMap.get(apiChange.hashCodeForDuplication()); if (apiChangesSameHashCode == null) { apiChangesSameHashCode = new HashSet<ApiChange>(); - apiChangeMap.put(apiChange.hashCodeForDuplication(), - apiChangesSameHashCode); + apiChangeMap.put(apiChange.hashCodeForDuplication(), apiChangesSameHashCode); } Collection<ApiChange> apiChangesToRemove = new HashSet<ApiChange>(); boolean addNewElement = true; for (ApiChange oldApiChange : apiChangesSameHashCode) { String oldApiChangeStr = oldApiChange.getApiElement().getRelativeSignature(); - Relation relation = getRelationOfApiClassOfFirstArgToThatOfSecond( - apiChange.getApiElement(), oldApiChange.getApiElement()); + Relation relation = + getRelationOfApiClassOfFirstArgToThatOfSecond(apiChange.getApiElement(), oldApiChange + .getApiElement()); if (relation == Relation.SUPERCLASS) { apiChangesToRemove.add(oldApiChange); if (ApiCompatibilityChecker.DEBUG_DUPLICATE_REMOVAL && oldApiChangeStr.indexOf(HAY_API_CHANGE) != -1) { - System.out.println(oldApiChangeStr + " replaced by " + apiChangeStr - + ", status = " + oldApiChange.getStatus()); + System.out.println(oldApiChangeStr + " replaced by " + apiChangeStr + ", status = " + + oldApiChange.getStatus()); } } else if (relation == Relation.SUBCLASS) { addNewElement = false; @@ -226,12 +225,11 @@ private void computeApiDiff() throws NotFoundException { Set<String> newApiPackageNames = newApi.getApiPackageNames(); missingPackageNames = oldApi.getApiPackageNames(); - Set<String> intersection = removeIntersection(newApiPackageNames, - missingPackageNames); + Set<String> intersection = removeIntersection(newApiPackageNames, missingPackageNames); // Inspect each of the classes in each of the packages in the intersection for (String packageName : intersection) { - ApiPackageDiffGenerator tempPackageDiffGenerator = new ApiPackageDiffGenerator( - packageName, this); + ApiPackageDiffGenerator tempPackageDiffGenerator = + new ApiPackageDiffGenerator(packageName, this); intersectingPackages.put(packageName, tempPackageDiffGenerator); tempPackageDiffGenerator.computeApiDiff(); } @@ -241,8 +239,8 @@ * Returns how ApiClass for first element is "related" to the ApiClass for * secondElement. */ - private Relation getRelationOfApiClassOfFirstArgToThatOfSecond( - ApiElement firstApiElement, ApiElement secondApiElement) { + private Relation getRelationOfApiClassOfFirstArgToThatOfSecond(ApiElement firstApiElement, + ApiElement secondApiElement) { JClassType firstClassType = null; JClassType secondClassType = null; if (firstApiElement instanceof ApiField) { @@ -262,9 +260,8 @@ } return Relation.NONE; } - throw new RuntimeException( - "Inconsistent types for ApiElements: newApiElement " + firstApiElement - + ", oldApiElement : " + secondApiElement); + throw new RuntimeException("Inconsistent types for ApiElements: newApiElement " + + firstApiElement + ", oldApiElement : " + secondApiElement); } }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiField.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiField.java index a7778c7..73a8ea4 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiField.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiField.java
@@ -28,8 +28,7 @@ final class ApiField implements Comparable<ApiField>, ApiElement { static String computeApiSignature(JField tempField) { - return tempField.getEnclosingType().getQualifiedSourceName() + "::" - + tempField.getName(); + return tempField.getEnclosingType().getQualifiedSourceName() + "::" + tempField.getName(); } private final ApiClass apiClass; @@ -115,11 +114,10 @@ + "::" + signature + " defined in " - + (enclosingType == null ? "null enclosing type " - : enclosingType.getQualifiedSourceName()); + + (enclosingType == null ? "null enclosing type " : enclosingType + .getQualifiedSourceName()); } - return apiClass.getClassObject().getQualifiedSourceName() + "::" - + signature; + return apiClass.getClassObject().getQualifiedSourceName() + "::" + signature; } } \ No newline at end of file
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiMethod.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiMethod.java index 1667a2d..11e4448 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiMethod.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiMethod.java
@@ -56,17 +56,15 @@ firstType = ((JMethod) method).getReturnType(); secondType = ((JMethod) newMethod.getMethod()).getReturnType(); } else { - throw new AssertionError("Different types for method = " - + method.getClass() + ", and newMethodObject = " - + newMethod.getMethod().getClass() + ", signature = " + throw new AssertionError("Different types for method = " + method.getClass() + + ", and newMethodObject = " + newMethod.getMethod().getClass() + ", signature = " + getApiSignature()); } StringBuffer sb = new StringBuffer(); if (firstType.getSimpleSourceName().indexOf("void") != -1) { return null; } - boolean compatible = ApiDiffGenerator.isFirstTypeAssignableToSecond( - secondType, firstType); + boolean compatible = ApiDiffGenerator.isFirstTypeAssignableToSecond(secondType, firstType); if (compatible) { return null; } @@ -74,8 +72,7 @@ sb.append(firstType.getQualifiedSourceName()); sb.append(" to "); sb.append(secondType.getQualifiedSourceName()); - return new ApiChange(this, ApiChange.Status.RETURN_TYPE_ERROR, - sb.toString()); + return new ApiChange(this, ApiChange.Status.RETURN_TYPE_ERROR, sb.toString()); } /** @@ -94,17 +91,14 @@ // check return type if (!existingMethod.getReturnType().getJNISignature().equals( newMethod.getReturnType().getJNISignature())) { - changeApis.add(new ApiChange(this, - ApiChange.Status.OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE, " from " - + existingMethod.getReturnType() + " to " - + newMethod.getReturnType())); + changeApis.add(new ApiChange(this, ApiChange.Status.OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE, + " from " + existingMethod.getReturnType() + " to " + newMethod.getReturnType())); } // check argument type JParameter[] newParametersList = newMethod.getParameters(); JParameter[] existingParametersList = existingMethod.getParameters(); if (newParametersList.length != existingParametersList.length) { - changeApis.add(new ApiChange(this, - ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, + changeApis.add(new ApiChange(this, ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, "number of parameters changed")); } else { int length = newParametersList.length; @@ -112,9 +106,8 @@ if (!existingParametersList[i].getType().getJNISignature().equals( newParametersList[i].getType().getJNISignature())) { changeApis.add(new ApiChange(this, - ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, - " at position " + i + " from " - + existingParametersList[i].getType() + " to " + ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, " at position " + i + + " from " + existingParametersList[i].getType() + " to " + newParametersList[i].getType())); } } @@ -138,16 +131,13 @@ } ApiDiffGenerator.removeIntersection(existingExceptionsSet, newExceptionsSet); removeUncheckedExceptions(newMethod, newExceptionsSet, newExceptionsMap); - removeUncheckedExceptions(existingMethod, existingExceptionsSet, - existingExceptionsMap); + removeUncheckedExceptions(existingMethod, existingExceptionsSet, existingExceptionsMap); if (existingExceptionsSet.size() > 0) { - changeApis.add(new ApiChange(this, - ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, + changeApis.add(new ApiChange(this, ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, "existing method had more exceptions: " + existingExceptionsSet)); } if (newExceptionsSet.size() > 0) { - changeApis.add(new ApiChange(this, - ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, + changeApis.add(new ApiChange(this, ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, "new method has more exceptions: " + newExceptionsSet)); } return changeApis; @@ -169,14 +159,12 @@ newjmethod = (JMethod) newMethod.getMethod(); oldjmethod = (JMethod) method; } else { - throw new AssertionError("Different types for method = " - + method.getClass() + " and newMethod = " - + newMethod.getMethod().getClass() + ", signature = " + throw new AssertionError("Different types for method = " + method.getClass() + + " and newMethod = " + newMethod.getMethod().getClass() + ", signature = " + getApiSignature()); } List<ApiChange.Status> statuses = new ArrayList<ApiChange.Status>(); - if (!oldjmethod.isFinal() && !apiClass.getClassObject().isFinal() - && newjmethod.isFinal()) { + if (!oldjmethod.isFinal() && !apiClass.getClassObject().isFinal() && newjmethod.isFinal()) { statuses.add(ApiChange.Status.FINAL_ADDED); } if (!oldjmethod.isAbstract() && newjmethod.isAbstract()) { @@ -189,8 +177,8 @@ } // remove Error.class, RuntimeException.class, and their sub-classes - private void removeUncheckedExceptions(JMethod method, - Set<String> exceptionsSet, Map<String, JType> exceptionsMap) { + private void removeUncheckedExceptions(JMethod method, Set<String> exceptionsSet, + Map<String, JType> exceptionsMap) { if (exceptionsSet.size() == 0) { return; } @@ -201,10 +189,11 @@ for (String exceptionString : exceptionsSet) { JType exception = exceptionsMap.get(exceptionString); assert (exception != null); - boolean remove = (errorType != null && ApiDiffGenerator.isFirstTypeAssignableToSecond( - exception, errorType)) - || (rteType != null && ApiDiffGenerator.isFirstTypeAssignableToSecond( - exception, rteType)); + boolean remove = + (errorType != null && ApiDiffGenerator + .isFirstTypeAssignableToSecond(exception, errorType)) + || (rteType != null && ApiDiffGenerator.isFirstTypeAssignableToSecond(exception, + rteType)); if (remove) { exceptionsToRemove.add(exceptionString); }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackage.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackage.java index 32b1c79..34aa1b7 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackage.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackage.java
@@ -51,7 +51,7 @@ public int compareTo(ApiPackage other) { return this.getName().compareTo(other.getName()); } - + @Override public boolean equals(Object o) { if (!(o instanceof ApiPackage)) { @@ -75,26 +75,25 @@ } List<JClassType> getAllClasses() { - List<JClassType> allClasses = new ArrayList<JClassType>( - Arrays.asList(packageObject.getTypes())); - logger.log(TreeLogger.SPAM, "API " + packageObject + " has " - + allClasses.size() + " outer classes", null); + List<JClassType> allClasses = + new ArrayList<JClassType>(Arrays.asList(packageObject.getTypes())); + logger.log(TreeLogger.SPAM, "API " + packageObject + " has " + allClasses.size() + + " outer classes", null); int index = 0; while (index < allClasses.size()) { JClassType classObject = allClasses.get(index); allClasses.addAll(Arrays.asList(classObject.getNestedTypes())); index++; } - logger.log(TreeLogger.SPAM, "API " + packageObject + " has " - + allClasses.size() + " total classes", null); + logger.log(TreeLogger.SPAM, "API " + packageObject + " has " + allClasses.size() + + " total classes", null); return allClasses; } String getApiAsString() { StringBuffer sb = new StringBuffer(); sb.append(name + ", size = " + apiClasses.size() + "\n"); - ArrayList<ApiClass> apiClassesList = new ArrayList<ApiClass>( - apiClasses.values()); + ArrayList<ApiClass> apiClassesList = new ArrayList<ApiClass>(apiClasses.values()); Collections.sort(apiClassesList); for (ApiClass apiClass : apiClassesList) { sb.append(apiClass.getApiAsString()); @@ -138,8 +137,8 @@ } if (notAddedClassNames.size() > 0) { logger.log(TreeLogger.SPAM, "API " + apiContainer.getName() + ", package: " + name - + ", not adding " + notAddedClassNames.size() + " nonApi classes: " - + notAddedClassNames, null); + + ", not adding " + notAddedClassNames.size() + " nonApi classes: " + notAddedClassNames, + null); } }
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackageDiffGenerator.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackageDiffGenerator.java index b69f915..e52b298 100644 --- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackageDiffGenerator.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiPackageDiffGenerator.java
@@ -29,10 +29,10 @@ /** * encapsulates a class that produces the diff between the api of two packages. */ -final class ApiPackageDiffGenerator implements - Comparable<ApiPackageDiffGenerator> { +final class ApiPackageDiffGenerator implements Comparable<ApiPackageDiffGenerator> { private final ApiDiffGenerator apiDiffGenerator; - private Map<String, ApiClassDiffGenerator> intersectingClasses = new HashMap<String, ApiClassDiffGenerator>(); + private Map<String, ApiClassDiffGenerator> intersectingClasses = + new HashMap<String, ApiClassDiffGenerator>(); private Set<String> missingClassNames = null; private final String name; private final ApiPackage newPackage; @@ -42,10 +42,8 @@ throws NotFoundException { this.apiDiffGenerator = apiDiffGenerator; name = packageName; - newPackage = apiDiffGenerator.getNewApiContainer().getApiPackage( - packageName); - oldPackage = apiDiffGenerator.getOldApiContainer().getApiPackage( - packageName); + newPackage = apiDiffGenerator.getNewApiContainer().getApiPackage(packageName); + oldPackage = apiDiffGenerator.getOldApiContainer().getApiPackage(packageName); if (newPackage == null || oldPackage == null) { throw new NotFoundException("for package " + packageName + ", one of the package objects is null"); @@ -55,7 +53,7 @@ public int compareTo(ApiPackageDiffGenerator other) { return this.getName().compareTo(other.getName()); } - + @Override public boolean equals(Object o) { if (!(o instanceof ApiPackageDiffGenerator)) { @@ -72,13 +70,12 @@ void computeApiDiff() throws NotFoundException { Set<String> newClassNames = newPackage.getApiClassNames(); missingClassNames = oldPackage.getApiClassNames(); - Set<String> intersection = ApiDiffGenerator.removeIntersection( - newClassNames, missingClassNames); + Set<String> intersection = + ApiDiffGenerator.removeIntersection(newClassNames, missingClassNames); /* Inspect each of the classes in each of the packages in the intersection */ for (String className : intersection) { - ApiClassDiffGenerator tempClassDiffGenerator = new ApiClassDiffGenerator( - className, this); + ApiClassDiffGenerator tempClassDiffGenerator = new ApiClassDiffGenerator(className, this); intersectingClasses.put(className, tempClassDiffGenerator); tempClassDiffGenerator.computeApiDiff(); } @@ -94,8 +91,8 @@ for (ApiClass missingClass : missingClasses) { collection.add(new ApiChange(missingClass, ApiChange.Status.MISSING)); } - List<ApiClassDiffGenerator> intersectingClassesList = new ArrayList<ApiClassDiffGenerator>( - intersectingClasses.values()); + List<ApiClassDiffGenerator> intersectingClassesList = + new ArrayList<ApiClassDiffGenerator>(intersectingClasses.values()); Collections.sort(intersectingClassesList); for (ApiClassDiffGenerator intersectingClass : intersectingClasses.values()) { collection.addAll(intersectingClass.getApiDiff());
diff --git a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityTest.java b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityTest.java index 4ca625c..862090e 100644 --- a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityTest.java +++ b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityTest.java
@@ -51,16 +51,12 @@ private static StaticJavaResource[] getScuArray() { return new StaticJavaResource[] { new StaticJavaResource("test.apicontainer.ApiClass", getSourceForApiClass()), - new StaticJavaResource("test.apicontainer.NonApiClass", - getSourceForNonApiClass()), - new StaticJavaResource("test.nonapipackage.TestClass", - getSourceForTestClass()), + new StaticJavaResource("test.apicontainer.NonApiClass", getSourceForNonApiClass()), + new StaticJavaResource("test.nonapipackage.TestClass", getSourceForTestClass()), new StaticJavaResource("java.lang.Object", getSourceForObject()), new StaticJavaResource("java.lang.Throwable", getSourceForThrowable()), - new StaticJavaResource("test.apicontainer.OneMoreApiClass", - getSourceForOneMoreApiClass()), - new StaticJavaResource("java.lang.RuntimeException", - getSourceForRuntimeException()),}; + new StaticJavaResource("test.apicontainer.OneMoreApiClass", getSourceForOneMoreApiClass()), + new StaticJavaResource("java.lang.RuntimeException", getSourceForRuntimeException()),}; } private static String getSourceForApiClass() { @@ -149,14 +145,15 @@ AbstractTreeLogger logger = new PrintWriterTreeLogger(); logger.setMaxDetail(TreeLogger.ERROR); - api1 = new ApiContainer("Api1", new HashSet<Resource>( - Arrays.asList(ApiContainerTest.getScuArray())), new HashSet<String>(), - logger); - apiSameAs1 = new ApiContainer("ApiSameAs1", new HashSet<Resource>( - Arrays.asList(ApiContainerTest.getScuArray())), new HashSet<String>(), - logger); - api2 = new ApiContainer("Api2", new HashSet<Resource>( - Arrays.asList(getScuArray())), new HashSet<String>(), logger); + api1 = + new ApiContainer("Api1", new HashSet<Resource>(Arrays + .asList(ApiContainerTest.getScuArray())), new HashSet<String>(), logger); + apiSameAs1 = + new ApiContainer("ApiSameAs1", new HashSet<Resource>(Arrays.asList(ApiContainerTest + .getScuArray())), new HashSet<String>(), logger); + api2 = + new ApiContainer("Api2", new HashSet<Resource>(Arrays.asList(getScuArray())), + new HashSet<String>(), logger); } // setup is called before every test*. To avoid the overhead of setUp() each @@ -168,17 +165,18 @@ private void checkBasicStuff() throws NotFoundException { HashSet<String> hashSet = new HashSet<String>(); - assertEquals(0, ApiCompatibilityChecker.getApiDiff(api1, apiSameAs1, - hashSet).size()); + assertEquals(0, ApiCompatibilityChecker.getApiDiff(api1, apiSameAs1, hashSet).size()); ApiDiffGenerator apiDiff = new ApiDiffGenerator(api2, api1); - String strWithDuplicates = getStringRepresentation(ApiCompatibilityChecker.getApiDiff( - apiDiff, hashSet, !ApiCompatibilityChecker.FILTER_DUPLICATES)); + String strWithDuplicates = + getStringRepresentation(ApiCompatibilityChecker.getApiDiff(apiDiff, hashSet, + !ApiCompatibilityChecker.FILTER_DUPLICATES)); if (DEBUG) { System.out.println("computing apiDiff, now with duplicates"); System.out.println(strWithDuplicates); } - String strWithoutDuplicates = getStringRepresentation(ApiCompatibilityChecker.getApiDiff( - apiDiff, hashSet, ApiCompatibilityChecker.FILTER_DUPLICATES)); + String strWithoutDuplicates = + getStringRepresentation(ApiCompatibilityChecker.getApiDiff(apiDiff, hashSet, + ApiCompatibilityChecker.FILTER_DUPLICATES)); if (DEBUG) { System.out.println("computing apiDiff, now without duplicates"); System.out.println(strWithoutDuplicates); @@ -186,47 +184,44 @@ String delimiter = ApiDiffGenerator.DELIMITER; // test if missing packages are reported correctly - String statusString = "java.newpackage" + delimiter - + ApiChange.Status.MISSING; + String statusString = "java.newpackage" + delimiter + ApiChange.Status.MISSING; assertEquals(1, countPresence(statusString, strWithDuplicates)); assertEquals(1, countPresence(statusString, strWithoutDuplicates)); // test if missing classes are reported correctly - assertEquals(1, countPresence( - "test.apicontainer.NonApiClass.AnotherApiClassInNonApiClass" - + delimiter + ApiChange.Status.MISSING, strWithoutDuplicates)); + assertEquals(1, countPresence("test.apicontainer.NonApiClass.AnotherApiClassInNonApiClass" + + delimiter + ApiChange.Status.MISSING, strWithoutDuplicates)); // test if modifier changes of a class are reported - assertEquals(1, countPresence( - "test.apicontainer.NonApiClass.ApiClassInNonApiClass" + delimiter - + ApiChange.Status.ABSTRACT_ADDED, strWithoutDuplicates)); + assertEquals(1, countPresence("test.apicontainer.NonApiClass.ApiClassInNonApiClass" + delimiter + + ApiChange.Status.ABSTRACT_ADDED, strWithoutDuplicates)); // test if methods are still reported even if class becomes abstract (as // long as it is sub-classable) assertEquals(0, countPresence( - "test.apicontainer.NonApiClass.ApiClassInNonApiClass::ApiClassInNonApiClass()" - + delimiter + ApiChange.Status.MISSING, strWithoutDuplicates)); + "test.apicontainer.NonApiClass.ApiClassInNonApiClass::ApiClassInNonApiClass()" + delimiter + + ApiChange.Status.MISSING, strWithoutDuplicates)); assertEquals(0, countPresence( - "test.apicontainer.NonApiClass.ApiClassInNonApiClass::protectedMethod()" - + delimiter + ApiChange.Status.MISSING, strWithoutDuplicates)); + "test.apicontainer.NonApiClass.ApiClassInNonApiClass::protectedMethod()" + delimiter + + ApiChange.Status.MISSING, strWithoutDuplicates)); // test if modifier changes of fields and methods are reported assertEquals(1, countPresence("java.lang.Object::apiField" + delimiter + ApiChange.Status.FINAL_ADDED, strWithoutDuplicates)); - assertEquals(1, countPresence("java.lang.Object::protectedMethod()" - + delimiter + ApiChange.Status.FINAL_ADDED, strWithoutDuplicates)); - - // test if duplicates are weeded out from intersecting methods - assertEquals(4, countPresence("protectedMethod()" + delimiter - + ApiChange.Status.FINAL_ADDED, strWithDuplicates)); - assertEquals(1, countPresence("protectedMethod()" + delimiter + assertEquals(1, countPresence("java.lang.Object::protectedMethod()" + delimiter + ApiChange.Status.FINAL_ADDED, strWithoutDuplicates)); + // test if duplicates are weeded out from intersecting methods + assertEquals(4, countPresence("protectedMethod()" + delimiter + ApiChange.Status.FINAL_ADDED, + strWithDuplicates)); + assertEquals(1, countPresence("protectedMethod()" + delimiter + ApiChange.Status.FINAL_ADDED, + strWithoutDuplicates)); + // test if duplicates are weeded out from missing fields - assertEquals(4, countPresence("apiFieldWillBeMissing" + delimiter - + ApiChange.Status.MISSING, strWithDuplicates)); - assertEquals(1, countPresence("apiFieldWillBeMissing" + delimiter - + ApiChange.Status.MISSING, strWithoutDuplicates)); + assertEquals(4, countPresence("apiFieldWillBeMissing" + delimiter + ApiChange.Status.MISSING, + strWithDuplicates)); + assertEquals(1, countPresence("apiFieldWillBeMissing" + delimiter + ApiChange.Status.MISSING, + strWithoutDuplicates)); // test error in non-final version String nonFinalMethodSignature = "checkParametersAndReturnTypes(Ltest/apicontainer/ApiClass;)"; @@ -234,11 +229,12 @@ ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, ApiChange.Status.OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE}) { - assertEquals(1, countPresence(nonFinalMethodSignature + delimiter - + status, strWithoutDuplicates)); + assertEquals(1, countPresence(nonFinalMethodSignature + delimiter + status, + strWithoutDuplicates)); } // test return type and exception type error in final version - String finalMethodSignature = "checkParametersAndReturnTypesFinalVersion(Ltest/apicontainer/ApiClass;)"; + String finalMethodSignature = + "checkParametersAndReturnTypesFinalVersion(Ltest/apicontainer/ApiClass;)"; assertEquals(1, countPresence(finalMethodSignature + delimiter + ApiChange.Status.RETURN_TYPE_ERROR, strWithoutDuplicates)); assertEquals(1, countPresence(finalMethodSignature + delimiter @@ -253,26 +249,27 @@ + ApiChange.Status.OVERLOADED_METHOD_CALL, strWithoutDuplicates)); // test unchecked exceptions - assertEquals(0, countPresence("testUncheckedExceptions", - strWithoutDuplicates)); + assertEquals(0, countPresence("testUncheckedExceptions", strWithoutDuplicates)); // test overloaded and overridable detection - String methodSignature = "test.apicontainer.OneMoreApiClass::checkOverloadedAndOverridableDetection(Ljava/lang/Object;)"; + String methodSignature = + "test.apicontainer.OneMoreApiClass::checkOverloadedAndOverridableDetection(Ljava/lang/Object;)"; for (ApiChange.Status status : new ApiChange.Status[] { ApiChange.Status.OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE, ApiChange.Status.OVERRIDABLE_METHOD_EXCEPTION_TYPE_CHANGE, ApiChange.Status.OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE}) { - assertEquals(0, countPresence(methodSignature + delimiter + status, - strWithoutDuplicates)); + assertEquals(0, countPresence(methodSignature + delimiter + status, strWithoutDuplicates)); } // the method should be satisfied by the method in the super-class - methodSignature = "test.apicontainer.OneMoreApiClass::checkOverloadedMethodAccounted(Ltest/apicontainer/OneMoreApiClass;)"; - assertEquals(0, countPresence(methodSignature + delimiter - + ApiChange.Status.MISSING, strWithoutDuplicates)); + methodSignature = + "test.apicontainer.OneMoreApiClass::checkOverloadedMethodAccounted(Ltest/apicontainer/OneMoreApiClass;)"; + assertEquals(0, countPresence(methodSignature + delimiter + ApiChange.Status.MISSING, + strWithoutDuplicates)); // the method should throw unchecked exceptions error - methodSignature = "test.apicontainer.OneMoreApiClass::checkOverloadedMethodAccounted(Ljava/lang/Object;)"; + methodSignature = + "test.apicontainer.OneMoreApiClass::checkOverloadedMethodAccounted(Ljava/lang/Object;)"; assertEquals(1, countPresence(methodSignature + delimiter + ApiChange.Status.EXCEPTION_TYPE_ERROR, strWithoutDuplicates)); } @@ -280,12 +277,12 @@ private void checkWhiteList() throws NotFoundException { ApiDiffGenerator apiDiff = new ApiDiffGenerator(api2, api1); boolean removeDuplicates = false; - String whiteList = "java.newpackage" + ApiDiffGenerator.DELIMITER - + ApiChange.Status.MISSING; + String whiteList = "java.newpackage" + ApiDiffGenerator.DELIMITER + ApiChange.Status.MISSING; HashSet<String> hashSet = new HashSet<String>(); hashSet.add(whiteList); - String strWithoutDuplicates = getStringRepresentation(ApiCompatibilityChecker.getApiDiff( - apiDiff, hashSet, !removeDuplicates)); + String strWithoutDuplicates = + getStringRepresentation(ApiCompatibilityChecker.getApiDiff(apiDiff, hashSet, + !removeDuplicates)); // test if missing packages are reported correctly assertEquals(0, countPresence(whiteList, strWithoutDuplicates));
diff --git a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityUnitTest.java b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityUnitTest.java index 701446e..9289570 100644 --- a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityUnitTest.java +++ b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiCompatibilityUnitTest.java
@@ -88,15 +88,13 @@ // firstApi is the reference Api Collection<ApiChange> apiChanges = getApiChanges(firstApi, secondApi); - assertEquals(Arrays.asList(new ApiChange[] {new ApiChange( - new MockApiElement("java.lang.Object::foo"), - ApiChange.Status.FINAL_ADDED),}), apiChanges); + assertEquals(Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( + "java.lang.Object::foo"), ApiChange.Status.FINAL_ADDED),}), apiChanges); // secondApi is the reference Api apiChanges = getApiChanges(secondApi, firstApi); - assertEquals( - Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( - "java.lang.Object"), ApiChange.Status.FINAL_ADDED),}), apiChanges); + assertEquals(Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( + "java.lang.Object"), ApiChange.Status.FINAL_ADDED),}), apiChanges); } } @@ -148,23 +146,20 @@ // firstApi is the reference Api Collection<ApiChange> apiChanges = getApiChanges(firstApi, secondApi); - assertEquals( - Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( - "java.lang.Object.Bar::Bar(Ljava/lang/Object$Bar;)"), - ApiChange.Status.OVERLOADED_METHOD_CALL),}), apiChanges); + assertEquals(Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( + "java.lang.Object.Bar::Bar(Ljava/lang/Object$Bar;)"), + ApiChange.Status.OVERLOADED_METHOD_CALL),}), apiChanges); // secondApi is the reference Api apiChanges = getApiChanges(secondApi, firstApi); assertEquals(Arrays.asList(new ApiChange[] { - new ApiChange(new MockApiElement( - "java.lang.Object.Foo::Foo(Ljava/lang/Object;)"), + new ApiChange(new MockApiElement("java.lang.Object.Foo::Foo(Ljava/lang/Object;)"), ApiChange.Status.MISSING), - new ApiChange(new MockApiElement( - "java.lang.Object.Bar::Bar(Ljava/lang/Object$Foo;)"), + new ApiChange(new MockApiElement("java.lang.Object.Bar::Bar(Ljava/lang/Object$Foo;)"), ApiChange.Status.MISSING),}), apiChanges); } } - + /** * Test when method overloading results in Api incompatibilities. * <p> @@ -213,19 +208,16 @@ // firstApi is the reference Api Collection<ApiChange> apiChanges = getApiChanges(firstApi, secondApi); - assertEquals( - Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( - "java.lang.Object::fooBar(Ljava/lang/Object$Foo;)"), - ApiChange.Status.OVERLOADED_METHOD_CALL),}), apiChanges); + assertEquals(Arrays.asList(new ApiChange[] {new ApiChange(new MockApiElement( + "java.lang.Object::fooBar(Ljava/lang/Object$Foo;)"), + ApiChange.Status.OVERLOADED_METHOD_CALL),}), apiChanges); // secondApi is the reference Api apiChanges = getApiChanges(secondApi, firstApi); assertEquals(Arrays.asList(new ApiChange[] { - new ApiChange(new MockApiElement( - "java.lang.Object::fooBar(Ljava/lang/Object$Bar;)"), + new ApiChange(new MockApiElement("java.lang.Object::fooBar(Ljava/lang/Object$Bar;)"), ApiChange.Status.MISSING), - new ApiChange(new MockApiElement( - "java.lang.Object::fooObject(Ljava/lang/Object;)"), + new ApiChange(new MockApiElement("java.lang.Object::fooObject(Ljava/lang/Object;)"), ApiChange.Status.MISSING),}), apiChanges); } } @@ -291,15 +283,14 @@ assert apiChange1 != null; assert apiChange2 != null; assertEquals(apiChange1.getStatus(), apiChange2.getStatus()); - assertEquals(apiChange1.getApiElement().getRelativeSignature(), - apiChange2.getApiElement().getRelativeSignature()); + assertEquals(apiChange1.getApiElement().getRelativeSignature(), apiChange2.getApiElement() + .getRelativeSignature()); } /** * Assert that two sets of ApiChanges are equal. */ - static void assertEquals(Collection<ApiChange> collection1, - Collection<ApiChange> collection2) { + static void assertEquals(Collection<ApiChange> collection1, Collection<ApiChange> collection2) { assertEquals(collection1.size(), collection2.size()); List<ApiChange> list1 = new ArrayList<ApiChange>(); @@ -322,10 +313,8 @@ * @param newTypesToSourcesMap new Api * @return A collection of ApiChange */ - static Collection<ApiChange> getApiChanges( - Map<String, String> existingTypesToSourcesMap, - Map<String, String> newTypesToSourcesMap) - throws UnableToCompleteException, NotFoundException { + static Collection<ApiChange> getApiChanges(Map<String, String> existingTypesToSourcesMap, + Map<String, String> newTypesToSourcesMap) throws UnableToCompleteException, NotFoundException { AbstractTreeLogger logger = new PrintWriterTreeLogger(); logger.setMaxDetail(TreeLogger.ERROR); @@ -340,29 +329,24 @@ set2.add(new StaticJavaResource(type, newTypesToSourcesMap.get(type))); } - ApiContainer existingApi = new ApiContainer("existingApi", set1, emptyList, - logger); + ApiContainer existingApi = new ApiContainer("existingApi", set1, emptyList, logger); ApiContainer newApi = new ApiContainer("newApi", set2, emptyList, logger); return ApiCompatibilityChecker.getApiDiff(newApi, existingApi, emptyList); } - public void testConstructorOverloading() throws NotFoundException, - UnableToCompleteException { + public void testConstructorOverloading() throws NotFoundException, UnableToCompleteException { new OverloadedConstructorRefactoring().testBothWays(); } - - public void testFinalKeywordRefactoring() throws NotFoundException, - UnableToCompleteException { + + public void testFinalKeywordRefactoring() throws NotFoundException, UnableToCompleteException { new FinalKeywordRefactoring().testBothWays(); } - public void testMethodOverloading() throws NotFoundException, - UnableToCompleteException { + public void testMethodOverloading() throws NotFoundException, UnableToCompleteException { new OverloadedMethodRefactoring().testBothWays(); } - public void testSuperClassRefactoring() throws NotFoundException, - UnableToCompleteException { + public void testSuperClassRefactoring() throws NotFoundException, UnableToCompleteException { new SuperClassRefactoring().testBothWays(); }
diff --git a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiContainerTest.java b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiContainerTest.java index a73c13d..ee9b8b1 100644 --- a/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiContainerTest.java +++ b/tools/api-checker/test/com/google/gwt/tools/apichecker/ApiContainerTest.java
@@ -63,15 +63,11 @@ public static StaticJavaResource[] getScuArray() { return new StaticJavaResource[] { - new StaticJavaResource("test.apicontainer.ApiClass", - getSourceForApiClass()), - new StaticJavaResource("test.apicontainer.NonApiClass", - getSourceForNonApiClass()), - new StaticJavaResource("test.nonapipackage.TestClass", - getSourceForTestClass()), + new StaticJavaResource("test.apicontainer.ApiClass", getSourceForApiClass()), + new StaticJavaResource("test.apicontainer.NonApiClass", getSourceForNonApiClass()), + new StaticJavaResource("test.nonapipackage.TestClass", getSourceForTestClass()), new StaticJavaResource("java.lang.Object", getSourceForObject()), - new StaticJavaResource("test.apicontainer.OneMoreApiClass", - getSourceForOneMoreApiClass()), + new StaticJavaResource("test.apicontainer.OneMoreApiClass", getSourceForOneMoreApiClass()), new StaticJavaResource("java.newpackage.Test", getSourceForTest()),}; } @@ -162,8 +158,9 @@ public void setUp() throws UnableToCompleteException { logger.setMaxDetail(com.google.gwt.core.ext.TreeLogger.ERROR); - apiCheck = new ApiContainer("ApiContainerTest", new HashSet<Resource>( - Arrays.asList(getScuArray())), new HashSet<String>(), logger); + apiCheck = + new ApiContainer("ApiContainerTest", new HashSet<Resource>(Arrays.asList(getScuArray())), + new HashSet<String>(), logger); } /* @@ -180,11 +177,10 @@ sb.append("class Temp {\n"); sb.append("}"); - ApiContainer apiCheckLoop = new ApiContainer("ApiClassTest", - new HashSet<Resource>( - Arrays.asList(new StaticJavaResource[] {new StaticJavaResource( - "java.lang.Object", sb.toString())})), new HashSet<String>(), - logger); + ApiContainer apiCheckLoop = + new ApiContainer("ApiClassTest", new HashSet<Resource>(Arrays + .asList(new StaticJavaResource[] {new StaticJavaResource("java.lang.Object", sb + .toString())})), new HashSet<String>(), logger); ApiPackage javaLangPackage = apiCheckLoop.getApiPackage("java.lang"); assertNotNull(javaLangPackage); assertNotNull(javaLangPackage.getApiClass("java.lang.Object")); @@ -211,7 +207,8 @@ assertNotNull(package1.getApiClass("java.lang.Object")); assertNotNull(package2.getApiClass("test.apicontainer.ApiClass")); assertNotNull(package2.getApiClass("test.apicontainer.NonApiClass.ApiClassInNonApiClass")); - assertNotNull(package2.getApiClass("test.apicontainer.NonApiClass.AnotherApiClassInNonApiClass")); + assertNotNull(package2 + .getApiClass("test.apicontainer.NonApiClass.AnotherApiClassInNonApiClass")); assertEquals(1, package1.getApiClassNames().size()); assertEquals(4, package2.getApiClassNames().size()); } @@ -225,18 +222,18 @@ * */ void checkApiMembers() { - ApiClass object = apiCheck.getApiPackage("java.lang").getApiClass( - "java.lang.Object"); - ApiClass apiClass = apiCheck.getApiPackage("test.apicontainer").getApiClass( - "test.apicontainer.ApiClass"); - ApiClass innerClass = apiCheck.getApiPackage("test.apicontainer").getApiClass( - "test.apicontainer.NonApiClass.ApiClassInNonApiClass"); - ApiClass oneMoreApiClass = apiCheck.getApiPackage("test.apicontainer").getApiClass( - "test.apicontainer.OneMoreApiClass"); + ApiClass object = apiCheck.getApiPackage("java.lang").getApiClass("java.lang.Object"); + ApiClass apiClass = + apiCheck.getApiPackage("test.apicontainer").getApiClass("test.apicontainer.ApiClass"); + ApiClass innerClass = + apiCheck.getApiPackage("test.apicontainer").getApiClass( + "test.apicontainer.NonApiClass.ApiClassInNonApiClass"); + ApiClass oneMoreApiClass = + apiCheck.getApiPackage("test.apicontainer") + .getApiClass("test.apicontainer.OneMoreApiClass"); // constructors - assertEquals(1, innerClass.getApiMemberNames( - ApiClass.MethodType.CONSTRUCTOR).size()); + assertEquals(1, innerClass.getApiMemberNames(ApiClass.MethodType.CONSTRUCTOR).size()); // fields assertEquals(3, object.getApiFieldNames().size()); @@ -245,27 +242,24 @@ // methods assertEquals(4, object.getApiMemberNames(ApiClass.MethodType.METHOD).size()); - assertEquals(7, - apiClass.getApiMemberNames(ApiClass.MethodType.METHOD).size()); + assertEquals(7, apiClass.getApiMemberNames(ApiClass.MethodType.METHOD).size()); // the method definition lowest in the class hierarchy is kept - assertNotSame(getMethodByName("apiMethod0", apiClass), getMethodByName( - "apiMethod0", object)); - assertEquals(getMethodByName("protectedMethod0", apiClass), - getMethodByName("protectedMethod0", object)); + assertNotSame(getMethodByName("apiMethod0", apiClass), getMethodByName("apiMethod0", object)); + assertEquals(getMethodByName("protectedMethod0", apiClass), getMethodByName("protectedMethod0", + object)); assertNotNull(getMethodByName("methodInNonApiClass1", apiClass)); - assertEquals(5, oneMoreApiClass.getApiMemberNames( - ApiClass.MethodType.METHOD).size()); - Set<String> methodNames = new HashSet<String>( - Arrays.asList(new String[] {"checkOverloadedAndOverridableDetection1"})); - assertEquals(1, oneMoreApiClass.getApiMembersBySet(methodNames, - ApiClass.MethodType.METHOD).size()); + assertEquals(5, oneMoreApiClass.getApiMemberNames(ApiClass.MethodType.METHOD).size()); + Set<String> methodNames = + new HashSet<String>(Arrays.asList(new String[] {"checkOverloadedAndOverridableDetection1"})); + assertEquals(1, oneMoreApiClass.getApiMembersBySet(methodNames, ApiClass.MethodType.METHOD) + .size()); // checkOverloadedMethodAccounted should appear twice. - methodNames = new HashSet<String>( - Arrays.asList(new String[] {"checkOverloadedMethodAccounted1"})); - assertEquals(2, oneMoreApiClass.getApiMembersBySet(methodNames, - ApiClass.MethodType.METHOD).size()); + methodNames = + new HashSet<String>(Arrays.asList(new String[] {"checkOverloadedMethodAccounted1"})); + assertEquals(2, oneMoreApiClass.getApiMembersBySet(methodNames, ApiClass.MethodType.METHOD) + .size()); } /**