use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class WorkspaceScenariosTest method createProjectWithJarDependency.
protected IProject createProjectWithJarDependency(final Function1<? super String, ? extends Boolean> jarFilter) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package mypack");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.annotations.Data");
_builder.newLine();
_builder.newLine();
_builder.append("@Data class MyData {");
_builder.newLine();
_builder.append("\t");
_builder.append("String someProp");
_builder.newLine();
_builder.append("\t");
_builder.append("int anotherProp");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("mypack/MyData.xtend", _builder.toString());
final byte[] jarData = this.createJar(Collections.<Pair<? extends String, ? extends String>>unmodifiableList(CollectionLiterals.<Pair<? extends String, ? extends String>>newArrayList(_mappedTo)), jarFilter);
final IProject project = WorkbenchTestHelper.createPluginProject("my.project", "org.eclipse.xtext.xbase.lib");
this.addJarToProject(project, jarData);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package pack");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import mypack.MyData");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("class MyClass {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def String myMethod() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("val myData = new MyData(\'foo\', 42)");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("return myData.getSomeProp() + myData.getAnotherProp()");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
IResourcesSetupUtil.createFile("my.project/src/pack/MyClass.xtend", _builder_1.toString());
IResourcesSetupUtil.waitForBuild();
return project;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class WorkspaceScenariosTest method createJar.
public byte[] createJar(final Iterable<? extends Pair<? extends String, ? extends String>> sourceFiles, final Function1<? super String, ? extends Boolean> filter) {
try {
final IProject project = WorkbenchTestHelper.createPluginProject("my.temporary.data.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
final HashMap<String, InputStream> listOfContents = CollectionLiterals.<String, InputStream>newHashMap();
try {
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "src");
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "xtend-gen");
for (final Pair<? extends String, ? extends String> sourceFile : sourceFiles) {
String _key = sourceFile.getKey();
IResourcesSetupUtil.createFile(("my.temporary.data.project/src/" + _key), sourceFile.getValue());
}
IResourcesSetupUtil.waitForBuild();
final IResourceVisitor _function = (IResource it) -> {
if ((it instanceof IFile)) {
final String path = ((IFile) it).getProjectRelativePath().removeFirstSegments(1).toString();
if (((!(filter.apply(path)).booleanValue()) && (!listOfContents.containsKey(path)))) {
listOfContents.put(path, ((IFile) it).getContents());
}
}
return true;
};
final IResourceVisitor visitor = _function;
project.getFolder("src").accept(visitor);
project.getFolder("xtend-gen").accept(visitor);
project.getFolder("bin").accept(visitor);
final Function1<Map.Entry<String, InputStream>, Pair<String, InputStream>> _function_1 = (Map.Entry<String, InputStream> it) -> {
String _key_1 = it.getKey();
InputStream _value = it.getValue();
return Pair.<String, InputStream>of(_key_1, _value);
};
final InputStream jarin = JavaProjectSetupUtil.jarInputStream(((Pair<String, InputStream>[]) Conversions.unwrapArray(IterableExtensions.<Pair<String, InputStream>>toList(IterableExtensions.<Map.Entry<String, InputStream>, Pair<String, InputStream>>map(listOfContents.entrySet(), _function_1)), Pair.class)));
return ByteStreams.toByteArray(jarin);
} finally {
final Consumer<InputStream> _function_2 = (InputStream it) -> {
try {
it.close();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
listOfContents.values().forEach(_function_2);
project.delete(true, true, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class XtendGenerator method compileLocalTypeStubs.
public void compileLocalTypeStubs(final JvmFeature feature, final ITreeAppendable appendable, final GeneratorConfig config) {
final Function1<JvmGenericType, Boolean> _function = (JvmGenericType it) -> {
boolean _isAnonymous = it.isAnonymous();
return Boolean.valueOf((!_isAnonymous));
};
final Consumer<JvmGenericType> _function_1 = (JvmGenericType it) -> {
appendable.newLine();
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
final ITreeAppendable childAppendable = appendable.trace(anonymousClass);
childAppendable.append("abstract class ");
this._treeAppendableUtil.traceSignificant(childAppendable, anonymousClass).append(it.getSimpleName());
boolean _isEmpty = it.getTypeParameters().isEmpty();
if (_isEmpty) {
childAppendable.append(" ");
}
this.generateExtendsClause(it, childAppendable, null);
childAppendable.append("{").increaseIndentation();
boolean _needSyntheticThisVariable = this.needSyntheticThisVariable(anonymousClass, it);
if (_needSyntheticThisVariable) {
Pair<String, JvmGenericType> _mappedTo = Pair.<String, JvmGenericType>of("this", it);
String _simpleName = it.getSimpleName();
String _plus = ("_this" + _simpleName);
final String thisName = childAppendable.declareSyntheticVariable(_mappedTo, _plus);
childAppendable.newLine().append("final ").append(it.getSimpleName()).append(" ").append(thisName).append(" = this;").newLine();
}
final Procedure1<LoopParams> _function_2 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_3 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_3);
};
final Procedure1<JvmMember> _function_3 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(childAppendable, it_1);
memberAppendable.openScope();
if ((it_1 instanceof JvmOperation)) {
final ITreeAppendable tracedAppendable = childAppendable.trace(it_1);
tracedAppendable.newLine();
this.generateJavaDoc(it_1, tracedAppendable, config);
this.generateVisibilityModifier(it_1, tracedAppendable);
tracedAppendable.append("abstract ");
this.generateTypeParameterDeclaration(((JvmTypeParameterDeclarator) it_1), tracedAppendable, null);
JvmTypeReference _returnType = ((JvmOperation) it_1).getReturnType();
boolean _tripleEquals = (_returnType == null);
if (_tripleEquals) {
tracedAppendable.append("void");
} else {
this._errorSafeExtensions.serializeSafely(((JvmOperation) it_1).getReturnType(), "Object", tracedAppendable);
}
tracedAppendable.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(((JvmOperation) it_1).getSimpleName());
tracedAppendable.append("(");
this.generateParameters(((JvmExecutable) it_1), tracedAppendable, null);
tracedAppendable.append(")");
this.generateThrowsClause(((JvmExecutable) it_1), tracedAppendable, null);
tracedAppendable.append(";");
} else {
if ((it_1 instanceof JvmField)) {
final ITreeAppendable tracedAppendable_1 = childAppendable.trace(it_1);
tracedAppendable_1.newLine();
this.generateJavaDoc(it_1, tracedAppendable_1, config);
this.generateAnnotations(((JvmField) it_1).getAnnotations(), tracedAppendable_1, true, config);
boolean _isStatic = ((JvmField) it_1).isStatic();
if (_isStatic) {
tracedAppendable_1.append("static ");
}
if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
tracedAppendable_1.append("final ");
}
boolean _isTransient = ((JvmField) it_1).isTransient();
if (_isTransient) {
tracedAppendable_1.append("transient ");
}
boolean _isVolatile = ((JvmField) it_1).isVolatile();
if (_isVolatile) {
tracedAppendable_1.append("volatile ");
}
this._errorSafeExtensions.serializeSafely(((JvmField) it_1).getType(), "Object", tracedAppendable_1);
tracedAppendable_1.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable_1, it_1).append(((JvmField) it_1).getSimpleName());
if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
Object _constantValue = ((JvmField) it_1).getConstantValue();
boolean _tripleNotEquals = (_constantValue != null);
if (_tripleNotEquals) {
tracedAppendable_1.append(" = ");
this.generateJavaConstant(((JvmField) it_1).getConstantValue(), tracedAppendable_1);
} else {
this.generateInitialization(((JvmField) it_1), tracedAppendable_1, config);
}
}
tracedAppendable_1.append(";");
} else {
this.generateMember(it_1, memberAppendable, config);
}
}
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(childAppendable, this.getAddedDeclarations(it, anonymousClass), _function_2, _function_3);
childAppendable.decreaseIndentation().newLine().append("}");
appendable.newLine();
};
IterableExtensions.<JvmGenericType>filter(feature.getLocalClasses(), _function).forEach(_function_1);
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class XbaseEditorOpenClassFileTest method createJar.
public byte[] createJar(final Pair<? extends String, ? extends String>... sourceFiles) {
try {
final IProject project = WorkbenchTestHelper.createPluginProject("my.temporary.data.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
final HashMap<String, InputStream> listOfContents = CollectionLiterals.<String, InputStream>newHashMap();
try {
final IFolder folder = JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "src");
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "xtend-gen");
for (final Pair<? extends String, ? extends String> sourceFile : sourceFiles) {
IResourcesSetupUtil.createFile(folder.getFullPath().append(sourceFile.getKey()), sourceFile.getValue());
}
IResourcesSetupUtil.waitForBuild();
final IResourceVisitor _function = (IResource it) -> {
if ((it instanceof IFile)) {
final String path = ((IFile) it).getProjectRelativePath().removeFirstSegments(1).toString();
boolean _containsKey = listOfContents.containsKey(path);
boolean _not = (!_containsKey);
if (_not) {
listOfContents.put(path, ((IFile) it).getContents());
}
}
return true;
};
final IResourceVisitor visitor = _function;
project.getFolder("src").accept(visitor);
project.getFolder("xtend-gen").accept(visitor);
project.getFolder("bin").accept(visitor);
final Function1<Map.Entry<String, InputStream>, Pair<String, InputStream>> _function_1 = (Map.Entry<String, InputStream> it) -> {
String _key = it.getKey();
InputStream _value = it.getValue();
return Pair.<String, InputStream>of(_key, _value);
};
final InputStream jarin = JavaProjectSetupUtil.jarInputStream(((Pair<String, InputStream>[]) Conversions.unwrapArray(IterableExtensions.<Pair<String, InputStream>>toList(IterableExtensions.<Map.Entry<String, InputStream>, Pair<String, InputStream>>map(listOfContents.entrySet(), _function_1)), Pair.class)));
return ByteStreams.toByteArray(jarin);
} finally {
final Consumer<InputStream> _function_2 = (InputStream it) -> {
try {
it.close();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
listOfContents.values().forEach(_function_2);
project.delete(true, true, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-eclipse by eclipse.
the class AbstractCallHierarchyViewPart method createLocationViewer.
protected TableViewer createLocationViewer(Composite parent) {
TableViewer locationViewer = new TableViewer(parent);
locationViewer.setContentProvider(new ArrayContentProvider());
locationViewer.setLabelProvider(createLocationLabelProvider());
TableLayout layout = new TableLayout();
locationViewer.getTable().setLayout(layout);
locationViewer.getTable().setHeaderVisible(true);
Pair<String, ColumnLayoutData>[] locationColumnDescriptions = getLocationColumnDescriptions();
IntStream.range(0, locationColumnDescriptions.length).forEach(index -> {
layout.addColumnData(locationColumnDescriptions[index].getValue());
createColumn(locationViewer.getTable(), locationColumnDescriptions[index], index);
});
return locationViewer;
}
Aggregations