Extending a class implementing a class - dart

Looking in the Flutter Firebase source code I've found this :
class FirebaseAuthException extends FirebaseException implements Exception {...}
class FirebaseException implements Exception {...}
why does FirebaseAuthException have to implement Exception when FirebaseException already does ?

Related

FirebaseFirestore cannot be provided without an #Inject constructor or an #Provides-annotated method

Im struggling with the following issue and I cant find a solution. I have multi module project. I set up all the modules and dependencies but im still getting this error for firestore: error: [Dagger/MissingBinding] com.google.firebase.firestore
My DI setup is following
FirebaseDiModule(part of the firestore module)
#Module
#InstallIn(SingletonComponent::class)
object FirebaseDiModule {
#Singleton
#Provides
fun provideFirebaseAuth(): FirebaseAuth {
return FirebaseAuth.getInstance()
}
#Singleton
#Provides
fun provideFirestoreFirebase(): FirebaseFirestore {
return FirebaseFirestore.getInstance()
}
#Singleton
#Provides
fun provideUserFirebaseDataSource(
firebaseFirestore: FirebaseFirestore,
firebaseAuth: FirebaseAuth,
): UserFirestoreDataSource {
return UserFirestoreDataSource(
firebaseFirestore = firebaseFirestore,
firebaseAuth = firebaseAuth,
)
}
}
UserFirestoreDataSource (part of the firebase module)
class UserFirestoreDataSource #Inject constructor(
private val firebaseFirestore: FirebaseFirestore,
private val firebaseAuth: FirebaseAuth,
)
Then I have authentication module which is beasicly a feature module contaning jetpack compose and viewmodel's.
The ViewModel i use is set as this:
#HiltViewModel
class OnBoardingViewModel #Inject constructor(
userFirestoreDataSource: UserFirestoreDataSource,
) : ViewModel() {
The authentication module is added to the app module where I use the OnBoardingViewModel and composables.
In the app module I have this:
#HiltAndroidApp
class AppController : Application()
class MainActivity : ComponentActivity()
When I run the project I get the following error:
error: [Dagger/MissingBinding] com.google.firebase.firestore.FirebaseFirestore cannot be provided without an #Inject constructor or an #Provides-annotated method.
public abstract static class SingletonC implements AppController_GeneratedInjector,
But this error only occurs when I add #HiltViewModel annotation to the OnBoardingViewModel. Im really frustrated by this problem and I cant figure it out what am I doing wrong.
There is nothing to try because it's a DI setup.
You need to create a #HiltViewModel class and annotate it with the #HiltViewModel annotation.
here is an example code:
#HiltViewModel
class OnBoardingViewModel #ViewModelInject constructor(
userFirestoreDataSource: UserFirestoreDataSource
) : ViewModel() {
//ViewModel code
}
it's like telling DI (#ViewModelInject) hey this is a ViewModel class inject the necessary dependencies into the ViewModel

Why doesn't this Dart code with generic classes and constraints compile?

I can't understand why this code doesn't compile.
In my intentions, the following snippet should declare a BaseGenericClass with no constraint on its argument, and a GenericClass deriving from BaseGenericClass with a constraint on type T telling the compiler to accept only classes derived from AbstractArgClass.
abstract class BaseGenericClass<T> {
final T _arg;
 
BaseGenericClass(this._arg);
}
class GenericClass<T extends AbstractArgClass> extends BaseGenericClass<T> {
GenericClass() : super(ArgClass());
}
abstract class AbstractArgClass {}
class ArgClass extends AbstractArgClass {}
ArgClass derives from AbstractArgClass, still lines 8 raises this error:
The argument type 'ArgClass' can't be assigned to parameter type 'T'
I think the compiler is correct here. ArgClass and AbstractArgClass in fact do not extend T, and I can't see a way to tell them that T is meant to be ArgClass.
It should work if you change it like this:
class GenericClass<T extends AbstractArgClass> extends BaseGenericClass<T> {
GenericClass(T t) : super(t);
}
You have to supply your instance of ArgClass to the constructor of GenericClass:
final g = GenericClass(ArgClass());
If you do not want to provide this from ouside, you can add a static function to make a new instance, like:
class GenericClass<T extends AbstractArgClass> extends BaseGenericClass<T> {
GenericClass._(T t) : super(t);
static GenericClass make() => GenericClass._(ArgClass());
}
and get an instance:
final g = GenericClass.make();
Ber's answer apparently works around the problem introducing a sort of intermediation... I tried to create a useless IntermediateClass that just introduces the restrictions on the type T (T has to derive from AbstractArgClass). This works!!!
AnotherGenericClass, as expected, does not compile because AnotherClass does not extend AbstractArgClass.
Still the question: why?
It looks like a compiler glitch to me, do you agree?
abstract class BaseGenericClass<T> {
final T _arg;
BaseGenericClass(this._arg);
}
class IntermediateClass<T extends AbstractArgClass> extends BaseGenericClass<T> {
IntermediateClass(T arg) : super(arg);
}
class GenericClass extends IntermediateClass {
GenericClass() : super(ArgClass());
}
abstract class AbstractArgClass {}
class ArgClass extends AbstractArgClass {}
class AnotherClass {}
class AnotherGenericClass extends IntermediateClass {
AnotherGenericClass() : super(AnotherClass());
}

