Search in sources :

Example 11 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method testGetResource_02.

@Test
public void testGetResource_02() {
    URI primitivesURI = URI.createURI("java:/Primitives");
    TypeResource resource = (TypeResource) resourceSet.getResource(primitivesURI, false);
    assertNull(resource);
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 12 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProvider method createResourceAndFindType.

/* @Nullable */
private JvmType createResourceAndFindType(/* @NonNull */
URI resourceURI, /* @NonNull */
IType type, /* @NonNull */
String signature, boolean traverseNestedTypes) throws IOException {
    TypeResource resource = createResource(resourceURI, type);
    resource.load(Collections.singletonMap(TypeResource.OPTION_CLASSPATH_CONTEXT, javaProject));
    return findTypeBySignature(signature, resource, traverseNestedTypes);
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource)

Example 13 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-eclipse by eclipse.

the class JdtTypeProvider method createResource.

private TypeResource createResource(URI resourceURI, IType type) {
    TypeResource resource = doCreateResource(resourceURI);
    getResourceSet().getResources().add(resource);
    if (type.exists()) {
        IMirror mirror = createMirror(type);
        resource.setMirror(mirror);
    }
    return resource;
}
Also used : IMirror(org.eclipse.xtext.common.types.access.IMirror) TypeResource(org.eclipse.xtext.common.types.access.TypeResource)

Example 14 with TypeResource

use of org.eclipse.xtext.common.types.access.TypeResource in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method evaluateField.

protected Object evaluateField(final XAbstractFeatureCall call, final JvmField field, final Context context) {
    if ((field.isSetConstant() || (field.eResource() instanceof TypeResource))) {
        boolean _isConstant = field.isConstant();
        if (_isConstant) {
            return field.getConstantValue();
        } else {
            String _simpleName = field.getDeclaringType().getSimpleName();
            String _plus = ("Field " + _simpleName);
            String _plus_1 = (_plus + ".");
            String _simpleName_1 = field.getSimpleName();
            String _plus_2 = (_plus_1 + _simpleName_1);
            String _plus_3 = (_plus_2 + " is not a constant");
            throw new ConstantExpressionEvaluationException(_plus_3);
        }
    }
    final XExpression expression = this.containerProvider.getAssociatedExpression(field);
    boolean _contains = context.getAlreadyEvaluating().contains(expression);
    if (_contains) {
        throw new ConstantExpressionEvaluationException("Endless recursive evaluation detected.");
    }
    try {
        final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
        JvmTypeReference _type = field.getType();
        ClassFinder _classFinder = context.getClassFinder();
        Set<XExpression> _alreadyEvaluating = context.getAlreadyEvaluating();
        final Context ctx = new Context(_type, _classFinder, visibleFeatures, _alreadyEvaluating);
        return this.evaluate(expression, ctx);
    } catch (final Throwable _t) {
        if (_t instanceof ConstantExpressionEvaluationException) {
            final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
            throw new StackedConstantExpressionEvaluationException(call, field, e);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : Context(org.eclipse.xtext.xbase.interpreter.Context) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ClassFinder(org.eclipse.xtext.common.types.access.impl.ClassFinder) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

TypeResource (org.eclipse.xtext.common.types.access.TypeResource)14 URI (org.eclipse.emf.common.util.URI)8 Test (org.junit.Test)6 Resource (org.eclipse.emf.ecore.resource.Resource)3 IResource (org.eclipse.core.resources.IResource)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 IMirror (org.eclipse.xtext.common.types.access.IMirror)2 ArrayDeque (java.util.ArrayDeque)1 IStorage (org.eclipse.core.resources.IStorage)1 EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IMember (org.eclipse.jdt.core.IMember)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 NamedElement (org.eclipse.n4js.n4JS.NamedElement)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1 ICrossEReferenceAndEObject (org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject)1