Java Code Examples for org.eclipse.xtext.common.types.JvmType#getIdentifier()
The following examples show how to use
org.eclipse.xtext.common.types.JvmType#getIdentifier() .
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: ArrayTypeReference.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override /* @Nullable */ public LightweightTypeReference getSuperType(JvmType rawType) { if (rawType.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType rawComponentType = ((JvmArrayType) rawType).getComponentType(); LightweightTypeReference result = component.getSuperType(rawComponentType); if (result == null) { return null; } if (result == component) return this; return getOwner().newArrayTypeReference(result); } else if (rawType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { String identifier = rawType.getIdentifier(); if (Object.class.getName().equals(identifier) || Cloneable.class.getName().equals(identifier) || Serializable.class.getName().equals(identifier)) { return getOwner().newParameterizedTypeReference(rawType); } } return null; }
Example 2
Source File: XFunctionTypeRefs.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public static JvmType getWrappedType(JvmType type) { String name = type.getIdentifier(); if ("int".equals(name)) { return getType(Integer.class, type); } else if ("boolean".equals(name)) { return getType(Boolean.class, type); } else if ("char".equals(name)) { return getType(Character.class, type); } else if ("long".equals(name)) { return getType(Long.class, type); } else if ("double".equals(name)) { return getType(Double.class, type); } else if ("byte".equals(name)) { return getType(Byte.class, type); } else if ("float".equals(name)) { return getType(Float.class, type); } else if ("short".equals(name)) { return getType(Short.class, type); } return null; }
Example 3
Source File: JdtBasedProcessorProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Object getProcessorInstance(final JvmType type) { try { final ClassLoader classLoader = this.getClassLoader(type); final Class<?> result = classLoader.loadClass(type.getIdentifier()); return result.getDeclaredConstructor().newInstance(); } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception e = (Exception)_t; String _identifier = type.getIdentifier(); String _plus = ("Problem during instantiation of " + _identifier); String _plus_1 = (_plus + " : "); String _message = e.getMessage(); String _plus_2 = (_plus_1 + _message); throw new IllegalStateException(_plus_2, e); } else { throw Exceptions.sneakyThrow(_t); } } }
Example 4
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getFirstForRawType(Multimap<JvmType, LightweightTypeReference> all, JvmType rawType) { Iterator<LightweightTypeReference> iterator = all.get(rawType).iterator(); while(iterator.hasNext()) { LightweightTypeReference result = iterator.next(); if (result instanceof ParameterizedTypeReference || result instanceof ArrayTypeReference) { return result; } } throw new IllegalStateException(all.toString() + " does not contain a useful type reference for rawtype " + rawType.getIdentifier()); }
Example 5
Source File: Utils.java From sarl with Apache License 2.0 | 5 votes |
private static String getSignatureType(JvmType type, ImportManager importManager) { if (importManager != null) { importManager.addImportFor(type); return type.getSimpleName(); } return type.getIdentifier(); }
Example 6
Source File: MissedMethodAddModification.java From sarl with Apache License 2.0 | 5 votes |
private static String typeParameterId(JvmTypeReference type) { final JvmType realType = type.getType(); if (realType instanceof JvmTypeParameter) { final JvmDeclaredType container = EcoreUtil2.getContainerOfType(realType, JvmDeclaredType.class); if (container != null) { return container.getQualifiedName() + "$" + realType.getIdentifier(); //$NON-NLS-1$ } } return type.getQualifiedName(); }
Example 7
Source File: AnnotationReferenceBuildContextImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected String getAnnotationValueTypeName(final JvmType type) { String _switchResult = null; String _identifier = null; if (type!=null) { _identifier=type.getIdentifier(); } String _replace = null; if (_identifier!=null) { _replace=_identifier.replace("$", "."); } final String result = _replace; if (result != null) { switch (result) { case "java.lang.Class": _switchResult = TypeReference.class.getName(); break; case "java.lang.Class[]": String _name = TypeReference.class.getName(); _switchResult = (_name + "[]"); break; default: _switchResult = result; break; } } else { _switchResult = result; } return _switchResult; }
Example 8
Source File: XtendMemberDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isDeprecated() { final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> { String _name = Deprecated.class.getName(); JvmType _annotationType = it.getAnnotationType(); String _identifier = null; if (_annotationType!=null) { _identifier=_annotationType.getIdentifier(); } return Boolean.valueOf(Objects.equal(_name, _identifier)); }; return IterableExtensions.<XAnnotation>exists(this.getDelegate().getAnnotations(), _function); }
Example 9
Source File: ConstantExpressionsInterpreter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected Class<?> getJavaType(final JvmType type, final ClassFinder classFinder) throws ClassNotFoundException { if ((type instanceof JvmArrayType)) { JvmType t = type; String dimensions = ""; while ((t instanceof JvmArrayType)) { { dimensions = (dimensions + "[]"); t = ((JvmArrayType)t).getComponentType(); } } final Class<?> componentClass = this.getJavaType(t, classFinder); String _name = componentClass.getName(); String _plus = (_name + dimensions); return classFinder.forName(_plus); } String _identifier = type.getIdentifier(); boolean _equals = Objects.equal(_identifier, "java.lang.Class"); if (_equals) { return JvmTypeReference.class; } if ((type instanceof JvmEnumerationType)) { return JvmEnumerationLiteral.class; } if ((type instanceof JvmAnnotationType)) { return XAnnotation.class; } return classFinder.forName(type.getIdentifier()); }
Example 10
Source File: JvmTypeReferenceImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public String getIdentifier() { JvmType type = getType(); if (type != null) return type.getIdentifier(); return null; }
Example 11
Source File: XImportDeclarationImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public String getImportedTypeName() { String result = getImportedNamespace(); if (result == null) { if (this.eIsSet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE)) { JvmType unresolvedType = (JvmType) this.eGet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, false); if(!unresolvedType.eIsProxy()) return unresolvedType.getIdentifier(); List<INode> list = NodeModelUtils.findNodesForFeature(this, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE); StringBuilder sb = new StringBuilder(); for (INode iNode : list) { sb.append(NodeModelUtils.getTokenText(iNode).replace("^", "")); } result = sb.toString().replace(" ", ""); if (isStatic()) { return trim(result, 1); } return result; } return null; } if (isWildcard()) { return trim(result, 2); } return result; }
Example 12
Source File: TypeConvertingCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private boolean identifierStartWith(LightweightTypeReference typeReference, String prefix) { JvmType type = typeReference.getType(); if (type == null) return false; String identifier = type.getIdentifier(); if (identifier != null) return identifier.startsWith(prefix); return false; }
Example 13
Source File: JvmTypeReferenceBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param type * the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} */ public JvmTypeReference typeRef(JvmType type, JvmTypeReference... typeArgs) { int typeParams = 0; if (type instanceof JvmGenericType) { typeParams = ((JvmGenericType) type).getTypeParameters().size(); } if (typeParams < typeArgs.length) { throw new IllegalArgumentException("The type "+type.getIdentifier()+" only declares "+typeParams+" type parameters. You passed "+typeArgs.length+"."); } LightweightTypeReference reference = typeReferenceOwner.toPlainTypeReference(type); for (JvmTypeReference jvmTypeReference : typeArgs) { ((ParameterizedTypeReference)reference).addTypeArgument(typeReferenceOwner.toLightweightTypeReference(jvmTypeReference)); } return reference.toJavaCompliantTypeReference(); }
Example 14
Source File: LightweightTypeReference.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getUniqueIdentifier(JvmType type) { String typeIdentifier = type.getIdentifier(); if (type instanceof JvmTypeParameter) { JvmIdentifiableElement declarator = (JvmIdentifiableElement) ((JvmTypeParameter) type).getDeclarator(); // may happen in unit tests if (declarator != null) { typeIdentifier = typeIdentifier + ":" + declarator.getQualifiedName(); } else { typeIdentifier = typeIdentifier + ":"; } } return typeIdentifier; }
Example 15
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private boolean removeTypeImport(Map<String, List<XImportDeclaration>> imports, JvmType declaringType) { String identifier = declaringType.getIdentifier(); List<XImportDeclaration> list = imports.get(identifier); if (list == null) { return false; } if (list.size() == 1) { imports.remove(identifier); return true; } list.remove(0); return true; }
Example 16
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @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; }
Example 17
Source File: IndexedJvmTypeAccess.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * Locate a locale type with the given fragment. Does not consider types that * are defined in operations or constructors as inner classes. */ public EObject resolveJavaObject(JvmType rootType, String fragment) throws UnknownNestedTypeException { if (fragment.endsWith("[]")) { return resolveJavaArrayObject(rootType, fragment); } int slash = fragment.indexOf('/'); if (slash != -1) { if (slash == 0) return null; String containerFragment = fragment.substring(0, slash); EObject container = resolveJavaObject(rootType, containerFragment); if (container != null) { String parameterName = fragment.substring(slash + 1); if (container instanceof JvmTypeParameterDeclarator) { JvmTypeParameterDeclarator executable = (JvmTypeParameterDeclarator) container; for(JvmTypeParameter parameter: executable.getTypeParameters()) { if (parameter.getName().equals(parameterName)) return parameter; } } } } else { if (rootType.getIdentifier().equals(fragment)) { return rootType; } if (!fragment.startsWith(rootType.getIdentifier())) { return null; } int rootNameLength = rootType.getIdentifier().length(); char sep = fragment.charAt(rootNameLength); Iterator<String> iter = Splitter.on(sep).split(fragment.substring(rootNameLength+1)).iterator(); JvmDeclaredType current = (JvmDeclaredType) rootType; while (iter.hasNext()) { String segment = iter.next(); Iterator<JvmDeclaredType> members = current.findAllNestedTypesByName(segment).iterator(); if (members.hasNext()) { current = members.next(); } else { throw new UnknownNestedTypeException("Couldn't resolve nested type for "+rootType.getIdentifier()+" and fragment "+fragment); } } return current; } return null; }
Example 18
Source File: JavaResource.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override protected String getTypeName(JvmType type) { return type.getIdentifier(); }