| /** |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.strategy.jvmmodel; |
| |
| import com.google.common.base.Objects; |
| import com.google.inject.Inject; |
| import java.util.Arrays; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.osbp.xtext.strategy.FocusingEnhancer; |
| import org.eclipse.osbp.xtext.strategy.FocusingStrategy; |
| import org.eclipse.osbp.xtext.strategy.LayoutingStrategy; |
| import org.eclipse.osbp.xtext.strategy.Strategy; |
| import org.eclipse.osbp.xtext.strategy.StrategyDefault; |
| import org.eclipse.osbp.xtext.strategy.StrategyPackage; |
| import org.eclipse.osbp.xtext.strategy.StrategyTarget; |
| import org.eclipse.osbp.xtext.strategy.jvmmodel.StrategyDSLFocusingEnhancerCreator; |
| import org.eclipse.osbp.xtext.strategy.jvmmodel.StrategyDSLFocusingStrategyCreator; |
| import org.eclipse.osbp.xtext.strategy.jvmmodel.StrategyDSLLayoutingStrategyCreator; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.common.types.JvmDeclaredType; |
| import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer; |
| import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; |
| import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor.IPostIndexingInitializing; |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; |
| import org.eclipse.xtext.xbase.lib.Extension; |
| import org.eclipse.xtext.xbase.lib.InputOutput; |
| |
| /** |
| * <p>Infers a JVM model from the source model.</p> |
| * |
| * <p>The JVM model should contain all elements that would appear in the Java code |
| * which is generated from the source model. Other models link against the JVM model rather than the source model.</p> |
| */ |
| @SuppressWarnings("all") |
| public class StrategyDSLJvmModelInferrer extends AbstractModelInferrer { |
| /** |
| * convenience API to build and initialize JVM types and their members. |
| */ |
| @Inject |
| @Extension |
| private JvmTypesBuilder _jvmTypesBuilder; |
| |
| @Inject |
| @Extension |
| private StrategyDSLLayoutingStrategyCreator _strategyDSLLayoutingStrategyCreator; |
| |
| @Inject |
| @Extension |
| private StrategyDSLFocusingStrategyCreator _strategyDSLFocusingStrategyCreator; |
| |
| @Inject |
| @Extension |
| private StrategyDSLFocusingEnhancerCreator _strategyDSLFocusingEnhancerCreator; |
| |
| /** |
| * The dispatch method {@code infer} is called for each instance of the |
| * given element's type that is contained in a resource. |
| * |
| * @param pckg |
| * the model to create one or more |
| * {@link JvmDeclaredType declared |
| * types} from. |
| * @param acceptor |
| * each created |
| * {@link JvmDeclaredType type} |
| * without a container should be passed to the acceptor in order |
| * get attached to the current resource. The acceptor's |
| * {@link IJvmDeclaredTypeAcceptor#accept(org.eclipse.xtext.common.types.JvmDeclaredType) |
| * accept(..)} method takes the constructed empty type for the |
| * pre-indexing phase. This one is further initialized in the |
| * indexing phase using the closure you pass to the returned |
| * {@link IPostIndexingInitializing#initializeLater(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) |
| * initializeLater(..)}. |
| * @param isPreIndexingPhase |
| * whether the method is called in a pre-indexing phase, i.e. |
| * when the global index is not yet fully updated. You must not |
| * rely on linking using the index if isPreIndexingPhase is |
| * <code>true</code>. |
| */ |
| protected void _infer(final StrategyPackage pckg, final IJvmDeclaredTypeAcceptor acceptor, final boolean isPreIndexingPhase) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("isPreIndexingPhase: "); |
| _builder.append(isPreIndexingPhase, ""); |
| InputOutput.<String>println(_builder.toString()); |
| if ((!isPreIndexingPhase)) { |
| Strategy strategy = pckg.getStrategy(); |
| boolean _notEquals = (!Objects.equal(strategy, null)); |
| if (_notEquals) { |
| StrategyTarget _targets = strategy.getTargets(); |
| EList<LayoutingStrategy> _layoutingStrategies = _targets.getLayoutingStrategies(); |
| for (final LayoutingStrategy layoutingStrategy : _layoutingStrategies) { |
| { |
| this._strategyDSLLayoutingStrategyCreator.createLayoutingStrategy(pckg, layoutingStrategy, acceptor, this._annotationTypesBuilder, |
| this._typeReferenceBuilder); |
| StrategyDefault _strategyDefault = strategy.getStrategyDefault(); |
| LayoutingStrategy _defaultLayouting = _strategyDefault.getDefaultLayouting(); |
| boolean _equals = layoutingStrategy.equals(_defaultLayouting); |
| if (_equals) { |
| this._strategyDSLLayoutingStrategyCreator.createLayoutingStrategy(pckg, layoutingStrategy, acceptor, this._annotationTypesBuilder, |
| this._typeReferenceBuilder, true); |
| } |
| } |
| } |
| StrategyTarget _targets_1 = strategy.getTargets(); |
| EList<FocusingStrategy> _focusingStrategies = _targets_1.getFocusingStrategies(); |
| for (final FocusingStrategy focusingStrategy : _focusingStrategies) { |
| this._strategyDSLFocusingStrategyCreator.createFocusingStrategy(pckg, focusingStrategy, acceptor, this._annotationTypesBuilder, |
| this._typeReferenceBuilder); |
| } |
| StrategyTarget _targets_2 = strategy.getTargets(); |
| EList<FocusingEnhancer> _focusingEnhancer = _targets_2.getFocusingEnhancer(); |
| for (final FocusingEnhancer focusingEnhancer : _focusingEnhancer) { |
| { |
| this._strategyDSLFocusingEnhancerCreator.createFocusingEnhancer(pckg, focusingEnhancer, acceptor, this._annotationTypesBuilder, |
| this._typeReferenceBuilder); |
| StrategyDefault _strategyDefault = strategy.getStrategyDefault(); |
| FocusingEnhancer _defaultFocusing = _strategyDefault.getDefaultFocusing(); |
| boolean _equals = focusingEnhancer.equals(_defaultFocusing); |
| if (_equals) { |
| this._strategyDSLFocusingEnhancerCreator.createFocusingEnhancer(pckg, focusingEnhancer, acceptor, this._annotationTypesBuilder, |
| this._typeReferenceBuilder, true); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| public void infer(final EObject pckg, final IJvmDeclaredTypeAcceptor acceptor, final boolean isPreIndexingPhase) { |
| if (pckg instanceof StrategyPackage) { |
| _infer((StrategyPackage)pckg, acceptor, isPreIndexingPhase); |
| return; |
| } else if (pckg != null) { |
| _infer(pckg, acceptor, isPreIndexingPhase); |
| return; |
| } else { |
| throw new IllegalArgumentException("Unhandled parameter types: " + |
| Arrays.<Object>asList(pckg, acceptor, isPreIndexingPhase).toString()); |
| } |
| } |
| } |