Java Code Examples for org.eclipse.xtext.common.types.JvmType#getSimpleName()

The following examples show how to use org.eclipse.xtext.common.types.JvmType#getSimpleName() . 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: TypeConvertingCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void doReassignThisInClosure(final ITreeAppendable b, JvmType prevType) {
	final String proposedName = prevType.getSimpleName()+".this";
	if (!b.hasObject(proposedName)) {
		b.declareSyntheticVariable(prevType, proposedName);
		if (b.hasObject("super")) {
			Object superElement = b.getObject("super");
			if (superElement instanceof JvmType) {
				// Don't reassign the super of the enclosing type if it has already been reassigned
				String superVariable = b.getName(superElement);
				if ("super".equals(superVariable)) {
					b.declareSyntheticVariable(superElement, prevType.getSimpleName()+".super");
				}
			}
		}
	}
}
 
Example 2
Source File: DocumentSourceAppender.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void appendType(final /* @NonNull */ JvmType type, /* @NonNull */ StringBuilder builder) {
	if (type instanceof JvmPrimitiveType || type instanceof JvmVoid || type instanceof JvmTypeParameter) {
		builder.append(type.getQualifiedName(getInnerTypeSeparator()));
	} else if (type instanceof JvmArrayType) {
		appendType(((JvmArrayType) type).getComponentType(), builder);
		builder.append("[]");
	} else {
		final String qualifiedName = type.getQualifiedName(getInnerTypeSeparator());
		final String simpleName = type.getSimpleName();
		JvmDeclaredType importedType = getImportedType(type);
		if (importedType == type) {
			builder.append(simpleName);
		} else if (importedType == null) {
			importSection.addImport((JvmDeclaredType) type);
			builder.append(simpleName);
		} else {
			builder.append(qualifiedName);
		}
	}
}
 
Example 3
Source File: ImportManager.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public boolean addImportFor(JvmType type) {
	final String qualifiedName = type.getQualifiedName(getInnerTypeSeparator());
	final String simpleName = type.getSimpleName();
	final Map<String, String> imps = internalGetImports();
	if (!allowsSimpleName(qualifiedName, simpleName) && !needsQualifiedName(qualifiedName, simpleName) && !imps.containsKey(simpleName)) {
		imps.put(simpleName, qualifiedName);
		return true;
	}
	return false;
}
 
Example 4
Source File: JvmTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSimpleName() {
	JvmType type = getType();
	if (type != null)
		return type.getSimpleName();
	return null;
}
 
Example 5
Source File: SARLHoverSignatureProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the type name for the given type.
 *
 * @param type the type.
 * @return the string representation of the given type.
 */
protected String getTypeName(JvmType type) {
	if (type != null) {
		if (type instanceof JvmDeclaredType) {
			final ITypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, type);
			return owner.toLightweightTypeReference(type).getHumanReadableName();
		}
		return type.getSimpleName();
	}
	return Messages.SARLHoverSignatureProvider_1;
}
 
Example 6
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static String getSignatureType(JvmType type, ImportManager importManager) {
	if (importManager != null) {
		importManager.addImportFor(type);
		return type.getSimpleName();
	}
	return type.getIdentifier();
}
 
Example 7
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private int internalGetPrimitiveKind(ParameterizedTypeReference typeReference) {
	JvmType type = typeReference.getType();
	EClass eClass = type.eClass();
	if (eClass == TypesPackage.Literals.JVM_PRIMITIVE_TYPE) {
		if (type.eIsProxy())
			return PRIMITIVE_NONE;
		String name = type.getSimpleName();
		switch (name.length()) {
			case 3:
				if ("int".equals(name)) {
					return PRIMITIVE_INT;
				}
				break;
			case 4:
				if ("long".equals(name)) {
					return PRIMITIVE_LONG;
				} else if ("char".equals(name)) {
					return PRIMITIVE_CHAR;
				} else if ("byte".equals(name)) {
					return PRIMITIVE_BYTE;
				}
				break;
			case 5:
				if ("short".equals(name)) {
					return PRIMITIVE_SHORT;
				} else if ("float".equals(name)) {
					return PRIMITIVE_FLOAT;
				}
				break;
			case 6:
				if ("double".equals(name)) {
					return PRIMITIVE_DOUBLE;
				}
				break;
			case 7:
				if ("boolean".equals(name)) {
					return PRIMITIVE_BOOLEAN;
				}
				break;
		}
	} else if (eClass == TypesPackage.Literals.JVM_VOID) {
		if (type.eIsProxy())
			return PRIMITIVE_NONE;
		return PRIMITIVE_VOID;
	}
	return PRIMITIVE_NONE;
}
 
Example 8
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private String reassignSuperType(final ITreeAppendable b, final JvmDeclaredType declaredType, final GeneratorConfig config) {
  String _xblockexpression = null;
  {
    JvmTypeReference _extendedClass = declaredType.getExtendedClass();
    JvmType _type = null;
    if (_extendedClass!=null) {
      _type=_extendedClass.getType();
    }
    final JvmType superType = _type;
    boolean _hasObject = b.hasObject("super");
    if (_hasObject) {
      final Object element = b.getObject("this");
      if ((element instanceof JvmDeclaredType)) {
        final Object superElement = b.getObject("super");
        final String superVariable = b.getName(superElement);
        boolean _equals = "super".equals(superVariable);
        if (_equals) {
          String _simpleName = ((JvmDeclaredType)element).getSimpleName();
          final String proposedName = (_simpleName + ".super");
          b.declareVariable(superElement, proposedName);
        }
      }
    }
    boolean _isAtLeast = config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8);
    if (_isAtLeast) {
      Iterable<JvmTypeReference> _extendedInterfaces = declaredType.getExtendedInterfaces();
      for (final JvmTypeReference interfaceRef : _extendedInterfaces) {
        {
          final JvmType interfaze = interfaceRef.getType();
          String _simpleName_1 = interfaze.getSimpleName();
          final String simpleVarName = (_simpleName_1 + ".super");
          boolean _hasObject_1 = b.hasObject(simpleVarName);
          if (_hasObject_1) {
            final Object element_1 = b.getObject(simpleVarName);
            boolean _notEquals = (!Objects.equal(element_1, interfaceRef));
            if (_notEquals) {
              String _qualifiedName = interfaze.getQualifiedName();
              final String qualifiedVarName = (_qualifiedName + ".super");
              b.declareVariable(interfaze, qualifiedVarName);
            }
          } else {
            b.declareVariable(interfaze, simpleVarName);
          }
        }
      }
    }
    String _xifexpression = null;
    if ((superType != null)) {
      _xifexpression = b.declareVariable(superType, "super");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}