Java Code Examples for org.eclipse.xtext.common.types.JvmGenericType#eContainer()

The following examples show how to use org.eclipse.xtext.common.types.JvmGenericType#eContainer() . 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 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_01() {
	String typeName = NestedTypes.Outer.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertFalse(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 2
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer() {
	String typeName = StaticNestedTypes.Outer.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 3
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_Inner_01() {
	String typeName = NestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName() + "$"
			+ NestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 4
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_01() {
	String typeName = NestedTypes.Outer.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertFalse(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 5
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedInterface_Outer_Inner_01() {
	String typeName = NestedInterfaces.class.getName() + "$Outer$Inner";
	String expectedSuffix = NestedInterfaces.class.getSimpleName() + "$Outer$Inner";
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedInterfaces.class.getName() + "$Outer", outerType.getIdentifier());
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer_Inner() {
	String typeName = StaticNestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 7
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer_Inner() {
	String typeName = StaticNestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 8
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer() {
	String typeName = StaticNestedTypes.Outer.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 9
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_Inner_01() {
	String typeName = NestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName() + "$"
			+ NestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 10
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedInterface_Outer_01() {
	String typeName = NestedInterfaces.class.getName() + "$Outer";
	String expectedSuffix = NestedInterfaces.class.getSimpleName() + "$Outer";
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedInterfaces.class.getName(), outerType.getIdentifier());
}
 
Example 11
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedInterface_Outer_Inner_01() {
	String typeName = NestedInterfaces.class.getName() + "$Outer$Inner";
	String expectedSuffix = NestedInterfaces.class.getSimpleName() + "$Outer$Inner";
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedInterfaces.class.getName() + "$Outer", outerType.getIdentifier());
}
 
Example 12
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedInterface_Outer_01() {
	String typeName = NestedInterfaces.class.getName() + "$Outer";
	String expectedSuffix = NestedInterfaces.class.getSimpleName() + "$Outer";
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedInterfaces.class.getName(), outerType.getIdentifier());
}
 
Example 13
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable childAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
    this.generateModifier(it, childAppendable, config);
    boolean _isInterface = it.isInterface();
    if (_isInterface) {
      childAppendable.append("interface ");
    } else {
      childAppendable.append("class ");
    }
    this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
    this.generateTypeParameterDeclaration(it, childAppendable, config);
    boolean _isEmpty = it.getTypeParameters().isEmpty();
    if (_isEmpty) {
      childAppendable.append(" ");
    }
    this.generateExtendsClause(it, childAppendable, config);
    this.generateMembersInBody(it, childAppendable, config);
    ITreeAppendable _xifexpression = null;
    if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) {
      _xifexpression = appendable.newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 14
Source File: TypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean hasTypeParameters(JvmGenericType type) {
	if (!type.getTypeParameters().isEmpty()) {
		return true;
	}
	if (type.eContainer() instanceof JvmGenericType && !type.isStatic()) {
		return hasTypeParameters((JvmGenericType) type.eContainer());
	}
	return false;
}
 
Example 15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer_Inner() {
	String typeName = StaticNestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 16
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_staticNestedTypes_Outer() {
	String typeName = StaticNestedTypes.Outer.class.getName();
	String expectedSuffix = StaticNestedTypes.class.getSimpleName() + "$"
			+ StaticNestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertTrue(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(StaticNestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 17
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_Inner_01() {
	String typeName = NestedTypes.Outer.Inner.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName() + "$"
			+ NestedTypes.Outer.Inner.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.Outer.class.getName(), outerType.getIdentifier());
}
 
Example 18
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedTypes_Outer_01() {
	String typeName = NestedTypes.Outer.class.getName();
	String expectedSuffix = NestedTypes.class.getSimpleName() + "$" + NestedTypes.Outer.class.getSimpleName();
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertFalse(type.isStatic());
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedTypes.class.getName(), outerType.getIdentifier());
}
 
Example 19
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_nestedInterface_Outer_Inner_01() {
	String typeName = NestedInterfaces.class.getName() + "$Outer$Inner";
	String expectedSuffix = NestedInterfaces.class.getSimpleName() + "$Outer$Inner";
	assertTrue(typeName + " endsWith " + expectedSuffix, typeName.endsWith(expectedSuffix));
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	assertNotNull(type);
	assertEquals(typeName, type.getIdentifier());
	JvmType outerType = (JvmType) type.eContainer();
	assertEquals(NestedInterfaces.class.getName() + "$Outer", outerType.getIdentifier());
}
 
Example 20
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return a fresh {@link JvmParameterizedTypeReference} for the given {@link JvmType} parameterized with the given
 *         typeArgs. This method does not check whether the given type can handle the given type arguments.
 */
public JvmParameterizedTypeReference createTypeRef(JvmType type, JvmTypeReference... typeArgs) {
	if (type == null)
		throw new NullPointerException("type");
	List<JvmTypeReference> typeReferences = Collections.emptyList();
	if (typeArgs != null && typeArgs.length > 0) {
		typeReferences = Lists.newArrayListWithCapacity(typeArgs.length);
		for (int i = 0; i < typeArgs.length; i++) {
			JvmTypeReference jvmTypeReference = typeArgs[i];
			typeReferences.add(EcoreUtil2.cloneIfContained(jvmTypeReference));
		}
	}
	JvmParameterizedTypeReference reference;
	if (type instanceof JvmGenericType) {
		JvmGenericType casted = (JvmGenericType) type;
		List<JvmTypeParameter> list = casted.getTypeParameters();
		if (!typeReferences.isEmpty() && list.size() != typeReferences.size()) {
			throw new IllegalArgumentException("The type " + type.getIdentifier() + " expects " + list.size()
					+ " type arguments, but was " + typeReferences.size()
					+ ". Either pass zero arguments (raw type) or the correct number.");
		}
		// Raw type -> create type references to type param
		if (typeReferences.isEmpty() && !list.isEmpty()) {
			typeReferences = Lists.newArrayListWithCapacity(list.size());
			for (JvmTypeParameter typeParameter : list) {
				typeReferences.add(createTypeRef(typeParameter));
			}
		}
		if (!casted.isStatic() && casted.eContainer() instanceof JvmType) {
			JvmParameterizedTypeReference outer = createTypeRef((JvmType)casted.eContainer());
			reference = factory.createJvmInnerTypeReference();
			((JvmInnerTypeReference) reference).setOuter(outer);
		} else {
			reference = factory.createJvmParameterizedTypeReference();	
		}
	} else {
		reference = factory.createJvmParameterizedTypeReference();
	}
	reference.setType(type);
	if (!typeReferences.isEmpty())
		reference.getArguments().addAll(typeReferences);
	return reference;
}