blob: 5878e33beae7149de20546004f231c63f38c889d [file] [log] [blame]
/**
* <copyright>
*
* Copyright (c) 2011, 2012 E.D.Willink and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*
* </copyright>
*
* $Id: ImplicitCollectionFilter.java,v 1.3 2011/04/25 19:39:51 ewillink Exp $
*/
package org.eclipse.ocl.examples.xtext.essentialocl.attributes;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.domain.elements.DomainElement;
import org.eclipse.ocl.examples.pivot.Iteration;
import org.eclipse.ocl.examples.pivot.Operation;
import org.eclipse.ocl.examples.pivot.Parameter;
import org.eclipse.ocl.examples.pivot.ParameterableElement;
import org.eclipse.ocl.examples.pivot.TemplateParameter;
import org.eclipse.ocl.examples.pivot.TemplateSignature;
import org.eclipse.ocl.examples.pivot.Type;
import org.eclipse.ocl.examples.pivot.scoping.EnvironmentView;
import org.eclipse.ocl.examples.pivot.utilities.PivotUtil;
public class ImplicitCollectionFilter extends AbstractOperationFilter
{
public ImplicitCollectionFilter(@NonNull Type sourceType) {
super(sourceType);
}
public boolean matches(@NonNull EnvironmentView environmentView, @NonNull DomainElement eObject) {
if (eObject instanceof Iteration) {
return false;
}
else if (eObject instanceof Operation) {
Operation candidateOperation = (Operation)eObject;
List<Parameter> candidateParameters = candidateOperation.getOwnedParameter();
if (candidateParameters.size() != 0) {
return false;
}
Map<TemplateParameter, ParameterableElement> bindings = PivotUtil.getAllTemplateParameterSubstitutions(null, sourceType);
TemplateSignature templateSignature = candidateOperation.getOwnedTemplateSignature();
if (templateSignature != null) {
for (TemplateParameter templateParameter : templateSignature.getOwnedParameter()) {
if (bindings == null) {
bindings = new HashMap<TemplateParameter, ParameterableElement>();
}
bindings.put(templateParameter, null);
}
}
if (bindings != null) {
installBindings(environmentView, eObject, bindings);
}
return true;
}
else {
return false;
}
}
}