Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] compiler use wrong classes if a annotation has the same name as classes in java.lang #2309

Open
Lexanius opened this issue Apr 27, 2018 · 5 comments

Comments

@Lexanius
Copy link

What happend:

If a annotation (maybe classes too) named as a class in java.lang (eg. Exception) is it not possible anymore to use the java.lang-Class in this package anymore.

ExceptionAnnotation.xtend:

package foo

import org.eclipse.xtend.lib.macro.AbstractClassProcessor
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration

@Active(ExceptionProcessor)
annotation Exception {

    Class<? extends java.lang.Exception> value;
}

class ExceptionProcessor extends AbstractClassProcessor {

    override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {
        val a = new java.lang.Exception("bar")
        if(!java.lang.Exception.isAssignableFrom(RuntimeException)) {
            throw new RuntimeException("wrong")
        }
    }
}

will compile to:

ExceptionProcessor.java:

package foo;

import org.eclipse.xtend.lib.macro.AbstractClassProcessor;
import org.eclipse.xtend.lib.macro.TransformationContext;
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration;
import org.eclipse.xtext.xbase.lib.Extension;

@SuppressWarnings("all")
public class ExceptionProcessor extends AbstractClassProcessor {
  @Override
  public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    final Exception a = new Exception("bar");
    boolean _isAssignableFrom = Exception.class.isAssignableFrom(RuntimeException.class);
    boolean _not = (!_isAssignableFrom);
    if (_not) {
      throw new RuntimeException("wrong");
    }
  }
}

and

Exception.java:

package foo;

import org.eclipse.xtend.lib.macro.Active;
import org.infai.sakop.generator.annotation.ExceptionProcessor;

@Active(ExceptionProcessor.class)
public @interface Exception {
  public Class<? extends java.lang.Exception> value();
}

What should happend

the compile should check, if there are a class the same as java.lang-Class is in the packag and so

final Exception a = new Exception("bar");

should

final java.lang.Exception a = new java.lang.Exception("bar");

and

boolean _isAssignableFrom = Exception.class.isAssignableFrom(RuntimeException.class);

should

boolean _isAssignableFrom = java.lang.Exception.class.isAssignableFrom(RuntimeException.class);

System

  • Xtend IDE 2.14.0.v20180424-2303 org.eclipse.xtend.sdk.feature.group Eclipse Xtend
  • Xtext Complete SDK 2.14.0.v20180424-2303 org.eclipse.xtext.sdk.feature.group Eclipse Xtext
  • java 8

Workaround

  • use a other class-name
@Lexanius Lexanius changed the title [Bug] compiler use wrong classes if a annotation has the same name as classes injava.lang [Bug] compiler use wrong classes if a annotation has the same name as classes in java.lang Apr 27, 2018
@cdietrich
Copy link
Member

Happens independent from AA

package aaa

class Exception {
	
}
package aaa

class Other {
	
	public var java.lang.Exception e
	
}

generates wrongly to

package aaa;

@SuppressWarnings("all")
public class Other {
  public Exception e;
}

@szarnekow
Copy link
Contributor

@cdietrich do you consider this relevant for 2.14?

@cdietrich
Copy link
Member

I don’t see an easy fix for this so I am not sure

@szarnekow
Copy link
Contributor

Let me think this through.

@cdietrich
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants