org.eclipse.xtext.util.IAcceptor Java Examples
The following examples show how to use
org.eclipse.xtext.util.IAcceptor.
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: FinalFieldsConstructorCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testOnGenericClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor"); _builder.newLine(); _builder.append("@FinalFieldsConstructor class C<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("val T a"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String source = _builder.toString(); this._validationTestHelper.assertNoErrors(this.clazz(source)); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getSingleGeneratedCode().contains("C(final T a)")); }; this.compilationTestHelper.compile(source, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: NfaUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected <S> void findCycles(Nfa<S> nfa, S node, IAcceptor<List<S>> cycleAcceptor, Map<S, Integer> dfsMark, LinkedList<S> dfsStack) { dfsStack.push(node); dfsMark.put(node, DFS_ON_STACK); for (S follower : nfa.getFollowers(node)) { Integer followerMark = dfsMark.get(follower); if (followerMark == null) { // The follower is not visited yet, so go deeper. findCycles(nfa, follower, cycleAcceptor, dfsMark, dfsStack); } else if (followerMark == DFS_ON_STACK) { // If the follower is on the stack that means we have a cycle // that includes all nodes between // the follower node and the current node. LinkedList<S> cycle = Lists.newLinkedList(); Iterator<S> stackIter = dfsStack.iterator(); S cycleNode; do { cycleNode = stackIter.next(); cycle.addFirst(cycleNode); } while (cycleNode != follower && stackIter.hasNext()); cycleAcceptor.accept(cycle); } } dfsStack.pop(); dfsMark.put(node, DFS_VISITED); }
Example #3
Source File: RuleOverrideUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public List<IEObjectDescription> getOverridingRules(final AbstractRule originalRule) { Grammar grammar = GrammarUtil.getGrammar(originalRule); final List<IEObjectDescription> overridingRules = newArrayList(); IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() { @Override public void accept(IReferenceDescription referenceToGrammar) { if (referenceToGrammar.getEReference() == XtextPackage.Literals.GRAMMAR__USED_GRAMMARS) { IResourceDescription resourceDescription = resourceDescriptions .getResourceDescription(referenceToGrammar.getSourceEObjectUri().trimFragment()); for (IEObjectDescription rule : resourceDescription.getExportedObjectsByType(originalRule.eClass())) { if (Strings.equal(originalRule.getName(), rule.getQualifiedName().getLastSegment())) { overridingRules.add(rule); break; } } } } }; referenceFinder.findAllReferences(singleton(EcoreUtil2.getPlatformResourceOrNormalizedURI(grammar)), localContextProvider, acceptor, new NullProgressMonitor()); return overridingRules; }
Example #4
Source File: ScopeResourceDescriptionStrategy.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
@Override public boolean createEObjectDescriptions(final EObject eObject, final IAcceptor<IEObjectDescription> acceptor) { if (getQualifiedNameProvider() == null || !(eObject instanceof ScopeModel)) { return false; } ScopeModel model = (ScopeModel) eObject; try { QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(model); if (qualifiedName != null) { Hasher hasher = Hashing.murmur3_32().newHasher(HASHER_CAPACITY); hasher.putUnencodedChars(getSourceText(model)); for (ScopeModel include : model.getIncludedScopes()) { hasher.putUnencodedChars(getSourceText(include)); } acceptor.accept(EObjectDescription.create(qualifiedName, model, Collections.singletonMap("fingerprint", hasher.hash().toString()))); } // CHECKSTYLE:CHECK-OFF IllegalCatch } catch (RuntimeException e) { // CHECKSTYLE:CHECK-ON LOG.error(e.getMessage(), e); } return false; }
Example #5
Source File: ActiveAnnotationContextProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void registerMacroAnnotations(final XtendAnnotationTarget candidate, final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> acceptor) { final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> { return Boolean.valueOf(this._xAnnotationExtensions.isProcessed(it)); }; Iterable<XAnnotation> _filter = IterableExtensions.<XAnnotation>filter(candidate.getAnnotations(), _function); for (final XAnnotation annotation : _filter) { { final JvmAnnotationType activeAnnotationDeclaration = this._xAnnotationExtensions.tryFindAnnotationType(annotation); if ((activeAnnotationDeclaration != null)) { boolean _isValid = this.isValid(annotation, activeAnnotationDeclaration); if (_isValid) { Pair<JvmAnnotationType, XAnnotation> _mappedTo = Pair.<JvmAnnotationType, XAnnotation>of(activeAnnotationDeclaration, annotation); acceptor.accept(_mappedTo); } } } } }
Example #6
Source File: N4JSResourceValidator.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Don't validate the inferred module since all validation information should be available on the AST elements. */ @Override protected void validate(Resource resource, CheckMode mode, CancelIndicator cancelIndicator, IAcceptor<Issue> acceptor) { operationCanceledManager.checkCanceled(cancelIndicator); List<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { EObject firstElement = contents.get(0); // // Mark the scoping as sealed. (No other usage-flags should be set for import-declarations.) // if (firstElement instanceof Script) { // ((Script) firstElement).setFlaggedBound(true); // } validate(resource, firstElement, mode, cancelIndicator, acceptor); // UtilN4.takeSnapshotInGraphView("post validation", resource); } }
Example #7
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void findAllReferences( Iterable<URI> targetURIs, ILocalResourceAccess localResourceAccess, IAcceptor<IReferenceDescription> referenceAcceptor, IProgressMonitor monitor) { TargetURIs converted = converter.fromIterable(targetURIs); if (!converted.isEmpty()) { findAllIndexedReferences(referenceAcceptor, SubMonitor.convert(monitor, 1), converted.asSet(), localResourceAccess); if (localResourceAccess != null && !converted.isEmpty() && getClass() != DefaultReferenceFinder.class) { // All the references have already been collected, but if this method was overridden, // we have to call it again from here findLocalReferences(converted, localResourceAccess, referenceAcceptor, monitor); } } }
Example #8
Source File: N4JSResourceDescriptionStrategy.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public boolean createEObjectDescriptions(final EObject eObject, IAcceptor<IEObjectDescription> acceptor) { if (getQualifiedNameProvider() == null) return false; if (eObject instanceof TModule) { TModule module = (TModule) eObject; internalCreateEObjectDescriptionForRoot(module, acceptor); for (Type type : module.getTopLevelTypes()) { internalCreateEObjectDescription(type, acceptor); } for (TVariable variable : module.getVariables()) { internalCreateEObjectDescription(variable, acceptor); } } // export is only possible for top-level elements return false; }
Example #9
Source File: InferredModelAssociator.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new acceptor for the given resource. * * @param resource * resource, must not be {@code null} * @return new acceptor, never {@code null} */ protected IAcceptor<EObject> createAcceptor(final DerivedStateAwareResource resource) { return new IAcceptor<EObject>() { private InferenceContainer container; @Override public void accept(final EObject t) { if (t != null) { if (container == null) { container = ModelInferenceFactory.eINSTANCE.createInferenceContainer(); resource.getContents().add(container); } container.getContents().add(t); } } }; }
Example #10
Source File: FileSystemScanner.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public void scan(URI root, IAcceptor<URI> acceptor) { File rootFile = URIUtils.toFile(root); if (rootFile.isDirectory()) { try { Path rootPath = rootFile.toPath(); if (acceptor instanceof FileVisitingAcceptor) { Files.walkFileTree(rootPath, (FileVisitingAcceptor) acceptor); } else { Files.walk(rootPath).forEach(p -> { File file = p.toFile(); if (!file.isDirectory()) { acceptor.accept(new FileURI(p.toFile()).toURI()); } }); } } catch (IOException e) { throw new RuntimeIOException(e); } } }
Example #11
Source File: GlobalObjectScope.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) { IDefaultResourceDescriptionStrategy strategy = ((XtextResource) resource).getResourceServiceProvider() .get(IDefaultResourceDescriptionStrategy.class); TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(resource, false); IAcceptor<IEObjectDescription> acceptor = new IAcceptor<>() { @Override public void accept(IEObjectDescription description) { elements.put(description.getQualifiedName(), description); } }; while (allProperContents.hasNext()) { EObject content = allProperContents.next(); if (!strategy.createEObjectDescriptions(content, acceptor)) { allProperContents.prune(); } } }
Example #12
Source File: XtendConfigurableIssueCodes.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected void initialize(IAcceptor<PreferenceKey> iAcceptor) { super.initialize(iAcceptor); iAcceptor.accept(create(IssueCodes.SINGLE_DISPATCH_FUNCTION, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.DISPATCH_PLAIN_FUNCTION_NAME_CLASH, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.DISPATCH_FUNCTIONS_DIFFERENT_PRIMITIVE_ARGS, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.INVALID_OPERATOR_SIGNATURE, SeverityConverter.SEVERITY_ERROR)); iAcceptor.accept(createDelegate(IssueCodes.UNUSED_PRIVATE_MEMBER, JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); iAcceptor.accept(createDelegate(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC, JavaCore.COMPILER_PB_INVALID_JAVADOC, SeverityConverter.SEVERITY_IGNORE)); iAcceptor.accept(create(IssueCodes.API_TYPE_INFERENCE, SeverityConverter.SEVERITY_IGNORE)); iAcceptor.accept(create(IssueCodes.IMPLICIT_RETURN, SeverityConverter.SEVERITY_IGNORE)); iAcceptor.accept(create(IssueCodes.ORPHAN_ELEMENT, SeverityConverter.SEVERITY_IGNORE)); iAcceptor.accept(create(IssueCodes.WRONG_FILE, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.UNNECESSARY_MODIFIER, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.MODIFIER_DOES_NOT_MATCH_TYPENAME, SeverityConverter.SEVERITY_WARNING)); iAcceptor.accept(create(IssueCodes.TERNARY_EXPRESSION_NOT_ALLOWED, SeverityConverter.SEVERITY_IGNORE)); // overwrite xbase default iAcceptor.accept(create(org.eclipse.xtext.validation.IssueCodes.COPY_JAVA_PROBLEMS, SeverityConverter.SEVERITY_ERROR)); }
Example #13
Source File: SuspiciouslyOverloadedCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { if (chosenCandidate.validate(result)) { StringBuilder messageBuilder = new StringBuilder("Suspiciously overloaded method.\n"); messageBuilder.append("The ").append(getFeatureTypeName()).append("\n\t"); appendCandidate(chosenCandidate, messageBuilder); messageBuilder.append("\noverloads the ").append(getFeatureTypeName()).append("\n\t"); appendCandidate(rejectedCandidate, messageBuilder); messageBuilder.append("."); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(chosenCandidate.getSeverity(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE), IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, messageBuilder.toString(), getExpression(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); } return false; }
Example #14
Source File: EcoreResourceDescriptionStrategy.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedNameProvider, boolean isNsURI, EObject eObject, IAcceptor<IEObjectDescription> acceptor) { try { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject); if (qualifiedName != null) { Map<String, String> userData = Maps.newHashMapWithExpectedSize(1); userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData); acceptor.accept(description); return true; } } catch (Exception exc) { LOG.error(exc.getMessage(), exc); } return false; }
Example #15
Source File: ImplicitFirstArgument.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { if (!getState().isInstanceContext()) { JvmIdentifiableElement implicitFeature = getFeature(); if (implicitFeature instanceof JvmType) { JvmIdentifiableElement feature = getState().getResolvedTypes().getLinkedFeature(getOwner()); if (feature == null || feature.eIsProxy() || !(feature instanceof JvmFeature)) return true; String message = "Cannot make an implicit reference to this from a static context"; AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.STATIC_ACCESS_TO_INSTANCE_MEMBER, message, getOwner(), XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null); result.accept(diagnostic); return false; } } return super.validate(result); }
Example #16
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) { IssueImpl issue = new Issue.IssueImpl(); issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic); issue.setSeverity(severity); issue.setLineNumber(diagnostic.getLine()); issue.setColumn(diagnostic.getColumn()); issue.setMessage(diagnostic.getMessage()); if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) { org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic; issue.setOffset(xtextDiagnostic.getOffset()); issue.setLength(xtextDiagnostic.getLength()); } if (diagnostic instanceof AbstractDiagnostic) { AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic)diagnostic; issue.setUriToProblem(castedDiagnostic.getUriToProblem()); issue.setCode(castedDiagnostic.getCode()); issue.setData(castedDiagnostic.getData()); issue.setLineNumberEnd(castedDiagnostic.getLineEnd()); issue.setColumnEnd(castedDiagnostic.getColumnEnd()); } issue.setType(CheckType.FAST); acceptor.accept(issue); }
Example #17
Source File: OldDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAndSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar<X> extends Foo<X> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final X foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #18
Source File: DefaultImportsConfiguration.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) { final List<JvmDeclaredType> locallyDefinedTypes = newArrayList(); for (TreeIterator<EObject> i = resource.getAllContents(); i.hasNext();) { EObject next = i.next(); if (next instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) next; locallyDefinedTypes.add(declaredType); addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() { @Override public void accept(JvmDeclaredType t) { locallyDefinedTypes.add(t); } }); i.prune(); } if(next instanceof XExpression) { i.prune(); } } return locallyDefinedTypes; }
Example #19
Source File: DispatchRenameSupport.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
/** * Returns all operations of the declaring type that have to be renamed with the given Xtend function. I.e. all * dispatch functions with the same name of all sub- and super types as well as the artificial dispatchers. * * The method will likely load all subtypes into the resource set of the dispatch function, so you might want to * hand in a reloaded instance instead. */ public Iterable<JvmOperation> getAllDispatchOperations(XtendFunction dispatchFunction) { Assert.isLegal(dispatchFunction.isDispatch()); IProject project = projectUtil.getProject(dispatchFunction.eResource().getURI()); final ResourceSet tempResourceSet = resourceSetProvider.get(project); JvmOperation localDispatcher = associations.getDispatchOperation(dispatchFunction); XtendClass xtendClass = (XtendClass) dispatchFunction.eContainer(); final Set<JvmOperation> dispatchCases = newLinkedHashSet(); IAcceptor<JvmOperation> operationAcceptor = new IAcceptor<JvmOperation>() { @Override public void accept(JvmOperation operation) { dispatchCases.add(operation); } }; final Set<JvmGenericType> processedTypes = newHashSet(); addDispatcher(associations.getInferredType(xtendClass), new DispatchHelper.DispatchSignature(localDispatcher.getSimpleName(), localDispatcher.getParameters().size()), operationAcceptor, processedTypes, tempResourceSet); return dispatchCases; }
Example #20
Source File: NewDataCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAndSuperClassWithTypeParameters() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.Data"); _builder.newLine(); _builder.append("@Data class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("T foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("@Data class Bar<X> extends Foo<X> {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getGeneratedCode("Bar").contains("public Bar(final X foo) {")); }; this.compilationTestHelper.compile(_builder, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #21
Source File: EqualsHashCodeCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testGenericClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import org.eclipse.xtend.lib.annotations.EqualsHashCode"); _builder.newLine(); _builder.append("@EqualsHashCode class Foo<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("int a = 1"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String text = _builder.toString(); final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { Assert.assertTrue(it.getSingleGeneratedCode().contains("Foo<?> other = (Foo<?>) obj")); }; this.compilationTestHelper.compile(text, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #22
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected boolean validateArity(IAcceptor<? super AbstractDiagnostic> result) { if (getArityMismatch() != 0) { String message; if (getArguments().isEmpty()) { message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable without arguments" , getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString()); } else { message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable for the arguments %4$s" , getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString(), getArgumentTypesAsString()); } AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_NUMBER_OF_ARGUMENTS, message, getExpression(), getInvalidArgumentsValidationFeature(), -1, null); result.accept(diagnostic); return false; } return true; }
Example #23
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected boolean validateVisibility(IAcceptor<? super AbstractDiagnostic> result) { if (!isVisible()) { String message = String.format("The %1$s %2$s%3$s is not visible", getFeatureTypeName(), getSimpleFeatureName(), getFeatureParameterTypesAsString()); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.FEATURE_NOT_VISIBLE, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return true; }
Example #24
Source File: JavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void parseImportSection(XImportSection importSection, IAcceptor<String> visiblePackages, IAcceptor<String> importedTypes) { for (XImportDeclaration importDeclaration : importSection.getImportDeclarations()) { if (!importDeclaration.isStatic()) { if (importDeclaration.getImportedNamespace() != null) { String importedAsString = importDeclaration.getImportedNamespace(); if (importDeclaration.isWildcard()) { importedAsString = importedAsString.substring(0, importedAsString.length() - 2); visiblePackages.accept(importedAsString); } else { importedTypes.accept(importedAsString); } } else { importedTypes.accept(importDeclaration.getImportedTypeName()); } } } }
Example #25
Source File: Bug456264Test.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testAddError() { StringConcatenation _builder = new StringConcatenation(); _builder.append("@org.eclipse.xtend.core.tests.macro.Bug456264 class C {}"); _builder.newLine(); final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> { final List<? extends Problem> problems = it.getAllProblems(); final Function1<Problem, String> _function_1 = (Problem it_1) -> { return it_1.getMessage(); }; Assert.assertEquals(ListExtensions.map(problems, _function_1).toString(), 1, problems.size()); Assert.assertEquals("My error message", IterableExtensions.head(problems).getMessage()); final List<? extends Problem> specificProblems = it.getProblems(IterableExtensions.head(it.getCompilationUnit().getSourceTypeDeclarations())); Assert.assertEquals(specificProblems.toString(), 1, problems.size()); Assert.assertEquals("My error message", IterableExtensions.head(specificProblems).getMessage()); }; this._xtendCompilerTester.compile(_builder, _function); }
Example #26
Source File: AbstractXtendCompilerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected XtendFile doAssertCompilesTo(final CharSequence input, final CharSequence expected, final GeneratorConfig config, final boolean serializeAllTypes) { try { final XtendFile file = this.file(input.toString(), true); final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList(); Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class); for (final JvmDeclaredType inferredType : _filter) { { Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType)); CharSequence javaCode = this.generator.generateType(inferredType, config); javaCode = this.postProcessor.postProcess(null, javaCode); results.add(javaCode); if (this.useJavaCompiler) { final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> { it.getCompiledClass(); }; this.compilationTestHelper.compile(input, _function); } } } if (serializeAllTypes) { Assert.assertEquals(expected.toString(), IterableExtensions.join(results, "\n")); } else { Assert.assertEquals(expected.toString(), IterableExtensions.<CharSequence>head(results).toString()); } return file; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #27
Source File: ConfigurableIssueCodesProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public ConfigurableIssueCodesProvider() { final Map<String, PreferenceKey> map = Maps.newLinkedHashMap(); initialize(new IAcceptor<PreferenceKey>() { @Override public void accept(PreferenceKey prefKey) { map.put(prefKey.getId(), prefKey); } }); this.issueCodes = ImmutableMap.copyOf(map); }
Example #28
Source File: SemverResourceValidator.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Validates Semver {@link EObject}s * * @param root * A Semver {@link EObject}, usually {@link NPMVersionRequirement} */ public List<Issue> validate(EObject root, CheckMode mode, CancelIndicator monitor) { List<Issue> result = new ArrayList<>(); IAcceptor<Issue> acceptor = createAcceptor(result); operationCanceledManager.checkCanceled(monitor); validate(null, root, mode, monitor, acceptor); return result; }
Example #29
Source File: FindReferencesTestUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void init(EObject target, String expectedLabel, final IAcceptor<IReferenceDescription> acceptor) { targetURIs = getTargetURIs(target); filter = getFilter(target); assertEquals(expectedLabel, getLabel(target)); this.filteringAcceptor = new IAcceptor<IReferenceDescription>() { @Override public void accept(IReferenceDescription t) { if (filter.apply(t)) acceptor.accept(t); } }; localResourceAccess = resourceAccessProvider.get(); localResourceAccess.registerResourceSet(target.eResource().getResourceSet()); }
Example #30
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void findLocalReferences( Iterable<URI> localTargets, ILocalResourceAccess localResourceAccess, final IAcceptor<IReferenceDescription> acceptor, IProgressMonitor monitor) { if ((monitor != null && monitor.isCanceled())) throw new OperationCanceledException(); final TargetURIs targetURIs = converter.fromIterable(localTargets); Collection<URI> resourceURIs = targetURIs.getTargetResourceURIs(); final SubMonitor subMonitor = SubMonitor.convert(monitor, resourceURIs.size() / MONITOR_FIND_LOCAL_CHUNK_SIZE + 1); int i = 0; for(final URI resourceURI: resourceURIs) { if (subMonitor.isCanceled()) throw new OperationCanceledException(); localResourceAccess.readOnly(resourceURI, new IUnitOfWork.Void<ResourceSet>() { @Override public void process(ResourceSet resourceSet) throws Exception { Resource resource = resourceSet.getResource(resourceURI, true); DefaultReferenceFinder.super.findReferences(targetURIs, resource, toAcceptor(acceptor), subMonitor); } }); i++; if (i % MONITOR_FIND_LOCAL_CHUNK_SIZE == 0) subMonitor.worked(1); } }