org.eclipse.xtext.common.types.access.impl.URIHelperConstants Java Examples

The following examples show how to use org.eclipse.xtext.common.types.access.impl.URIHelperConstants. 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: LightweightTypeReference.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @noreference This method is not intended to be referenced by clients.
 */
/* @Nullable */
protected LightweightTypeReference internalFindTopLevelType(Class<?> rawType) {
	try {
		ResourceSet resourceSet = getOwner().getContextResourceSet();
		Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true);
		List<EObject> resourceContents = typeResource.getContents();
		if (resourceContents.isEmpty())
			return null;
		JvmType type = (JvmType) resourceContents.get(0);
		return getOwner().newParameterizedTypeReference(type);
	} catch(WrappedException e) {
		/* no java project / class path context available, e.g. opened from history view */
		return null;
	}
}
 
Example #2
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmType findKnownTopLevelType(Class<?> rawType, Notifier context) {
	if (rawType.isArray()) {
		throw new IllegalArgumentException(rawType.getCanonicalName());
	}
	if (rawType.isPrimitive()) {
		throw new IllegalArgumentException(rawType.getName());
	}
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null) {
		return null;
	}
	Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true);
	List<EObject> resourceContents = typeResource.getContents();
	if (resourceContents.isEmpty())
		return null;
	JvmType type = (JvmType) resourceContents.get(0);
	return type;
}
 
Example #3
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmType findKnownType(Class<?> rawType, Notifier context) {
	if (rawType.isArray()) {
		throw new IllegalArgumentException(rawType.getCanonicalName());
	}
	if (rawType.isPrimitive()) {
		throw new IllegalArgumentException(rawType.getName());
	}		ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null) {
		return null;
	}
	Class<?> declaringClass = rawType.getDeclaringClass();
	if (declaringClass == null) {
		return findKnownTopLevelType(rawType, resourceSet);
	}
	JvmType result = (JvmType) resourceSet.getEObject(URIHelperConstants.OBJECTS_URI.appendSegment(declaringClass.getName()).appendFragment(rawType.getName()), true);
	return result;
}
 
Example #4
Source File: JvmCompoundTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * Returns the value of the 'Type' reference. If there is no type set, 
 * a reference to <code>java.lang.Object</code> is assumed as soon as there is more 
 * than one contained reference.
 * If there is only one contained reference, its type is returned.
 */
@Override
public JvmType getType() {
	if (references != null && !references.isEmpty()) {
		if (references.size() == 1) {
			return references.get(0).getType();
		}
		if (type == null) {
			JvmGenericType objectType = TypesFactory.eINSTANCE.createJvmGenericType();
			String objectClassName = Object.class.getName();
			((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName));
			type = objectType;
		}
	}
	return super.getType();
}
 
Example #5
Source File: TypeResource.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public EObject resolveJavaObjectURIProxy(InternalEObject proxy, EObject sender) {
	final URI proxyURI = proxy.eProxyURI();
       if (proxyURI != null && URIHelperConstants.PROTOCOL.equals(proxyURI.scheme())) {
           if ("Objects".equals(proxyURI.segment(0))) {
			if (indexedJvmTypeAccess != null) {
				try {
					EObject result = indexedJvmTypeAccess.getIndexedJvmType(proxy.eProxyURI(), getResourceSet());
					if (result != null) {
						return result;
					}
				} catch(UnknownNestedTypeException e) {
					return proxy;
				}
			}
			return EcoreUtil.resolve(proxy, sender);
           }
       }
       return null;
}
 
Example #6
Source File: BinaryTypeSignature.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public URI getURI() {
	BinaryTypeSignature typeErasure = getArrayComponentType().getTypeErasure();
	switch(typeErasure.chars.charAt(typeErasure.offset)) {
		case 'B':
		case 'C':
		case 'D':
		case 'F':
		case 'I':
		case 'J':
		case 'S':
		case 'Z':
		case 'V': {
			return URIHelperConstants.PRIMITIVES_URI.appendFragment(toIdentifier());
		}
	}
	String identifier = typeErasure.toIdentifier();
	URI result = URIHelperConstants.OBJECTS_URI.appendSegment(identifier).appendFragment(toIdentifier());
	return result;
}
 
Example #7
Source File: ParameterizedTypeReference.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private LightweightTypeReference findPrimitive(String primitive) {
	JvmType result = (JvmType) getOwner().getContextResourceSet().getEObject(URIHelperConstants.PRIMITIVES_URI.appendFragment(primitive), true);
	if (result != null) {
		return getOwner().newParameterizedTypeReference(result);
	}
	throw new IllegalStateException("Cannot find primitive type: " + primitive);
}
 
