-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 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
31 changes: 31 additions & 0 deletions
31
plugin/src/software/aws/toolkits/eclipse/amazonq/observers/EventObserver.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,31 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.observers; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
public interface EventObserver<T> { | ||
|
||
@SuppressWarnings("unchecked") | ||
default Class<T> getEventType() { | ||
Class<?> currentClass = getClass(); | ||
while (currentClass != null) { | ||
for (Type type : currentClass.getGenericInterfaces()) { | ||
if (type instanceof ParameterizedType paramType && (paramType.getRawType() == EventObserver.class)) { | ||
Type typeArg = paramType.getActualTypeArguments()[0]; | ||
if (typeArg instanceof Class<?>) { | ||
return (Class<T>) typeArg; | ||
} | ||
throw new IllegalStateException("Generic type parameter is not a Class"); | ||
} | ||
} | ||
currentClass = currentClass.getSuperclass(); | ||
} | ||
throw new IllegalStateException("Could not determine generic type"); | ||
} | ||
|
||
void onEvent(T event); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
plugin/src/software/aws/toolkits/eclipse/amazonq/observers/StreamObserver.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,33 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.observers; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
public interface StreamObserver<T> extends EventObserver<T> { | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
default Class<T> getEventType() { | ||
Class<?> currentClass = getClass(); | ||
while (currentClass != null) { | ||
for (Type type : currentClass.getGenericInterfaces()) { | ||
if (type instanceof ParameterizedType paramType && (paramType.getRawType() == StreamObserver.class)) { | ||
Type typeArg = paramType.getActualTypeArguments()[0]; | ||
if (typeArg instanceof Class<?>) { | ||
return (Class<T>) typeArg; | ||
} | ||
throw new IllegalStateException("Generic type parameter is not a Class"); | ||
} | ||
} | ||
currentClass = currentClass.getSuperclass(); | ||
} | ||
throw new IllegalStateException("Could not determine generic type"); | ||
} | ||
|
||
void onError(Throwable error); | ||
void onComplete(); | ||
|
||
} |
32 changes: 0 additions & 32 deletions
32
plugin/src/software/aws/toolkits/eclipse/amazonq/subscriber/Subscriber.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.