Java源码示例:org.eclipse.xtext.xbase.XConstructorCall

示例1
public JvmDeclaredType getSuperTypeNonResolving(AnonymousClass anonymousClass, IScope typeScope) {
	XConstructorCall constructorCall = anonymousClass.getConstructorCall();
	EObject constructorProxy = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
	IEObjectDescription description = null;
	if (constructorProxy != null) {
		if (!constructorProxy.eIsProxy()) {
			return getSuperType(anonymousClass);
		}
		String fragment = EcoreUtil.getURI(constructorProxy).fragment();
		INode node = uriEncoder.getNode(constructorCall, fragment);
		String name = linkingHelper.getCrossRefNodeAsString(node, true);
		QualifiedName superTypeName = qualifiedNameConverter.toQualifiedName(name);
		description = typeScope.getSingleElement(superTypeName);
	}
	if (description == null || !EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
		description = typeScope.getSingleElement(QualifiedName.create("java", "lang", "Object"));
	}
	if (description != null && EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
		JvmDeclaredType type = (JvmDeclaredType) description.getEObjectOrProxy();
		if (!type.eIsProxy())
			return type;
		return (JvmDeclaredType) EcoreUtil.resolve(type, anonymousClass);
	}
	return null;
}
 
示例2
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
	boolean result = super.isVariableDeclarationRequired(expr, b, recursive);
	if (result && expr instanceof XConstructorCall) {
		EObject container = expr.eContainer();
		if (container instanceof AnonymousClass) {
			AnonymousClass anonymousClass = (AnonymousClass) container;
			result = isVariableDeclarationRequired(anonymousClass, b, recursive);
			if (result) {
				JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
				JvmDeclaredType type = constructor.getDeclaringType();
				if (((JvmGenericType) type).isAnonymous()) {
					return false;
				}
			}
		}
	}
	return result;
}
 
示例3
@Override
public List<IConstructorLinkingCandidate> getLinkingCandidates(XConstructorCall constructorCall) {
	IConstructorLinkingCandidate result = reentrantTypeResolver.getScopeProviderAccess().getKnownConstructor(constructorCall, this, resolvedTypes);
	if(result != null) {
		return Collections.singletonList(result);
	}
	EObject proxyOrResolved = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
	Iterable<IEObjectDescription> descriptions = reentrantTypeResolver.getScopeProviderAccess().getCandidateDescriptions(
			constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, proxyOrResolved, featureScopeSession, resolvedTypes);
	List<IConstructorLinkingCandidate> resultList = Lists.newArrayList();
	for(IEObjectDescription description: descriptions) {
		resultList.add(createCandidate(constructorCall, toIdentifiableDescription(description)));
	}
	if (resultList.isEmpty()) {
		resultList.add(new NullConstructorLinkingCandidate(constructorCall, this));
	}
	return resultList;
}
 
示例4
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referencedElement = super.resolveCrossReferencedElement(node);
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if(referenceOwner instanceof XConstructorCall) {
		if (referenceOwner.eContainer() instanceof AnonymousClass) {
			AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
			JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
			if(superType != null) {
				if (referencedElement instanceof JvmGenericType)  
					return superType;
				else if(referencedElement instanceof JvmConstructor) {
					if(superType.isInterface())
						return superType;
					JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
					if(superConstructor != null)
						return superConstructor;
				}
			}
		}
	}
	return referencedElement;
}
 
示例5
/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject,
		ISynNavigable transition, List<INode> nodes) {

	Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();

	if (nodes == null) {
		if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
			EObject cnt = semanticObject.eContainer();
			if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression)
					&& !(cnt instanceof XForLoopExpression))
				acceptUnassignedKeyword(kw, kw.getValue(), null);
		}
		if (semanticObject instanceof XConstructorCall) {
			XConstructorCall call = (XConstructorCall) semanticObject;
			if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
				acceptUnassignedKeyword(kw, kw.getValue(), null);
			}
		}
	}
	acceptNodes(transition, nodes);
}
 
示例6
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if (referenceOwner != null) {
		EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
				referenceOwner.eClass());
		if (!crossReference.isMany()) {
			EObject resultOrProxy = (EObject) referenceOwner.eGet(crossReference);
			if (resultOrProxy != null && resultOrProxy.eIsProxy() && crossReference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR) {
				if (referenceOwner instanceof XConstructorCall) {
					JvmIdentifiableElement linkedType = batchTypeResolver.resolveTypes(referenceOwner).getLinkedFeature((XConstructorCall)referenceOwner);
					if (linkedType != null)
						return linkedType;
				}
			} 
			return resultOrProxy;
		} else {
			return super.resolveCrossReferencedElement(node);
		}
	}
	return null;
}
 