Example #8
Source File: JvmTypesAwareDirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void processDelta(IResourceDescription.Delta delta, Resource context, List<Resource> result) {
	super.processDelta(delta, context, result);
	ResourceSet resourceSet = context.getResourceSet();
	if(delta.getNew() != null){
		Iterable<IEObjectDescription> exportedJvmTypes = delta.getNew().getExportedObjectsByType(TypesPackage.Literals.JVM_GENERIC_TYPE);
		for(IEObjectDescription jvmTypeDesc : exportedJvmTypes){
			URI uriToJvmType = URIHelperConstants.OBJECTS_URI.appendSegment(jvmTypeDesc.getQualifiedName().toString());
			Resource jvmResourceInResourceSet = resourceSet.getResource(uriToJvmType, false);
			if(jvmResourceInResourceSet != null)
				result.add(jvmResourceInResourceSet);
		}
	}
}
 
Example #9
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void createResourceURIForClassImpl(String signature, StringBuilder uriBuilder) {
	String topLevel = signature;
	int idx = topLevel.indexOf('$');
	if (idx != -1) {
		topLevel = topLevel.substring(0, idx) + ';';
		if (topLevel.endsWith(".;") || topLevel.endsWith("$;")) {
			topLevel = signature.substring(1, signature.length() - 1);
		} else {
			topLevel = Signature.toString(topLevel);
		}
	} else {
		topLevel = Signature.toString(topLevel);
	}
	uriBuilder.append(URIHelperConstants.OBJECTS).append(topLevel);
}
 
Example #10
Source File: JdtValidationJobScheduler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean isDirty(URI uri) {
	if (uri == null)
		return false;
	if (URIHelperConstants.PROTOCOL.equals(uri.scheme())) {
		String path = uri.path();
		if (URIHelperConstants.PRIMITIVES.equals(path))
			return false;
		String topLevelTypeName = path.substring(URIHelperConstants.OBJECTS.length());
		ICompilationUnit[] workingCopies = JavaCore.getWorkingCopies(null);
		for(ICompilationUnit cu: workingCopies) {
			try {
				if (cu.hasUnsavedChanges()) {
					IType primaryType = cu.findPrimaryType();
					if (primaryType != null) {
						if (topLevelTypeName.equals(primaryType.getFullyQualifiedName())) {
							return true;
						}
					}
				}
			} catch (JavaModelException e) {
				// ignore
			}
		}
	}
	return super.isDirty(uri);
}
 
Example #11
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void queueJavaChange(String typeName) {
	URI typeURI = URIHelperConstants.OBJECTS_URI.appendSegment(typeName);
	QualifiedName qualifiedName = QualifiedName.create(Strings.split(typeName, '.'));
	NameBasedEObjectDescription nameBasedEObjectDescription = new NameBasedEObjectDescription(qualifiedName);
	TypeResourceDescription oldDescription = new TypeResourceDescription(typeURI, Collections.<IEObjectDescription>singletonList(nameBasedEObjectDescription));
	Delta delta = new ChangedResourceDescriptionDelta(oldDescription, null);
	queuedBuildData.queueChange(delta);
}
 
Example #12
Source File: JvmAnyTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * Returns the value of the 'Type' reference. If there is no type set, 
 * a reference to <code>java.lang.Object</code> is assumed.
 */
@Override
public JvmType getType() {
	if (type == null) {
		JvmGenericType objectType = TypesFactory.eINSTANCE.createJvmGenericType();
		String objectClassName = Object.class.getName();
		((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName));
		setType(objectType);
	}
	return super.getType();
}
 
Example #13
Source File: ReflectURIHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void createResourceURIForClass(Class<?> clazz, StringBuilder uriBuilder) {
	if (clazz.isArray()) {
		createResourceURIForClass(clazz.getComponentType(), uriBuilder);
	}
	else if (clazz.isMemberClass()) {
		createResourceURIForClass(clazz.getDeclaringClass(), uriBuilder);
	}
	else if (clazz.isPrimitive()) {
		uriBuilder.append(URIHelperConstants.PRIMITIVES);
	}
	else {
		uriBuilder.append(URIHelperConstants.OBJECTS).append(clazz.getName());
	}
}
 
Example #14
Source File: BinaryObjectTypeSignature.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public URI getURI() {
	BinaryTypeSignature typeErasure = getArrayComponentType().getTypeErasure();
	String identifier = typeErasure.toIdentifier();
	URI result = URIHelperConstants.OBJECTS_URI.appendSegment(identifier).appendFragment(toIdentifier());
	return result;
}
 
Example #15
Source File: WrapperTypeLookup.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private static LightweightTypeReference findTopLevelType(LightweightTypeReference context, String typeName) {
	ITypeReferenceOwner owner = context.getOwner();
	ResourceSet resourceSet = owner.getContextResourceSet();
	Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(typeName), true);
	EList<EObject> contents = typeResource.getContents();
	if (contents.isEmpty()) {
		return null;
	}
	JvmType type = (JvmType) contents.get(0);
	if (type == null)
		return null;
	return owner.newParameterizedTypeReference(type);
}
 
