This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert adding Builder subclasses to unions
Using builder subclasses in unions in Swift-generated code causes separate errors to be triggered: Error: Inject method com.facebook.swift.foo is not allowed on struct class, since struct has a builder Attempted to resolve a recursive reference to type 'com.facebook.swift.foo' before the referenced type was cached (most likely a recursive type support bug)
- Loading branch information
Ryan Wilson
committed
Oct 7, 2016
1 parent
58d06fd
commit 732bfac
Showing
7 changed files
with
221 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
swift-codec/src/test/java/com/facebook/swift/codec/UnionConstructorDuplicateTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) 2012 Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.facebook.swift.codec; | ||
|
||
import com.facebook.swift.codec.ThriftField.Requiredness; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
|
||
@ThriftUnion("UnionConstructorDuplicateTypes") | ||
public class UnionConstructorDuplicateTypes { | ||
private Object value; | ||
private short id = -1; | ||
private String name; | ||
|
||
@ThriftConstructor | ||
public UnionConstructorDuplicateTypes() { | ||
} | ||
|
||
@ThriftField | ||
public void setFirstIntValue(final int firstIntValue) { | ||
this.value = firstIntValue; | ||
this.id = 1; | ||
this.name = "firstIntValue"; | ||
} | ||
|
||
@ThriftField | ||
public void setSecondIntValue(final int secondIntValue) { | ||
this.value = secondIntValue; | ||
this.id = 2; | ||
this.name = "secondIntValue"; | ||
} | ||
|
||
@ThriftField(value = 1, name = "firstIntValue", requiredness = Requiredness.NONE) | ||
public int getFirstIntValue() { | ||
if (this.id != 1) { | ||
throw new IllegalStateException("Not a firstIntValue element!"); | ||
} | ||
return (int) value; | ||
} | ||
|
||
public boolean isSetFirstIntValue() { | ||
return this.id == 1; | ||
} | ||
|
||
@ThriftField(value = 2, name = "secondIntValue", requiredness = Requiredness.NONE) | ||
public int getSecondIntValue() { | ||
if (this.id != 2) { | ||
throw new IllegalStateException("Not a secondIntValue element!"); | ||
} | ||
return (int) value; | ||
} | ||
|
||
public boolean isSetSecondIntValue() { | ||
return this.id == 2; | ||
} | ||
|
||
@ThriftUnionId | ||
public short getThriftId() { | ||
return this.id; | ||
} | ||
|
||
public String getThriftName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Arrays.deepHashCode(new Object[] { | ||
id, | ||
value, | ||
name | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} else if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
UnionConstructorDuplicateTypes that = (UnionConstructorDuplicateTypes) obj; | ||
return Objects.equals(this.id, that.id) | ||
&& Objects.equals(this.value, that.value) | ||
&& Objects.equals(this.name, that.name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toStringHelper(this) | ||
.add("value", value) | ||
.add("id", id) | ||
.add("name", name) | ||
.add("type", value == null ? "<null>" : value.getClass().getSimpleName()) | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.