示例7
protected void _toJavaStatement(final XConstructorCall expr, ITreeAppendable b, final boolean isReferenced) {
	for (XExpression arg : expr.getArguments()) {
		prepareExpression(arg, b);
	}
	
	if (!isReferenced) {
		b.newLine();
		constructorCallToJavaExpression(expr, b);
		b.append(";");
	} else if (isVariableDeclarationRequired(expr, b, true)) {
		Later later = new Later() {
			@Override
			public void exec(ITreeAppendable appendable) {
				constructorCallToJavaExpression(expr, appendable);
			}
		};
		declareFreshLocalVariable(expr, b, later);
	}
}
 
示例8
/** Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
	XtendFile file = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertFalse(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
示例9
protected Object _doEvaluate(XConstructorCall constructorCall, IEvaluationContext context, CancelIndicator indicator) {
	JvmConstructor jvmConstructor = constructorCall.getConstructor();
	List<Object> arguments = evaluateArgumentExpressions(jvmConstructor, constructorCall.getArguments(), context, indicator);
	Constructor<?> constructor = javaReflectAccess.getConstructor(jvmConstructor);
	try {
		if (constructor == null)
			throw new NoSuchMethodException("Could not find constructor " + jvmConstructor.getIdentifier());
		constructor.setAccessible(true);
		Object result = constructor.newInstance(arguments.toArray(new Object[arguments.size()]));
		return result;
	} catch (InvocationTargetException targetException) {
		throw new EvaluationException(targetException.getTargetException());
	} catch (Exception e) {
		throw new IllegalStateException("Could not invoke constructor: " + jvmConstructor.getIdentifier(), e);
	}
}
 
示例10
@Override
protected void highlightConstructorCall(XConstructorCall constructorCall, IHighlightedPositionAcceptor acceptor) {
	if (constructorCall.eContainer() instanceof AnonymousClass) {
		final JvmGenericType superType = anonymousClassUtil.getSuperType((AnonymousClass) constructorCall.eContainer());
		if (superType != null) {
			highlightFeature(acceptor, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, getStyle(superType));
		}
	} else {
		super.highlightConstructorCall(constructorCall, acceptor);
	}
}
 
示例11
protected Keyword getParameterListOpenParenthesis(XExpression call) {
	if (call instanceof XFeatureCall)
		return grammarAccess.getXFeatureCallAccess().findKeywords("(").get(0);
	else if (call instanceof XMemberFeatureCall)
		return grammarAccess.getXMemberFeatureCallAccess().findKeywords("(").get(0);
	else if (call instanceof XConstructorCall)
		return grammarAccess.getXConstructorCallAccess().findKeywords("(").get(0);
	else
		return null;
}
 
示例12
@Check
public void checkReferInvalidTypes(XConstructorCall constructorCall) {
	checkReferInvalidTypes(
			constructorCall.getConstructor(),
			constructorCall,
			XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR);
}
 
示例13
@Override
protected String _signature(XConstructorCall featureCall, boolean typeAtEnd) {
	final JvmIdentifiableElement feature = featureCall.getConstructor();
	if (feature != null) {
		return internalGetSignature(feature, typeAtEnd);
	}
	return ""; //$NON-NLS-1$
}
 
示例14
protected void addReferencesToSuper(final AnonymousClass anonymousClass, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) {
  final XConstructorCall constructorCall = anonymousClass.getConstructorCall();
  final JvmGenericType superType = this._anonymousClassUtil.getSuperType(anonymousClass);
  if (superType!=null) {
    this.addReferenceIfTarget(superType, targetURISet, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, acceptor);
  }
  final JvmConstructor superConstructor = this._anonymousClassUtil.getSuperTypeConstructor(anonymousClass);
  if (superConstructor!=null) {
    this.addReferenceIfTarget(superConstructor, targetURISet, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, acceptor);
  }
}
 
示例15
@Check
public void checkRestrictedType(XConstructorCall constructorCall) {
	if (isRestrictionCheckIgnored())
		return;
	JvmConstructor constructor = constructorCall.getConstructor();
	if (constructor == null)
		return;
	JvmDeclaredType declaringType = constructor.getDeclaringType();
	checkRestrictedType(constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, declaringType);
}
 
示例16
/** Only the simple name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_1() throws Exception {
	XtendFile file1 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n");
	assertNotNull(file1);
	XtendFile file2 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertTrue(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
示例17
@Test public void testOverloadedConstructors_02() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(chars, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.Collection,java.lang.Iterable)", constructor.getIdentifier());
}
 
示例18
protected XExpression getContainerCall(EObject element) {
	if (element == null || element instanceof XClosure)
		return null;
	else if (element instanceof XConstructorCall || element instanceof XFeatureCall
			|| element instanceof XMemberFeatureCall)
		return (XExpression) element;
	else 
		return getContainerCall(element.eContainer());
}
 
示例19
protected IConstructorLinkingCandidate createCandidate(XConstructorCall constructorCall, IIdentifiableElementDescription description) {
	StackedResolvedTypes stackedResolvedTypes = resolvedTypes.pushTypes(constructorCall);
	ExpressionTypeComputationState state = createExpressionComputationState(constructorCall, stackedResolvedTypes);
	if (description instanceof ScopeProviderAccess.ErrorDescription) {
		return new UnresolvableConstructorCall(constructorCall, ((ScopeProviderAccess.ErrorDescription) description).getNode(), description.getName().toString(), state);
	} else if (description.getElementOrProxy() instanceof JvmType) {
		return new TypeInsteadOfConstructorLinkingCandidate(constructorCall, description, state);
	} else {
		return new ConstructorLinkingCandidate(constructorCall, description, getSingleExpectation(state), state);
	}
}
 
示例20
@Override
protected IScope doCreateConstructorCallSerializationScope(XConstructorCall context) {
	if (context.eContainer() instanceof AnonymousClass) {
		final AnonymousClass anonymousClass = (AnonymousClass) context.eContainer(); 
		final JvmType superType = anonymousClassUtil.getSuperType(anonymousClass);
		if(superType != null) {
			return createAnonymousClassConstructorScope(context, superType);
		}
	}
	return super.doCreateConstructorCallSerializationScope(context);
}
 
示例21
protected List<XExpression> getArguments(XExpression call) {
	if (call instanceof XFeatureCall)
		return ((XFeatureCall) call).getFeatureCallArguments();
	else if (call instanceof XMemberFeatureCall)
		return ((XMemberFeatureCall) call).getMemberCallArguments();
	else if (call instanceof XConstructorCall)
		return ((XConstructorCall) call).getArguments();
	else
		return emptyList();
}
 
示例22
@Override
public IConstructorLinkingCandidate getLinkingCandidate(/* @Nullable */ XConstructorCall constructorCall) {
	if (constructorCall == null)
		return null;
	IResolvedTypes delegate = getDelegate(constructorCall);
	return delegate.getLinkingCandidate(constructorCall);
}
 
