Java源码示例:org.eclipse.xtend2.lib.StringConcatenationClient
示例1
@Test
public void testSeparatorLoopWithWhitespace2() {
final List<String> strings = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("a", "b", "c"));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
boolean _hasElements = false;
for(final String s : strings) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",", "");
}
_builder.append(s);
_builder.append(" ");
_builder.append(s);
_builder.newLineIfNotEmpty();
}
}
}
};
this.assertEquals(_client);
}
示例2
public void generateProjectInfo() {
final TypeReference projectInfoClass = TypeReference.typeRef(this.getProjectInfoClassName());
final JavaFileAccess file = this.fileAccessFactory.createJavaFile(projectInfoClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = projectInfoClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.wizard.DefaultProjectInfo");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
示例3
public void createStateProposal(ContentAssistContext context, IIdeContentProposalAcceptor acceptor) {
StringConcatenationClient template = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation target) {
target.append("state ");
target.append(variable("name"));
target.newLineIfNotEmpty();
target.append("\t");
target.append(cursor(), "\t");
target.newLineIfNotEmpty();
target.append("end");
target.newLine();
}
};
acceptProposal("state", "Create a new state", template, context, acceptor);
}
示例4
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
super.doTransform(annotatedClass, context);
Type _findTypeGlobally = context.findTypeGlobally("de.test.Test");
final MutableInterfaceDeclaration ifType = ((MutableInterfaceDeclaration) _findTypeGlobally);
final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("System.out.println(\"Hello World\");");
}
};
it.setBody(_client);
it.setDefault(true);
};
ifType.addMethod("sayHello", _function);
}
示例5
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
super.doTransform(annotatedClass, context);
Type _findTypeGlobally = context.findTypeGlobally(this.generatedAnnotationName(annotatedClass));
final MutableAnnotationTypeDeclaration annotationType = ((MutableAnnotationTypeDeclaration) _findTypeGlobally);
final Procedure1<MutableAnnotationTypeElementDeclaration> _function = (MutableAnnotationTypeElementDeclaration it) -> {
it.setDocComment("Best building strategy game ever");
it.setType(context.newTypeReference(Integer.TYPE));
boolean _booleanValue = annotatedClass.findAnnotation(context.findTypeGlobally(ToAnno.class)).getBooleanValue("defaultValue");
if (_booleanValue) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("1602");
}
};
it.setDefaultValueExpression(_client);
}
};
annotationType.addAnnotationTypeElement("anno", _function);
}
示例6
private EObject getNearestClosureOrTypeDeclaration(EObject object, IResolvedTypes resolvedTypes) {
EObject candidate = object;
while(candidate != null) {
if (candidate instanceof XClosure) {
return candidate;
}
if (candidate instanceof XConstructorCall) {
// skip anonymous class constructors themselves
if (candidate.eContainingFeature() == XtendPackage.Literals.ANONYMOUS_CLASS__CONSTRUCTOR_CALL) {
candidate = candidate.eContainer();
}
} else if (candidate instanceof XtendTypeDeclaration) {
return candidate;
}
if (candidate instanceof RichString) {
LightweightTypeReference type = resolvedTypes.getActualType((RichString)candidate);
if (type != null && type.isType(StringConcatenationClient.class)) {
return candidate;
}
}
candidate = candidate.eContainer();
}
return null;
}
示例7
private StringConcatenationClient genParameterSelector(final EObject obj, final Set<ISerializationContext> contexts, final IGrammarConstraintProvider.IConstraint constraint) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(" ");
_builder.append("&& (");
{
boolean _hasElements = false;
for(final ISerializationContext context : contexts) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n\t\t\t|| ", " ");
}
StringConcatenationClient _genParameterCondition = SerializerFragment2.this.genParameterCondition(context, constraint);
_builder.append(_genParameterCondition, " ");
}
}
_builder.append(")");
}
};
return _client;
}
示例8
@Test
public void testIndentedIf() {
final boolean condition = true;
final String string = "foo";
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("Very wise:");
_builder.newLine();
{
if (condition) {
_builder.append("\t");
_builder.append("who ");
_builder.append(string, "\t");
_builder.append(" do");
_builder.newLineIfNotEmpty();
}
}
}
};
this.assertEquals(_client);
}
示例9
public void generateGenQuickfixProvider() {
final TypeReference genClass = this.getQuickfixProviderClass(this.getGrammar());
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _quickfixProviderSuperClass = QuickfixProviderFragment2.this.getQuickfixProviderSuperClass(QuickfixProviderFragment2.this.getGrammar());
_builder.append(_quickfixProviderSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
}
示例10
private StringConcatenationClient someCodeGen(final int n) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, n, true);
for(final Integer i : _doubleDotLessThan) {
_builder.append("before ");
CompositeGeneratorNode _append = GeneratorNodeTest.this.exts.append(GeneratorNodeTest.this.exts.trace(GeneratorNodeTest.this.loc((10 + (i).intValue()))), "Hello");
_builder.append(_append);
_builder.append(" after");
_builder.newLineIfNotEmpty();
_builder.append(" ");
StringConcatenationClient _someCodeGen = GeneratorNodeTest.this.someCodeGen((n - 1));
_builder.append(_someCodeGen, " ");
_builder.newLineIfNotEmpty();
}
}
}
};
return _client;
}
示例11
public StringConcatenationClient __generatePropertyWithDebugging(final Property it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("Property ");
IGeneratorNode __name = TracingSugarTest.this._myExtensions._name(it, true);
_builder.append(__name);
_builder.append(" : ");
final Function1<Type, String> _function = (Type it_1) -> {
return it_1.getName();
};
IGeneratorNode __type = TracingSugarTest.this._myExtensions._type(it, _function);
_builder.append(__type);
_builder.newLineIfNotEmpty();
}
};
return _client;
}
示例12
protected ContentAssistEntry createProposal(StringConcatenationClient template, ContentAssistContext context,
boolean adaptIndentation) {
ContentAssistEntry entry = new ContentAssistEntry();
entry.setPrefix(context.getPrefix());
TemplateStringConcatenation stringConcat = new TemplateStringConcatenation(context, entry, getLineDelimiter());
String indentation = null;
if (adaptIndentation) {
indentation = getIndentation(context);
}
if (indentation == null) {
stringConcat.append(template);
} else {
stringConcat.append(template, indentation);
}
entry.setProposal(stringConcat.toString());
return entry;
}
示例13
protected void generateServices() {
if (((this.projectConfig.getGenericIde().getSrcGen() == null) || this.languageConfigs.isEmpty())) {
return;
}
final TextFileAccess file = new TextFileAccess();
file.setPath("META-INF/services/org.eclipse.xtext.ISetup");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
for(final XtextGeneratorLanguage lang : XtextGenerator.this.languageConfigs) {
TypeReference _genericIdeSetup = XtextGenerator.this.naming.getGenericIdeSetup(lang.getGrammar());
_builder.append(_genericIdeSetup);
_builder.newLineIfNotEmpty();
}
}
}
};
file.setContent(_client);
file.writeTo(this.projectConfig.getGenericIde().getSrcGen());
}
示例14
@Test
public void testSeparatorLoopWithWhitespace3() {
final List<String> strings = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("a", "b", "c"));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
boolean _hasElements = false;
for(final String s : strings) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",", "");
}
_builder.newLine();
_builder.append(s);
_builder.append(" ");
_builder.newLineIfNotEmpty();
_builder.newLine();
}
}
}
};
this.assertEquals(_client);
}
示例15
protected StringConcatenationClient _cache(final ParserRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("private final ");
String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
_builder.append(_gaRuleAccessorClassName);
_builder.append(" ");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
示例16
protected StringConcatenationClient _initializer(final TerminalRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("this.");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName);
_builder.append(" = (");
_builder.append(TerminalRule.class);
_builder.append(") ");
_builder.append(GrammarUtil.class);
_builder.append(".findRuleForName(getGrammar(), \"");
String _qualifiedName = GrammarAccessFragment2.this.getQualifiedName(it);
_builder.append(_qualifiedName);
_builder.append("\");");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
示例17
public void generateWizardNewProjectCreationPage() {
final TypeReference mainPageClass = TypeReference.typeRef(this.getProjectWizardCreationPageClassName());
final JavaFileAccess file = this.fileAccessFactory.createJavaFile(mainPageClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = mainPageClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.dialogs.WizardNewProjectCreationPage");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = mainPageClass.getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(String pageName) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(pageName);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
示例18
protected StringConcatenationClient initializer(final AbstractRule it) {
if (it instanceof EnumRule) {
return _initializer((EnumRule)it);
} else if (it instanceof ParserRule) {
return _initializer((ParserRule)it);
} else if (it instanceof TerminalRule) {
return _initializer((TerminalRule)it);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(it).toString());
}
}
示例19
protected void generateXtendScopeProvider() {
TypeReference _scopeProviderClass = this.getScopeProviderClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* This class contains custom scoping description.");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
_builder.newLine();
_builder.append(" ");
_builder.append("* on how and when to use it.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("class ");
String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
_builder.append(_abstractScopeProviderClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createXtendFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
示例20
private void generateStandaloneSetup(final LanguageConfig config1, final XpandExecutionContext ctx) {
ctx.getOutput().openFile(null, StringConcatOutputImpl.STRING_OUTLET);
try {
final IXtextGeneratorLanguage config2 = this.getLanguage();
if ((this.fragment instanceof IGeneratorFragmentExtension2)) {
((IGeneratorFragmentExtension2)this.fragment).addToStandaloneSetup(config1, ctx);
} else {
this.fragment.addToStandaloneSetup(config1.getGrammar(), ctx);
}
Output _output = ctx.getOutput();
final StringConcatenation result = ((StringConcatOutputImpl) _output).getStringOutlet();
List<StringConcatenationClient> _registrations = config2.getRuntimeGenSetup().getRegistrations();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
StringBuilder _decreaseIndentation = FragmentAdapter.this.decreaseIndentation(result.toString(), 2);
_builder.append(_decreaseIndentation);
}
};
_registrations.add(_client);
Set<TypeReference> _imports = config2.getRuntimeGenSetup().getImports();
TypeReference _typeReference = new TypeReference("org.eclipse.emf.ecore.EPackage");
_imports.add(_typeReference);
Set<TypeReference> _imports_1 = config2.getRuntimeGenSetup().getImports();
TypeReference _typeReference_1 = new TypeReference("org.eclipse.emf.ecore.resource.Resource");
_imports_1.add(_typeReference_1);
} finally {
ctx.getOutput().closeFile();
}
}
示例21
@Test
public void testAppendStringConcatClientNull() {
final StringConcatenation c = new StringConcatenation();
c.append((StringConcatenationClient)null);
c.append((StringConcatenationClient)null, "");
c.append((StringConcatenationClient)null, " ");
assertEquals("", c.toString());
}
示例22
protected MutableMethodDeclaration generateFactory(final MutableClassDeclaration factory, final MutableClassDeclaration impl, final TypeReference targetType, @Extension final TransformationContext context) {
MutableMethodDeclaration _xblockexpression = null;
{
TypeReference _newTypeReference = context.newTypeReference("com.google.gson.TypeAdapterFactory");
factory.setImplementedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference)));
final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
final MutableTypeParameterDeclaration t = it.addTypeParameter("T");
it.addParameter("gson", context.newTypeReference("com.google.gson.Gson"));
it.addParameter("typeToken", context.newTypeReference("com.google.gson.reflect.TypeToken", context.newTypeReference(t)));
it.setReturnType(context.newTypeReference("com.google.gson.TypeAdapter", context.newTypeReference(t)));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("if (!");
_builder.append(targetType);
_builder.append(".class.isAssignableFrom(typeToken.getRawType())) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return null;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("return (TypeAdapter<T>) new ");
_builder.append(impl);
_builder.append("(gson);");
_builder.newLineIfNotEmpty();
}
};
it.setBody(_client);
};
_xblockexpression = factory.addMethod("create", _function);
}
return _xblockexpression;
}
示例23
@Override
public void setConstantValueAsBoolean(final boolean value) {
this.internalGenericSetConstantValue(Boolean.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(value);
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例24
@Override
public void generate() {
boolean _isGenerateStub = this.isGenerateStub();
boolean _not = (!_isGenerateStub);
if (_not) {
return;
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IPreferenceValuesProvider.class);
_builder.append(".class).annotatedWith(");
_builder.append(FormatterPreferences.class);
_builder.append(".class).to(");
_builder.append(FormatterPreferenceValuesProvider.class);
_builder.append(".class);");
}
};
final StringConcatenationClient statement = _client;
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"),
TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage + ".formatting2");
_exportedPackages.add(_plus);
}
this.doGenerateStubFile();
}
示例25
@Override
public void setConstantValueAsInt(final int value) {
this.internalGenericSetConstantValue(Integer.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(value);
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例26
@Override
public void setConstantValueAsShort(final short value) {
this.internalGenericSetConstantValue(Short.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(value);
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例27
@Override
public void setConstantValueAsLong(final long value) {
this.internalGenericSetConstantValue(Long.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(value);
_builder.append("L");
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例28
@Override
public void setConstantValueAsDouble(final double value) {
this.internalGenericSetConstantValue(Double.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(value);
_builder.append("d");
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例29
@Override
public void setConstantValueAsChar(final char value) {
this.internalGenericSetConstantValue(Character.valueOf(value));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("\'");
String _convertToJavaString = Strings.convertToJavaString(Character.toString(value));
_builder.append(_convertToJavaString);
_builder.append("\'");
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
示例30
@Override
public void setConstantValueAsString(final String value) {
this.internalGenericSetConstantValue(value);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("\"");
String _convertToJavaString = Strings.convertToJavaString(value);
_builder.append(_convertToJavaString);
_builder.append("\"");
}
};
this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}