protected IScope getThisOrSuperScope(XAbstractFeatureCall call, JvmConstructor constructor) { QualifiedName name = THIS; JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(call); if (logicalContainer instanceof JvmConstructor) { JvmDeclaredType thisType = ((JvmConstructor) logicalContainer).getDeclaringType(); if (thisType != constructor.getDeclaringType()) { name = SUPER; } } return new SingletonScope(EObjectDescription.create(name, constructor), IScope.NULLSCOPE); }
/** * @return the {@link Constructor} corresponding to the given {@link JvmConstructor} or <code>null</code>. */ public Constructor<?> getConstructor(JvmConstructor constructor) { Class<?> declaringType = getRawType(constructor.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(constructor); try { return declaringType.getDeclaredConstructor(paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
/** * @return the {@link Constructor} corresponding to the given {@link JvmConstructor} or <code>null</code>. */ public Constructor<?> getConstructor(JvmConstructor constructor) { Class<?> declaringType = getRawType(constructor.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(constructor); try { return declaringType.getDeclaredConstructor(paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
public List<JvmTypeParameter> getDeclaredTypeParameters(JvmConstructor constructor) { List<JvmTypeParameter> constructorTypeParameters = constructor.getTypeParameters(); if (constructorTypeParameters.isEmpty()) { JvmDeclaredType createdType = constructor.getDeclaringType(); if (createdType instanceof JvmTypeParameterDeclarator) { return ((JvmTypeParameterDeclarator) createdType).getTypeParameters(); } } else { JvmDeclaredType createdType = constructor.getDeclaringType(); if (createdType instanceof JvmTypeParameterDeclarator) { List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) createdType).getTypeParameters(); if (typeParameters.isEmpty()) { return constructorTypeParameters; } List<JvmTypeParameter> result = Lists.newArrayList(constructorTypeParameters); result.addAll(typeParameters); return result; } return constructorTypeParameters; } return Collections.emptyList(); }
@Override public Iterable<IEObjectDescription> getElements(EObject object) { if (!(object instanceof JvmConstructor)) { return Collections.emptyList(); } JvmConstructor constructor = (JvmConstructor) object; Iterable<IEObjectDescription> typeDescriptions = typeScope.getElements(constructor.getDeclaringType()); List<IEObjectDescription> result = Lists.newArrayListWithCapacity(3); boolean visible = visibilityHelper.isVisible(constructor); for(IEObjectDescription typeDescription: typeDescriptions) { ConstructorDescription constructorDescription = createConstructorDescription(typeDescription, constructor, visible); result.add(constructorDescription); } return result; }
protected void _visit(final XConstructorCall semanticElement, final INode originNode, final ImportsAcceptor acceptor) { this.visit(semanticElement.getConstructor().getDeclaringType(), originNode, acceptor); }
public void completeJvmConstructor(JvmConstructor constructor) { JvmDeclaredType declaringType = constructor.getDeclaringType(); if(declaringType != null) { String simpleName = declaringType.getSimpleName(); if(simpleName != null) { constructor.setSimpleName(simpleName); return; } } constructor.setSimpleName("unset"); }
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()); } }
@Override protected boolean isBoundTypeArgumentSkipped(JvmTypeParameter type, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, ITypeReferenceOwner owner) { if (super.isBoundTypeArgumentSkipped(type, mapping, owner)) { if (getConstructor().getDeclaringType() != type.getDeclarator()) { return true; } } return false; }
public boolean isSingleSyntheticDefaultConstructor(final JvmConstructor it) { return ((((it.getParameters().isEmpty() && (this._iLogicalContainerProvider.getAssociatedExpression(it) == null)) && (this.getCompilationStrategy(it) == null)) && (this.getCompilationTemplate(it) == null)) && (IterableExtensions.size(Iterables.<JvmConstructor>filter(it.getDeclaringType().getMembers(), JvmConstructor.class)) == 1)); }
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; }
@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); } } };
@SuppressWarnings("unused") protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmConstructor constructor, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) { StackedResolvedTypes childResolvedTypes = declareTypeParameters(resolvedTypes, constructor, resolvedTypesByContext); JvmDeclaredType producedType = constructor.getDeclaringType(); LightweightTypeReference lightweightReference = childResolvedTypes.getReferenceOwner().toLightweightTypeReference(producedType); childResolvedTypes.setType(constructor, lightweightReference); }
/** 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); }
@Override protected List<JvmTypeParameter> getDeclaredTypeParameters() { if (isAnonymousClassConstructorCall()) { JvmDeclaredType anonymousType = getConstructor().getDeclaringType(); JvmTypeReference superType = Iterables.getLast(anonymousType.getSuperTypes()); JvmType rawSuperType = superType.getType(); if (rawSuperType instanceof JvmTypeParameterDeclarator) { return ((JvmTypeParameterDeclarator) rawSuperType).getTypeParameters(); } return Collections.emptyList(); } return new FeatureLinkHelper().getDeclaredTypeParameters(getConstructor()); } }
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)); } } }
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); } }
protected JvmTypeReference getDeclaredType(JvmIdentifiableElement identifiable) { if (identifiable instanceof JvmOperation) { return ((JvmOperation) identifiable).getReturnType(); } if (identifiable instanceof JvmField) { return ((JvmField) identifiable).getType(); } if (identifiable instanceof JvmConstructor) { return shared.resolver.getServices().getTypeReferences().createTypeRef(((JvmConstructor) identifiable).getDeclaringType()); } if (identifiable instanceof JvmFormalParameter) { JvmTypeReference parameterType = ((JvmFormalParameter) identifiable).getParameterType(); return parameterType; } return null; }
@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; }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmDeclaredType declaringType = getConstructor().getDeclaringType(); if (declaringType.isAbstract()) { String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.ABSTRACT_CLASS_INSTANTIATION, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return super.validate(result); }