org.eclipse.xtext.xbase.lib.Procedures.Procedure2 Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.lib.Procedures.Procedure2.
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: ExtraLanguagePreferenceAccess.java From sarl with Apache License 2.0 | 6 votes |
/** Parse the given input which is the preference string representation. * * @param input the string representation from the preferences. * @param output the function to call for saving the parsed element. The first parameter is the element to be * converted. The second parameter is the target string. * @return {@code true} if a data was parsed. {@code false} if no value was parsed. */ public static boolean parseConverterPreferenceValue(String input, Procedure2<? super String, ? super String> output) { final StringTokenizer tokenizer = new StringTokenizer(input, PREFERENCE_SEPARATOR); String key = null; boolean foundValue = false; while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken(); if (key != null) { output.apply(key, token); foundValue = true; key = null; } else { key = token; } } return foundValue; }
Example #2
Source File: DefaultCallHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void findSourceDeclarations(URI targetDeclarationURI, IProgressMonitor monitor, Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) { TargetURIs targetURIs = collectTargetURIs(targetDeclarationURI); ReferenceAcceptor referenceAcceptor = new ReferenceAcceptor(getResourceServiceProviderRegistry(), reference -> { if (filterReference(reference)) { IEObjectDescription sourceDeclaration = null; if (reference != null) { sourceDeclaration = findSourceDeclaration(reference); } acceptor.apply(sourceDeclaration, reference); } }); getReferenceFinder().findAllReferences(targetURIs, getResourceAccess(), getIndexData(), referenceAcceptor, monitor); }
Example #3
Source File: DefaultCallHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void findTargetDeclarations(URI sourceDeclarationURI, IProgressMonitor monitor, Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) { readOnly(sourceDeclarationURI, (EObject sourceDeclaration) -> { ReferenceAcceptor referenceAcceptor = new ReferenceAcceptor(getResourceServiceProviderRegistry(), reference -> { if (filterReference(reference)) { IEObjectDescription targetDeclaration = null; if (reference != null) { targetDeclaration = findTargetDeclaration(reference); } acceptor.apply(targetDeclaration, reference); } }); getReferenceFinder().findAllReferences(sourceDeclaration, referenceAcceptor, monitor); return null; }); }
Example #4
Source File: WorkspaceManagerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Before public void setup() { try { ServerModule _serverModule = new ServerModule(); final Injector injector = Guice.createInjector(_serverModule); injector.injectMembers(this); File _file = new File("./test-data/test-project"); this.root = _file; boolean _mkdirs = this.root.mkdirs(); boolean _not = (!_mkdirs); if (_not) { Files.cleanFolder(this.root, null, true, false); } this.root.deleteOnExit(); final Procedure2<URI, Iterable<Issue>> _function = (URI $0, Iterable<Issue> $1) -> { this.diagnostics.put($0, IterableExtensions.<Issue>toList($1)); }; this.workspaceManger.initialize(this.uriExtensions.withEmptyAuthority(URI.createFileURI(this.root.getAbsolutePath())), _function, null); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #5
Source File: MultiProjectTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Before public void setup() { ServerModule _serverModule = new ServerModule(); final Injector injector = Guice.createInjector(Modules2.mixin(_serverModule, new AbstractModule() { @Override protected void configure() { this.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class).to(MultiProjectWorkspaceConfigFactory.class); } })); injector.injectMembers(this); final File workspaceRoot = this.getRoot("test-data"); File _file = new File(workspaceRoot, "test-project0"); this.project0 = _file; File _file_1 = new File(workspaceRoot, "test-project1"); this.project1 = _file_1; this.project0.mkdir(); this.project1.mkdir(); final Procedure2<URI, Iterable<Issue>> _function = (URI $0, Iterable<Issue> $1) -> { this.diagnostics.put($0, IterableExtensions.<Issue>toList($1)); }; this.workspaceManager.initialize(URI.createFileURI(workspaceRoot.getAbsolutePath()), _function, null); }
Example #6
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public boolean visit(final VariableDeclarationExpression it) { final Procedure2<VariableDeclarationFragment, Integer> _function = (VariableDeclarationFragment frag, Integer counter) -> { this.appendModifiers(it, it.modifiers()); this.appendToBuffer(this._aSTFlattenerUtils.handleVariableDeclaration(it.modifiers())); this.appendSpaceToBuffer(); it.getType().accept(this); this.appendSpaceToBuffer(); frag.accept(this); int _size = it.fragments().size(); int _minus = (_size - 1); boolean _lessThan = ((counter).intValue() < _minus); if (_lessThan) { this.appendToBuffer(","); this.appendSpaceToBuffer(); } }; IterableExtensions.<VariableDeclarationFragment>forEach(it.fragments(), _function); return false; }
Example #7
Source File: MemberFromSuperImplementor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) { final JvmExecutable executable = overridden.getDeclaration(); builder.setContext(overrider); builder.setVisibility(overridden.getDeclaration().getVisibility()); final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> { final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue()); final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder(); parameterBuilder.setName(declaredParameter.getSimpleName()); parameterBuilder.setType(it); JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class); boolean _tripleNotEquals = (_findAnnotation != null); parameterBuilder.setExtensionFlag(_tripleNotEquals); }; IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function); builder.setVarArgsFlag(executable.isVarArgs()); builder.setExceptions(overridden.getResolvedExceptions()); }
Example #8
Source File: DocumentRewriterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected String rewrite(final CharSequence model, final Procedure2<? super DocumentRewriter, ? super XtextResource> test) { try { String _xblockexpression = null; { final XtextDocument document = this.createDocument(model.toString()); final IUnitOfWork<TextEdit, XtextResource> _function = (XtextResource it) -> { TextEdit _xblockexpression_1 = null; { final DocumentRewriter rewriter = this.factory.create(document, it); test.apply(rewriter, it); _xblockexpression_1 = this._replaceConverter.convertToTextEdit(rewriter.getChanges()); } return _xblockexpression_1; }; document.<TextEdit>readOnly(_function).apply(document); _xblockexpression = document.get(); } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #9
Source File: ClassFileCache.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public boolean popCompileResult(char[] fileName, Procedure2<? super List<String>, ? super Map<String, byte[]>> consumer) { if (allTopLevelTypes.containsKey(fileName)) { consumer.apply(allTopLevelTypes.remove(fileName), allClassMaps.remove(fileName)); return true; } return false; }
Example #10
Source File: DefaultCallHierarchyBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void findDeclarations(IHierarchyNode parent, IProgressMonitor monitor, Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) { if (hierarchyType != null) { switch (hierarchyType) { case CALLEE: findTargetDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor); break; default: findSourceDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor); break; } } else { findSourceDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor); } }
Example #11
Source File: ProjectManager.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void initialize(ProjectDescription description, IProjectConfig projectConfig, Procedure2<? super URI, ? super Iterable<Issue>> acceptor, IExternalContentSupport.IExternalContentProvider openedDocumentsContentProvider, Provider<Map<String, ResourceDescriptionsData>> indexProvider, CancelIndicator cancelIndicator) { this.projectDescription = description; this.projectConfig = projectConfig; this.baseDir = projectConfig.getPath(); this.issueAcceptor = acceptor; this.openedDocumentsContentProvider = openedDocumentsContentProvider; this.indexProvider = indexProvider; }
Example #12
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean visit(final CatchClause node) { int _nodeType = node.getException().getType().getNodeType(); boolean _tripleEquals = (_nodeType == 84); if (_tripleEquals) { this.appendToBuffer(" catch ("); final List<ASTNode> types = this._aSTFlattenerUtils.genericChildListProperty(node.getException().getType(), "types"); if (types!=null) { final Procedure2<ASTNode, Integer> _function = (ASTNode child, Integer index) -> { child.accept(this); int _size = types.size(); int _minus = (_size - 1); boolean _lessThan = ((index).intValue() < _minus); if (_lessThan) { this.appendSpaceToBuffer(); this.appendToBuffer("|"); this.appendSpaceToBuffer(); } }; IterableExtensions.<ASTNode>forEach(types, _function); } this.appendSpaceToBuffer(); this.appendToBuffer(this._aSTFlattenerUtils.toSimpleName(node.getException().getName())); this.appendToBuffer(") "); node.getBody().accept(this); } else { this.appendToBuffer(" catch ("); node.getException().accept(this); this.appendToBuffer(") "); node.getBody().accept(this); } return false; }
Example #13
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void visitAll(final Iterable<? extends ASTNode> iterable, final String separator) { final Procedure2<ASTNode, Integer> _function = (ASTNode node, Integer counter) -> { node.accept(this); if (((separator != null) && ((counter).intValue() < (IterableExtensions.size(iterable) - 1)))) { this.appendToBuffer(separator); } }; IterableExtensions.forEach(iterable, _function); }
Example #14
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void acceptSyntaticBlock(final Block node) { final int childrenCount = node.statements().size(); if ((childrenCount > 0)) { final Procedure2<ASTNode, Integer> _function = (ASTNode child, Integer counter) -> { child.accept(this); this.appendLineWrapToBuffer(); }; IterableExtensions.<ASTNode>forEach(node.statements(), _function); } }
Example #15
Source File: BoundTypeArgumentMergerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public LightweightMergedBoundTypeArgument mergeWithSource(final Object source, final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def void method("); final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> { return it.getFirst(); }; String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>)Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function); _builder.append(_join); _builder.append(") {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(); final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> { final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()]; LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType()); Object _elvis = null; if (source != null) { _elvis = source; } else { Object _object = new Object(); _elvis = _object; } VarianceInfo _second = input.getSecond(); VarianceInfo _third = input.getThird(); LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _elvis, _second, _third); mergable.add(_lightweightBoundTypeArgument); }; IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1); return this.merger.merge(mergable, this.getOwner()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #16
Source File: Solution_022.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public static void main(final String[] args) { try { InputStream _resourceAsStream = Solution_022.class.getResourceAsStream("names.txt"); InputStreamReader _inputStreamReader = new InputStreamReader(_resourceAsStream); final BufferedReader reader = new BufferedReader(_inputStreamReader); try { final String line = reader.readLine(); final Matcher matcher = Pattern.compile("\"(\\w+)\"").matcher(line); final ArrayList<String> names = CollectionLiterals.<String>newArrayList(); while (matcher.find()) { names.add(matcher.group(1)); } final AtomicLong result = new AtomicLong(); final Procedure2<String, Integer> _function = (String name, Integer i) -> { final Function1<Character, Integer> _function_1 = (Character it) -> { int _numericValue = Character.getNumericValue((it).charValue()); return Integer.valueOf((_numericValue - 9)); }; final Function2<Integer, Integer, Integer> _function_2 = (Integer i1, Integer i2) -> { return Integer.valueOf(((i1).intValue() + (i2).intValue())); }; Integer _reduce = IterableExtensions.<Integer>reduce(ListExtensions.<Character, Integer>map(((List<Character>)Conversions.doWrapArray(name.toCharArray())), _function_1), _function_2); int _multiply = ((_reduce).intValue() * ((i).intValue() + 1)); result.addAndGet(_multiply); }; IterableExtensions.<String>forEach(IterableExtensions.<String>sort(names), _function); InputOutput.<AtomicLong>println(result); } finally { reader.close(); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #17
Source File: DocumentRewriterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testEmptyLinesAround() { StringConcatenation _builder = new StringConcatenation(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("def foo() {}"); _builder.newLine(); _builder.append("\t"); _builder.append("def bar() {}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String model = _builder.toString(); final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> { final DocumentRewriter.Section beforeDefBar = it.newSection(model.indexOf("def bar"), 0, true); beforeDefBar.append("val x = 42"); }; String _rewrite = this.rewrite(model, _function); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("class Foo {"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("def foo() {}"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("val x = 42"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("def bar() {}"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); this.andExpect(_rewrite, _builder_1); }
Example #18
Source File: DocumentRewriterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testInsertExistingType() { StringConcatenation _builder = new StringConcatenation(); _builder.append("import java.io.Serializable"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo implements Serializable {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("def foo() {}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String model = _builder.toString(); final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> { final DocumentRewriter.Section beforeFoo = it.newSection(model.indexOf("foo"), 0); beforeFoo.append(this.services.getTypeReferences().findDeclaredType(Serializable.class, r)); beforeFoo.append(" "); }; String _rewrite = this.rewrite(model, _function); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import java.io.Serializable"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("class Foo implements Serializable {"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("def Serializable foo() {}"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); this.andExpect(_rewrite, _builder_1); }
Example #19
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _assertEqualLinkingData(final IClosureCandidate left, final IClosureCandidate right) { Assert.assertEquals("type", left.getParameters().size(), right.getParameters().size()); final Procedure2<JvmFormalParameter, Integer> _function = (JvmFormalParameter leftParam, Integer idx) -> { final JvmFormalParameter rightParam = right.getParameters().get((idx).intValue()); Assert.assertEquals(leftParam.getName(), rightParam.getName()); EStructuralFeature _eContainingFeature = leftParam.eContainingFeature(); boolean _notEquals = (!Objects.equal(_eContainingFeature, XbasePackage.Literals.XCLOSURE__DECLARED_FORMAL_PARAMETERS)); if (_notEquals) { Assert.assertEquals(leftParam.getParameterType().getIdentifier(), rightParam.getParameterType().getIdentifier()); } }; IterableExtensions.<JvmFormalParameter>forEach(left.getParameters(), _function); }
Example #20
Source File: AbstractClosureTypeTest2.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void withEquivalents(final List<Object> references, final String... types) { final Procedure2<Object, Integer> _function = (Object reference, Integer index) -> { final Callable<Object> _function_1 = () -> { Assert.assertTrue((reference instanceof FunctionTypeReference)); return null; }; this.collector.<Object>checkSucceeds(_function_1); final Callable<Object> _function_2 = () -> { Assert.assertEquals(types[(index).intValue()], this.getEquivalent(((FunctionTypeReference) reference))); return null; }; this.collector.<Object>checkSucceeds(_function_2); }; IterableExtensions.<Object>forEach(references, _function); }
Example #21
Source File: StringLiteralTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void resolvesStringLiteralsTo(final String expression, final String... types) { final String expressionWithQualifiedNames = expression.replace("$$", "org::eclipse::xtext::xbase::lib::"); final List<XStringLiteral> featureCalls = this.findLiterals(expressionWithQualifiedNames); Assert.assertFalse(featureCalls.isEmpty()); Assert.assertEquals(((List<String>)Conversions.doWrapArray(types)).size(), featureCalls.size()); final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XStringLiteral>head(featureCalls)); final Procedure2<XStringLiteral, Integer> _function = (XStringLiteral featureCall, Integer index) -> { final LightweightTypeReference type = resolvedTypes.getActualType(featureCall); StringConcatenation _builder = new StringConcatenation(); _builder.append("failed for literal at "); _builder.append(index); Assert.assertEquals(_builder.toString(), types[(index).intValue()], type.getSimpleName()); }; IterableExtensions.<XStringLiteral>forEach(featureCalls, _function); }
Example #22
Source File: IteratorExtensions.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
/** * Applies {@code procedure} for each element of the given iterator. * The procedure takes the element and a loop counter. If the counter would overflow, {@link Integer#MAX_VALUE} * is returned for all subsequent elements. The first element is at index zero. * * @param iterator * the iterator. May not be <code>null</code>. * @param procedure * the procedure. May not be <code>null</code>. */ public static <T> void forEach(Iterator<T> iterator, Procedure2<? super T, ? super Integer> procedure) { if (procedure == null) throw new NullPointerException("procedure"); int i = 0; while(iterator.hasNext()) { procedure.apply(iterator.next(), i); if (i != Integer.MAX_VALUE) i++; } }
Example #23
Source File: ProcedureExtensions.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
/** * Curries a procedure that takes three arguments. * * @param procedure * the original procedure. May not be <code>null</code>. * @param argument * the fixed first argument of {@code procedure}. * @return a procedure that takes two arguments. Never <code>null</code>. */ @Pure public static <P1, P2, P3> Procedure2<P2, P3> curry(final Procedure3<? super P1, ? super P2, ? super P3> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure2<P2, P3>() { @Override public void apply(P2 p2, P3 p3) { procedure.apply(argument, p2, p3); } }; }
Example #24
Source File: ProcedureExtensions.java From xtext-lib with Eclipse Public License 2.0 | 5 votes |
/** * Curries a procedure that takes two arguments. * * @param procedure * the original procedure. May not be <code>null</code>. * @param argument * the fixed first argument of {@code procedure}. * @return a procedure that takes one argument. Never <code>null</code>. */ @Pure public static <P1, P2> Procedure1<P2> curry(final Procedure2<? super P1, ? super P2> procedure, final P1 argument) { if (procedure == null) throw new NullPointerException("procedure"); return new Procedure1<P2>() { @Override public void apply(P2 p) { procedure.apply(argument, p); } }; }
Example #25
Source File: PyGenerator.java From sarl with Apache License 2.0 | 4 votes |
/** Generate the given type. * * @param fullyQualifiedName the fully qualified name of the type. * @param name the name of the type. * @param isAbstract indicates if the type is abstract. * @param superTypes the super types. * @param comment the comment. * @param ignoreObjectType ignores the "Object" type if the super types. * @param members the members. * @param it the output. * @param context the context. * @param memberGenerator the generator of members. * @return {@code true} if the type declaration was generated. */ @SuppressWarnings({ "checkstyle:parameternumber" }) protected boolean generateTypeDeclaration( String fullyQualifiedName, String name, boolean isAbstract, List<? extends JvmTypeReference> superTypes, String comment, boolean ignoreObjectType, List<? extends XtendMember> members, PyAppendable it, IExtraLanguageGeneratorContext context, Procedure2<? super PyAppendable, ? super IExtraLanguageGeneratorContext> memberGenerator) { if (!Strings.isEmpty(name)) { if (!generatePythonClassDeclaration(name, isAbstract, superTypes, comment, ignoreObjectType, it, context) || context.getCancelIndicator().isCanceled()) { return false; } // it.openScope(); // if (!generateSarlMembers(members, it, context) || context.getCancelIndicator().isCanceled()) { return false; } // if (memberGenerator != null) { memberGenerator.apply(it, context); } // if (!generatePythonConstructors(fullyQualifiedName, members, it, context) || context.getCancelIndicator().isCanceled()) { return false; } // it.decreaseIndentation().newLine().newLine(); // it.closeScope(); // if (context.getCancelIndicator().isCanceled()) { return false; } return true; } return false; }
Example #26
Source File: SARLJvmModelInferrer.java From sarl with Apache License 2.0 | 4 votes |
/** Copy the JVM operations from the source to the destination. * * @param source the source. * @param target the destination. * @param createdActions the set of actions that are created before (input) or during (output) the invocation. * @param bodyBuilder the builder of the target's operations. * @since 0.5 */ @SuppressWarnings("checkstyle:npathcomplexity") protected void copyNonStaticPublicJvmOperations(JvmGenericType source, JvmGenericType target, Set<ActionPrototype> createdActions, Procedure2<? super JvmOperation, ? super ITreeAppendable> bodyBuilder) { final Iterable<JvmOperation> operations = Iterables.transform(Iterables.filter(source.getMembers(), it -> { if (it instanceof JvmOperation) { final JvmOperation op = (JvmOperation) it; return !op.isStatic() && op.getVisibility() == JvmVisibility.PUBLIC; } return false; }), it -> (JvmOperation) it); for (final JvmOperation operation : operations) { final ActionParameterTypes types = this.sarlSignatureProvider.createParameterTypesFromJvmModel( operation.isVarArgs(), operation.getParameters()); final ActionPrototype actSigKey = this.sarlSignatureProvider.createActionPrototype( operation.getSimpleName(), types); if (createdActions.add(actSigKey)) { final JvmOperation newOp = this.typesFactory.createJvmOperation(); target.getMembers().add(newOp); newOp.setAbstract(false); newOp.setFinal(false); newOp.setNative(false); newOp.setStatic(false); newOp.setSynchronized(false); newOp.setVisibility(JvmVisibility.PUBLIC); newOp.setDefault(operation.isDefault()); newOp.setDeprecated(operation.isDeprecated()); newOp.setSimpleName(operation.getSimpleName()); newOp.setStrictFloatingPoint(operation.isStrictFloatingPoint()); copyTypeParametersFromJvmOperation(operation, newOp); for (final JvmTypeReference exception : operation.getExceptions()) { newOp.getExceptions().add(cloneWithTypeParametersAndProxies(exception, newOp)); } for (final JvmFormalParameter parameter : operation.getParameters()) { final JvmFormalParameter newParam = this.typesFactory.createJvmFormalParameter(); newOp.getParameters().add(newParam); newParam.setName(parameter.getSimpleName()); newParam.setParameterType(cloneWithTypeParametersAndProxies(parameter.getParameterType(), newOp)); } newOp.setVarArgs(operation.isVarArgs()); newOp.setReturnType(cloneWithTypeParametersAndProxies(operation.getReturnType(), newOp)); setBody(newOp, it -> bodyBuilder.apply(operation, it)); } } }
Example #27
Source File: ErrorSafeExtensions.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public <T extends EObject> void forEachSafely(ITreeAppendable appendable, Iterable<T> elements, Procedure1<? super LoopParams> loopInitializer, Procedure2<? super T, ? super ITreeAppendable> body) { if (Iterables.isEmpty(elements)) { return; } LoopParams loopParams = ObjectExtensions.operator_doubleArrow(new LoopParams(), loopInitializer); boolean allElementsBroken = Iterables .size(Iterables.<T>filter(elements, (T it) -> hasErrors(it))) == Iterables.size(elements); ITreeAppendable currentAppendable = null; if (allElementsBroken) { currentAppendable = openErrorAppendable(appendable, null); } else { currentAppendable = appendable; } loopParams.appendPrefix(currentAppendable); boolean isFirst = true; boolean isFirstBroken = true; for (T element : elements) { if (!hasErrors(element)) { currentAppendable = closeErrorAppendable(appendable, currentAppendable); if (!isFirst) { loopParams.appendSeparator(appendable); } isFirst = false; body.apply(element, appendable); } else { if (!allElementsBroken) { currentAppendable = openErrorAppendable(appendable, currentAppendable); } if (!isFirst || !isFirstBroken) { loopParams.appendSeparator(currentAppendable); } isFirstBroken = false; try { body.apply(element, currentAppendable); } catch (Exception ignoreMe) { } } } if (!allElementsBroken) { currentAppendable = closeErrorAppendable(appendable, currentAppendable); } loopParams.appendSuffix(currentAppendable); closeErrorAppendable(appendable, currentAppendable); }
Example #28
Source File: ProjectManager.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected Procedure2<? super URI, ? super Iterable<Issue>> getIssueAcceptor() { return issueAcceptor; }
Example #29
Source File: IteratorExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 4 votes |
@Override protected void forEach(Iterator<Integer> input, Procedure2<Integer, Integer> proc) { IteratorExtensions.forEach(input, proc); }
Example #30
Source File: IterableExtensionsTest.java From xtext-lib with Eclipse Public License 2.0 | 4 votes |
@Override protected void forEach(Iterable<Integer> input, Procedure2<Integer, Integer> proc) { IterableExtensions.forEach(input, proc); }