/** * Performs the actual deletion (or display, if in dry-run mode) of the typedef annotation * files */ private void deleteAnnotationClasses() { for (File mFile : mAnnotationClassFiles) { if (mVerbose) { if (mDryRun) { mExtractor.info("Would delete " + mFile); } else { mExtractor.info("Deleting " + mFile); } } if (!mDryRun) { boolean deleted = mFile.delete(); if (!deleted) { Extractor.warning("Could not delete " + mFile); } } } } }
private void mergeAnnotationsXml(@NonNull String path, @NonNull String xml) { try { Document document = XmlUtils.parseDocument(xml, false); mergeDocument(document); } catch (Exception e) { warning("Failed to merge " + path + ": " + e.toString()); if (!(e instanceof IOException)) { e.printStackTrace(); } } }
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull Annotation[] annotations) { for (Annotation annotation : annotations) { String typeName = Extractor.getFqn(annotation); if ("java.lang.annotation.Retention".equals(typeName)) { MemberValuePair[] pairs = annotation.memberValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; } MemberValuePair pair = pairs[0]; Expression value = pair.value; if (value instanceof NameReference) { NameReference reference = (NameReference) value; Binding binding = reference.binding; if (binding != null) { if (binding instanceof FieldBinding) { FieldBinding fb = (FieldBinding) binding; if ("SOURCE".equals(new String(fb.name)) && "java.lang.annotation.RetentionPolicy".equals( new String(fb.declaringClass.readableName()))) { return true; } } } } } } return false; }
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull Annotation[] annotations) { for (Annotation annotation : annotations) { String typeName = Extractor.getFqn(annotation); if ("java.lang.annotation.Retention".equals(typeName)) { MemberValuePair[] pairs = annotation.memberValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; } MemberValuePair pair = pairs[0]; Expression value = pair.value; if (value instanceof NameReference) { NameReference reference = (NameReference) value; Binding binding = reference.binding; if (binding != null) { if (binding instanceof FieldBinding) { FieldBinding fb = (FieldBinding) binding; if ("SOURCE".equals(new String(fb.name)) && "java.lang.annotation.RetentionPolicy".equals( new String(fb.declaringClass.readableName()))) { return true; } } } } } } return false; }
/** * Performs the actual deletion (or display, if in dry-run mode) of the typedef annotation * files */ private void deleteAnnotationClasses(@NonNull File classDir) { for (String relative : mAnnotationClassFiles) { File file = new File(classDir, relative.replace('/', File.separatorChar)); if (!file.isFile()) { Extractor.error("Warning: Could not find class file " + file + " for typedef"); continue; } if (mVerbose) { if (mDryRun) { info("Would delete " + file); } else { info("Deleting " + file); } } if (!mDryRun) { boolean deleted = file.delete(); if (!deleted) { Extractor.warning("Could not delete " + file); } } } } }
Matcher matcher = METHOD.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Matcher matcher = CTOR.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Matcher matcher = PACKAGE.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a package: " + line); } else { currentPackage = matcher.group(1); Matcher matcher = CLASS.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a class/interface: " + line); } else { currentClass = currentPackage + '.' + matcher.group(4);
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull AnnotationBinding a) { if (new String(a.getAnnotationType().readableName()).equals("java.lang.annotation.Retention")) { ElementValuePair[] pairs = a.getElementValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; } ElementValuePair pair = pairs[0]; Object value = pair.getValue(); if (value instanceof FieldBinding) { FieldBinding field = (FieldBinding) value; if ("SOURCE".equals(new String(field.readableName()))) { return true; } } } return false; }
Matcher matcher = METHOD.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Matcher matcher = CTOR.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Matcher matcher = PACKAGE.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a package: " + line); } else { currentPackage = matcher.group(1); Matcher matcher = CLASS.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a class/interface: " + line); } else { currentClass = currentPackage + '.' + matcher.group(4);
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull AnnotationBinding a) { if (new String(a.getAnnotationType().readableName()).equals("java.lang.annotation.Retention")) { ElementValuePair[] pairs = a.getElementValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; } ElementValuePair pair = pairs[0]; Object value = pair.getValue(); if (value instanceof FieldBinding) { FieldBinding field = (FieldBinding) value; if ("SOURCE".equals(new String(field.readableName()))) { return true; } } } return false; }
String documentation = stringBuffer.toString(); if (!documentation.contains("@hide")) { Extractor.warning(getFileName() + ": The typedef annotation " + fqn + " should specify @hide in a doc comment"); Extractor.warning(getFileName() + ": The typedef annotation " + fqn + " should have @Retention(RetentionPolicy.SOURCE)");
@Nullable private static Document checkDocument(@NonNull String pkg, @NonNull String xml, boolean namespaceAware) { try { return XmlUtils.parseDocument(xml, namespaceAware); } catch (SAXException sax) { warning("Failed to parse document for package " + pkg + ": " + sax.toString()); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
@Nullable private static Document checkDocument(@NonNull String pkg, @NonNull String xml, boolean namespaceAware) { try { return XmlUtils.parseDocument(xml, namespaceAware); } catch (SAXException sax) { warning("Failed to parse document for package " + pkg + ": " + sax.toString()); } catch (Exception e) { // pass // This method is deliberately silent; will return null } return null; }
warning("Found both @Nullable and @NonNull after import for " + item); continue;
warning("Found both @Nullable and @NonNull after import for " + item); continue;