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

The following examples show how to use org.eclipse.xtext.common.types.JvmEnumerationType. 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: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMemberCount_16() {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	int innerTypesCount = TestEnum.class.getDeclaredClasses().length;
	// Nested
	assertEquals(1, innerTypesCount);
	int methodCount = TestEnum.class.getDeclaredMethods().length;
	// TestEnum.values + TestEnum.valueOf
	assertEquals(2, methodCount);
	int constructorCount = TestEnum.class.getDeclaredConstructors().length;
	// TestEnum(String, int, String), TestEnum(String, int, String, EnumType)
	assertEquals(2, constructorCount);
	int fieldCount = TestEnum.class.getDeclaredFields().length;
	// FirstValue, SecondValue, string, ENUM$VALUES
	assertEquals(Arrays.toString(TestEnum.class.getDeclaredFields()), 4, fieldCount);
	// ENUM$VALUES is synthetic
	// TestEnum(String, String, EnumType) is synthetic
	assertEquals(type.getMembers().toString(), innerTypesCount + methodCount + constructorCount + fieldCount - 2,
			type.getMembers().size());
}
 
Example #2
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedEnum_04() throws Exception {
	String typeName = TestEnum.Nested.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(0, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #3
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMemberCount_16() {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	int innerTypesCount = TestEnum.class.getDeclaredClasses().length;
	// Nested
	assertEquals(1, innerTypesCount);
	int methodCount = TestEnum.class.getDeclaredMethods().length;
	// TestEnum.values + TestEnum.valueOf
	assertEquals(2, methodCount);
	int constructorCount = TestEnum.class.getDeclaredConstructors().length;
	// TestEnum(String, int, String), TestEnum(String, int, String, EnumType)
	assertEquals(2, constructorCount);
	int fieldCount = TestEnum.class.getDeclaredFields().length;
	// FirstValue, SecondValue, string, ENUM$VALUES
	assertEquals(Arrays.toString(TestEnum.class.getDeclaredFields()), 4, fieldCount);
	// ENUM$VALUES is synthetic
	// TestEnum(String, String, EnumType) is synthetic
	assertEquals(type.getMembers().toString(), innerTypesCount + methodCount + constructorCount + fieldCount - 2,
			type.getMembers().size());
}
 
Example #4
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnum_04() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(1, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnum_04() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(1, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedEnum_04() throws Exception {
	String typeName = TestEnum.Nested.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(0, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #7
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected Iterable<JvmMember> _getMembersToBeCompiled(final JvmEnumerationType type) {
  Iterable<JvmMember> _xblockexpression = null;
  {
    String _identifier = type.getIdentifier();
    String _plus = (_identifier + ".");
    String _plus_1 = (_plus + "valueOf(java.lang.String)");
    String _identifier_1 = type.getIdentifier();
    String _plus_2 = (_identifier_1 + ".");
    String _plus_3 = (_plus_2 + "values()");
    final Set<String> syntheticEnumMethods = Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet(_plus_1, _plus_3));
    final Function1<JvmMember, Boolean> _function = (JvmMember it) -> {
      return Boolean.valueOf((!((it instanceof JvmOperation) && syntheticEnumMethods.contains(it.getIdentifier()))));
    };
    _xblockexpression = IterableExtensions.<JvmMember>filter(type.getMembers(), _function);
  }
  return _xblockexpression;
}
 
Example #8
Source File: JvmModelCompleter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void complete(JvmIdentifiableElement element) {
	if (element instanceof JvmGenericType) {
		completeJvmGenericType((JvmGenericType)element);
	}
	if (element instanceof JvmDeclaredType) {
		JvmDeclaredType declaredType = (JvmDeclaredType) element;
		complete(declaredType.getMembers());
	}
	if(element instanceof JvmConstructor) {
		completeJvmConstructor((JvmConstructor) element);
	}
	if (element instanceof JvmEnumerationType) {
		completeJvmEnumerationType((JvmEnumerationType)element);
	}
	if (element instanceof JvmEnumerationLiteral) {
		completeJvmEnumerationLiteral((JvmEnumerationLiteral)element);
	}
	if (element instanceof JvmAnnotationType) {
		completeJvmAnnotationType((JvmAnnotationType)element);
	}
}
 
Example #9
Source File: JvmModelTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnumIsFinal() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("enum Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("BAR");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final JvmEnumerationType inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString()));
    Assert.assertTrue(inferred.isFinal());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #10
Source File: TypeInsteadOfConstructorLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
	JvmType type = (JvmType) description.getElementOrProxy();
	String typeKind = "";
	if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) {
		typeKind = "primitive type";
	} else if (type instanceof JvmAnnotationType) {
		typeKind = "annotation type";
	} else if (type instanceof JvmEnumerationType) {
		typeKind = "enum type";
	} else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) {
		typeKind = "interface type";
	} else if (type instanceof JvmTypeParameter) {
		typeKind = "type parameter";
	}
	String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName());
	AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
			IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(),
			XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null);
	result.accept(diagnostic);
	return false;
}
 
Example #11
Source File: ResourceDescriptionProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testStubGeneration_03() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public enum MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("FOO, BAR");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue((_eObjectOrProxy instanceof JvmEnumerationType));
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
 
Example #12
Source File: JvmModelTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTopLevelEnumIsNotStatic() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("enum Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("BAR");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final JvmEnumerationType inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString()));
    Assert.assertFalse(inferred.isStatic());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #13
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedEnum_04() throws Exception {
	String typeName = TestEnum.Nested.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(0, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #14
Source File: JvmModelTests.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnumInAnnotationIsStatic() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("annotation Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("enum E { L0, L1 }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final JvmAnnotationType inferred = this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString()));
    JvmMember _head = IterableExtensions.<JvmMember>head(inferred.getMembers());
    final JvmEnumerationType e = ((JvmEnumerationType) _head);
    Assert.assertTrue(e.isStatic());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #15
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnumerationWithCompleter() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmEnumerationType> _function = (JvmEnumerationType it) -> {
      EList<JvmMember> _members = it.getMembers();
      JvmEnumerationLiteral _enumerationLiteral = this.builder.toEnumerationLiteral(expression, "BAR");
      this.builder.<JvmEnumerationLiteral>operator_add(_members, _enumerationLiteral);
      EList<JvmMember> _members_1 = it.getMembers();
      JvmEnumerationLiteral _enumerationLiteral_1 = this.builder.toEnumerationLiteral(expression, "BAZ");
      this.builder.<JvmEnumerationLiteral>operator_add(_members_1, _enumerationLiteral_1);
    };
    final JvmEnumerationType enumeration = this.builder.toEnumerationType(expression, "my.test.Foo", _function);
    expression.eResource().getContents().add(enumeration);
    this.completer.complete(enumeration);
    final Class<?> compiled = this.compile(expression.eResource(), enumeration);
    final Method valuesMethod = compiled.getMethod("values");
    Object _invoke = valuesMethod.invoke(null);
    final Object[] values = ((Object[]) _invoke);
    Assert.assertEquals("BAR", (values[0]).toString());
    Assert.assertEquals("BAZ", (values[1]).toString());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMemberCount_16() {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	int innerTypesCount = TestEnum.class.getDeclaredClasses().length;
	// Nested
	assertEquals(1, innerTypesCount);
	int methodCount = TestEnum.class.getDeclaredMethods().length;
	// TestEnum.values + TestEnum.valueOf
	assertEquals(2, methodCount);
	int constructorCount = TestEnum.class.getDeclaredConstructors().length;
	// TestEnum(String, int, String), TestEnum(String, int, String, EnumType)
	assertEquals(2, constructorCount);
	int fieldCount = TestEnum.class.getDeclaredFields().length;
	// FirstValue, SecondValue, string, ENUM$VALUES
	assertEquals(Arrays.toString(TestEnum.class.getDeclaredFields()), 4, fieldCount);
	// ENUM$VALUES is synthetic
	// TestEnum(String, String, EnumType) is synthetic
	assertEquals(type.getMembers().toString(), innerTypesCount + methodCount + constructorCount + fieldCount - 2,
			type.getMembers().size());
}
 
Example #17
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void transform(XtendEnumLiteral literal, JvmEnumerationType container) {
	if (literal.getName() == null)
		return;
	JvmEnumerationLiteral jvmLiteral = typesFactory.createJvmEnumerationLiteral();
	associator.associatePrimary(literal, jvmLiteral);
	jvmLiteral.setSimpleName(literal.getName());
	jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
	jvmLiteral.setStatic(true);
	jvmLiteral.setFinal(true);
	jvmTypesBuilder.copyDocumentationTo(literal, jvmLiteral);
	for (XAnnotation anno : literal.getAnnotations()) {
		if (!annotationTranslationFilter.apply(anno))
			continue;
		JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
		if(annotationReference != null)
			jvmLiteral.getAnnotations().add(annotationReference);
	}
	container.getMembers().add(jvmLiteral);
}
 
Example #18
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmEnumerationType createEnumerationType(Class<?> clazz) {
	JvmEnumerationType result = TypesFactory.eINSTANCE.createJvmEnumerationType();
	result.internalSetIdentifier(clazz.getName());
	result.setSimpleName(clazz.getSimpleName());
	if (clazz.getDeclaringClass() == null && clazz.getPackage() != null)
		result.setPackageName(clazz.getPackage().getName());
	setVisibility(clazz, result);
	setTypeModifiers(clazz, result);
	createNestedTypes(clazz, result);
	createMethods(clazz, result);
	createFields(clazz, result);
	createConstructors(clazz, result);
	setSuperTypes(clazz, result);
	createAnnotationValues(clazz, result);
	return result;
}
 
Example #19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnum_04() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	List<JvmMember> members = type.getMembers();
	boolean constructorFound = false;
	for (JvmMember member : members) {
		if (member instanceof JvmConstructor) {
			assertFalse(constructorFound);
			constructorFound = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(1, parameters.size()); // synthetic parameters are not returned
		}
	}
	assertTrue(constructorFound);
}
 
Example #20
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private boolean isEnumExpectationInAnnotationValue(final XFeatureCall it, final JvmType expectedRawType) {
  if (((expectedRawType instanceof JvmEnumerationType) || ((expectedRawType instanceof JvmArrayType) && (((JvmArrayType) expectedRawType).getComponentType() instanceof JvmEnumerationType)))) {
    EObject container = it.eContainer();
    if ((container instanceof XAnnotationElementValuePair)) {
      return true;
    }
    if ((container instanceof XAnnotation)) {
      return true;
    }
    if ((container instanceof XListLiteral)) {
      container = ((XListLiteral)container).eContainer();
      if ((container instanceof XAnnotationElementValuePair)) {
        return true;
      }
      if ((container instanceof XAnnotation)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #21
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void transform(XtendMember sourceMember, JvmGenericType container, boolean allowDispatch) {
	if (sourceMember instanceof XtendFunction) {
		transform((XtendFunction) sourceMember, container, allowDispatch);
	} else if (sourceMember instanceof XtendField) {
		transform((XtendField) sourceMember, container);
	} else if (sourceMember instanceof XtendConstructor) {
		transform((XtendConstructor) sourceMember, container);
	} else if (sourceMember instanceof XtendEnumLiteral && container instanceof JvmEnumerationType) {
		transform((XtendEnumLiteral) sourceMember, (JvmEnumerationType) container);
	} else {
		throw new IllegalArgumentException("Cannot transform " + String.valueOf(sourceMember) + " to a JvmMember");
	}
}
 
Example #22
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void initialize(XtendEnum source, JvmEnumerationType inferredJvmType) {
	inferredJvmType.setVisibility(source.getVisibility());
	inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
	translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
	for (XtendMember member : source.getMembers()) {
		if (member instanceof XtendEnumLiteral) 
			transform((XtendEnumLiteral) member, inferredJvmType);
	}
	jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
}
 
Example #23
Source File: XbaseLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return the {@code ImageDescriptor} for a given {@code obj}
 * @throws NullPointerException
 *             if the passed {@code obj} is null
 */
protected ImageDescriptor imageDescriptor(Object obj) {
	Preconditions.checkNotNull(obj);

	if (obj instanceof JvmConstructor) {
		return _imageDescriptor((JvmConstructor) obj);
	} else if (obj instanceof JvmOperation) {
		return _imageDescriptor((JvmOperation) obj);
	} else if (obj instanceof JvmAnnotationType) {
		return _imageDescriptor((JvmAnnotationType) obj);
	} else if (obj instanceof JvmEnumerationType) {
		return _imageDescriptor((JvmEnumerationType) obj);
	} else if (obj instanceof JvmField) {
		return _imageDescriptor((JvmField) obj);
	} else if (obj instanceof JvmGenericType) {
		return _imageDescriptor((JvmGenericType) obj);
	} else if (obj instanceof JvmTypeParameter) {
		return _imageDescriptor((JvmTypeParameter) obj);
	} else if (obj instanceof JvmFormalParameter) {
		return _imageDescriptor((JvmFormalParameter) obj);
	} else if (obj instanceof XVariableDeclaration) {
		return _imageDescriptor((XVariableDeclaration) obj);
	} else if (obj instanceof IResolvedConstructor) {
		return _imageDescriptor((IResolvedConstructor) obj);
	} else if (obj instanceof IResolvedOperation) {
		return _imageDescriptor((IResolvedOperation) obj);
	} else if (obj instanceof XImportDeclaration) {
		return _imageDescriptor((XImportDeclaration) obj);
	} else if (obj instanceof XImportSection) {
		return _imageDescriptor((XImportSection) obj);
	} else if (obj instanceof IResolvedField) {
		return _imageDescriptor((IResolvedField) obj);
	}
	return _imageDescriptor(obj);
}
 
Example #24
Source File: AnnotationValidation.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
  JvmTypeReference _switchResult = null;
  boolean _matched = false;
  if (reference instanceof JvmGenericArrayTypeReference) {
    _matched=true;
    _switchResult = ((JvmGenericArrayTypeReference)reference).getComponentType();
  }
  if (!_matched) {
    _switchResult = reference;
  }
  final JvmTypeReference toCheck = _switchResult;
  if ((toCheck == null)) {
    return true;
  }
  JvmType _type = toCheck.getType();
  if ((_type instanceof JvmPrimitiveType)) {
    return true;
  }
  JvmType _type_1 = toCheck.getType();
  if ((_type_1 instanceof JvmEnumerationType)) {
    return true;
  }
  JvmType _type_2 = toCheck.getType();
  if ((_type_2 instanceof JvmAnnotationType)) {
    return true;
  }
  if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
    return true;
  }
  return false;
}
 
Example #25
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnum_06() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	JvmOperation valuesOperation = (JvmOperation) Iterables.getFirst(type.findAllFeaturesByName("valueOf"), null);
	String qualifiedReturnValue = valuesOperation.getReturnType().getQualifiedName();
	assertEquals(typeName, qualifiedReturnValue);
}
 
Example #26
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnum_05() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	JvmOperation valuesOperation = (JvmOperation) Iterables.getOnlyElement(type.findAllFeaturesByName("values"));
	String qualifiedReturnValue = valuesOperation.getReturnType().getQualifiedName();
	assertEquals(typeName + "[]", qualifiedReturnValue);
}
 
Example #27
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnum_03() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	assertEquals(2, type.getLiterals().size());
	Set<String> expectedLiterals = Sets.newHashSet(TestEnum.FirstValue.name(), TestEnum.SecondValue.name());
	for (JvmEnumerationLiteral literal : type.getLiterals()) {
		assertTrue(expectedLiterals.remove(literal.getSimpleName()));
		assertSame(type, literal.getEnumType());
		assertEquals(JvmVisibility.PUBLIC, literal.getVisibility());
	}
	assertTrue(expectedLiterals.toString(), expectedLiterals.isEmpty());
}
 
Example #28
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnum_02() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	assertEquals(1, type.getSuperTypes().size());
	assertEquals(Enum.class.getName(), type.getSuperTypes().get(0).getType().getIdentifier());
	String superTypeName = Enum.class.getName() + "<" + typeName + ">";
	assertEquals(superTypeName, type.getSuperTypes().get(0).getIdentifier());
}
 
Example #29
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEnum_01() throws Exception {
	String typeName = TestEnum.class.getName();
	JvmType type = getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type instanceof JvmEnumerationType);
	assertTrue(((JvmEnumerationType) type).isFinal());
	assertFalse(((JvmEnumerationType) type).isStatic());
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
}
 
Example #30
Source File: AbstractJdtTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestEnum_07(String paramName) throws Exception {
	String typeName = TestEnum.class.getName();
	JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName);
	boolean constructorSeen = false;
	for(JvmMember member: type.getMembers()) {
		if (member instanceof JvmConstructor) {
			constructorSeen = true;
			List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters();
			assertEquals(1, parameters.size());
			JvmFormalParameter singleParam = parameters.get(0);
			assertEquals(paramName, singleParam.getName());
		}
	}
	assertTrue("constructorSeen", constructorSeen);
}