示例23
protected JvmParameterizedTypeReference createSuperTypeReference(JvmType superType, XConstructorCall constructorCall) {
	JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
	result.setType(superType);
	for(JvmTypeReference typeReference: constructorCall.getTypeArguments()) {
		result.getArguments().add(typesBuilder.cloneWithProxies(typeReference));
	}
	return result;
}
 
示例24
@Override
/* @Nullable */
protected IConstructorLinkingCandidate doGetConstructor(XConstructorCall constructorCall) {
	IConstructorLinkingCandidate result = super.doGetConstructor(constructorCall);
	if (result == null) {
		result = parent.doGetConstructor(constructorCall);
	}
	return result;
}
 
示例25
public ResolvedConstructor(
		XConstructorCall constructorCall,
		JvmConstructor constructor,
		ITypeExpectation expectation, 
		ExpressionTypeComputationState state) {
	super(constructorCall, constructor, expectation, state);
}
 
示例26
@Override
public JvmIdentifiableElement getLinkedFeature(/* @Nullable */ XConstructorCall constructorCall) {
	if (!shared.allLinking.contains(constructorCall)) {
		return null;
	}
	return doGetLinkedFeature(constructorCall);
}
 
示例27
@Override
public IConstructorLinkingCandidate getLinkingCandidate(/* @Nullable */ XConstructorCall constructorCall) {
	if (!shared.allLinking.contains(constructorCall)) {
		return null;
	}
	return (IConstructorLinkingCandidate) doGetCandidate(constructorCall);
}
 
示例28
@Test public void testOverloadedConstructors_03() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(strings, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.util.Collection)", constructor.getIdentifier());
}
 
示例29
@Test public void testOverloadedConstructors_08() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<Object>(chars, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
示例30
public void assertCopyQualifiedName(final EObject featureCall, final String expectedQualifiedName) {
  if (featureCall instanceof XAbstractFeatureCall) {
    _assertCopyQualifiedName((XAbstractFeatureCall)featureCall, expectedQualifiedName);
    return;
  } else if (featureCall instanceof XConstructorCall) {
    _assertCopyQualifiedName((XConstructorCall)featureCall, expectedQualifiedName);
    return;
  } else if (featureCall != null) {
    _assertCopyQualifiedName(featureCall, expectedQualifiedName);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(featureCall, expectedQualifiedName).toString());
  }
}