Remove localName from NamedType

The Formatter CL introduced definedName to type which is the very thing
that NamedType::localName already did.

Thus localName should be removed.

Bug: 137553653
Test: ./test/run_all_*_test.sh
Change-Id: I61bff460d77d7b880831115be0602a49669fd7be
diff --git a/AST.cpp b/AST.cpp
index edb7ff9..5453e85 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -496,7 +496,7 @@
 FQName AST::makeFullName(const char* localName, Scope* scope) const {
     std::vector<std::string> pathComponents{{localName}};
     for (; scope != &mRootScope; scope = scope->parent()) {
-        pathComponents.push_back(scope->localName());
+        pathComponents.push_back(scope->definedName());
     }
 
     std::reverse(pathComponents.begin(), pathComponents.end());
diff --git a/CompoundType.cpp b/CompoundType.cpp
index 0be78a8..136ab34 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -102,9 +102,9 @@
 
 void CompoundType::emitInvalidSubTypeNamesError(const std::string& subTypeName,
                                                 const Location& location) const {
-    std::cerr << "ERROR: Type name '" << subTypeName << "' defined at "
-              << location << " conflicts with a member function of "
-              << "safe_union " << localName() << ". Consider renaming or "
+    std::cerr << "ERROR: Type name '" << subTypeName << "' defined at " << location
+              << " conflicts with a member function of "
+              << "safe_union " << definedName() << ". Consider renaming or "
               << "moving its definition outside the safe_union scope.\n";
 }
 
@@ -113,9 +113,8 @@
     const auto& subTypes = Scope::getSubTypes();
 
     for (const auto& subType : subTypes) {
-        if (subType->localName() == "getDiscriminator") {
-            emitInvalidSubTypeNamesError(subType->localName(),
-                                         subType->location());
+        if (subType->definedName() == "getDiscriminator") {
+            emitInvalidSubTypeNamesError(subType->definedName(), subType->location());
             return UNKNOWN_ERROR;
         }
     }
@@ -142,13 +141,13 @@
 std::string CompoundType::typeName() const {
     switch (mStyle) {
         case STYLE_STRUCT: {
-            return "struct " + localName();
+            return "struct " + definedName();
         }
         case STYLE_UNION: {
-            return "union " + localName();
+            return "union " + definedName();
         }
         case STYLE_SAFE_UNION: {
-            return "safe_union " + localName();
+            return "safe_union " + definedName();
         }
     }
     CHECK(!"Should not be here");
@@ -500,9 +499,7 @@
 }
 
 void CompoundType::emitSafeUnionTypeDeclarations(Formatter& out) const {
-    out << "struct "
-        << localName()
-        << " final {\n";
+    out << "struct " << definedName() << " final {\n";
 
     out.indent();
 
@@ -532,12 +529,12 @@
     });
     out << ";\n\n";
 
-    out << localName() << "();\n"  // Constructor
-        << "~" << localName() << "();\n"  // Destructor
-        << localName() << "(" << localName() << "&&);\n"  // Move constructor
-        << localName() << "(const " << localName() << "&);\n"  // Copy constructor
-        << localName() << "& operator=(" << localName() << "&&);\n"  // Move assignment
-        << localName() << "& operator=(const " << localName() << "&);\n\n";  // Copy assignment
+    out << definedName() << "();\n"                                              // Constructor
+        << "~" << definedName() << "();\n"                                       // Destructor
+        << definedName() << "(" << definedName() << "&&);\n"                     // Move constructor
+        << definedName() << "(const " << definedName() << "&);\n"                // Copy constructor
+        << definedName() << "& operator=(" << definedName() << "&&);\n"          // Move assignment
+        << definedName() << "& operator=(const " << definedName() << "&);\n\n";  // Copy assignment
 
     for (const auto& field : *mFields) {
         // Setter (copy)
@@ -661,10 +658,7 @@
         return;
     }
 
-    out << ((mStyle == STYLE_STRUCT) ? "struct" : "union")
-        << " "
-        << localName()
-        << " final {\n";
+    out << ((mStyle == STYLE_STRUCT) ? "struct" : "union") << " " << definedName() << " final {\n";
 
     out.indent();
 
@@ -742,7 +736,7 @@
             CHECK(!"Should not be here");
         }
     }