Example #16
Source File: FunctionTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected FunctionTypeReference getAsProcedureOrNull(ParameterizedTypeReference typeReference) {
	ITypeReferenceOwner owner = typeReference.getOwner();
	JvmType type = typeReference.getType();
	FunctionTypeReference functionType = new FunctionTypeReference(owner, type);
	if (!tryAssignTypeArguments(typeReference.getTypeArguments(), functionType))
		return null;
	JvmType voidType = (JvmType) owner.getContextResourceSet().getEObject(URIHelperConstants.PRIMITIVES_URI.appendFragment("void"), true);
	functionType.setReturnType(owner.newParameterizedTypeReference(voidType));
	return functionType;
}
 
Example #17
Source File: JvmTypesBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JvmTypeReference newObjectReference() {
	JvmType objectType = typesFactory.createJvmGenericType();
	String objectClassName = Object.class.getName();
	((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName));
	JvmParameterizedTypeReference result = typesFactory.createJvmParameterizedTypeReference();
	result.setType(objectType);
	return result;
}
 
Example #18
Source File: JavaResource.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IndexedJvmTypeAccess getIndexJvmTypeAccess() {
	if (indexedJvmTypeAccess == null) {
		Object provider = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap()
				.get(URIHelperConstants.PROTOCOL);
		if (provider instanceof AbstractJvmTypeProvider) {
			indexedJvmTypeAccess = ((AbstractJvmTypeProvider) provider).getIndexedJvmTypeAccess();
		}
	}
	return indexedJvmTypeAccess;
}
 
Example #19
Source File: ReflectURIHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public URI createResourceURI(String withoutProtocol) {
	StringBuilder uriBuilder = new StringBuilder(URIHelperConstants.PROTOCOL.length() + 1 + withoutProtocol.length());
	uriBuilder.append(URIHelperConstants.PROTOCOL).append(":").append(withoutProtocol);
	return createURI(uriBuilder);
}
 
Example #20
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void createResourceURIForClassImpl2(String fqn, StringBuilder uriBuilder) {
	uriBuilder.append(URIHelperConstants.OBJECTS).append(fqn);
}
 
Example #21
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void createResourceURIForPrimitive(StringBuilder uriBuilder) {
	uriBuilder.append(URIHelperConstants.PRIMITIVES);
}
 
Example #22
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public StringBuilder createURIBuilder() {
	StringBuilder builder = new StringBuilder(48);
	builder.append(URIHelperConstants.PROTOCOL);
	builder.append(':');
	return builder;
}
 
Example #23
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public URI createResourceURIFromString(String withoutProtocol) {
	StringBuilder uriBuilder = new StringBuilder(URIHelperConstants.PROTOCOL.length() + 1 + withoutProtocol.length());
	uriBuilder.append(URIHelperConstants.PROTOCOL).append(":").append(withoutProtocol);
	return createURI(uriBuilder);
}
 
Example #24
Source File: NullJdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public NullJdtTypeProvider(ResourceSet resourceSet) {
	doLogMessage("Creating NullJdtTypeProvider");
	this.resourceSet = resourceSet;
	resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(URIHelperConstants.PROTOCOL, this);
	typeURIHelper = new TypeURIHelper();
}
 
Example #25
Source File: JdtTypeProviderFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateTypeProvider_03() {
	IJdtTypeProvider typeProvider = factory.createTypeProvider(new ResourceSetImpl());
	ResourceSet resourceSet = typeProvider.getResourceSet();
	Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap();
	assertEquals(typeProvider, map.get(URIHelperConstants.PROTOCOL));
}
 
Example #26
Source File: JdtTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testSetup_01() {
	Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap();
	assertSame(typeProvider, map.get(URIHelperConstants.PROTOCOL));
}
 
Example #27
Source File: TypeResourceDescription.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public TypeResourceDescription(QualifiedName typeName) {
	uri = URIHelperConstants.OBJECTS_URI.appendSegment(typeName.toString("."));
	ClassDescription classDescription = new ClassDescription(
			typeName);
	exportedObjects = Collections.singletonList(classDescription);
}
 
Example #28
Source File: ClasspathTypeProviderFactoryTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateTypeProvider_03() {
	ClasspathTypeProvider typeProvider = factory.createTypeProvider();
	ResourceSet resourceSet = typeProvider.getResourceSet();
	Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap();
	assertEquals(typeProvider, map.get(URIHelperConstants.PROTOCOL));
}
 
Example #29
Source File: ReflectionTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testSetup_01() {
	Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap();
	assertSame(getTypeProvider(), map.get(URIHelperConstants.PROTOCOL));
}
 
Example #30
Source File: AbstractTypeProviderFactory.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IJvmTypeProvider findTypeProvider(ResourceSet resourceSet) {
	if (resourceSet == null)
		throw new IllegalArgumentException("resourceSet may not be null.");
	return (IJvmTypeProvider) resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().get(URIHelperConstants.PROTOCOL);
}