Search in sources :

Example 11 with JvmVisibility

use of org.eclipse.xtext.common.types.JvmVisibility in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testDispatchFunction_05.

@Test
public void testDispatchFunction_05() throws Exception {
    XtendFile xtendFile = file("class Foo {" + "  def private dispatch private_private  (Integer x) {} def private   dispatch private_private  (Double x) {}" + "  def private dispatch private_protected(Integer x) {} def protected dispatch private_protected(Double x) {}" + "  def private dispatch private_public   (Integer x) {} def public    dispatch private_public   (Double x) {}" + "  def private dispatch private_default  (Integer x) {} def           dispatch private_default  (Double x) {}" + "  def protected dispatch protected_private  (Integer x) {} def private   dispatch protected_private  (Double x) {}" + "  def protected dispatch protected_protected(Integer x) {} def protected dispatch protected_protected(Double x) {}" + "  def protected dispatch protected_public   (Integer x) {} def public    dispatch protected_public   (Double x) {}" + "  def protected dispatch protected_default  (Integer x) {} def           dispatch protected_default  (Double x) {}" + "  def public dispatch public_private  (Integer x) {} def private   dispatch public_private  (Double x) {}" + "  def public dispatch public_protected(Integer x) {} def protected dispatch public_protected(Double x) {}" + "  def public dispatch public_public   (Integer x) {} def public    dispatch public_public   (Double x) {}" + "  def public dispatch public_default  (Integer x) {} def           dispatch public_default  (Double x) {}" + "  def dispatch default_private  (Integer x) {} def private   dispatch default_private  (Double x) {}" + "  def dispatch default_protected(Integer x) {} def protected dispatch default_protected(Double x) {}" + "  def dispatch default_public   (Integer x) {} def public    dispatch default_public   (Double x) {}" + "  def dispatch default_default  (Integer x) {} def           dispatch default_default  (Double x) {}" + "}");
    JvmGenericType inferredType = getInferredType(xtendFile);
    for (JvmOperation op : inferredType.getDeclaredOperations()) {
        String[] split = op.getSimpleName().toUpperCase().split("_");
        JvmVisibility expectedVisibility = null;
        if (!op.getSimpleName().startsWith("_")) {
            if (equal(split[0], split[1]))
                expectedVisibility = "DEFAULT".equals(split[0]) ? JvmVisibility.PUBLIC : JvmVisibility.get(split[0]);
            else
                expectedVisibility = JvmVisibility.PUBLIC;
        } else if (equal(op.getParameters().get(0).getParameterType().getIdentifier(), "java.lang.Integer"))
            expectedVisibility = "DEFAULT".equals(split[1]) ? JvmVisibility.PROTECTED : JvmVisibility.get(split[1]);
        else
            expectedVisibility = "DEFAULT".equals(split[2]) ? JvmVisibility.PROTECTED : JvmVisibility.get(split[2]);
        assertEquals(op.getIdentifier(), expectedVisibility, op.getVisibility());
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmVisibility(org.eclipse.xtext.common.types.JvmVisibility) Test(org.junit.Test)

Aggregations

JvmVisibility (org.eclipse.xtext.common.types.JvmVisibility)11 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)1 CreateExtensionInfo (org.eclipse.xtend.core.xtend.CreateExtensionInfo)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1