Project health: remove duplicated functionality (extracting ObjectiveCName from package-info file).
Change on 2019/06/13 by antoniocortes
@@ -16,18 +16,12 @@ package com.google.devtools.j2objc.pipeline;
import com.google.common.io.Files;
import com.google.devtools.j2objc.Options;
-import com.google.devtools.j2objc.ast.Annotation;
-import com.google.devtools.j2objc.ast.CompilationUnit;
-import com.google.devtools.j2objc.ast.SingleMemberAnnotation;
import com.google.devtools.j2objc.file.InputFile;
import com.google.devtools.j2objc.file.RegularInputFile;
import com.google.devtools.j2objc.util.ErrorUtil;
import com.google.devtools.j2objc.util.Parser;
-import com.google.devtools.j2objc.util.TypeUtil;
-import com.google.j2objc.annotations.ObjectiveCName;
import java.io.File;
import java.io.IOException;
-import java.util.List;
import java.util.logging.Logger;
/**
@@ -56,9 +50,7 @@ public class InputFilePreprocessor {
private void processInput(ProcessingContext input) {
try {
- if (input.getFile().getUnitName().endsWith("package-info.java")) {
- processPackageInfoSource(input);
- } else {
+ if (!input.getFile().getUnitName().endsWith("package-info.java")) {
processRegularSource(input);
}
} catch (IOException e) {
@@ -107,31 +99,4 @@ public class InputFilePreprocessor {
input.setFile(new RegularInputFile(strippedFile.getPath(), relativePath));
}
}
-
- private void processPackageInfoSource(ProcessingContext input) {
- InputFile file = input.getFile();
- CompilationUnit compilationUnit = parser.parse(file);
- if (compilationUnit != null) {
- extractPackagePrefix(file, compilationUnit);
- }
- }
-
- private void extractPackagePrefix(InputFile file, CompilationUnit unit) {
- // We should only reach here if it's a package-info.java file.
- assert file.getUnitName().endsWith("package-info.java");
- List<Annotation> annotations = (List<Annotation>) unit.getPackage().getAnnotations();
- for (Annotation annotation : annotations) {
- // getFullyQualifiedName() might not actually return a fully qualified name.
- String name = annotation.getTypeName().getFullyQualifiedName();
- if (name.endsWith("ObjectiveCName")) {
- // Per Eclipse docs, binding resolution can be a resource hog.
- if (TypeUtil.getQualifiedName(annotation.getAnnotationMirror().getAnnotationType()).equals(
- ObjectiveCName.class.getCanonicalName())) {
- String key = unit.getPackage().getName().getFullyQualifiedName();
- String val = (String) ((SingleMemberAnnotation) annotation).getValue().getConstantValue();
- options.getPackagePrefixes().addPrefix(key, val);
- }
- }
- }
- }
}
