org.eclipse.xtext.common.types.JvmDoubleAnnotationValue Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmDoubleAnnotationValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createDoubleAnnotationValue(Object value) {
	JvmDoubleAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmDoubleAnnotationValue();
	if (value != null) {
		@SuppressWarnings("unchecked")
		InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof Double) {
					values.addUnique(element);
				} else if (element != null) {
					values.addUnique(((Number)element).doubleValue());
				}
			}
		} else if (value instanceof Double) {
			values.addUnique(value);
		} else if (value instanceof Number) {
			values.addUnique(((Number)value).doubleValue());
		}
	}
	return annotationValue;
}
 
Example #2
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_02() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getMethodParameterAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #3
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final char[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Character> _function = (Character v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).charValue())));
  };
  ((List<Character>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #4
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final byte[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Byte> _function = (Byte v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).byteValue())));
  };
  ((List<Byte>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #5
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final short[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Short> _function = (Short v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).shortValue())));
  };
  ((List<Short>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #6
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final int[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Integer> _function = (Integer v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).intValue())));
  };
  ((List<Integer>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #7
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final long[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Long> _function = (Long v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).longValue())));
  };
  ((List<Long>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #8
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final float[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Float> _function = (Float v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).floatValue())));
  };
  ((List<Float>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example #9
Source File: JvmDoubleAnnotationValueItemProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This handles model notifications by calling {@link #updateChildren} to update any cached
 * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void notifyChanged(Notification notification)
{
	updateChildren(notification);

	switch (notification.getFeatureID(JvmDoubleAnnotationValue.class))
	{
		case TypesPackage.JVM_DOUBLE_ANNOTATION_VALUE__VALUES:
			fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
			return;
	}
	super.notifyChanged(notification);
}
 
Example #10
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getDefaultAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(23d, d.doubleValue(), 0.0001);
}
 
Example #11
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_03() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getConstructorParameterAnnotationValue(
			"doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #12
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_02() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getMethodParameterAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #13
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getDefaultAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(23d, d.doubleValue(), 0.0001);
}
 
Example #15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_03() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getConstructorParameterAnnotationValue(
			"doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_02() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getMethodParameterAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #17
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #18
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final Procedure1<Double> _function = (Double it_1) -> {
    String _switchResult = null;
    boolean _matched = false;
    boolean _isNaN = Double.isNaN((it_1).doubleValue());
    if (_isNaN) {
      _matched=true;
      _switchResult = "Double.NaN";
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.POSITIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.POSITIVE_INFINITY";
      }
    }
    if (!_matched) {
      if (Objects.equal(it_1, Double.NEGATIVE_INFINITY)) {
        _matched=true;
        _switchResult = "Double.NEGATIVE_INFINITY";
      }
    }
    if (!_matched) {
      String _string = it_1.toString();
      _switchResult = (_string + "d");
    }
    appendable.append(_switchResult);
  };
  this._loopExtensions.<Double>forEachWithShortcut(appendable, it.getValues(), _function);
}
 
Example #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDefaultDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getDefaultAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(23d, d.doubleValue(), 0.0001);
}
 
Example #20
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_03() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getConstructorParameterAnnotationValue(
			"doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAnnotationValue_01() throws Exception {
	JvmDoubleAnnotationValue value = (JvmDoubleAnnotationValue) getAnnotationValue("doubleValue");
	assertEquals(1, value.getValues().size());
	Double d = value.getValues().get(0);
	assertEquals(0.5, d.doubleValue(), 0.0001);
}
 
Example #22
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final double[] value, final String componentType, final boolean mustBeArray) {
  EList<Double> _values = it.getValues();
  Iterables.<Double>addAll(_values, ((Iterable<? extends Double>)Conversions.doWrapArray(value)));
}
 
Example #23
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void toJavaLiteral(final JvmAnnotationValue value, final ITreeAppendable appendable, final GeneratorConfig config) {
  if (value instanceof JvmAnnotationAnnotationValue) {
    _toJavaLiteral((JvmAnnotationAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmBooleanAnnotationValue) {
    _toJavaLiteral((JvmBooleanAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmByteAnnotationValue) {
    _toJavaLiteral((JvmByteAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCharAnnotationValue) {
    _toJavaLiteral((JvmCharAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmCustomAnnotationValue) {
    _toJavaLiteral((JvmCustomAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmDoubleAnnotationValue) {
    _toJavaLiteral((JvmDoubleAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmEnumAnnotationValue) {
    _toJavaLiteral((JvmEnumAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmFloatAnnotationValue) {
    _toJavaLiteral((JvmFloatAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmIntAnnotationValue) {
    _toJavaLiteral((JvmIntAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmLongAnnotationValue) {
    _toJavaLiteral((JvmLongAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmShortAnnotationValue) {
    _toJavaLiteral((JvmShortAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmStringAnnotationValue) {
    _toJavaLiteral((JvmStringAnnotationValue)value, appendable, config);
    return;
  } else if (value instanceof JvmTypeAnnotationValue) {
    _toJavaLiteral((JvmTypeAnnotationValue)value, appendable, config);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(value, appendable, config).toString());
  }
}
 
Example #24
Source File: SarlCompiler.java    From sarl with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"checkstyle:returncount", "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"})
private static String getAnnotationStringValue(JvmAnnotationValue value) {
	if (value instanceof JvmAnnotationAnnotationValue) {
		return ((JvmAnnotationAnnotationValue) value).getValues().get(0).getAnnotation().getIdentifier();
	}
	if (value instanceof JvmBooleanAnnotationValue) {
		return ((JvmBooleanAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmByteAnnotationValue) {
		return ((JvmByteAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCharAnnotationValue) {
		return ((JvmCharAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmCustomAnnotationValue) {
		final EObject evalue = ((JvmCustomAnnotationValue) value).getValues().get(0);
		if (evalue instanceof XStringLiteral) {
			return ((XStringLiteral) evalue).getValue();
		}
		if (evalue instanceof XNumberLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XBooleanLiteral) {
			return ((XNumberLiteral) evalue).getValue();
		}
		if (evalue instanceof XTypeLiteral) {
			return ((XTypeLiteral) evalue).getType().getIdentifier();
		}
	}
	if (value instanceof JvmDoubleAnnotationValue) {
		return ((JvmDoubleAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmEnumAnnotationValue) {
		return ((JvmEnumAnnotationValue) value).getValues().get(0).getSimpleName();
	}
	if (value instanceof JvmFloatAnnotationValue) {
		return ((JvmFloatAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmIntAnnotationValue) {
		return ((JvmIntAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmLongAnnotationValue) {
		return ((JvmLongAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmShortAnnotationValue) {
		return ((JvmShortAnnotationValue) value).getValues().get(0).toString();
	}
	if (value instanceof JvmStringAnnotationValue) {
		return ((JvmStringAnnotationValue) value).getValues().get(0);
	}
	if (value instanceof JvmTypeAnnotationValue) {
		return ((JvmTypeAnnotationValue) value).getValues().get(0).getIdentifier();
	}
	return null;
}