Java Code Examples for org.eclipse.xtext.util.IAcceptor#accept()
The following examples show how to use
org.eclipse.xtext.util.IAcceptor#accept() .
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: 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 2
Source File: ClassFileBasedOpenerContributor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) { if (!(editor instanceof XtextEditor) && editor.getEditorInput() != null) { try { IClassFile classFile = Adapters.adapt(editor, IClassFile.class); if (classFile == null) { return false; } ITrace trace = traceForTypeRootProvider.getTraceToSource(classFile); if (trace == null) { return false; } for (ILocationInResource location : trace.getAllAssociatedLocations()) { String name = location.getAbsoluteResourceURI().getURI().lastSegment(); IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(name); acceptor.accept(createEditorOpener(editor.getEditorInput(), editorDescriptor.getId())); return true; } } catch (PartInitException e) { LOG.error(e.getMessage(), e); } } return false; }
Example 3
Source File: AbstractResourceDescriptionStrategy.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Creates all inferred and implicit reference descriptions and adds them to the acceptor. * * @param resource * resource to create implicit references for * @param acceptor * acceptor */ public void createImplicitReferenceDescriptions(final Resource resource, final IAcceptor<IReferenceDescription> acceptor) { ImplicitReferencesAdapter adapter = ImplicitReferencesAdapter.find(resource); if (adapter != null) { for (IReferenceDescription ref : adapter.getImplicitReferences()) { acceptor.accept(ref); } } }
Example 4
Source File: SharedAppendableState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void appendType(final Class<?> type, IAcceptor<String> content) { // don't import if a local variable with the same name is on the scope //TODO logic should be moved to ImportManager eventually. if (hasObject(type.getSimpleName())) { content.accept(type.getCanonicalName()); } else { StringBuilder builder = new StringBuilder(); importManager.appendType(type, builder); content.accept(builder.toString()); } }
Example 5
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean validateTypeArgumentConformance(IAcceptor<? super AbstractDiagnostic> result) { if (getTypeArgumentConformanceFailures(result) == 0) { // TODO use early exit computation List<XExpression> arguments = getSyntacticArguments(); for(int i = 0; i < arguments.size(); i++) { XExpression argument = arguments.get(i); if (isDefiniteEarlyExit(argument)) { XExpression errorOn = getExpression(); String message = "Unreachable code."; EStructuralFeature errorFeature = null; if (i < arguments.size() - 1) { errorOn = arguments.get(i + 1); } else { errorFeature = getDefaultValidationFeature(); if (errorOn instanceof XBinaryOperation) { message = "Unreachable code. The right argument expression does not complete normally."; } else { message = "Unreachable code. The last argument expression does not complete normally."; } } AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.UNREACHABLE_CODE, message, errorOn, errorFeature, -1, null); result.accept(diagnostic); return false; } } } else { return false; } return true; }
Example 6
Source File: LogicalContainerAwareReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void requestCapturedLocalVariables(JvmTypeReference toBeWrapped, JvmDeclaredType type, ResolvedTypes resolvedTypes, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, IAcceptor<JvmTypeReference> result) { LocalVariableCapturerImpl capturer = new LocalVariableCapturerImpl(toBeWrapped, type, this, resolvedTypes, resolvedTypesByContext); XComputedTypeReference ref = getServices().getXtypeFactory().createXComputedTypeReference(); ref.setTypeProvider(capturer); result.accept(ref); capturer.awaitCapturing(); }
Example 7
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) { Severity severity = getSeverity(diagnostic); if (severity == null) return; IssueImpl issue = new Issue.IssueImpl(); issue.setSeverity(severity); IssueLocation locationData = getLocationData(diagnostic); if (locationData != null) { issue.setLineNumber(locationData.lineNumber); issue.setColumn(locationData.column); issue.setOffset(locationData.offset); issue.setLength(locationData.length); issue.setLineNumberEnd(locationData.lineNumberEnd); issue.setColumnEnd(locationData.columnEnd); } final EObject causer = getCauser(diagnostic); if (causer != null) issue.setUriToProblem(EcoreUtil.getURI(causer)); issue.setCode(getIssueCode(diagnostic)); issue.setType(getIssueType(diagnostic)); issue.setData(getIssueData(diagnostic)); // marker.put(IXtextResourceChecker.DIAGNOSTIC_KEY, diagnostic); issue.setMessage(diagnostic.getMessage()); // marker.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_LOW)); acceptor.accept(issue); }
Example 8
Source File: RuleOverrideUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void findOverriddenRule(AbstractRule originalRule, List<Grammar> grammars, IAcceptor<AbstractRule> acceptor) { for (Grammar grammar : grammars) { for (AbstractRule rule : grammar.getRules()) { if (rule.eClass() == originalRule.eClass() && Strings.equal(rule.getName(), originalRule.getName())) { acceptor.accept(rule); } } findOverriddenRule(originalRule, grammar.getUsedGrammars(), acceptor); } }
Example 9
Source File: N4JSResourceDescriptionStrategy.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Create EObjectDescriptions for variables for which N4JSQualifiedNameProvider provides a FQN; variables with a FQN * of <code>null</code> (currently all non-exported variables) will be ignored. */ private void internalCreateEObjectDescription(TVariable variable, IAcceptor<IEObjectDescription> acceptor) { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(variable); if (qualifiedName != null) { // e.g. non-exported variables will return null for FQN Map<String, String> userData = new HashMap<>(); addAccessModifierUserData(userData, variable.getTypeAccessModifier()); addConstUserData(userData, variable); IEObjectDescription eod = EObjectDescription.create(qualifiedName, variable, userData); acceptor.accept(eod); } }
Example 10
Source File: N4JSResourceDescriptionStrategy.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Create EObjectDescriptions for elements for which N4JSQualifiedNameProvider provides a FQN; elements with a FQN * of <code>null</code> will be ignored. */ private void internalCreateEObjectDescription(Type type, IAcceptor<IEObjectDescription> acceptor) { final String exportedName = type.getExportedName(); final String typeName = exportedName != null ? exportedName : type.getName(); if (typeName != null && typeName.length() != 0) { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type); if (qualifiedName != null) { // e.g. non-exported declared functions will return null for FQN Map<String, String> userData = new HashMap<>(); addAccessModifierUserData(userData, type.getTypeAccessModifier()); addVersionableVersion(userData, type); // Add additional user data for descriptions representing a TClass if (type instanceof TClass) { final TClass tClass = (TClass) type; addClassUserData(userData, tClass); if (N4JSLanguageConstants.EXPORT_DEFAULT_NAME.equals(tClass.getExportedName())) { userData.put(EXPORT_DEFAULT_KEY, Boolean.toString(true)); } } else if (N4JSLanguageConstants.EXPORT_DEFAULT_NAME.equals(type.getExportedName())) { userData.put(EXPORT_DEFAULT_KEY, Boolean.toString(true)); } IEObjectDescription eod = N4JSEObjectDescription.create(qualifiedName, type, userData); acceptor.accept(eod); } } }
Example 11
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) { StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend(); if (importDeclarationsToAppend.length() == 0) return; importRegion = regionUtil.addLeadingWhitespace(importRegion, resource); importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource); int insertOffset = importRegion.getOffset() + importRegion.getLength(); if (insertOffset != 0 && originalImportDeclarations.isEmpty()) importDeclarationsToAppend.insert(0, lineSeparator); importDeclarationsToAppend.append(lineSeparator); int insertLength = -importRegion.getLength(); insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength(); ReplaceRegion appendDeclarations = new ReplaceRegion(new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString()); acceptor.accept(appendDeclarations); }
Example 12
Source File: RelatedXtextResourceUpdater.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) { XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource()); if (!referenceUpdater.isAffected(deltas, getResource())) { return; } ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create(); ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base); ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter, getResource()); referenceUpdater.update(context); if (!context.getModifications().isEmpty()) { ChangeRecorder rec = createChangeRecorder(res); try { for (Runnable run : context.getModifications()) { run.run(); } ChangeDescription recording = rec.endRecording(); ResourceSet rs = res.getResourceSet(); ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording); ResourceRecording recordedResource = tree.getRecordedResource(res); if (recordedResource != null) { serializer.serializeChanges(recordedResource, rewriter); } } finally { rec.dispose(); } } for (IUpdatableReference upd : context.getUpdatableReferences()) { referenceUpdater.updateReference(rewriter, upd); } ITextRegionAccessDiff rewritten = rewriter.create(); List<ITextReplacement> rep = formatter.format(rewritten); TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep); changeAcceptor.accept(change); }
Example 13
Source File: N4JSCrossReferenceComputer.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void handleType(Resource resource, IAcceptor<EObject> acceptor, Type to) { if (to != null) { if (isLocatedInOtherResource(resource, to)) { acceptor.accept(to); } } }
Example 14
Source File: ClassFileBasedOpenerContributor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean collectGeneratedFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) { if (editor instanceof XtextEditor && editor.getEditorInput() != null) { if (Adapters.adapt(editor.getEditorInput(), IClassFile.class) != null) { acceptor.accept(createEditorOpener(editor.getEditorInput(), JavaUI.ID_CF_EDITOR)); return true; } } return false; }
Example 15
Source File: RuntimeTestSetup.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override protected void initialize(IAcceptor<PreferenceKey> iAcceptor) { super.initialize(iAcceptor); iAcceptor.accept(create(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, SeverityConverter.SEVERITY_ERROR)); iAcceptor.accept(create(org.eclipse.xtend.core.validation.IssueCodes.ORPHAN_ELEMENT, SeverityConverter.SEVERITY_WARNING)); }
Example 16
Source File: XbaseInjectorProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected void initialize(IAcceptor<PreferenceKey> iAcceptor) { super.initialize(iAcceptor); iAcceptor.accept(create(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, SeverityConverter.SEVERITY_ERROR)); }
Example 17
Source File: SharedAppendableState.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public void appendNewLineAndIndentation(IAcceptor<String> content) { content.accept(lineSeparator); for(int i = 0; i < indentationlevel; i++) { content.accept(indentation); } }
Example 18
Source File: HelloWorldConfigurableIssueCodesProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
@Override protected void initialize(IAcceptor<PreferenceKey> acceptor) { super.initialize(acceptor); acceptor.accept(create(DEPRECATED_MODEL_PART, SeverityConverter.SEVERITY_WARNING)); }
Example 19
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean validateUnhandledExceptions(JvmExecutable executable, IAcceptor<? super AbstractDiagnostic> result) { TypeParameterSubstitutor<?> substitutor = createArgumentTypeSubstitutor(); List<LightweightTypeReference> unhandledExceptions = null; List<LightweightTypeReference> expectedExceptions = getState().getExpectedExceptions(); ITypeReferenceOwner referenceOwner = getState().getReferenceOwner(); outer: for(JvmTypeReference typeReference: executable.getExceptions()) { LightweightTypeReference exception = referenceOwner.toLightweightTypeReference(typeReference); LightweightTypeReference resolvedException = substitutor.substitute(exception); if (resolvedException.isSubtypeOf(Throwable.class) && !resolvedException.isSubtypeOf(RuntimeException.class) && !resolvedException.isSubtypeOf(Error.class)) { for (LightweightTypeReference expectedException : expectedExceptions) { if (expectedException.isAssignableFrom(resolvedException)) { continue outer; } } if (unhandledExceptions == null) { unhandledExceptions = Lists.newArrayList(resolvedException); } else { unhandledExceptions.add(resolvedException); } } } if (unhandledExceptions != null) { String message = null; int count = unhandledExceptions.size(); if (count > 1) { message = String.format("Unhandled exception types %s and %s", IterableExtensions.join(unhandledExceptions.subList(0, count - 1), ", "), unhandledExceptions.get(count - 1)); } else { message = String.format("Unhandled exception type %s", unhandledExceptions.get(0).getHumanReadableName()); } String[] data = new String[unhandledExceptions.size() + 1]; for(int i = 0; i < data.length - 1; i++) { LightweightTypeReference unhandled = unhandledExceptions.get(i); data[i] = EcoreUtil.getURI(unhandled.getType()).toString(); } data[data.length - 1] = EcoreUtil.getURI(getExpression()).toString(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( getUnhandledExceptionSeverity(executable), IssueCodes.UNHANDLED_EXCEPTION, message, getExpression(), getDefaultValidationFeature(), -1, data); result.accept(diagnostic); return false; } return true; }
Example 20
Source File: XbaseInjectorProvider.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override protected void initialize(IAcceptor<PreferenceKey> iAcceptor) { super.initialize(iAcceptor); iAcceptor.accept(create(IssueCodes.SUSPICIOUSLY_OVERLOADED_FEATURE, SeverityConverter.SEVERITY_ERROR)); }