Analyzer warns that an argument type can't be itself - dart

The error: The argument type 'AdvformBaseComponent(advform/base.dart)' can't be assigned to the parameter type 'AdvformBaseComponent(advform/base.dart)'.
The analyzer is warning that the argument type can't be AdvformBaseComponent, but the function is expecting that exact class as argument:
void addControl(AdvformBaseComponent baseComponent, String fieldName);
the below snippet is within a ngOnInit of AdvformBaseComponent.
objector.addControl(this, name);
It only hides the warning if I do a "addControl(this as dynamic", but that is so hacky and non performant...
sdk 1.22.1
EDIT:
The AdvformBaseComponent is an abstract class that is implemented by other components. It is essentially a base class for form components.
The AdvformObjectComponent is a panel group of AdvformBaseComponent based components. It is mandatory that any AdvformBaseComponent have a parent of AdvformObjectComponent.
They are in the same project and same directory.
I can share these files if you find it useful, they are browser components anyway.
abstract class AdvformBaseComponent implements OnInit, AfterViewInit,
OnDestroy {
AdvformObjectComponent objector;
AdvformBaseComponent(this.objector, #Optional() this._submitter, this.translator, #Optional() this._group) {
if (objector == null)
throw new Exception(
'Advform inputs must have a advform-object as parent.');
}
}
class AdvformObjectComponent implements OnInit {
void addControl(AdvformBaseComponent baseComponent, String fieldName) {
...
}
}

the error stopped after the 1.23.0

Related

Java compiler error: raw type with method returning Optional

I'm trying to understand the Java compiler's thinking (I know, bad idea)...
Consider this program:
import java.util.Optional;
public class xx {
public static class Foo<T> {
public interface Bar<T> {
int getX();
}
public Optional<Bar<T>> getBar() {
return Optional.empty();
}
}
public static void main(String[] args) throws Exception {
Foo foo = new Foo(); // note raw type
foo.getBar().get().getX();
}
}
The java 1.8.0_112 compiler gives:
xx.java:15: error: cannot find symbol
foo.getBar().get().getX();
^
symbol: method getX()
location: class Object
1 error
The question is: why doesn't the compiler, given the raw type Foo for foo, realize that the return type of foo.getBar() is Optional<? extends Bar> instead of what it apparently thinks, which is Optional<?> ?
Note: I know how to change this program to make it compile, that's not the question.
Once you use raw types in conjunction with type inference, the following from JLS 18.5.2 will apply
If unchecked conversion was necessary for the method to be applicable during constraint set reduction in ยง18.5.1, then [...] the return type and thrown types of the invocation type of m are given by the erasure of the return type and thrown types of m's type.
From this follows, that the return type of foo.getBar() is indeed just Optional with all type arguments erased.
Solution: avoid raw types, always.

Calling .filter() on a stream looses generic type

I have the following code. "Protectable" is an interface. My compiler gives the following error: "Incompatible types: Object cannot be converted to Collection"
When I remove the .filter line, everything works. Why does the compiler loose my type here?
Thanks,
Hannes
Collection<Protectable> requiredItems prefs.getConnectedProtectables(fuzDoc)
.stream()
.filter(protectable -> !protectable.itemVisibleForCurrentUser(fuzDoc))
.collect(Collectors.toList());
The variable prefs implements HasConnectedRights which is implemented as follows:
public interface HasConnectedRights {
public Collection<Protectable> getConnectedProtectables(FuzDocument doc);
}
The interface Protectable declares the method itemVisibleForCurrentUser like this:
default public boolean itemVisibleForCurrentUser(Docker<FuzDocument> doc) {
User user = UserCtrl.getCurrentUser(doc.getDoc());
return user == null || itemVisibleFor(user);
}

Is there any way to ask Weld SE to inject a specific implementation at a given time?

