org.eclipse.emf.codegen.ecore.generator.Generator Java Examples

The following examples show how to use org.eclipse.emf.codegen.ecore.generator.Generator. 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: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
void updateBuildProperties(XpandExecutionContext ctx) throws Exception {
	if (!updateBuildProperties || modelPluginID != null)
		return;
	Outlet rootOutlet = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT);
	Outlet modelOutlet = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.MODEL);
	String buildPropertiesPath = rootOutlet.getPath() + "/build.properties";
	String modelPath = modelOutlet.getPath().substring(rootOutlet.getPath().length() + 1) + "/";
	Properties buildProperties = new Properties();
	Reader reader = new InputStreamReader(new FileInputStream(new File(buildPropertiesPath)), Charset.forName(rootOutlet.getFileEncoding()));
	try {
		String existingContent = CharStreams.toString(reader);
		// for encoding details, see Properties.load
		buildProperties.load(new StringInputStream(existingContent, "ISO-8859-1"));
		String binIncludes = buildProperties.getProperty("bin.includes");
		boolean changed = false;
		if (binIncludes == null) {
			existingContent += "bin.includes = " + modelPath + Strings.newLine()+ "               ";
			changed = true;
		} else if (!binIncludes.contains(modelPath)) {
			existingContent = existingContent.replace("bin.includes = ", "bin.includes = " + modelPath + ",\\" + Strings.newLine() +"               ");
			changed = true;
		}
		if (changed) {
			Writer writer = new OutputStreamWriter(new FileOutputStream(new File(buildPropertiesPath)), Charset.forName(rootOutlet.getFileEncoding()));
			writer.write(existingContent);
			writer.close();
		}
	} finally {
		reader.close();
	}
}
 
Example #2
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getEditDirectory(XpandExecutionContext ctx) {
	if (this.editDirectory == null || "".equals(this.editDirectory)) {
		return ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath()
				+ ".edit/src";
	}
	return editDirectory;
}
 
Example #3
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getEditorDirectory(XpandExecutionContext ctx) {
	if (editorDirectory == null || "".equals(editorDirectory)) {
		return ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath()
				+ ".editor/src";
	}
	return editorDirectory;
}
 
Example #4
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getJavaModelDirectory(XpandExecutionContext ctx) {
	String javaPath;
	if (javaModelDirectory == null || "".equals(javaModelDirectory))
		javaPath = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.SRC_GEN).getPath();
	else
		javaPath = javaModelDirectory;
	return javaPath;
}
 
Example #5
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private List<Object> getParameters(Grammar grammar, XpandExecutionContext ctx) {
	try {
		File projectRootFile = new File(ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.PLUGIN_RT).getPath());
		String projectRoot = projectRootFile.getCanonicalPath();
		URI genmodelURI = getGenModelUri(grammar, ctx);
		if (genmodelURI.toFileString().startsWith(projectRoot)) {
			URI relative = genmodelURI.deresolve(URI.createFileURI(projectRoot).appendSegment(""));
			String genModelPath = relative.toString();
			return Lists.<Object>newArrayList(getBasePackage(grammar), genModelPath);
		}
		throw new ConfigurationException("Invalid configuration of genmodel location: " + genmodelURI + "  and project root: " + projectRoot);
	} catch(IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #6
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getXmiModelDirectory(Grammar grammar, String javaPath, XpandExecutionContext ctx) {
	String xmiPath;
	if (getXmiModelDirectory() == null || "".equals(getXmiModelDirectory())) {
		xmiPath = javaPath + "/"
				+ grammar.getName().substring(0, grammar.getName().lastIndexOf('.')).replace('.', '/');
	} else {
		if (xmiModelDirectorySet)
			xmiPath = getXmiModelDirectory();
		else {
			xmiPath = ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.MODEL).getPath() + getXmiModelDirectory();
		}
	}
	return xmiPath;
}
 
Example #7
Source File: CustomClassEcoreGeneratorFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void generate(final Grammar grammar, final XpandExecutionContext ctx) {
  if (javaModelSrcDirectories.isEmpty()) {
    javaModelSrcDirectories.add(ctx.getOutput().getOutlet(org.eclipse.xtext.generator.Generator.SRC).getPath());
  }
  super.generate(grammar, ctx);
}
 
