| 207 | FileGenerator::~FileGenerator() {} |
| 208 | |
| 209 | bool FileGenerator::Validate(std::string* error) { |
| 210 | // Check that no class name matches the file's class name. This is a common |
| 211 | // problem that leads to Java compile errors that can be hard to understand. |
| 212 | // It's especially bad when using the java_multiple_files, since we would |
| 213 | // end up overwriting the outer class with one of the inner ones. |
| 214 | if (name_resolver_->HasConflictingClassName(file_, classname_, |
| 215 | NameEquality::EXACT_EQUAL)) { |
| 216 | error->assign(file_->name()); |
| 217 | error->append( |
| 218 | ": Cannot generate Java output because the file's outer class name, " |
| 219 | "\""); |
| 220 | error->append(classname_); |
| 221 | error->append( |
| 222 | "\", matches the name of one of the types declared inside it. " |
| 223 | "Please either rename the type or use the java_outer_classname " |
| 224 | "option to specify a different outer class name for the .proto file."); |
| 225 | return false; |
| 226 | } |
| 227 | // Similar to the check above, but ignore the case this time. This is not a |
| 228 | // problem on Linux, but will lead to Java compile errors on Windows / Mac |
| 229 | // because filenames are case-insensitive on those platforms. |
| 230 | if (name_resolver_->HasConflictingClassName( |
| 231 | file_, classname_, NameEquality::EQUAL_IGNORE_CASE)) { |
| 232 | GOOGLE_LOG(WARNING) |
| 233 | << file_->name() << ": The file's outer class name, \"" << classname_ |
| 234 | << "\", matches the name of one of the types declared inside it when " |
| 235 | << "case is ignored. This can cause compilation issues on Windows / " |
| 236 | << "MacOS. Please either rename the type or use the " |
| 237 | << "java_outer_classname option to specify a different outer class " |
| 238 | << "name for the .proto file to be safe."; |
| 239 | } |
| 240 | |
| 241 | // Print a warning if optimize_for = LITE_RUNTIME is used. |
| 242 | if (file_->options().optimize_for() == FileOptions::LITE_RUNTIME && |
| 243 | !options_.enforce_lite) { |
| 244 | GOOGLE_LOG(WARNING) |
| 245 | << "The optimize_for = LITE_RUNTIME option is no longer supported by " |
| 246 | << "protobuf Java code generator and is ignored--protoc will always " |
| 247 | << "generate full runtime code for Java. To use Java Lite runtime, " |
| 248 | << "users should use the Java Lite plugin instead. See:\n" |
| 249 | << " " |
| 250 | "https://github.com/protocolbuffers/protobuf/blob/master/java/" |
| 251 | "lite.md"; |
| 252 | } |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | void FileGenerator::Generate(io::Printer* printer) { |
| 257 | // We don't import anything because we refer to all classes by their |
no test coverage detected