Remove extra from getJavaType.
Bug: 32559427
Test: hidl_test_java
Change-Id: I1a96630eed1b61ab4ff2959ced2e83f94e8fb36d
diff --git a/ArrayType.cpp b/ArrayType.cpp
index 24f2a2c..a506e0c 100644
--- a/ArrayType.cpp
+++ b/ArrayType.cpp
@@ -92,30 +92,24 @@
CHECK(!"Should not be here");
}
-std::string ArrayType::getJavaType(
- std::string *extra, bool forInitializer) const {
- std::string baseExtra;
- const std::string base =
- mElementType->getJavaType(&baseExtra, forInitializer);
-
- CHECK(baseExtra.empty());
-
- extra->clear();
+std::string ArrayType::getJavaType(bool forInitializer) const {
+ std::string base =
+ mElementType->getJavaType(forInitializer);
for (size_t i = 0; i < mSizes.size(); ++i) {
- *extra += "[";
+ base += "[";
if (forInitializer) {
- *extra += mSizes[i]->javaValue();
+ base += mSizes[i]->javaValue();
}
if (!forInitializer || !mSizes[i]->descriptionIsTrivial()) {
if (forInitializer)
- *extra += " ";
- *extra += "/* " + mSizes[i]->description() + " */";
+ base += " ";
+ base += "/* " + mSizes[i]->description() + " */";
}
- *extra += "]";
+ base += "]";
}
return base;
@@ -348,10 +342,8 @@
const std::string &argName,
bool isReader) const {
if (isReader) {
- std::string extra;
out << "new "
- << getJavaType(&extra, true /* forInitializer */)
- << extra
+ << getJavaType(true /* forInitializer */)
<< ";\n";
}
@@ -391,20 +383,15 @@
void ArrayType::emitJavaFieldInitializer(
Formatter &out, const std::string &fieldName) const {
- std::string extra;
- std::string typeName = getJavaType(&extra, false /* forInitializer */);
-
- std::string extraInit;
- getJavaType(&extraInit, true /* forInitializer */);
+ std::string typeName = getJavaType(false /* forInitializer */);
+ std::string initName = getJavaType(true /* forInitializer */);
out << "final "
<< typeName
- << extra
<< " "
<< fieldName
<< " = new "
- << typeName
- << extraInit
+ << initName
<< ";\n";
}
@@ -443,11 +430,8 @@
}
if (isReader && mElementType->isCompoundType()) {
- std::string extra;
std::string typeName =
- mElementType->getJavaType(&extra, false /* forInitializer */);
-
- CHECK(extra.empty());
+ mElementType->getJavaType(false /* forInitializer */);
out << fieldName
<< indexString
diff --git a/ArrayType.h b/ArrayType.h
index d993960..a7e5083 100644
--- a/ArrayType.h
+++ b/ArrayType.h
@@ -45,8 +45,7 @@
void addNamedTypesToSet(std::set<const FQName> &set) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
std::string getJavaWrapperType() const override;
diff --git a/CompoundType.cpp b/CompoundType.cpp
index b55b4ea..e3ed250 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -82,9 +82,7 @@
}
}
-std::string CompoundType::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
- extra->clear();
+std::string CompoundType::getJavaType(bool /* forInitializer */) const {
return fullJavaName();
}
diff --git a/CompoundType.h b/CompoundType.h
index 4d1a8e9..340938e 100644
--- a/CompoundType.h
+++ b/CompoundType.h
@@ -41,8 +41,7 @@
std::string getCppType(StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
std::string getVtsType() const override;
diff --git a/EnumType.cpp b/EnumType.cpp
index 4a25bbe..4c77701 100644
--- a/EnumType.cpp
+++ b/EnumType.cpp
@@ -76,10 +76,8 @@
return specifyNamespaces ? fullName() : partialCppName();
}
-std::string EnumType::getJavaType(
- std::string *extra, bool forInitializer) const {
- return mStorageType->resolveToScalarType()->getJavaType(
- extra, forInitializer);
+std::string EnumType::getJavaType(bool forInitializer) const {
+ return mStorageType->resolveToScalarType()->getJavaType(forInitializer);
}
std::string EnumType::getJavaSuffix() const {
@@ -251,9 +249,8 @@
out.indent();
- std::string extra; // unused, because ScalarType leaves this empty.
const std::string typeName =
- scalarType->getJavaType(&extra, false /* forInitializer */);
+ scalarType->getJavaType(false /* forInitializer */);
std::vector<const EnumType *> chain;
getTypeChain(&chain);
@@ -408,9 +405,8 @@
out << "// Values declared in " << localName() << " follow.\n";
}
- std::string extra; // unused, because ScalarType leaves this empty.
const std::string typeName =
- scalarType->getJavaType(&extra, false /* forInitializer */);
+ scalarType->getJavaType(false /* forInitializer */);
std::vector<const EnumType *> chain;
getTypeChain(&chain);
diff --git a/EnumType.h b/EnumType.h
index 7fd3ea7..b03d328 100644
--- a/EnumType.h
+++ b/EnumType.h
@@ -45,8 +45,7 @@
std::string getCppType(StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
std::string getJavaSuffix() const override;
diff --git a/GenericBinder.cpp b/GenericBinder.cpp
index 6f5e636..5c5106e 100644
--- a/GenericBinder.cpp
+++ b/GenericBinder.cpp
@@ -49,9 +49,7 @@
}
}
-std::string GenericBinder::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
- extra->clear();
+std::string GenericBinder::getJavaType(bool /* forInitializer */) const {
return "IHwBinder";
}
diff --git a/GenericBinder.h b/GenericBinder.h
index e1fdb2d..55e7587 100644
--- a/GenericBinder.h
+++ b/GenericBinder.h
@@ -33,8 +33,7 @@
StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
void emitReaderWriter(
Formatter &out,
diff --git a/Interface.cpp b/Interface.cpp
index 64bde04..78dc679 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -205,9 +205,7 @@
}
}
-std::string Interface::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
- extra->clear();
+std::string Interface::getJavaType(bool /* forInitializer */) const {
return fullJavaName();
}
diff --git a/Interface.h b/Interface.h
index 414516d..61981cc 100644
--- a/Interface.h
+++ b/Interface.h
@@ -67,8 +67,7 @@
StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
void emitReaderWriter(
Formatter &out,
diff --git a/Method.cpp b/Method.cpp
index fabf801..e3db869 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -160,9 +160,7 @@
out += ", ";
}
- std::string extra;
- out += arg->type().getJavaType(&extra);
- out += extra;
+ out += arg->type().getJavaType();
out += " ";
out += arg->name();
diff --git a/ScalarType.cpp b/ScalarType.cpp
index f537310..0e4beaf 100644
--- a/ScalarType.cpp
+++ b/ScalarType.cpp
@@ -55,8 +55,7 @@
return kName[mKind];
}
-std::string ScalarType::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
+std::string ScalarType::getJavaType(bool /* forInitializer */) const {
static const char *const kName[] = {
"boolean",
"byte",
@@ -71,7 +70,6 @@
"double"
};
- extra->clear();
return kName[mKind];
}
diff --git a/ScalarType.h b/ScalarType.h
index 21e0d3a..f7890f5 100644
--- a/ScalarType.h
+++ b/ScalarType.h
@@ -49,8 +49,7 @@
StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
std::string getJavaWrapperType() const override;
std::string getJavaSuffix() const override;
diff --git a/StringType.cpp b/StringType.cpp
index 66a3fb7..6001fac 100644
--- a/StringType.cpp
+++ b/StringType.cpp
@@ -44,9 +44,7 @@
}
}
-std::string StringType::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
- extra->clear();
+std::string StringType::getJavaType(bool /* forInitializer */) const {
return "String";
}
diff --git a/StringType.h b/StringType.h
index 587cc68..d161fdb 100644
--- a/StringType.h
+++ b/StringType.h
@@ -31,8 +31,7 @@
StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool /* forInitializer */) const override;
+ std::string getJavaType(bool /* forInitializer */) const override;
std::string getJavaSuffix() const override;
diff --git a/Type.cpp b/Type.cpp
index f97af23..d7ae31a 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -98,16 +98,13 @@
return getCppType(mode, specifyNamespaces) + " " + name;
}
-std::string Type::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
+std::string Type::getJavaType(bool /* forInitializer */) const {
CHECK(!"Should not be here");
- extra->clear();
return std::string();
}
std::string Type::getJavaWrapperType() const {
- std::string extra;
- return getJavaType(&extra);
+ return getJavaType();
}
std::string Type::getJavaSuffix() const {
@@ -192,8 +189,7 @@
void Type::emitJavaFieldInitializer(
Formatter &out,
const std::string &fieldName) const {
- std::string extra;
- out << getJavaType(&extra)
+ out << getJavaType()
<< " "
<< fieldName
<< ";\n";
diff --git a/Type.h b/Type.h
index 473af85..7c1cca0 100644
--- a/Type.h
+++ b/Type.h
@@ -82,11 +82,11 @@
std::string getCppArgumentType(bool specifyNamespaces = true) const;
- // For an array type, "extra" accumulates dimensionality information,
+ // For an array type, dimensionality information will be accumulated at the
+ // end of the returned string.
// if forInitializer == true, actual dimensions are included, i.e. [3][5],
// otherwise (and by default), they are omitted, i.e. [][].
- virtual std::string getJavaType(
- std::string *extra, bool forInitializer = false) const;
+ virtual std::string getJavaType(bool forInitializer = false) const;
virtual std::string getJavaWrapperType() const;
virtual std::string getJavaSuffix() const;
diff --git a/VectorType.cpp b/VectorType.cpp
index 99449ab..5b6caf1 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -64,19 +64,17 @@
}
}
-std::string VectorType::getJavaType(
- std::string *extra, bool /* forInitializer */) const {
- extra->clear();
+std::string VectorType::getJavaType(bool /* forInitializer */) const {
- std::string elementExtra;
- std::string elementJavaType = mElementType->getJavaType(&elementExtra);
-
- CHECK(mElementType->isArray() || elementExtra.empty());
+ std::string elementJavaType;
+ if (mElementType->isArray()) {
+ elementJavaType = mElementType->getJavaType();
+ } else {
+ elementJavaType = mElementType->getJavaWrapperType();
+ }
return "ArrayList<"
- + (mElementType->isArray()
- ? elementJavaType : mElementType->getJavaWrapperType())
- + elementExtra
+ + elementJavaType
+ ">";
}
@@ -425,15 +423,14 @@
const std::string &argName,
bool isReader) const {
if (mElementType->isCompoundType()) {
- std::string extra; // unused, because CompoundType leaves this empty.
if (isReader) {
- out << mElementType->getJavaType(&extra)
+ out << mElementType->getJavaType()
<< ".readVectorFromParcel("
<< parcelObj
<< ");\n";
} else {
- out << mElementType->getJavaType(&extra)
+ out << mElementType->getJavaType()
<< ".writeVectorToParcel("
<< parcelObj
<< ", "
@@ -446,9 +443,8 @@
if (mElementType->isArray()) {
if (isReader) {
- std::string extra;
out << " new "
- << getJavaType(&extra, false /* forInitializer */)
+ << getJavaType(false /* forInitializer */)
<< "();\n";
}
@@ -499,8 +495,7 @@
void VectorType::emitJavaFieldInitializer(
Formatter &out, const std::string &fieldName) const {
- std::string extra;
- std::string javaType = getJavaType(&extra, false /* forInitializer */);
+ std::string javaType = getJavaType(false /* forInitializer */);
out << "final "
<< javaType
diff --git a/VectorType.h b/VectorType.h
index 1bf9a54..91ac811 100644
--- a/VectorType.h
+++ b/VectorType.h
@@ -34,8 +34,7 @@
StorageMode mode,
bool specifyNamespaces) const override;
- std::string getJavaType(
- std::string *extra, bool forInitializer) const override;
+ std::string getJavaType(bool forInitializer) const override;
std::string getVtsType() const override;
diff --git a/generateJava.cpp b/generateJava.cpp
index 63643e1..909696a 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -32,9 +32,7 @@
const TypedVar *arg,
bool isReader) const {
if (isReader) {
- std::string extra;
- out << arg->type().getJavaType(&extra)
- << extra
+ out << arg->type().getJavaType()
<< " "
<< arg->name()
<< " = ";
@@ -261,9 +259,7 @@
}
if (returnsValue && !needsCallback) {
- std::string extra;
- out << method->results()[0]->type().getJavaType(&extra)
- << extra;
+ out << method->results()[0]->type().getJavaType();
} else {
out << "void";
}
@@ -319,9 +315,7 @@
out << "public ";
if (returnsValue && !needsCallback) {
- std::string extra;
- out << method->results()[0]->type().getJavaType(&extra)
- << extra;
+ out << method->results()[0]->type().getJavaType();
} else {
out << "void";
}
@@ -433,10 +427,8 @@
// b/32383557 this is a hack. We need to change this if we have more reserved methods.
for (Method *method : iface->hidlReservedMethods()) {
- std::string extra;
out << "public final "
- << method->results()[0]->type().getJavaType(&extra)
- << extra
+ << method->results()[0]->type().getJavaType()
<< " "
<< method->name()
<< "() {\n";
@@ -508,10 +500,8 @@
if (!needsCallback && returnsValue) {
const TypedVar *returnArg = method->results()[0];
- std::string extra;
- out << returnArg->type().getJavaType(&extra)
- << extra
+ out << returnArg->type().getJavaType()
<< " "
<< returnArg->name()
<< " = ";