-    out << " " << localName() << ";\n";
+    out << " " << definedName() << ";\n";
 }
 
 void CompoundType::emitPackageTypeDeclarations(Formatter& out) const {
@@ -760,7 +754,7 @@
         out << "static inline bool operator!=("
             << getCppArgumentType() << " lhs, " << getCppArgumentType() << " rhs);\n";
     } else {
-        out << "// operator== and operator!= are not generated for " << localName() << "\n";
+        out << "// operator== and operator!= are not generated for " << definedName() << "\n";
     }
 
     out.endl();
@@ -882,7 +876,7 @@
             out << "return !(lhs == rhs);\n";
         }).endl().endl();
     } else {
-        out << "// operator== and operator!= are not generated for " << localName() << "\n\n";
+        out << "// operator== and operator!= are not generated for " << definedName() << "\n\n";
     }
 }
 
@@ -1048,10 +1042,7 @@
 void CompoundType::emitSafeUnionTypeConstructors(Formatter& out) const {
 
     // Default constructor
-    out << fullName()
-        << "::"
-        << localName()
-        << "() ";
+    out << fullName() << "::" << definedName() << "() ";
 
     out.block([&] {
         out << "static_assert(offsetof("
@@ -1087,46 +1078,34 @@
     }).endl().endl();
 
     // Destructor
-    out << fullName()
-        << "::~"
-        << localName()
-        << "() ";
+    out << fullName() << "::~" << definedName() << "() ";
 
     out.block([&] {
         out << "hidl_destructUnion();\n";
     }).endl().endl();
 
     // Move constructor
-    out << fullName() << "::" << localName() << "(" << localName() << "&& other) : " << fullName()
-        << "() ";
+    out << fullName() << "::" << definedName() << "(" << definedName()
+        << "&& other) : " << fullName() << "() ";
 
     emitSafeUnionCopyAndAssignDefinition(
             out, "other", true /* isCopyConstructor */, true /* usesMoveSemantics */);
 
     // Copy constructor
-    out << fullName() << "::" << localName() << "(const " << localName()
+    out << fullName() << "::" << definedName() << "(const " << definedName()
         << "& other) : " << fullName() << "() ";
 
     emitSafeUnionCopyAndAssignDefinition(
         out, "other", true /* isCopyConstructor */, false /* usesMoveSemantics */);
 
     // Move assignment operator
-    out << fullName()
-        << "& ("
-        << fullName()
-        << "::operator=)("
-        << localName()
-        << "&& other) ";
+    out << fullName() << "& (" << fullName() << "::operator=)(" << definedName() << "&& other) ";
 
     emitSafeUnionCopyAndAssignDefinition(
             out, "other", false /* isCopyConstructor */, true /* usesMoveSemantics */);
 
     // Copy assignment operator
-    out << fullName()
-        << "& ("
-        << fullName()
-        << "::operator=)(const "
-        << localName()
+    out << fullName() << "& (" << fullName() << "::operator=)(const " << definedName()
         << "& other) ";
 
     emitSafeUnionCopyAndAssignDefinition(
@@ -1225,7 +1204,7 @@
 
 void CompoundType::emitTypeDefinitions(Formatter& out, const std::string& prefix) const {
     std::string space = prefix.empty() ? "" : (prefix + "::");
-    Scope::emitTypeDefinitions(out, space + localName());
+    Scope::emitTypeDefinitions(out, space + definedName());
 
     if (needsEmbeddedReadWrite()) {
         emitStructReaderWriter(out, prefix, true /* isReader */);
@@ -1256,16 +1235,14 @@
         out << "static ";
     }
 
-    out << "class "
-        << localName()
-        << " {\n";
+    out << "class " << definedName() << " {\n";
 
     out.indent();
 
     Scope::emitJavaTypeDeclarations(out, false /* atTopLevel */);
 
     if (mStyle == STYLE_SAFE_UNION) {
-        out << "public " << localName() << "() ";
+        out << "public " << definedName() << "() ";
         out.block([&] {
             CHECK(!mFields->empty());
             mFields->at(0)->type().emitJavaFieldDefaultInitialValue(out, "hidl_o");
@@ -1447,7 +1424,7 @@
             out << ");\n";
         }).endl().endl();
     } else {
-        out << "// equals() is not generated for " << localName() << "\n";
+        out << "// equals() is not generated for " << definedName() << "\n";
     }
 
     ////////////////////////////////////////////////////////////////////////////
@@ -1556,11 +1533,11 @@
     size_t vecAlign, vecSize;
     VectorType::getAlignmentAndSizeStatic(&vecAlign, &vecSize);
 
-    out << "public static final java.util.ArrayList<" << localName()
+    out << "public static final java.util.ArrayList<" << definedName()
         << "> readVectorFromParcel(android.os.HwParcel parcel) {\n";
     out.indent();
 
-    out << "java.util.ArrayList<" << localName() << "> _hidl_vec = new java.util.ArrayList();\n";
+    out << "java.util.ArrayList<" << definedName() << "> _hidl_vec = new java.util.ArrayList();\n";
 
     if (containsInterface()) {
         out << "int size = parcel.readInt32();\n";
@@ -1693,7 +1670,8 @@
 
     out << "public static final void writeVectorToParcel(\n";
     out.indent(2);
-    out << "android.os.HwParcel parcel, java.util.ArrayList<" << localName() << "> _hidl_vec) {\n";
+    out << "android.os.HwParcel parcel, java.util.ArrayList<" << definedName()
+        << "> _hidl_vec) {\n";
     out.unindent();
 
     if (containsInterface()) {
@@ -1790,10 +1768,10 @@
 
     const std::string name = "obj";
     if (isReader) {
-        out << "const " << space << localName() << " &" << name << ",\n";
+        out << "const " << space << definedName() << " &" << name << ",\n";
         out << "const ::android::hardware::Parcel &parcel,\n";
     } else {
-        out << "const " << space << localName() << " &" << name << ",\n";
+        out << "const " << space << definedName() << " &" << name << ",\n";
         out << "::android::hardware::Parcel *parcel,\n";
     }
 
diff --git a/Coordinator.cpp b/Coordinator.cpp
index b75fd44..6e84c8f 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -289,10 +289,10 @@
                 fprintf(stderr,
                         "ERROR: File at '%s' declares an interface '%s' "
                         "instead of the expected types common to the package.\n",
-                        path.c_str(), (*ast)->getInterface()->localName().c_str());
+                        path.c_str(), (*ast)->getInterface()->definedName().c_str());
 
                 err = UNKNOWN_ERROR;
-            } else if ((*ast)->getInterface()->localName() != fqName.name()) {
+            } else if ((*ast)->getInterface()->definedName() != fqName.name()) {
                 fprintf(stderr,
                         "ERROR: File at '%s' does not declare interface type "
                         "'%s'.\n",
diff --git a/EnumType.cpp b/EnumType.cpp
index ec4a1e2..0728112 100644
--- a/EnumType.cpp
+++ b/EnumType.cpp
@@ -152,7 +152,7 @@
 }
 
 std::string EnumType::typeName() const {
-    return "enum " + localName();
+    return "enum " + definedName();
 }
 
 bool EnumType::isEnum() const {
@@ -186,7 +186,7 @@
 
 std::string EnumType::getBitfieldCppType(StorageMode /* mode */, bool specifyNamespaces) const {
     const std::string space = specifyNamespaces ? "::android::hardware::" : "";
-    return space + "hidl_bitfield<" + (specifyNamespaces ? fullName() : localName()) + ">";
+    return space + "hidl_bitfield<" + (specifyNamespaces ? fullName() : definedName()) + ">";
 }
 
 std::string EnumType::getBitfieldJavaType(bool forInitializer) const {
@@ -282,11 +282,7 @@
 
     const std::string storageType = scalarType->getCppStackType();
 
-    out << "enum class "
-        << localName()
-        << " : "
-        << storageType
-        << " {\n";
+    out << "enum class " << definedName() << " : " << storageType << " {\n";
 
     out.indent();
 
@@ -314,7 +310,7 @@
     const ScalarType* scalarType = mStorageType->resolveToScalarType();
     const std::string storageType = scalarType->getCppStackType();
 
-    out << "enum class " << localName() << " : " << storageType << ";\n";
+    out << "enum class " << definedName() << " : " << storageType << ";\n";
 }
 
 void EnumType::emitIteratorDeclaration(Formatter& out) const {
@@ -495,11 +491,7 @@
     const ScalarType *scalarType = mStorageType->resolveToScalarType();
     CHECK(scalarType != nullptr);
 
-    out << "public "
-        << (atTopLevel ? "" : "static ")
-        << "final class "
-        << localName()
-        << " {\n";
+    out << "public " << (atTopLevel ? "" : "static ") << "final class " << definedName() << " {\n";
 
     out.indent();
 
@@ -668,7 +660,7 @@
     const Annotation *annotation = findExportAnnotation();
     CHECK(annotation != nullptr);
 
-    std::string name = localName();
+    std::string name = definedName();
 
     const AnnotationParam *nameParam = annotation->getParam("name");
     if (nameParam != nullptr) {
@@ -711,7 +703,7 @@
 
             out.indent();
         } else {
-            out << "// Values declared in " << localName() << " follow.\n";
+            out << "// Values declared in " << definedName() << " follow.\n";
         }
 
         const std::string typeName =
diff --git a/Interface.cpp b/Interface.cpp
index 92aaa62..28918a4 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -76,7 +76,7 @@
     : Scope(localName, fullName, location, parent), mSuperType(superType), mFileHash(fileHash) {}
 
 std::string Interface::typeName() const {
-    return "interface " + localName();
+    return "interface " + definedName();
 }
 
 const Hash* Interface::getFileHash() const {
@@ -746,7 +746,7 @@
 }
 
 std::string Interface::getVtsType() const {
-    if (StringHelper::EndsWith(localName(), "Callback")) {
+    if (StringHelper::EndsWith(definedName(), "Callback")) {
         return "TYPE_HIDL_CALLBACK";
     } else {
         return "TYPE_HIDL_INTERFACE";
@@ -870,7 +870,7 @@
 void Interface::emitTypeDefinitions(Formatter& out, const std::string& prefix) const {
     std::string space = prefix.empty() ? "" : (prefix + "::");
 
-    Scope::emitTypeDefinitions(out, space + localName());
+    Scope::emitTypeDefinitions(out, space + definedName());
 }
 
 void Interface::emitJavaReaderWriter(
diff --git a/NamedType.cpp b/NamedType.cpp
index dba9248..a356617 100644
--- a/NamedType.cpp
+++ b/NamedType.cpp
@@ -20,7 +20,7 @@
 
 NamedType::NamedType(const char* localName, const FQName& fullName, const Location& loc,
                      Scope* parent)
-    : Type(parent, localName), mLocalName(localName), mFullName(fullName), mLocation(loc) {}
+    : Type(parent, localName), mFullName(fullName), mLocation(loc) {}
 
 bool NamedType::isNamedType() const {
     return true;
@@ -30,10 +30,6 @@
     return mFullName;
 }
 
-std::string NamedType::localName() const {
-    return mLocalName;
-}
-
 std::string NamedType::fullName() const {
     return mFullName.cppName();
 }
diff --git a/NamedType.h b/NamedType.h
index 857f3a3..df03704 100644
--- a/NamedType.h
+++ b/NamedType.h
@@ -34,8 +34,6 @@
 
     const FQName &fqName() const;
 
-    std::string localName() const;
-
     /* short for fqName().cppName() */
     std::string fullName() const;
     /* short for fqName().fullJavaName() */
@@ -49,7 +47,6 @@
             const std::string &name) const override;
 
    private:
-    const std::string mLocalName;
     const FQName mFullName;
     const Location mLocation;
 
diff --git a/Scope.cpp b/Scope.cpp
index cfe004d..2f58a62 100644
--- a/Scope.cpp
+++ b/Scope.cpp
@@ -36,13 +36,13 @@
 void Scope::addType(NamedType* type) {
     size_t index = mTypes.size();
     mTypes.push_back(type);
-    mTypeIndexByName[type->localName()] = index;
+    mTypeIndexByName[type->definedName()] = index;
 }
 
 status_t Scope::validateUniqueNames() const {
     for (const auto* type : mTypes) {
-        if (mTypes[mTypeIndexByName.at(type->localName())] != type) {
-            std::cerr << "ERROR: A type named '" << type->localName()
+        if (mTypes[mTypeIndexByName.at(type->definedName())] != type) {
+            std::cerr << "ERROR: A type named '" << type->definedName()
                       << "' is already declared in the scope at " << type->location() << std::endl;
             return UNKNOWN_ERROR;
         }
@@ -152,7 +152,7 @@
     std::sort(mTypes.begin(), mTypes.end(), less);
 
     for (size_t i = 0; i != mTypes.size(); ++i) {
-        mTypeIndexByName.at(mTypes[i]->localName()) = i;
+        mTypeIndexByName.at(mTypes[i]->definedName()) = i;
     }
 }
 
diff --git a/TypeDef.cpp b/TypeDef.cpp
index 2e36c28..39e87d4 100644
--- a/TypeDef.cpp
+++ b/TypeDef.cpp
@@ -47,7 +47,7 @@
 }
 
 std::string TypeDef::typeName() const {
-    return "typedef " + localName();
+    return "typedef " + definedName();
 }
 
 bool TypeDef::isTypeDef() const {
@@ -73,15 +73,11 @@
 }
 
 void TypeDef::emitTypeDeclarations(Formatter& out) const {
-    out << "typedef "
-        << mReferencedType->getCppStackType()
-        << " "
-        << localName()
-        << ";\n\n";
+    out << "typedef " << mReferencedType->getCppStackType() << " " << definedName() << ";\n\n";
 }
 
 void TypeDef::emitHidlDefinition(Formatter& out) const {
-    out << "typedef " << mReferencedType.localName() << " " << localName() << ";\n";
+    out << "typedef " << mReferencedType.localName() << " " << definedName() << ";\n";
 }
 
 }  // namespace android
diff --git a/generateCpp.cpp b/generateCpp.cpp
index a2a4e44..a238838 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -228,7 +228,7 @@
 
 void AST::generateInterfaceHeader(Formatter& out) const {
     const Interface *iface = getInterface();
-    std::string ifaceName = iface ? iface->localName() : "types";
+    std::string ifaceName = iface ? iface->definedName() : "types";
     const std::string guard = makeHeaderGuard(ifaceName);
 
     out << "#ifndef " << guard << "\n";
@@ -369,7 +369,7 @@
             out << "\n// skipped getService, registerAsService, registerForNotifications\n\n";
         } else {
             out << "\n// helper methods for interactions with the hwservicemanager\n";
-            declareServiceManagerInteractions(out, iface->localName());
+            declareServiceManagerInteractions(out, iface->definedName());
         }
     }
 
@@ -409,7 +409,7 @@
     out << "#ifndef " << guard << "\n";
     out << "#define " << guard << "\n\n";
 
-    generateCppPackageInclude(out, mPackage, iface ? iface->localName() : "types");
+    generateCppPackageInclude(out, mPackage, iface ? iface->definedName() : "types");
 
     out << "\n";
 
@@ -636,7 +636,7 @@
 
 void AST::generateTemplatizationLink(Formatter& out) const {
     DocComment("The pure class is what this class wraps.", HIDL_LOCATION_HERE).emit(out);
-    out << "typedef " << mRootScope.getInterface()->localName() << " Pure;\n\n";
+    out << "typedef " << mRootScope.getInterface()->definedName() << " Pure;\n\n";
 }
 
 void AST::generateCppTag(Formatter& out, const std::string& tag) const {
@@ -672,13 +672,11 @@
     }
 
     out.indent();
-    out << "explicit "
-        << klassName
-        << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl);"
+    out << "explicit " << klassName << "(const ::android::sp<" << iface->definedName()
+        << "> &_hidl_impl);"
         << "\n";
-    out << "explicit "
-        << klassName
-        << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl,"
+    out << "explicit " << klassName << "(const ::android::sp<" << iface->definedName()
+        << "> &_hidl_impl,"
         << " const std::string& HidlInstrumentor_package,"
         << " const std::string& HidlInstrumentor_interface);"
         << "\n\n";
@@ -701,7 +699,7 @@
             .emit(out);
     generateCppTag(out, "android::hardware::details::bnhw_tag");
 
-    out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; }\n";
+    out << "::android::sp<" << iface->definedName() << "> getImpl() { return _hidl_mImpl; }\n";
 
     generateMethods(out,
                     [&](const Method* method, const Interface*) {
@@ -743,7 +741,7 @@
         out << ";\n";
     });
 
-    out << "::android::sp<" << iface->localName() << "> _hidl_mImpl;\n";
+    out << "::android::sp<" << iface->definedName() << "> _hidl_mImpl;\n";
     out.unindent();
     out << "};\n\n";
 
@@ -777,11 +775,8 @@
     enterLeaveNamespace(out, true /* enter */);
     out << "\n";
 
-    out << "struct "
-        << proxyName
-        << " : public ::android::hardware::BpInterface<"
-        << iface->localName()
-        << ">, public ::android::hardware::details::HidlInstrumentor {\n";
+    out << "struct " << proxyName << " : public ::android::hardware::BpInterface<"
+        << iface->definedName() << ">, public ::android::hardware::details::HidlInstrumentor {\n";
 
     out.indent();
 
@@ -881,47 +876,36 @@
     enterLeaveNamespace(out, true /* enter */);
     out << "\n";
 
-    generateTypeSource(out, iface ? iface->localName() : "");
+    generateTypeSource(out, iface ? iface->definedName() : "");
 
     if (iface) {
         const Interface* iface = mRootScope.getInterface();
 
         // need to be put here, generateStubSource is using this.
-        out << "const char* "
-            << iface->localName()
-            << "::descriptor(\""
-            << iface->fqName().string()
-            << "\");\n\n";
+        out << "const char* " << iface->definedName() << "::descriptor(\""
+            << iface->fqName().string() << "\");\n\n";
         out << "__attribute__((constructor)) ";
         out << "static void static_constructor() {\n";
         out.indent([&] {
             out << "::android::hardware::details::getBnConstructorMap().set("
-                << iface->localName()
-                << "::descriptor,\n";
+                << iface->definedName() << "::descriptor,\n";
             out.indent(2, [&] {
                 out << "[](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n";
                 out.indent([&] {
-                    out << "return new "
-                        << iface->getStubName()
-                        << "(static_cast<"
-                        << iface->localName()
-                        << " *>(iIntf));\n";
+                    out << "return new " << iface->getStubName() << "(static_cast<"
+                        << iface->definedName() << " *>(iIntf));\n";
                 });
                 out << "});\n";
             });
             out << "::android::hardware::details::getBsConstructorMap().set("
-                << iface->localName()
-                << "::descriptor,\n";
+                << iface->definedName() << "::descriptor,\n";
             out.indent(2, [&] {
                 out << "[](void *iIntf) -> ::android::sp<"
                     << gIBaseFqName.cppName()
                     << "> {\n";
                 out.indent([&] {
-                    out << "return new "
-                        << iface->getPassthroughName()
-                        << "(static_cast<"
-                        << iface->localName()
-                        << " *>(iIntf));\n";
+                    out << "return new " << iface->getPassthroughName() << "(static_cast<"
+                        << iface->definedName() << " *>(iIntf));\n";
                 });
                 out << "});\n";
             });
@@ -931,11 +915,9 @@
         out << "static void static_destructor() {\n";
         out.indent([&] {
             out << "::android::hardware::details::getBnConstructorMap().erase("
-                << iface->localName()
-                << "::descriptor);\n";
+                << iface->definedName() << "::descriptor);\n";
             out << "::android::hardware::details::getBsConstructorMap().erase("
-                << iface->localName()
-                << "::descriptor);\n";
+                << iface->definedName() << "::descriptor);\n";
         });
         out << "};\n\n";
 
@@ -1275,7 +1257,7 @@
 }
 
 void AST::generateStubSource(Formatter& out, const Interface* iface) const {
-    const std::string interfaceName = iface->localName();
+    const std::string interfaceName = iface->definedName();
     const std::string klassName = iface->getStubName();
 
     out << klassName
@@ -1677,7 +1659,7 @@
     out << "#include <cutils/trace.h>\n";
     out << "#include <future>\n";
 
-    generateCppPackageInclude(out, mPackage, iface->localName());
+    generateCppPackageInclude(out, mPackage, iface->definedName());
     out << "\n";
 
     out << "#include <hidl/HidlPassthroughSupport.h>\n";
@@ -1686,16 +1668,11 @@
     enterLeaveNamespace(out, true /* enter */);
     out << "\n";
 
-    out << "struct "
-        << klassName
-        << " : " << iface->localName()
+    out << "struct " << klassName << " : " << iface->definedName()
         << ", ::android::hardware::details::HidlInstrumentor {\n";
 
     out.indent();
-    out << "explicit "
-        << klassName
-        << "(const ::android::sp<"
-        << iface->localName()
+    out << "explicit " << klassName << "(const ::android::sp<" << iface->definedName()
         << "> impl);\n";
 
     out.endl();
@@ -1709,7 +1686,7 @@
     out.unindent();
     out << "private:\n";
     out.indent();
-    out << "const ::android::sp<" << iface->localName() << "> mImpl;\n";
+    out << "const ::android::sp<" << iface->definedName() << "> mImpl;\n";
 
     out << "::android::hardware::details::TaskRunner mOnewayQueue;\n";
 
@@ -1739,7 +1716,7 @@
         if (!reserved) {
             out << "// no default implementation for: ";
         }
-        method->generateCppSignature(out, iface->localName());
+        method->generateCppSignature(out, iface->definedName());
         if (reserved) {
             out.block([&]() {
                 method->cppImpl(IMPL_INTERFACE, out);
@@ -1752,24 +1729,16 @@
     });
 
     for (const Interface *superType : iface->typeChain()) {
-        out << "::android::hardware::Return<"
-            << childTypeResult
-            << "> "
-            << iface->localName()
-            << "::castFrom("
-            << superType->getCppArgumentType()
-            << " parent, bool "
-            << (iface == superType ? "/* emitError */" : "emitError")
-            << ") {\n";
+        out << "::android::hardware::Return<" << childTypeResult << "> " << iface->definedName()
+            << "::castFrom(" << superType->getCppArgumentType() << " parent, bool "
+            << (iface == superType ? "/* emitError */" : "emitError") << ") {\n";
         out.indent();
         if (iface == superType) {
             out << "return parent;\n";
         } else {
             out << "return ::android::hardware::details::castInterface<";
-            out << iface->localName() << ", "
-                << superType->fqName().cppName() << ", "
-                << iface->getProxyName()
-                << ">(\n";
+            out << iface->definedName() << ", " << superType->fqName().cppName() << ", "
+                << iface->getProxyName() << ">(\n";
             out.indent();
             out.indent();
             out << "parent, \""
@@ -1790,7 +1759,7 @@
 
     out << klassName << "::" << klassName << "(const ::android::sp<" << iface->fullName()
         << "> impl) : ::android::hardware::details::HidlInstrumentor(\"" << mPackage.string()
-        << "\", \"" << iface->localName() << "\"), mImpl(impl) {\n";
+        << "\", \"" << iface->definedName() << "\"), mImpl(impl) {\n";
 
     out.indent([&] { out << "mOnewayQueue.start(3000 /* similar limit to binderized */);\n"; });
 
@@ -1821,7 +1790,7 @@
                                     InstrumentationEvent event,
                                     const Method *method) const {
     const Interface* iface = mRootScope.getInterface();
-    std::string baseString = "HIDL::" + iface->localName() + "::" + method->name();
+    std::string baseString = "HIDL::" + iface->definedName() + "::" + method->name();
     switch (event) {
         case SERVER_API_ENTRY:
         {
@@ -1942,17 +1911,9 @@
 
     out << "for (const auto &callback: mInstrumentationCallbacks) {\n";
     out.indent();
-    out << "callback("
-        << event_str
-        << ", \""
-        << superInterface->fqName().package()
-        << "\", \""
-        << superInterface->fqName().version()
-        << "\", \""
-        << superInterface->localName()
-        << "\", \""
-        << method->name()
-        << "\", &_hidl_args);\n";
+    out << "callback(" << event_str << ", \"" << superInterface->fqName().package() << "\", \""
+        << superInterface->fqName().version() << "\", \"" << superInterface->definedName()
+        << "\", \"" << method->name() << "\", &_hidl_args);\n";
     out.unindent();
     out << "}\n";
     out.unindent();
diff --git a/generateCppAdapter.cpp b/generateCppAdapter.cpp
index 1d88d3c..1f07fed 100644
--- a/generateCppAdapter.cpp
+++ b/generateCppAdapter.cpp
@@ -42,7 +42,7 @@
     out << "#define " << guard << "\n\n";
 
     if (AST::isInterface()) {
-        generateCppPackageInclude(out, mPackage, getInterface()->localName());
+        generateCppPackageInclude(out, mPackage, getInterface()->definedName());
 
         enterLeaveNamespace(out, true /* enter */);
         out.endl();
@@ -85,7 +85,7 @@
 
     if (AST::isInterface()) {
         out << "#include <hidladapter/HidlBinderAdapter.h>\n";
-        generateCppPackageInclude(out, mPackage, getInterface()->localName());
+        generateCppPackageInclude(out, mPackage, getInterface()->definedName());
 
         std::set<FQName> allImportedNames;
         getAllImportedNames(&allImportedNames);
diff --git a/generateCppImpl.cpp b/generateCppImpl.cpp
index 1485119..278334d 100644
--- a/generateCppImpl.cpp
+++ b/generateCppImpl.cpp
@@ -80,7 +80,7 @@
     out << "// FIXME: your file license if you have one\n\n";
     out << "#pragma once\n\n";
 
-    generateCppPackageInclude(out, mPackage, iface->localName());
+    generateCppPackageInclude(out, mPackage, iface->definedName());
 
     out << "#include <hidl/MQDescriptor.h>\n";
     out << "#include <hidl/Status.h>\n\n";
@@ -98,11 +98,7 @@
 
     out << "\n";
 
-    out << "struct "
-        << baseName
-        << " : public "
-        << iface->localName()
-        << " {\n";
+    out << "struct " << baseName << " : public " << iface->definedName() << " {\n";
 
     out.indent();
 
@@ -121,10 +117,8 @@
     out << "};\n\n";
 
     out << "// FIXME: most likely delete, this is only for passthrough implementations\n"
-        << "// extern \"C\" "
-        << iface->localName()
-        << "* ";
-    generateFetchSymbol(out, iface->localName());
+        << "// extern \"C\" " << iface->definedName() << "* ";
+    generateFetchSymbol(out, iface->definedName());
     out << "(const char* name);\n\n";
 
     out << "}  // namespace implementation\n";
@@ -151,9 +145,8 @@
     });
 
     out.setLinePrefix("//");
-    out << iface->localName()
-        << "* ";
-    generateFetchSymbol(out, iface->localName());
+    out << iface->definedName() << "* ";
+    generateFetchSymbol(out, iface->definedName());
     out << "(const char* /* name */) {\n";
     out.indent();
     out << "return new " << baseName << "();\n";
diff --git a/generateJava.cpp b/generateJava.cpp
index cb3fcbb..0618750 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -49,7 +49,7 @@
     CHECK(!limitToType.empty()) << getFilename();
 
     for (const auto& type : mRootScope.getSubTypes()) {
-        std::string typeName = type->localName();
+        std::string typeName = type->definedName();
 
         if (type->isTypeDef()) continue;
         if (typeName != limitToType) continue;
@@ -140,7 +140,7 @@
     }
 
     const Interface* iface = mRootScope.getInterface();
-    const std::string ifaceName = iface->localName();
+    const std::string ifaceName = iface->definedName();
     const std::string baseName = iface->getBaseName();
 
     out << "package " << mPackage.javaPackage() << ";\n\n";
diff --git a/generateJavaImpl.cpp b/generateJavaImpl.cpp
index 4f7dcac..93418e6 100644
--- a/generateJavaImpl.cpp
+++ b/generateJavaImpl.cpp
@@ -31,9 +31,9 @@
     out << "// FIXME: your file license if you have one\n\n";
     out << "// FIXME: add package information\n\n";
 
-    out << "import " << mPackage.javaPackage() << "." << iface->localName() << ";\n\n";
+    out << "import " << mPackage.javaPackage() << "." << iface->definedName() << ";\n\n";
 
-    out << "class " << baseName << " extends " << iface->localName() << ".Stub"
+    out << "class " << baseName << " extends " << iface->definedName() << ".Stub"
         << " {\n";
 
     out.indent([&] {
diff --git a/generateVts.cpp b/generateVts.cpp
index 722a656..3515e9a 100644
--- a/generateVts.cpp
+++ b/generateVts.cpp
@@ -53,9 +53,7 @@
     const Interface *iface = AST::getInterface();
 
     out << "component_class: HAL_HIDL\n";
-    out << "component_name: \""
-        << (iface ? iface->localName() : "types")
-        << "\"\n\n";
+    out << "component_name: \"" << (iface ? iface->definedName() : "types") << "\"\n\n";
 
     out << "component_type_version_major: " << mPackage.getPackageMajorVersion() << "\n";
     out << "component_type_version_minor: " << mPackage.getPackageMinorVersion() << "\n";
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 5f9238f..342c2fc 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -591,7 +591,7 @@
 
           std::string errorMsg;
           if ($2 != nullptr && $2->isNamedType() &&
-              !isValidInterfaceField(static_cast<NamedType*>($2)->localName().c_str(),
+              !isValidInterfaceField(static_cast<NamedType*>($2)->definedName().c_str(),
                     &errorMsg)) {
               std::cerr << "ERROR: " << errorMsg << " at "
                         << @2 << "\n";
@@ -1011,7 +1011,7 @@
 
           if ($1 != nullptr && $1->isNamedType() &&
               !isValidCompoundTypeField(style, static_cast<NamedType*>(
-                        $1)->localName().c_str(), &errorMsg)) {
+                        $1)->definedName().c_str(), &errorMsg)) {
               std::cerr << "ERROR: " << errorMsg << " at "
                         << @2 << "\n";
               YYERROR;
diff --git a/main.cpp b/main.cpp
index ab8380c..f707aa7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -167,7 +167,7 @@
     for (const NamedType* rootType : rootTypes) {
         if (rootType->isTypeDef()) continue;
 
-        FQName rootTypeName(fqName.package(), fqName.version(), "types." + rootType->localName());
+        FQName rootTypeName(fqName.package(), fqName.version(), "types." + rootType->definedName());
         exportedPackageInterfaces->push_back(rootTypeName);
     }
     return OK;