当前位置: 首页>>代码示例>>Java>>正文


Java JvmEnumerationType类代码示例

本文整理汇总了Java中org.eclipse.xtext.common.types.JvmEnumerationType的典型用法代码示例。如果您正苦于以下问题:Java JvmEnumerationType类的具体用法?Java JvmEnumerationType怎么用?Java JvmEnumerationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JvmEnumerationType类属于org.eclipse.xtext.common.types包,在下文中一共展示了JvmEnumerationType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMemberCount_16

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:22,代码来源:AbstractTypeProviderTest.java

示例2: testEnum_04

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:AbstractTypeProviderTest.java

示例3: testNestedEnum_04

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:AbstractTypeProviderTest.java

示例4: testStubGeneration_03

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:ResourceDescriptionProviderTest.java

示例5: validate

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:TypeInsteadOfConstructorLinkingCandidate.java

示例6: complete

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:22,代码来源:JvmModelCompleter.java

示例7: _getMembersToBeCompiled

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:JvmModelGenerator.java

示例8: testEnumerationWithCompleter

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:JvmModelGeneratorTest.java

示例9: createEnumerationType

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:ReflectionTypeFactory.java

示例10: testEnum_01

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:AbstractTypeProviderTest.java

示例11: testEnum_02

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:AbstractTypeProviderTest.java

示例12: testEnum_03

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:AbstractTypeProviderTest.java

示例13: testEnum_05

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:AbstractTypeProviderTest.java

示例14: testEnum_06

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:AbstractTypeProviderTest.java

示例15: testNestedEnum_01

import org.eclipse.xtext.common.types.JvmEnumerationType; //导入依赖的package包/类
@Test
public void testNestedEnum_01() throws Exception {
	String typeName = TestEnum.Nested.class.getName();
	JvmType type = getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type instanceof JvmEnumerationType);
	assertTrue(((JvmEnumerationType) type).isFinal());
	assertTrue(((JvmEnumerationType) type).isStatic());
	diagnose(type);
	Resource resource = type.eResource();
	getAndResolveAllFragments(resource);
	recomputeAndCheckIdentifiers(resource);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:AbstractTypeProviderTest.java


注:本文中的org.eclipse.xtext.common.types.JvmEnumerationType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。