Java Code Examples for org.eclipse.xtext.generator.IFileSystemAccess2#isFile()
The following examples show how to use
org.eclipse.xtext.generator.IFileSystemAccess2#isFile() .
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: MyGenerator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void doGenerate(Resource input, IFileSystemAccess fsa) { TreeIterator<EObject> allContents = input.getAllContents(); while (allContents.hasNext()) { EObject next = allContents.next(); if (next instanceof Element) { Element ele = (Element) next; String fileName = ele.getName() + ".txt"; if (fsa instanceof IFileSystemAccess2) { IFileSystemAccess2 fileSystemAccess2 = (IFileSystemAccess2) fsa; if (fileSystemAccess2.isFile(fileName)) { fileSystemAccess2.readTextFile(fileName); } } fsa.generateFile(fileName, "object " + ele.getName()); } } }
Example 2
Source File: PyGenerator.java From sarl with Apache License 2.0 | 6 votes |
/** Generate the Python package files. * * <p>This function generates the "__init__.py" files for all the packages. * * @param name the name of the generated type. * @param lineSeparator the line separator. * @param context the generation context. */ protected void writePackageFiles(QualifiedName name, String lineSeparator, IExtraLanguageGeneratorContext context) { final IFileSystemAccess2 fsa = context.getFileSystemAccess(); final String outputConfiguration = getOutputConfigurationName(); QualifiedName libraryName = null; for (final String segment : name.skipLast(1).getSegments()) { if (libraryName == null) { libraryName = QualifiedName.create(segment, LIBRARY_FILENAME); } else { libraryName = libraryName.append(segment).append(LIBRARY_FILENAME); } final String fileName = toFilename(libraryName); if (!fsa.isFile(fileName)) { final String content = PYTHON_FILE_HEADER + lineSeparator + getGenerationComment(context) + lineSeparator + LIBRARY_CONTENT; if (Strings.isEmpty(outputConfiguration)) { fsa.generateFile(fileName, content); } else { fsa.generateFile(fileName, outputConfiguration, content); } } libraryName = libraryName.skipLast(1); } }
Example 3
Source File: BuilderFactoryFragment.java From sarl with Apache License 2.0 | 5 votes |
@Override public void generateXtendStubs() { super.generateXtendStubs(); final TypeReference stub = getBuilderFactoryImplCustom(); final StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** User-defined builder factory of the " + getLanguageName() //$NON-NLS-1$ + " scripts."); //$NON-NLS-1$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("class "); //$NON-NLS-1$ it.append(stub); it.append(" extends "); //$NON-NLS-1$ it.append(getBuilderFactoryImpl()); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append("}"); //$NON-NLS-1$ it.newLine(); } }; final XtendFileAccess xtendFile = getFileAccessFactory().createXtendFile(stub, content); final IFileSystemAccess2 fileSystem = getSrc(); if (!fileSystem.isFile(xtendFile.getPath())) { xtendFile.writeTo(fileSystem); } }
Example 4
Source File: BuilderFactoryFragment.java From sarl with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("checkstyle:all") public void generateJavaStubs() { super.generateJavaStubs(); final TypeReference stub = getBuilderFactoryImplCustom(); StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** User-defined builder factory of the " + getLanguageName() + " scripts."); //$NON-NLS-1$//$NON-NLS-2$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("public class "); //$NON-NLS-1$ it.append(stub); it.append(" extends "); //$NON-NLS-1$ it.append(getBuilderFactoryImpl()); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append("}"); //$NON-NLS-1$ it.newLine(); } }; JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(stub, content); IFileSystemAccess2 fileSystem = getSrc(); if (!fileSystem.isFile(javaFile.getPath())) { javaFile.writeTo(fileSystem); } }
Example 5
Source File: BuilderFactoryFragment.java From sarl with Apache License 2.0 | 5 votes |
@Override public void generateRuntimeBindings(BindingFactory factory) { super.generateRuntimeBindings(factory); final IFileSystemAccess2 fileSystem = getSrc(); final TypeReference type; if ((fileSystem.isFile(getBuilderFactoryImplCustom().getJavaPath())) || (fileSystem.isFile(getBuilderFactoryImplCustom().getXtendPath()))) { type = getBuilderFactoryImplCustom(); } else { type = getBuilderFactoryImpl(); } factory.addfinalTypeToType(getBuilderFactoryImpl(), type); }
Example 6
Source File: AbstractSubCodeBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
/** Binds the given references according to the standard policy. * * <p>If an custom implementation is defined, it is binded to. Otherwise, the default implementation * is binded. * * @param factory the binding factory to use for creating the bindings. * @param interfaceType the type to bind to an implementation type. * @param implementationType the implementation to bind to the interface type. * @param customImplementationType the custom implementation to bind to the interface type. */ protected void bindTypeReferences(BindingFactory factory, TypeReference interfaceType, TypeReference implementationType, TypeReference customImplementationType) { final IFileSystemAccess2 fileSystem = getSrc(); final TypeReference type; if ((fileSystem.isFile(implementationType.getJavaPath())) || (fileSystem.isFile(customImplementationType.getXtendPath()))) { type = customImplementationType; } else { type = implementationType; } factory.addfinalTypeToType(interfaceType, type); }
Example 7
Source File: ScriptBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
@Override public void generateXtendStubs() { super.generateXtendStubs(); final TypeReference stub = getScriptBuilderImplCustom(); final StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** User-defined builder of the " + getLanguageName() + " scripts."); //$NON-NLS-1$//$NON-NLS-2$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("class "); //$NON-NLS-1$ it.append(stub); it.append(" extends "); //$NON-NLS-1$ it.append(getScriptBuilderImpl()); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append("}"); //$NON-NLS-1$ it.newLine(); } }; final XtendFileAccess xtendFile = getFileAccessFactory().createXtendFile(stub, content); final IFileSystemAccess2 fileSystem = getSrc(); if (!fileSystem.isFile(xtendFile.getPath())) { xtendFile.writeTo(fileSystem); } }
Example 8
Source File: ScriptBuilderFragment.java From sarl with Apache License 2.0 | 5 votes |
@Override public void generateJavaStubs() { super.generateJavaStubs(); final TypeReference stub = getScriptBuilderImplCustom(); final StringConcatenationClient content = new StringConcatenationClient() { @Override protected void appendTo(TargetStringConcatenation it) { it.append("/** User-defined builder of the " + getLanguageName() + " scripts."); //$NON-NLS-1$//$NON-NLS-2$ it.newLine(); it.append(" */"); //$NON-NLS-1$ it.newLine(); it.append("public class "); //$NON-NLS-1$ it.append(stub); it.append(" extends "); //$NON-NLS-1$ it.append(getScriptBuilderImpl()); it.append(" {"); //$NON-NLS-1$ it.newLineIfNotEmpty(); it.newLine(); it.append("}"); //$NON-NLS-1$ it.newLine(); } }; final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(stub, content); final IFileSystemAccess2 fileSystem = getSrc(); if (!fileSystem.isFile(javaFile.getPath())) { javaFile.writeTo(fileSystem); } }