@Override public Boolean caseXConstructorCall(XConstructorCall object) { JvmConstructor constructor = object.getConstructor(); accept(constructor); return Boolean.TRUE; }
protected void highlightConstructorCall(XConstructorCall constructorCall, IHighlightedPositionAcceptor acceptor) { if (constructorCall.getConstructor() != null && !constructorCall.getConstructor().eIsProxy()) { EObject declaringType = constructorCall.getConstructor().getDeclaringType(); if (declaringType instanceof JvmGenericType) { highlightFeature(acceptor, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, getStyle((JvmGenericType) declaringType)); } } }
public IScope createConstructorCallSerializationScope(EObject context) { if (!(context instanceof XConstructorCall)) { return IScope.NULLSCOPE; } XConstructorCall constructorCall = (XConstructorCall) context; JvmConstructor constructor = constructorCall.getConstructor(); if (constructor.eIsProxy()) { return IScope.NULLSCOPE; } return doCreateConstructorCallSerializationScope(constructorCall); }
@Check public void checkReferInvalidTypes(XConstructorCall constructorCall) { checkReferInvalidTypes( constructorCall.getConstructor(), constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR); }
protected void _visit(final XConstructorCall semanticElement, final INode originNode, final ImportsAcceptor acceptor) { this.visit(semanticElement.getConstructor().getDeclaringType(), originNode, acceptor); }
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); } }
/** Generate a constructor call. * * @param expr the call expression. */ public void generate(XConstructorCall expr) { final List<Object> leftOperand = new ArrayList<>(); final List<Object> receiver = new ArrayList<>(); final JvmConstructor feature = expr.getConstructor(); final List<XExpression> args = getActualArguments(expr); final JvmType type = expr.getConstructor().getDeclaringType(); this.codeReceiver.getImportManager().addImportFor(type); internalAppendCall(feature, leftOperand, receiver, type.getSimpleName(), args, null); }
@Check public void checkDeprecated(XConstructorCall expression) { if (!isIgnored(DEPRECATED_MEMBER_REFERENCE)) { JvmConstructor constructor = expression.getConstructor(); checkDeprecated( constructor, expression, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR); } }
protected void appendConstructedTypeName(XConstructorCall constructorCall, ITreeAppendable typeAppendable) { JvmDeclaredType type = constructorCall.getConstructor().getDeclaringType(); if (type instanceof JvmGenericType && ((JvmGenericType) type).isAnonymous()) { typeAppendable.append(Iterables.getLast(type.getSuperTypes()).getType()); } else { typeAppendable.append(constructorCall.getConstructor().getDeclaringType()); } }
public JvmGenericType getSuperType(AnonymousClass anonymousClass) { JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor(); if(constructor != null && ! constructor.eIsProxy()) { JvmDeclaredType declaringType = constructor.getDeclaringType(); JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType(); if(superType instanceof JvmGenericType) return (JvmGenericType) superType; } return null; }
public JvmConstructor getSuperTypeConstructor(AnonymousClass anonymousClass) { JvmGenericType superType = getSuperType(anonymousClass); if(superType != null) { JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor(); for(JvmMember superMember: superType.getMembers()) { if(superMember instanceof JvmConstructor && isSameSignature(constructor, (JvmConstructor) superMember)) return (JvmConstructor) superMember; } } return null; }
@Override public void exec(ITreeAppendable appendable) { constructorCallToJavaExpression(expr, appendable); if (expr.eContainer() instanceof AnonymousClass) { JvmConstructor constructor = expr.getConstructor(); JvmDeclaredType declaringType = constructor.getDeclaringType(); compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, appendable); } } };
protected ArrayList<JvmMember> getAddedDeclarations(final JvmGenericType it, final AnonymousClass anonymousClass) { final ArrayList<JvmMember> result = CollectionLiterals.<JvmMember>newArrayList(); final JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor(); int _size = constructor.getParameters().size(); boolean _greaterEqualsThan = (_size >= 1); if (_greaterEqualsThan) { result.add(0, constructor); } Iterable<JvmField> _declaredFields = it.getDeclaredFields(); Iterables.<JvmMember>addAll(result, _declaredFields); final Function1<JvmOperation, Boolean> _function = (JvmOperation it_1) -> { EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it_1)); final XtendFunction function = ((XtendFunction) _head); boolean _isOverride = function.isOverride(); return Boolean.valueOf((!_isOverride)); }; Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(it.getDeclaredOperations(), _function); Iterables.<JvmMember>addAll(result, _filter); Iterable<JvmDeclaredType> _filter_1 = Iterables.<JvmDeclaredType>filter(it.getMembers(), JvmDeclaredType.class); Iterables.<JvmMember>addAll(result, _filter_1); return result; }
String name = ((XConstructorCall) ex).getConstructor().getSimpleName(); return "_"+Strings.toFirstLower(name);
/** * @return whether the expression itself (not its children) possibly causes a side-effect */ public boolean hasSideEffects(XExpression expr) { if (expr instanceof XClosure || expr instanceof XStringLiteral || expr instanceof XTypeLiteral || expr instanceof XBooleanLiteral || expr instanceof XNumberLiteral || expr instanceof XNullLiteral || expr instanceof XAnnotation ) return false; if(expr instanceof XCollectionLiteral) { for(XExpression element: ((XCollectionLiteral)expr).getElements()) { if(hasSideEffects(element)) return true; } return false; } if (expr instanceof XAbstractFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr; return hasSideEffects(featureCall, true); } if (expr instanceof XConstructorCall) { XConstructorCall constrCall = (XConstructorCall) expr; return findPureAnnotation(constrCall.getConstructor()) == null; } return true; }
protected void _toJavaExpression(AnonymousClass anonymousClass, ITreeAppendable b) { String varName = getReferenceName(anonymousClass, b); if (varName != null) { b.trace(anonymousClass, false).append(varName); } else { XConstructorCall constructorCall = anonymousClass.getConstructorCall(); constructorCallToJavaExpression(constructorCall, b); JvmDeclaredType declaringType = constructorCall.getConstructor().getDeclaringType(); compileAnonymousClassBody(anonymousClass, declaringType, b); } }
@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; }
assert rootGenerator instanceof PyGenerator; final List<JvmTypeReference> types = new ArrayList<>(); for (final JvmTypeReference superType : anonClass.getConstructorCall().getConstructor().getDeclaringType().getSuperTypes()) { if (!Object.class.getCanonicalName().equals(superType.getIdentifier())) { types.add(superType);
protected IConstructorLinkingCandidate getKnownConstructor(XConstructorCall constructorCall, AbstractTypeComputationState state, ResolvedTypes resolvedTypes) { IConstructorLinkingCandidate result = resolvedTypes.getConstructor(constructorCall); if (result != null) { return result; } EObject proxyOrResolved = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false); if (proxyOrResolved == null) { result = new NullConstructorLinkingCandidate(constructorCall, state); return result; } if (!proxyOrResolved.eIsProxy()) { result = state.createResolvedLink(constructorCall, (JvmConstructor) proxyOrResolved); return result; } if (!encoder.isCrossLinkFragment(constructorCall.eResource(), EcoreUtil.getURI(proxyOrResolved).fragment())) { JvmConstructor constructor = constructorCall.getConstructor(); if (!constructor.eIsProxy()) { return state.createResolvedLink(constructorCall, constructor); } } return null; }
constructorCallToJavaExpression(expr, b); if (expr.eContainer() instanceof AnonymousClass) { JvmConstructor constructor = expr.getConstructor(); JvmDeclaredType declaringType = constructor.getDeclaringType(); compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);