/** * @since 2.4 */ protected TreeAppendable createChild(SharedAppendableState state, ILocationInFileProvider locationProvider, IJvmModelAssociations jvmModelAssociations, Set<ILocationData> newData, boolean useForDebugging) { return new TreeAppendable(state, traceURIConverter, locationProvider, jvmModelAssociations, newData, useForDebugging); }
public TreeAppendable appendUnsafe(String string) { accept(string); return this; }
@Override public ITreeAppendable append(CharSequence content) { if (content instanceof ITreeAppendable) { return appendTreeAppendable((ITreeAppendable)content); } closeLastChild(); if (content == null) { appendIndented("null"); log.warn("null was passed to treeappendable", new NullPointerException()); } else { appendIndented(content.toString()); } return this; }
public TreeAppendable trace(EObject object, ILocationInFileProviderExtension.RegionDescription region, boolean useForDebugging) { // TODO use locationProvider from service registry Set<ILocationData> locationData = createAllLocationData(traceURIConverter, locationProvider, jvmModelAssociations, object, region); if (locationData.isEmpty()) return this; return trace(locationData, useForDebugging); }
protected ITreeAppendable appendTreeAppendable(ITreeAppendable other) { closeLastChild(); if (other instanceof TreeAppendable) { ((TreeAppendable) other).markClosed(); } else { // TODO improve throw new IllegalArgumentException("Unexpected implementation"); } children.add(other); return this; }
public CharSequence generateType(final JvmDeclaredType type, final GeneratorConfig config) { final ImportManager importManager = this.createImportManager(type); final TreeAppendable bodyAppendable = this.createAppendable(type, importManager, config); bodyAppendable.openScope(); this.assignThisAndSuper(bodyAppendable, type, config); this.generateBody(type, bodyAppendable, config); bodyAppendable.closeScope(); final TreeAppendable importAppendable = this.createAppendable(type, importManager, config); this.generateFileHeader(type, importAppendable, config); String _packageName = type.getPackageName(); boolean _tripleNotEquals = (_packageName != null); if (_tripleNotEquals) { importAppendable.append("package ").append(type.getPackageName()).append(";"); importAppendable.newLine().newLine(); } List<String> _imports = importManager.getImports(); for (final String i : _imports) { importAppendable.append("import ").append(i).append(";").newLine(); } boolean _isEmpty = importManager.getImports().isEmpty(); boolean _not = (!_isEmpty); if (_not) { importAppendable.newLine(); } importAppendable.append(bodyAppendable); return importAppendable; }
@Override public CharSequence postProcess(URI fileURI, CharSequence content) { if (content instanceof TreeAppendable) { final String lineSeparator = getWhitespaceInformationProvider().getLineSeparatorInformation(fileURI).getLineSeparator(); return ((TreeAppendable) content).acceptVisitor(new TreeAppendable.Visitor() { @Override protected String visit(String string) { return replaceLineSeparators(string, lineSeparator); } }); } else { return super.postProcess(fileURI, content); } }
protected void markClosed() { if (closed) return; closeLastChild(); closed = true; }
final TreeAppendable appendable = new TreeAppendable(importManager, cachingConverter, this.locationProvider, this.jvmModelAssociations, context, " ", "\n"); SharedAppendableState _state = appendable.getState(); _state.setGeneratorConfig(config); return appendable;
/** * @since 2.16 */ protected void appendCompilationTemplate(final ITreeAppendable appendable, final JvmIdentifiableElement it) { boolean _matched = false; if (appendable instanceof TreeAppendable) { _matched=true; SharedAppendableState _state = ((TreeAppendable)appendable).getState(); StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.commonServices, it); final ImportingStringConcatenation target = this.createImportingStringConcatenation(_state, _standardTypeReferenceOwner); target.append(this._jvmTypeExtensions.getCompilationTemplate(it)); ((TreeAppendable)appendable).append(target); } if (!_matched) { String _name = appendable.getClass().getName(); String _plus = ("unexpected appendable: " + _name); throw new IllegalStateException(_plus); } }
protected TreeAppendable(SharedAppendableState state, ITraceURIConverter converter, ILocationInFileProvider locationProvider, IJvmModelAssociations jvmModelAssociations, EObject source) { this( state, converter, locationProvider, jvmModelAssociations, createAllLocationData( converter, locationProvider, jvmModelAssociations, source, ILocationInFileProviderExtension.RegionDescription.INCLUDING_COMMENTS, false), // don't skip empty root regions false); }
protected TreeAppendable trace(Set<ILocationData> newData, boolean useForDebugging) { if (this.useForDebugging == useForDebugging && newData.equals(locationData)) { return this; } TreeAppendable result = createChild(state, locationProvider, jvmModelAssociations, newData, useForDebugging); if(result != this) children.add(result); return result; }
@Override public TreeAppendable append(JvmType type) { if(type.eIsProxy()) { String fragment = ((InternalEObject)type).eProxyURI().fragment(); Triple<EObject, EReference, INode> unresolvedLink = encoder.decode(getState().getResource(), fragment); if(unresolvedLink != null) { INode linkNode = unresolvedLink.getThird(); if(linkNode != null) { append(NodeModelUtils.getTokenText(linkNode)); return this; } } append("unresolved type"); return this; } return super.append(type); }
@Override public CharSequence postProcess(URI fileURI, CharSequence content, /* @Nullable */ Charset targetCharset) { if (targetCharset != null && "java".equalsIgnoreCase(fileURI.fileExtension())) { final String lineSeparator = getWhitespaceInformationProvider().getLineSeparatorInformation(fileURI).getLineSeparator(); final CharsetEncoder encoder = targetCharset.newEncoder(); if (content instanceof TreeAppendable) { return ((TreeAppendable) content).acceptVisitor(new TreeAppendable.Visitor() { @Override protected /* @NonNull */ String visit(/* @NonNull */ String string) { return replaceLineSeparatorsAndEscapeChars(string, lineSeparator, encoder); } }); } else { String result = replaceLineSeparatorsAndEscapeChars(content, lineSeparator, encoder); return result; } } else { return postProcess(fileURI, content); } }
@Override public TreeAppendable increaseIndentation() { closeLastChild(); state.increaseIndentation(); return this; }
private static Set<ILocationData> createAllLocationData(ITraceURIConverter converter, ILocationInFileProvider locationProvider, IJvmModelAssociations jvmModelAssociations, EObject object, ILocationInFileProviderExtension.RegionDescription query) { return createAllLocationData(converter, locationProvider, jvmModelAssociations, object, query, true); }
@Override public ITreeAppendable append(Class<?> type) { closeLastChild(); state.appendType(type, this); return this; }
@Override public TreeAppendable append(JvmType type) { closeLastChild(); state.appendType(type, this); return this; }
@Override public TreeAppendable newLine() { closeLastChild(); state.appendNewLineAndIndentation(this); return this; }
@Override public TreeAppendable decreaseIndentation() { closeLastChild(); state.decreaseIndentation(); return this; }