Custom Exception class Jenkins Groovy

I created a custom exception class and put it inside src/org/team/pipeline/TestResultFailed.groovy:
package org.team.pipeline
public class TestResultFailed extends Exception {
// Parameterless Constructor
public TestResultFailed() {}
// Constructor that accepts a message
public TestResultFailed(String message) {
super(message);
}
}
The only issue is the class (and thus even exception) cannot be easily imported from shared library to Jenkins pipeline. Therefore, it's not possible to directly throw exception from Jenkins pipeline.
To bypass that, I tried to "wrap" my new exception into shared library function in vars/teamUtils.groovy:
import org.team.pipeline.*
def getTestResultFailedClass() {
return TestResultFailed
}
And then I import and use it in Jenkinsfile as follows:
TestResultFailed = teamUtils.getTestResultFailedClass()
try {
throw new TestResultFailed.TestResultFailed("error")
} catch (TestResultFailed err) {
log.info("Exception caught: ${err}")
}
However, I get this error:
unable to resolve class TestResultFailed.TestResultFailed
and no matter what I tried I'm still getting this error. Any help is very appreciated.

flutter: extension class on abstract class

I created an abstract class like this :
abstract class IRepository<T> {
}
After that I created an extension to this class :
extension Find<T> on IRepository<T>{
T get find => .....;
}
Now in other class, I try to use this extension like this: IRepository.find but I got this error The getter 'find' isn't defined for the type 'IRepository'.?
I imported locally my extension class for sure but I still have this error ?
You need to instantiate an object first and then try to use the find extensions. But abstract classes can't be instantiated. So you need to create some implementation first.
abstract class IRepository<T> {
}
class RepImpl extends IRepository<String>{
}
extension Find<T> on RepImpl{
String get find => ...;
}
and Then Create an object from RepImpl and you can access find getter.

Register HoverProvider with Xtend

I try to implement a custom HoverProvider according to this tutorial: enter link description here
However, I'm stuck translating to Java code of MyDSLUiModuleto Xtend.
The register-method should read like this:
def Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProviderr() {
return MyDSLHoverProvider.class
}
However, this doesn't compile since MyDSLHoverProvider only implements the IEObjectDocumentationProvider but not extend this class (MyDSLHoverProvider is the same as in the tutorial).
Therefore this error is thrown:
Type mismatch: cannot convert from Class<? extends Class> to Class<? extends IEObjectDocumentationProvider>
How can I get around this error?
Btw: If I test my DSL in an Eclipse instance, I get a wierd NPE:
!ENTRY org.eclipse.oomph.setup.ui 2 0 2016-09-16 16:42:34.203
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
at org.eclipse.oomph.setup.ui.SetupUIPlugin.performStartup(SetupUIPlugin.java:373)
at org.eclipse.oomph.setup.ui.SetupUIPlugin.access$4(SetupUIPlugin.java:344)
at org.eclipse.oomph.setup.ui.SetupUIPlugin$1$1.run(SetupUIPlugin.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
I have no clue where this exception comes from.
The class MyDSLHoverProvider looks like this:
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
class MyDSLHoverProvider implements IEObjectDocumentationProvider {
override getDocumentation(EObject o) {
println("Hover: " + o)
if (o instanceof MyFieldElements) {
return "This is a nice Greeting with nice <b>markup</b> in the <i>documentation</i>";
}
}
}
Edit:
I found a way to display the tooltips, but it seems strange.
A tooltip is shown for this rule:
name = ID
but if I rename it to
myField = ID
the tooltip is not triggered.
Is this the expected behaviour?
the correct Xtend syntax is
def Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProviderr() {
return MyDSLHoverProvider
}
or
def Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProviderr() {
MyDSLHoverProvider
}
MyDSLHoverProvider.classis the same as MyDslHoverProvider.class.getClass() in Java

Resources