Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#setPackageName()

The following examples show how to use org.eclipse.xtext.common.types.JvmDeclaredType#setPackageName() . 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 JvmDeclaredType createType(IType type, ITypeBinding binding) {
	// Maintain a string builder we pass along during recursion 
	// that contains the prefix for the fully qualified name of the binding instance being traversed.
	//
	StringBuilder fqn = new StringBuilder(100);
	IPackageBinding packageBinding = binding.getPackage();
	String packageName = null;
	if (packageBinding != null && !packageBinding.isUnnamed()) {
		packageName = packageBinding.getName();
		fqn.append(packageBinding.getName());
		fqn.append('.');
	}

	JvmDeclaredType result = createType(binding, type.getHandleIdentifier(), Lists.<String>newArrayList(), fqn);
	result.setPackageName(packageName);
	return result;
}
 
Example 2
Source File: JavaDerivedStateComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmDeclaredType createType(TypeDeclaration type, String packageName) {
	JvmDeclaredType jvmType = null;
	switch (TypeDeclaration.kind(type.modifiers)) {
	case TypeDeclaration.CLASS_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		break;
	case TypeDeclaration.INTERFACE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		((JvmGenericType) jvmType).setInterface(true);
		break;
	case TypeDeclaration.ENUM_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmEnumerationType();
		break;
	case TypeDeclaration.ANNOTATION_TYPE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmAnnotationType();
		break;
	default:
		throw new IllegalArgumentException("Cannot handle type " + type.toString());
	}
	jvmType.setPackageName(packageName);
	jvmType.setSimpleName(String.valueOf(type.name));
	if (jvmType instanceof JvmGenericType) {
		if (type.typeParameters != null) {
			for (TypeParameter typeParam : type.typeParameters) {
				JvmTypeParameter jvmTypeParam = TypesFactory.eINSTANCE.createJvmTypeParameter();
				jvmTypeParam.setName(String.valueOf(typeParam.name));
				((JvmGenericType) jvmType).getTypeParameters().add(jvmTypeParam);
			}
		}
	}
	if (type.memberTypes != null) {
		for (TypeDeclaration nestedType : type.memberTypes) {
			JvmDeclaredType nested = createType(nestedType, null);
			jvmType.getMembers().add(nested);
		}
	}
	return jvmType;
}
 
Example 3
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void setNameAndAssociate(XtendFile file, XtendTypeDeclaration xtendType, JvmDeclaredType javaType) {
	javaType.setPackageName(file.getPackage());
	javaType.setSimpleName(xtendType.getName());
	javaType.setVisibility(JvmVisibility.PUBLIC);
	setFileHeader(file, javaType);
	associator.associatePrimary(xtendType, javaType);
}
 
Example 4
Source File: RegisterGlobalsContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void setNameAndAccept(final JvmDeclaredType newType, final String qualifiedName) {
  ConditionUtils.checkQualifiedName(qualifiedName, "qualifiedName");
  JvmDeclaredType _findType = this.findType(qualifiedName);
  boolean _tripleEquals = (_findType == null);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("The type \'");
  _builder.append(qualifiedName);
  _builder.append("\' has already been registered.");
  Preconditions.checkArgument(_tripleEquals, _builder);
  this.compilationUnit.checkCanceled();
  final Pair<String, String> namespaceAndName = this.getNameParts(qualifiedName);
  final String headerText = this.compilationUnit.getFileHeaderProvider().getFileHeader(this.compilationUnit.getXtendFile().eResource());
  this.compilationUnit.getJvmTypesBuilder().setFileHeader(newType, headerText);
  String _key = namespaceAndName.getKey();
  boolean _tripleNotEquals = (_key != null);
  if (_tripleNotEquals) {
    final JvmDeclaredType parentType = this.findType(namespaceAndName.getKey());
    if ((parentType != null)) {
      EList<JvmMember> _members = parentType.getMembers();
      _members.add(newType);
      newType.setStatic(true);
    } else {
      newType.setPackageName(namespaceAndName.getKey());
      this.acceptor.<JvmDeclaredType>accept(newType);
    }
  } else {
    this.acceptor.<JvmDeclaredType>accept(newType);
  }
  newType.setSimpleName(namespaceAndName.getValue());
}