-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
@AutoFactory
constructors that throw checked exceptions.
The generated `create` method needs to declare the same exceptions. Fixes #90. RELNOTES=`@AutoFactory` constructors can now declare checked exceptions. The same exceptions will be declared on the generated `create` method. PiperOrigin-RevId: 347657308
- Loading branch information
1 parent
9cc29ca
commit 3141e79
Showing
13 changed files
with
262 additions
and
12 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
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
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
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
58 changes: 58 additions & 0 deletions
58
factory/src/test/resources/expected/ConstructorAnnotatedThrowsFactory.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,58 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import java.io.IOException; | ||
import javax.annotation.processing.Generated; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
|
||
@Generated( | ||
value = "com.google.auto.factory.processor.AutoFactoryProcessor", | ||
comments = "https://github.com/google/auto/tree/master/factory" | ||
) | ||
final class ConstructorAnnotatedThrowsFactory { | ||
private final Provider<Object> objProvider; | ||
|
||
@Inject ConstructorAnnotatedThrowsFactory(Provider<Object> objProvider) { | ||
this.objProvider = checkNotNull(objProvider, 1); | ||
} | ||
|
||
ConstructorAnnotatedThrows create() throws IOException, InterruptedException { | ||
return new ConstructorAnnotatedThrows(); | ||
} | ||
|
||
ConstructorAnnotatedThrows create(String s) { | ||
return new ConstructorAnnotatedThrows(checkNotNull(s, 1)); | ||
} | ||
|
||
ConstructorAnnotatedThrows create(int i) throws IOException { | ||
return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1), i); | ||
} | ||
|
||
ConstructorAnnotatedThrows create(char c) throws InterruptedException { | ||
return new ConstructorAnnotatedThrows(checkNotNull(objProvider.get(), 1), c); | ||
} | ||
|
||
private static <T> T checkNotNull(T reference, int argumentIndex) { | ||
if (reference == null) { | ||
throw new NullPointerException( | ||
"@AutoFactory method argument is null but is not marked @Nullable. Argument index: " | ||
+ argumentIndex); | ||
} | ||
return reference; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
factory/src/test/resources/expected/FactoryExtendingAbstractClassThrowsFactory.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,37 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import java.io.IOException; | ||
import javax.annotation.processing.Generated; | ||
import javax.inject.Inject; | ||
|
||
@Generated( | ||
value = "com.google.auto.factory.processor.AutoFactoryProcessor", | ||
comments = "https://github.com/google/auto/tree/master/factory" | ||
) | ||
final class FactoryExtendingAbstractClassThrowsFactory | ||
extends FactoryExtendingAbstractClassThrows.AbstractFactory { | ||
@Inject FactoryExtendingAbstractClassThrowsFactory() {} | ||
|
||
FactoryExtendingAbstractClassThrows create() throws IOException, InterruptedException { | ||
return new FactoryExtendingAbstractClassThrows(); | ||
} | ||
|
||
@Override public FactoryExtendingAbstractClassThrows newInstance() throws Exception { | ||
return create(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
factory/src/test/resources/expected/SimpleClassThrowsFactory.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,32 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import java.io.IOException; | ||
import javax.annotation.processing.Generated; | ||
import javax.inject.Inject; | ||
|
||
@Generated( | ||
value = "com.google.auto.factory.processor.AutoFactoryProcessor", | ||
comments = "https://github.com/google/auto/tree/master/factory" | ||
) | ||
final class SimpleClassThrowsFactory { | ||
@Inject SimpleClassThrowsFactory() {} | ||
|
||
SimpleClassThrows create() throws IOException, InterruptedException { | ||
return new SimpleClassThrows(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
factory/src/test/resources/good/ConstructorAnnotatedThrows.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,29 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import com.google.auto.factory.AutoFactory; | ||
import com.google.auto.factory.Provided; | ||
import java.io.IOException; | ||
|
||
final class ConstructorAnnotatedThrows { | ||
@AutoFactory ConstructorAnnotatedThrows() throws IOException, InterruptedException {} | ||
ConstructorAnnotatedThrows(Object obj) {} | ||
@AutoFactory ConstructorAnnotatedThrows(String s) {} | ||
@AutoFactory ConstructorAnnotatedThrows(@Provided Object obj, int i) throws IOException {} | ||
@AutoFactory ConstructorAnnotatedThrows(@Provided Object obj, char c) | ||
throws InterruptedException {} | ||
} |
29 changes: 29 additions & 0 deletions
29
factory/src/test/resources/good/FactoryExtendingAbstractClassThrows.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,29 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import com.google.auto.factory.AutoFactory; | ||
import java.io.IOException; | ||
import tests.FactoryExtendingAbstractClassThrows.AbstractFactory; | ||
|
||
@AutoFactory(extending = AbstractFactory.class) | ||
final class FactoryExtendingAbstractClassThrows { | ||
FactoryExtendingAbstractClassThrows() throws IOException, InterruptedException {} | ||
|
||
static abstract class AbstractFactory { | ||
abstract FactoryExtendingAbstractClassThrows newInstance() throws Exception; | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* 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 tests; | ||
|
||
import com.google.auto.factory.AutoFactory; | ||
import java.io.IOException; | ||
|
||
@AutoFactory | ||
final class SimpleClassThrows { | ||
SimpleClassThrows() throws IOException, InterruptedException {} | ||
} |