I use Weld SE in an application, in my application I have an interface for which I have 3 implementations but this causes an ambiguity for Weld. As far as I can see Weld ambiguity resolution technics are static, this can be done by mean of: #specialize, #alternative, #Named or using Qualifier. but this doesn't help me. I need to be able specify a given class implementation of the interface for each case.
I couldn't figure out a solution for my requirement.
Here is a code that illustrates my point
public class Foo {
#Inject
MyInterface target;
public void doSomething() {
target.doIt();
}
}
public class Bar1 implements MyInterface {
public void doIt() {
System.out.println("Hello");
}
}
public class Bar2 implements MyInterface {
public void doIt() {
System.out.println("Goodbye");
}
}
public class FooMain {
public static void main(String[] args) {
Weld weld = new Weld();
final WeldContainer container = weld.initialize();
Foo foo1 = container.instance().select(Foo.class).get();
Foo foo2 = container.instance().select(Foo.class).get();
}
}
This code causes this exception :
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type MyInterface with qualifiers #Default
at injection point [BackedAnnotatedField] #Inject com.lodh.arte.test.cdi.Foo.target
at com.lodh.arte.test.cdi.Foo.target(Foo.java:0)
Possible dependencies:
- Managed Bean [class com.lodh.arte.test.cdi.Bar2] with qualifiers [#Any #Default],
- Managed Bean [class com.lodh.arte.test.cdi.Bar1] with qualifiers [#Any #Default]
I need to dynamically tell Weld which implementation to use for injection, just like in this imaginary method Weld.use:
Weld.use ( MyInterface.class, Bar1.class);
Foo foo1 = container.instance().select(Foo.class).get();
Weld.use ( MyInterface.class, Bar2.class);
Foo foo2 = container.instance().select(Foo.class).get();
Thank you for your help
Regards
Nader
First you have two implementations of MyInterface. Bar1 and Bar2. Weld does not know which implementation to choose when injecting MyInterface, so it throws this "Ambiguous dependencies" error.
To avoid this error you should give your implementation different qualifiers.
You have to Qualify your implementations first:
#MyQualifier1
public class Bar1 implements MyInterface {
(...)
}
#MyQualifier2
public class Bar2 implements MyInterface {
(...)
}
This will allow to inject a specific implementation like this:
#Inject
#MyQualifier1
MyInterface target;
Now you're injecting an MyInterface qualified with #MyQualifier1. At runtime its Type will be Bar1 in this case.
Another approach if you want to decide at runtime which implementation you need would be the use of Instance:
#Inject
Instance<MyInterface> unqualifiedInstance;
void do(){
/// first attach the qualifier, we missed at the injection-point:
Instance qualifiedInstance = instance.select(new AnnotationLiteral<MyQualifier2>(){})
/// Now you have a qualified Instance, which is a new Object without touching the unqualifiedInstance!
MyInterface target = qualifiedInstance.get();
/// so you can decide which implementation you need by passing the qualifier per select-method. in this case its bar2
target.doIt();
}
If you need further help with qualifiers you may find the weld documentation and especially chapter 4.3 and the following helpful.
http://docs.jboss.org/weld/reference/latest/en-US/html/injection.html

Dart ClassMirror newInstance method says no such constructor

I tried to dynamically create a new instance of a class like this:
this.componentClass.newInstance(new Symbol(''), [this, el]).reflectee;
The class reflected in this.componentClass is called ButtonComponent and it is a subclass of Component. When running a test on this, I get an error:
Test failed: Caught No constructor 'ButtonComponent.' declared in class 'ButtonComponent'.
NoSuchMethodError : method not found: 'ButtonComponent.'
Receiver: Type: class 'ButtonComponent' Arguments: [...]
There are default constructors in both Component and ButtonComponent classes. Here is the code, to make sure I didn't miss anything:
class Component {
Element element ;
Template template;
Component(this.template, this.element) {
this.element.replaceWith(new Element.html(template.html));
}
}
class ButtonComponent extends Component {
ButtonComponent(template, element) : super(template, element) {};
}
Any ideas what is wrong here? Thank you.
I just made a similar test in 1.0.0.3_r30187 and I don't get this error. If you don't use the last stable version of Dart you should update your version.
Here's my tested code :
import 'dart:html';
import 'dart:mirrors';
class Component {
Element element ;
Component(this.element) {
this.element.children.add(new Element.html("<b>Dart rocks</b>"));
}
}
class ButtonComponent extends Component {
ButtonComponent(element) : super(element);
}
main() {
final a = reflectClass(ButtonComponent).newInstance(new Symbol(''),
[document.documentElement]).reflectee;
print(a); // display : Instance of 'ButtonComponent'
}

EL and covariant return types

i have these classes
public abstract class Unit
{
public abstract UnitType getType();
...
}
public class Item extends Unit
{
protected ItemType type;
#Override
public ItemType getType()
{
return type;
}
public void setType(ItemType type)
{
this.type = type;
}
...
}
and obvoiusly ItemType extends UnitType.
and i get:
javax.el.PropertyNotWritableException: /WEB-INF/facelets/general.xhtml #23,165 value="#{bean.item.type}": The class 'com.example.Item' does not have a writable property 'type'.
i can understand that covariant return type can confuse EL (2.2), so is this a bug?
i can workaround this using
generics
change setType signature to public void setType(UnitType type) and check instanceof inside
change method name to avoid override
is there a REAL solution instead of workarounds?
Seems like java.beans.Introspector is responsible. There were a lot of relevant bugs in Java:
7092744, 7122138, 6528714, 6794807, 6788525. Problems manifest with covariant return types and generics due to synthetic bridge methods. With some Java 7 updates (45, 51, 67, 71) problems manifest not right way but after running the server for some time - this is probably related to softly/weakly referenced caches in the Introspector and related classes.
All these problems seem to be fixed in Java 1.7.0_80 (tested with Mojarra 2.2.8 and Wildfly 8.2.0.Final).

Resources