Example #8
Source File: DataObjectGenerator.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public VirtualFile generate(VirtualFile basedir) throws DatabaseException {
		GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
		genModel.setRuntimeVersion(GenRuntimeVersion.EMF25);
		genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
		genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
		genModel.setRootExtendsClass("org.bimserver.emf.IdEObjectImpl");
		genModel.setRootExtendsInterface("org.bimserver.emf.IdEObject");
		genModel.setSuppressContainment(true);
		genModel.setCodeFormatting(true);
		genModel.setCopyrightText(StringUtils.readFromFile(new File("copyright.txt")));
		genModel.setCanGenerate(true);
		genModel.setModelDirectory("test");
		genModel.setModelName("model name");
		genModel.setForceOverwrite(true);
		genModel.setSuppressNotification(false);
		genModel.setContainmentProxies(false);
		genModel.setBinaryCompatibleReflectiveMethods(false);
		genModel.setPublicConstructors(false);
		genModel.setMinimalReflectiveMethods(true); // More code, but faster
		genModel.setUpdateClasspath(false);

		genModel.initialize(schema.getEPackages());
		
		GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
		Generator generator = new Generator();
		generator.setInput(genModel);
		generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor.Printing(System.out));

		
//		List<GenPackage> genPackages = createGenPackages(genModel, basedir);
//		generatePackages(genModel, genPackages, basedir);

		return basedir;
	}
 
Example #9
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void doGenerate(final GenModel genModel) {
  final Generator generator = new Generator() {
    @Override
    public JControlModel getJControlModel() {
      if ((this.jControlModel == null)) {
        JControlModel _jControlModel = new JControlModel();
        this.jControlModel = _jControlModel;
        this.jControlModel.initialize(null, this.options.mergeRulesURI);
      }
      return this.jControlModel;
    }
  };
  GeneratorAdapterFactory.Descriptor.Registry _adapterFactoryDescriptorRegistry = generator.getAdapterFactoryDescriptorRegistry();
  String _lineDelimiter = this.codeConfig.getLineDelimiter();
  CvsIdFilteringGeneratorAdapterFactoryDescriptor _cvsIdFilteringGeneratorAdapterFactoryDescriptor = new CvsIdFilteringGeneratorAdapterFactoryDescriptor(_lineDelimiter);
  _adapterFactoryDescriptorRegistry.addDescriptor(GenModelPackage.eNS_URI, _cvsIdFilteringGeneratorAdapterFactoryDescriptor);
  genModel.setCanGenerate(true);
  generator.setInput(genModel);
  BasicMonitor _basicMonitor = new BasicMonitor();
  final Diagnostic diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, _basicMonitor);
  int _severity = diagnostic.getSeverity();
  boolean _notEquals = (_severity != Diagnostic.OK);
  if (_notEquals) {
    EMFGeneratorFragment2.LOG.warn(diagnostic);
  }
  if (this.generateEdit) {
    BasicMonitor _basicMonitor_1 = new BasicMonitor();
    final Diagnostic editDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, _basicMonitor_1);
    int _severity_1 = editDiag.getSeverity();
    boolean _notEquals_1 = (_severity_1 != Diagnostic.OK);
    if (_notEquals_1) {
      EMFGeneratorFragment2.LOG.warn(editDiag);
    }
  }
  if (this.generateEditor) {
    BasicMonitor _basicMonitor_2 = new BasicMonitor();
    final Diagnostic editorDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, _basicMonitor_2);
    int _severity_2 = editorDiag.getSeverity();
    boolean _notEquals_2 = (_severity_2 != Diagnostic.OK);
    if (_notEquals_2) {
      EMFGeneratorFragment2.LOG.warn(editorDiag);
    }
  }
}
 
Example #10
Source File: CustomClassEcoreGeneratorFragment.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void doGenerate(final GenModel genModel) {
  if (LOGGER.isInfoEnabled()) {
    LOGGER.info("generating EMF code for " + genModel.eResource().getURI()); //$NON-NLS-1$
  }

  Generator generator = new Generator() {
    @Override
    public JControlModel getJControlModel() {
      return new JControlModel() {
        @Override
        public boolean canMerge() {
          return false;
        }
      };
    }
  };

  genModel.setNonNLSMarkers(generateNonNLSMarkers);

  generator.getAdapterFactoryDescriptorRegistry().addDescriptor(GenModelPackage.eNS_URI, new GeneratorAdapterDescriptor(loggedTypeMappings, getTypeMapper()));
  generator.setInput(genModel);

  Diagnostic diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor());

  if (diagnostic.getSeverity() != Diagnostic.OK) {
    LOGGER.info(diagnostic);
  }

  if (isGenerateEdit()) {
    Diagnostic editDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, new BasicMonitor());
    if (editDiag.getSeverity() != Diagnostic.OK) {
      LOGGER.info(editDiag);
    }
  }

  if (isGenerateEditor()) {
    Diagnostic editorDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, new BasicMonitor());
    if (editorDiag.getSeverity() != Diagnostic.OK) {
      LOGGER.info(editorDiag);
    }
  }
}