org.eclipse.xtext.xbase.typesystem.override.ResolvedConstructor Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.override.ResolvedConstructor. 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: OverrideProposalUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void addConstructorCandidates(ResolvedFeatures resolvedFeatures, IVisibilityHelper visibilityHelper,
		List<IResolvedExecutable> result) {
	LightweightTypeReference typeReference = resolvedFeatures.getType();
	List<LightweightTypeReference> superTypes = typeReference.getSuperTypes();
	for (LightweightTypeReference superType : superTypes) {
		if (!superType.isInterfaceType()) {
			List<IResolvedConstructor> declaredConstructors = resolvedFeatures.getDeclaredConstructors();
			Set<String> erasedSignatures = Sets.<String>newHashSet();
			for (IResolvedConstructor constructor : declaredConstructors) {
				erasedSignatures.add(constructor.getResolvedErasureSignature());
			}
			ResolvedFeatures superClass = overrideHelper.getResolvedFeatures(superType);
			for (IResolvedConstructor superclassConstructor : superClass.getDeclaredConstructors()) {
				IResolvedConstructor overriddenConstructor = new ResolvedConstructor(
						superclassConstructor.getDeclaration(), typeReference);
				if (isCandidate(typeReference, overriddenConstructor, visibilityHelper)) {
					if (erasedSignatures.add(superclassConstructor.getResolvedErasureSignature())) {
						result.add(overriddenConstructor);
					}
				}
			}
			return;
		}
	}
}
 
Example #2
Source File: SuperMemberImplementorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void checkImplementConstructor(final String firstParamType, String implementCode) {
	StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
	
	JvmConstructor constructor = Iterables.find(superClass.getDeclaredConstructors(), new Predicate<JvmConstructor>() {
		@Override
		public boolean apply(JvmConstructor c) {
			if (firstParamType == null)
				return c.getParameters().isEmpty();
			if (c.getParameters().size() >= 1) {
				return firstParamType.equals(c.getParameters().get(0).getParameterType().getSimpleName());
			}
			return false;
		}
	});
	LightweightTypeReference contextType = getContextType();
	ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, contextType);
	implementor.appendConstructorFromSuper(xtendClass, resolvedConstructor, appendable);
	String code = appendable.toString();
	if (!equalsIgnoreWhitespace(implementCode, code))
		assertEquals(implementCode, code);
}
 
Example #3
Source File: ExtendedEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResolvedExecutable getResolvedFeature(JvmExecutable executable, LightweightTypeReference contextType) {
	if (executable instanceof JvmOperation) {
		return new BottomResolvedOperation((JvmOperation) executable, contextType, overrideTester);
	}
	if (executable instanceof JvmConstructor) {
		return new ResolvedConstructor((JvmConstructor) executable, contextType);
	}
	throw new IllegalArgumentException(String.valueOf(executable));
}
 
Example #4
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.MISSING_CONSTRUCTOR)
public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) {
	if (issue.getData() != null) {
		for(int i=0; i<issue.getData().length; i+=2) {
			final URI constructorURI = URI.createURI(issue.getData()[i]);
			String javaSignature = issue.getData()[i+1];
			String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('('));
			acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif",
				new ISemanticModification() {
					@Override
					public void apply(EObject element, IModificationContext context) throws Exception {
						XtendClass clazz = (XtendClass) element;
						JvmGenericType inferredType = associations.getInferredType(clazz);
						ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType);
						ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(),
								insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {{ 
									ensureEmptyLinesAround = true;
									baseIndentationLevel = 1;	
								}});
						EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true);
						if (constructor instanceof JvmConstructor) {
							superMemberImplementor.appendConstructorFromSuper(
									clazz,
									new ResolvedConstructor((JvmConstructor) constructor, features.getType()),
									appendable);
						}
						appendable.commitChanges();
					}
				});
		}
	}
}