Skip to content

Commit

Permalink
Clean up some unused code in PackagePrefixes.java.
Browse files Browse the repository at this point in the history
	Change on 2016/11/18 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139606001
  • Loading branch information
kstanger authored and Keith Stanger committed Dec 1, 2016
1 parent 707a21c commit a9574ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 26 deletions.
Expand Up @@ -538,8 +538,7 @@ private void printBoxedOperators() {
}

private void printUnprefixedAlias() {
String pkg = ElementUtil.getName(ElementUtil.getPackage(typeElement));
if (nameTable.hasPrefix(pkg) && ElementUtil.isTopLevel(typeElement)) {
if (ElementUtil.isTopLevel(typeElement)) {
String unprefixedName =
NameTable.camelCaseQualifiedName(ElementUtil.getQualifiedName(typeElement));
if (!unprefixedName.equals(typeName)) {
Expand Down
Expand Up @@ -908,8 +908,4 @@ public static String getMainTypeFullName(CompilationUnit unit) {
public String getPrefix(PackageElement packageElement) {
return prefixMap.getPrefix(packageElement);
}

public boolean hasPrefix(String packageName) {
return prefixMap.hasPrefix(packageName);
}
}
Expand Up @@ -23,9 +23,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.PackageElement;
import javax.lang.model.type.DeclaredType;

/**
* Class that creates and stores the prefixes associated with Java packages.
Expand Down Expand Up @@ -101,10 +99,6 @@ public void addPrefix(String pkg, String prefix) {
}
}

public boolean hasPrefix(String packageName) {
return getPrefix(packageName) != null;
}

/**
* Return the prefix for a specified package. If a prefix was specified
* for the package, then that prefix is returned. Otherwise, a camel-cased
Expand All @@ -115,20 +109,12 @@ public String getPrefix(PackageElement packageElement) {
return "";
}
String packageName = packageElement.getQualifiedName().toString();
if (hasPrefix(packageName)) {
return getPrefix(packageName);
}

for (AnnotationMirror annotation : packageElement.getAnnotationMirrors()) {
DeclaredType annotationType = annotation.getAnnotationType();
if (annotationType.asElement().getSimpleName().toString().equals("ObjectiveCName")) {
String prefix = (String) ElementUtil.getAnnotationValue(annotation, "value");
addPrefix(packageName, prefix);
// Don't return, as there may be a prefix annotation that overrides this value.
}
String prefix = getPrefix(packageName);
if (prefix != null) {
return prefix;
}

String prefix = packageLookup.getObjectiveCName(packageName);
prefix = packageLookup.getObjectiveCName(packageName);
if (prefix == null) {
prefix = NameTable.camelCaseQualifiedName(packageName);
}
Expand Down
Expand Up @@ -41,8 +41,8 @@ public void testPackagePrefixesFile() throws IOException {
Properties properties = new Properties();
properties.load(reader);
PackagePrefixes prefixMap = Options.getPackagePrefixes();
assertFalse(prefixMap.hasPrefix("java.lang"));
assertFalse(prefixMap.hasPrefix("foo.bar"));
assertNull(prefixMap.getPrefix("java.lang"));
assertNull(prefixMap.getPrefix("foo.bar"));
prefixMap.addPrefixProperties(properties);
assertEquals("JL", prefixMap.getPrefix("java.lang"));
assertEquals("FB", prefixMap.getPrefix("foo.bar"));
Expand Down

0 comments on commit a9574ea

Please sign in to comment.