Java Code Examples for org.eclipse.xtext.common.types.JvmOperation#getDefaultValue()

The following examples show how to use org.eclipse.xtext.common.types.JvmOperation#getDefaultValue() . 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: XbaseWithAnnotationsValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkAllAttributesConfigured(XAnnotation annotation) {
	JvmType annotationType = annotation.getAnnotationType();
	if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType))
		return;
	Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations();
	for (JvmOperation jvmOperation : attributes) {
		XExpression value = annotationUtil.findValue(annotation, jvmOperation);
		if(value == null) {
			if (jvmOperation.getDefaultValue() == null) {
				error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, 
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION);
			}
		} else
			annotationValueValidator.validateAnnotationValue(value, this);
	}
}
 
Example 2
Source File: JvmAnnotationReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public EList<JvmAnnotationValue> getValues() {
	EList<JvmAnnotationValue> explicitValues = getExplicitValues();
	List<JvmOperation> operations = Lists.newArrayList(getAnnotation().getDeclaredOperations());
	if (operations.size() <= explicitValues.size()) {
		return ECollections.unmodifiableEList(explicitValues);
	}
	Set<JvmOperation> seenOperations = Sets.newHashSetWithExpectedSize(operations.size());
	BasicEList<JvmAnnotationValue> result = new BasicEList<JvmAnnotationValue>(operations.size());
	for(JvmAnnotationValue value: explicitValues) {
		seenOperations.add(value.getOperation());
		result.add(value);
	}
	for(JvmOperation operation: operations) {
		if (seenOperations.add(operation)) {
			JvmAnnotationValue defaultValue = operation.getDefaultValue();
			if (defaultValue != null) {
				result.add(defaultValue);
			}
		}
	}
	return ECollections.unmodifiableEList(result);
}
 
Example 3
Source File: JvmModelTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEmptyListAsAnnotationValueDefault() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotation Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String[] bar = #[]");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
    final JvmOperation inferred = ((JvmOperation) _head);
    Assert.assertEquals("java.lang.String[]", inferred.getReturnType().getIdentifier());
    JvmAnnotationValue _defaultValue = inferred.getDefaultValue();
    Assert.assertTrue((_defaultValue instanceof JvmCustomAnnotationValue));
    JvmAnnotationValue _defaultValue_1 = inferred.getDefaultValue();
    EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _defaultValue_1).getValues());
    Assert.assertTrue((_head_1 instanceof XListLiteral));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: JvmModelTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAnnotationDefaultAssociatedWithJvmOperation() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotation Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val bar = \'\'");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
    final JvmOperation inferred = ((JvmOperation) _head);
    final JvmAnnotationValue defaultValue = inferred.getDefaultValue();
    Assert.assertSame(inferred, defaultValue.getOperation());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultAnnotationValue(String name) {
	String typeName = TestAnnotationWithDefaults.class.getName();
	JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = getMethodFromType(type, TestAnnotationWithDefaults.class, name + "()");
	JvmAnnotationValue result = operation.getDefaultValue();
	assertNotNull(result);
	assertSame(operation, result.getOperation());
	return result;
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultAnnotationValue(String name) {
	String typeName = TestAnnotationWithDefaults.class.getName();
	JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = getMethodFromType(type, TestAnnotationWithDefaults.class, name + "()");
	JvmAnnotationValue result = operation.getDefaultValue();
	assertNotNull(result);
	assertSame(operation, result.getOperation());
	return result;
}
 
Example 7
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationValue getDefaultAnnotationValue(String name) {
	String typeName = TestAnnotationWithDefaults.class.getName();
	JvmAnnotationType type = (JvmAnnotationType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = getMethodFromType(type, TestAnnotationWithDefaults.class, name + "()");
	JvmAnnotationValue result = operation.getDefaultValue();
	assertNotNull(result);
	assertSame(operation, result.getOperation());
	return result;
}
 
Example 8
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void generateDefaultExpression(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
  Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it);
  boolean _tripleNotEquals = (_compilationStrategy != null);
  if (_tripleNotEquals) {
    appendable.append(" default ");
    appendable.increaseIndentation();
    this._jvmTypeExtensions.getCompilationStrategy(it).apply(appendable);
    appendable.decreaseIndentation();
  } else {
    StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it);
    boolean _tripleNotEquals_1 = (_compilationTemplate != null);
    if (_tripleNotEquals_1) {
      appendable.append(" default ").increaseIndentation();
      this.appendCompilationTemplate(appendable, it);
      appendable.decreaseIndentation();
    } else {
      boolean _isGenerateExpressions = config.isGenerateExpressions();
      if (_isGenerateExpressions) {
        final XExpression body = this._iLogicalContainerProvider.getAssociatedExpression(it);
        if ((body != null)) {
          boolean _hasErrors = this._errorSafeExtensions.hasErrors(body);
          if (_hasErrors) {
            appendable.append("/* skipped default expression with errors */");
          } else {
            appendable.append(" default ");
            this.compiler.compileAsJavaExpression(body, appendable, it.getReturnType());
          }
        } else {
          JvmAnnotationValue _defaultValue = it.getDefaultValue();
          boolean _tripleNotEquals_2 = (_defaultValue != null);
          if (_tripleNotEquals_2) {
            boolean _hasErrors_1 = this._errorSafeExtensions.hasErrors(it.getDefaultValue());
            if (_hasErrors_1) {
              appendable.append("/* skipped default expression with errors */");
            } else {
              appendable.append(" default ");
              this.toJavaLiteral(it.getDefaultValue(), appendable, config);
            }
          }
        }
      }
    }
  }
}