Java Code Examples for org.eclipse.jface.text.Region
The following examples show how to use
org.eclipse.jface.text.Region. These examples are extracted from open source projects.
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 Project: tlaplus Source File: TLAEditor.java License: MIT License | 6 votes |
public void selectAndReveal(final pcal.Region aRegion) throws BadLocationException { final IDocument document = getDocumentProvider().getDocument( getEditorInput()); // Translate pcal.Region coordinates into Java IDocument coordinates final PCalLocation begin = aRegion.getBegin(); final int startLineOffset = document.getLineOffset(begin.getLine()); final int startOffset = startLineOffset + begin.getColumn(); final PCalLocation end = aRegion.getEnd(); final int endLineOffset = document.getLineOffset(end.getLine()); final int endOffset = endLineOffset + end.getColumn(); final int length = endOffset - startOffset; selectAndReveal(startOffset, length); }
Example 2
Source Project: texlipse Source File: TexlipseAnnotationUpdater.java License: Eclipse Public License 1.0 | 6 votes |
/** * Creates and returns a background job which searches and highlights all \label and \*ref. * @param document * @param model * @param refName The name of the reference * @return The job */ private Job createMatchReferenceJob(final IDocument document, final IAnnotationModel model, final String refName) { return new Job("Update Annotations") { public IStatus run(IProgressMonitor monitor) { String text = document.get(); String refNameRegExp = refName.replaceAll("\\*", "\\\\*"); final String simpleRefRegExp = "\\\\([a-zA-Z]*ref|label)\\s*\\{" + refNameRegExp + "\\}"; Matcher m = (Pattern.compile(simpleRefRegExp)).matcher(text); while (m.find()) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; IRegion match = LatexParserUtils.getCommand(text, m.start()); //Test if it is a real LaTeX command if (match != null) { IRegion fi = new Region(m.start(), m.end()-m.start()); createNewAnnotation(fi, "References", model); } } return Status.OK_STATUS; } }; }
Example 3
Source Project: solidity-ide Source File: SolidityHyperlinkHelper.java License: Eclipse Public License 1.0 | 6 votes |
protected void createImportedNamespacesHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { INode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset); if (node != null) { List<INode> importNodes = NodeModelUtils.findNodesForFeature(node.getSemanticElement(), SolidityPackage.Literals.IMPORT_DIRECTIVE__IMPORTED_NAMESPACE); if (importNodes != null && !importNodes.isEmpty()) { for (INode importNode : importNodes) { ImportDirective importElement = (ImportDirective) importNode.getSemanticElement(); URI targetURI = getFileURIOfImport(importElement); XtextHyperlink result = getHyperlinkProvider().get(); result.setURI(targetURI); Region region = new Region(importNode.getOffset(), importNode.getLength()); result.setHyperlinkRegion(region); result.setHyperlinkText(targetURI.toString()); acceptor.accept(result); } } } }
Example 4
Source Project: xtext-eclipse Source File: QuickTypeHierarchyHandler.java License: Eclipse Public License 2.0 | 6 votes |
@Override protected void openPresentation(final XtextEditor editor, final IJavaElement javaElement, final EObject selectedElement) { final ISourceViewer sourceViewer = editor.getInternalSourceViewer(); ITextRegion significantTextRegion = locationInFileProvider.getSignificantTextRegion(selectedElement); InformationPresenter presenter = new HierarchyInformationPresenter(sourceViewer, javaElement, new Region(significantTextRegion.getOffset(),significantTextRegion.getLength())); presenter.setDocumentPartitioning(IDocumentExtension3.DEFAULT_PARTITIONING); presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL); IInformationProvider provider = new JavaElementProvider(editor, false); presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE); presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC); presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_COMMENT); presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT); presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING); presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER); presenter.setSizeConstraints(50, 20, true, false); presenter.install(sourceViewer); presenter.showInformation(); }
Example 5
Source Project: Eclipse-Postfix-Code-Completion Source File: PartitionDoubleClickSelector.java License: Eclipse Public License 1.0 | 6 votes |
@Override protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) { IRegion match= super.findExtendedDoubleClickSelection(document, offset); if (match != null) return match; try { ITypedRegion region= TextUtilities.getPartition(document, fPartitioning, offset, true); if (offset == region.getOffset() + fHitDelta || offset == region.getOffset() + region.getLength() - fHitDelta) { if (fLeftBorder == 0 && fRightBorder == 0) return region; if (fRightBorder == -1) { String delimiter= document.getLineDelimiter(document.getLineOfOffset(region.getOffset() + region.getLength() - 1)); if (delimiter == null) fRightBorder= 0; else fRightBorder= delimiter.length(); } return new Region(region.getOffset() + fLeftBorder, region.getLength() - fLeftBorder - fRightBorder); } } catch (BadLocationException e) { return null; } return null; }
Example 6
Source Project: texlipse Source File: LatexParserUtils.java License: Eclipse Public License 1.0 | 6 votes |
private static IRegion findEnvironment(String input, String envName, String command, int fromIndex) { int pos = input.indexOf("{" + envName + "}", fromIndex + command.length()); while (pos != -1) { int end = pos + envName.length() + 2; // Search for the command int beginStart = findLastCommand(input, command, pos); if (beginStart != -1 && beginStart >= fromIndex) { // Check for whitespaces between \begin and {...} while (pos != beginStart + command.length() && Character.isWhitespace(input.charAt(--pos))) ; if (pos == beginStart + command.length()) { return new Region(beginStart, end - beginStart); } } pos = input.indexOf("{" + envName + "}", pos + envName.length() + 2); } return null; }
Example 7
Source Project: xtext-eclipse Source File: AbstractCompositeHoverTest.java License: Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testEmptyHoverList () { AbstractCompositeHover hover = new AbstractCompositeHover() { @Override protected List<ITextHover> createHovers() { List<ITextHover> hovers = Lists.newArrayList(); return hovers; } }; assertEquals (0, hover.getHovers().size()); assertNull (hover.getHoverRegion(editor.getInternalSourceViewer(), 0)); assertNull (hover.getHoverControlCreator()); assertNull (hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0,0))); assertNull (hover.getHoverInfo2(editor.getInternalSourceViewer(), new Region(0,0))); }
Example 8
Source Project: APICloud-Studio Source File: Regions.java License: GNU General Public License v3.0 | 6 votes |
private static IRegion intersection(IRegion o1, IRegion o2) { int offset1 = o1.getOffset(); int offset2 = o2.getOffset(); int offset = Math.max(offset1, offset2); int length = Math.min(offset1 + o1.getLength(), offset2 + o2.getLength()) - offset; if (length <= 0) { return null; } if (offset == offset1 && length == o1.getLength()) { return o1; } if (offset == offset2 && length == o2.getLength()) { return o2; } return new Region(offset, length); }
Example 9
Source Project: Pydev Source File: ScopeSelectionAction.java License: Eclipse Public License 1.0 | 6 votes |
public void perform(IDocument doc, ICoreTextSelection selection, BaseEditor editor) { FastStack<IRegion> cache = getCache(editor); Region initialRegion = new Region(selection.getOffset(), selection.getLength()); if (cache.size() > 0) { IRegion peek = cache.peek(); if (!peek.equals(initialRegion)) { cache.clear(); } } if (cache.size() == 0) { cache.push(initialRegion); } ICoreTextSelection newSelection = getNewSelection(doc, selection, editor); if (initialRegion.equals(new Region(newSelection.getOffset(), newSelection.getLength()))) { return; } editor.setSelection(newSelection.getOffset(), newSelection.getLength()); cache.push(new Region(newSelection.getOffset(), newSelection.getLength())); }
Example 10
Source Project: gwt-eclipse-plugin Source File: XmlUtilities.java License: Eclipse Public License 1.0 | 6 votes |
/** * Gets a region for the attribute's value (without the quotes). */ public static IRegion getAttributeValueRegion(IDOMAttr attribute) { String attrValue = attribute.getValueRegionText(); if (attrValue == null) { return null; } int offset = attribute.getValueRegionStartOffset(); int length = attrValue.length(); // Strip off the quotes if (isXmlQuote(attrValue.charAt(0))) { offset++; length--; } if (isXmlQuote(attrValue.charAt(attrValue.length() - 1))) { length--; } return new Region(offset, length); }
Example 11
Source Project: APICloud-Studio Source File: OpenDeclarationAction.java License: GNU General Public License v3.0 | 6 votes |
/** * Open the declaration if possible. */ @Override public void run() { ITextEditor textEditor = getTextEditor(); if (textEditor instanceof JSSourceEditor) { ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection(); IRegion region = new Region(selection.getOffset(), 1); JSHyperlinkDetector detector = new JSHyperlinkDetector(); IHyperlink[] hyperlinks = detector.detectHyperlinks((AbstractThemeableEditor) textEditor, region, true); if (!ArrayUtil.isEmpty(hyperlinks)) { // give first link highest precedence hyperlinks[0].open(); } } }
Example 12
Source Project: APICloud-Studio Source File: ExcludeRegionList.java License: GNU General Public License v3.0 | 6 votes |
public IRegion[] selectValidRanges(int start, int end) { final List<Region> result = new ArrayList<Region>(); for (final IRegion region : excludes) { final int regionEnd = region.getOffset() + region.getLength(); if (start <= regionEnd && region.getOffset() <= end) { if (start < region.getOffset()) { int validEnd = Math.min(end, region.getOffset()); result.add(new Region(start, validEnd - start)); } start = regionEnd; if (start > end) { break; } } } if (start < end) { result.add(new Region(start, end - start)); } return result.toArray(new IRegion[result.size()]); }
Example 13
Source Project: APICloud-Studio Source File: CSSTextHover.java License: GNU General Public License v3.0 | 6 votes |
private RegionInfo getColorRegionInfo(CSSNode cssNode) { if (cssNode == null) { return null; } String text = cssNode.getText(); if (StringUtil.isEmpty(text)) { return null; } IRegion region = new Region(cssNode.getStartingOffset(), cssNode.getLength()); if (text.charAt(0) == '#') { return new RegionInfo(region, CSSColorsUI.hexToRGB(text)); } else if (CSSColors.namedColorExists(text)) { return new RegionInfo(region, CSSColorsUI.namedColorToRGB(text)); } return new RegionInfo(region, text); }
Example 14
Source Project: xtext-eclipse Source File: OpenDeclarationHandler.java License: Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); IRegion region = new Region(selection.getOffset(), selection.getLength()); ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer(); IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false); if (hyperlinks != null && hyperlinks.length > 0) { IHyperlink hyperlink = hyperlinks[0]; hyperlink.open(); } } return null; }
Example 15
Source Project: Eclipse-Postfix-Code-Completion Source File: NLSStringHover.java License: Eclipse Public License 1.0 | 6 votes |
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { if (!(getEditor() instanceof JavaEditor)) return null; ITypeRoot je= getEditorInputJavaElement(); if (je == null) return null; // Never wait for an AST in UI thread. CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null); if (ast == null) return null; ASTNode node= NodeFinder.perform(ast, offset, 1); if (node instanceof StringLiteral) { StringLiteral stringLiteral= (StringLiteral)node; return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength()); } else if (node instanceof SimpleName) { SimpleName simpleName= (SimpleName)node; return new Region(simpleName.getStartPosition(), simpleName.getLength()); } return null; }
Example 16
Source Project: xtext-eclipse Source File: DocumentUtil.java License: Eclipse Public License 2.0 | 6 votes |
/** * searches backwards for the given string within the same partition type * @return the region of the match or <code>null</code> if no match were found * @since 2.4 */ public IRegion searchBackwardsInSamePartition(String toFind, String documentText, IDocument document, int endOffset) throws BadLocationException { if (endOffset < 0) { return null; } int length = toFind.length(); String text = preProcessSearchString(documentText); ITypedRegion partition = document.getPartition(endOffset); int indexOf = text.lastIndexOf(toFind, endOffset - length); while (indexOf >= 0) { ITypedRegion partition2 = document.getPartition(indexOf); if (partition2.getType().equals(partition.getType())) { return new Region(indexOf, length); } indexOf = text.lastIndexOf(toFind, partition2.getOffset() - length); } String trimmed = toFind.trim(); if (trimmed.length() > 0 && trimmed.length() != length) { return searchBackwardsInSamePartition(trimmed, documentText, document, endOffset); } return null; }
Example 17
Source Project: e4macs Source File: SexpCharacterPairMatcher.java License: Eclipse Public License 1.0 | 6 votes |
protected synchronized IRegion performMatch(IDocument doc, int caretOffset) throws BadLocationException { int charOffset = caretOffset - 1; boolean forward = fPairs.isStartCharacter(doc.getChar(charOffset)); // simple documents (e.g. .txt) don't have type categories if (EmacsPlusUtils.getTypeCategory(doc) != null) { exPositions = EmacsPlusUtils.getExclusions(doc, EmacsPlusUtils.ALL_POS); // remember category position if first character is in a comment or string exPosition = EmacsPlusUtils.inPosition(doc, exPositions, charOffset); } IRegion reg = super.performMatch(doc, caretOffset); // if we started in a category position, make sure we end in the same one if (reg == null || (exPosition != null && !exPosition.includes(forward ? reg.getOffset() + reg.getLength() : reg.getOffset()))) { return new Region(charOffset, 1); } return reg; }
Example 18
Source Project: gama Source File: GamlEditor.java License: GNU General Public License v3.0 | 5 votes |
public void applyTemplate(final Template t) { // TODO Create a specific context type (with GAML specific variables ??) final XtextTemplateContextType ct = new XtextTemplateContextType(); final IDocument doc = getDocument(); final ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection(); final int offset = selection.getOffset(); final int length = selection.getLength(); final Position pos = new Position(offset, length); final DocumentTemplateContext dtc = new DocumentTemplateContext(ct, doc, pos); final IRegion r = new Region(offset, length); final TemplateProposal tp = new TemplateProposal(t, dtc, r, null); tp.apply(getInternalSourceViewer(), (char) 0, 0, offset); }
Example 19
Source Project: tlaplus Source File: DocumentHelper.java License: MIT License | 5 votes |
/** * At a given position in text retrieves the region marking the word, starting before and ending on current position * @param document document * @param documentOffset offset (position of the cursor) * @param detector for identification of words * @return a region expanded backwards */ public static IRegion getRegionExpandedBackwards(IDocument document, int documentOffset, IWordDetector detector) { // Use string buffer to collect characters int charCounter = 0; while (true) { try { // Read character backwards char c = document.getChar(--documentOffset); // This was the start of a word if (!detector.isWordPart(c)) break; // Count character charCounter++; } catch (BadLocationException e) { // Document start reached, no word break; } } return new Region(documentOffset + 1, charCounter); }
Example 20
Source Project: Eclipse-Postfix-Code-Completion Source File: JavaElementProvider.java License: Eclipse Public License 1.0 | 5 votes |
public IRegion getSubject(ITextViewer textViewer, int offset) { if (textViewer != null && fEditor != null) { IRegion region= JavaWordFinder.findWord(textViewer.getDocument(), offset); if (region != null) return region; else return new Region(offset, 0); } return null; }
Example 21
Source Project: Eclipse-Postfix-Code-Completion Source File: ImportReferencesCollector.java License: Eclipse Public License 1.0 | 5 votes |
private ImportReferencesCollector(IJavaProject project, CompilationUnit astRoot, Region rangeLimit, boolean skipMethodBodies, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) { super(processJavadocComments(astRoot)); fTypeImports= resultingTypeImports; fStaticImports= resultingStaticImports; fSubRange= rangeLimit; if (project == null || !JavaModelUtil.is50OrHigher(project)) { fStaticImports= null; // do not collect } fASTRoot= astRoot; // can be null fSkipMethodBodies= skipMethodBodies; }
Example 22
Source Project: Eclipse-Postfix-Code-Completion Source File: NLSKeyHyperlinkDetector.java License: Eclipse Public License 1.0 | 5 votes |
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class); if (region == null || textEditor == null) return null; IEditorSite site= textEditor.getEditorSite(); if (site == null) return null; ITypeRoot javaElement= getInputJavaElement(textEditor); if (javaElement == null) return null; CompilationUnit ast= SharedASTProvider.getAST(javaElement, SharedASTProvider.WAIT_NO, null); if (ast == null) return null; ASTNode node= NodeFinder.perform(ast, region.getOffset(), 1); if (!(node instanceof StringLiteral) && !(node instanceof SimpleName)) return null; if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) return null; IRegion nlsKeyRegion= new Region(node.getStartPosition(), node.getLength()); AccessorClassReference ref= NLSHintHelper.getAccessorClassReference(ast, nlsKeyRegion); if (ref == null) return null; String keyName= null; if (node instanceof StringLiteral) { keyName= ((StringLiteral)node).getLiteralValue(); } else { keyName= ((SimpleName)node).getIdentifier(); } if (keyName != null) return new IHyperlink[] {new NLSKeyHyperlink(nlsKeyRegion, keyName, ref, textEditor)}; return null; }
Example 23
Source Project: texlipse Source File: TexHover.java License: Eclipse Public License 1.0 | 5 votes |
public IRegion getHoverRegion(ITextViewer textViewer, int offset) { try { // Extract current line int lineNr = textViewer.getDocument().getLineOfOffset(offset); int lOffset = textViewer.getDocument().getLineOffset(lineNr); String line = textViewer.getDocument().get(lOffset, textViewer.getDocument().getLineLength(lineNr)); int start = offset - lOffset; IRegion r = LatexParserUtils.getCommand(line, start); if (r == null) return new Region(offset, 0); IRegion rArg = LatexParserUtils.getCommandArgument(line, r.getOffset()); if (rArg == null) return new Region(lOffset + r.getOffset(), r.getLength()); String command = line.substring(r.getOffset()+1, r.getOffset() + r.getLength()); if (command.indexOf("cite") >= 0 && start > r.getOffset() + r.getLength()) { //Return only the citation entry, not the full command string int cEnd = rArg.getOffset() + rArg.getLength(); int regionStart = line.lastIndexOf(',', start) < line.lastIndexOf('{', start) ? line.lastIndexOf('{', start) + 1 : line.lastIndexOf(',', start) + 1; int lastComma = line.indexOf(',', start); if (lastComma >= 0 && lastComma < cEnd) { return new Region(lOffset + regionStart, lastComma - regionStart); } else { return new Region(lOffset + regionStart, cEnd - regionStart); } } int length = rArg.getOffset() - r.getOffset() + rArg.getLength() + 1; return new Region(lOffset + r.getOffset(), length); } catch (BadLocationException ex) { return new Region(offset, 0); } }
Example 24
Source Project: birt Source File: NonRuleBasedDamagerRepairer.java License: Eclipse Public License 1.0 | 5 votes |
/** * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, * boolean) */ public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged ) { if ( !documentPartitioningChanged ) { try { IRegion info = fDocument.getLineInformationOfOffset( event.getOffset( ) ); int start = Math.max( partition.getOffset( ), info.getOffset( ) ); int end = event.getOffset( ) + ( event.getText( ) == null ? event.getLength( ) : event.getText( ).length( ) ); if ( info.getOffset( ) <= end && end <= info.getOffset( ) + info.getLength( ) ) { // optimize the case of the same line end = info.getOffset( ) + info.getLength( ); } else { end = endOfLineOf( end ); } end = Math.min( partition.getOffset( ) + partition.getLength( ), end ); return new Region( start, end - start ); } catch ( BadLocationException x ) { } } return partition; }
Example 25
Source Project: tlaplus Source File: DocumentHelper.java License: MIT License | 5 votes |
/** * Converts four-int-location that is 1-based to a two int {@link IRegion} that is * 0-based. * * TODO: unit test! * @param document * @param location * @return * @throws BadLocationException * @deprecated use {@link AdapterFactory#locationToRegion(IDocument, Location)} instead */ public static IRegion locationToRegion(IDocument document, Location location) throws BadLocationException { /* * The coordinates returned by location are 1-based and the coordinates * for a region in a document should be 0-based to be consistent with Positions * in documents. Therefore, we subtract 1 from each location coordinate. */ int offset = document.getLineOffset(location.beginLine() - 1) + location.beginColumn() - 1; /* * If location describes a two-character sequence beginning at column x, then it would * have location.endColumn() = x+1. This means that when computing the length, we add 1 to * the offset of the second point described by location. In other words, the offset of the * second point described by location is: * * document.getLineOffset(location.endLine() - 1) + location.endColumn()-1 * * So the length is: * * (document.getLineOffset(location.endLine() - 1) + location.endColumn()-1)+1 - offset * * which equals: * * document.getLineOffset(location.endLine() - 1) + location.endColumn() - offset */ int length = document.getLineOffset(location.endLine() - 1) + location.endColumn() - offset; return new Region(offset, length); }
Example 26
Source Project: xtext-eclipse Source File: ProblemHoverTest.java License: Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test public void testAnnotations () { assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(34, 1))); assertEquals("Couldn't resolve reference to Stuff '_mystuff'.", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(35, 7))); //The order of annotations in the annotation model is not stable final String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 1); String expected1 = "Multiple markers at this line\n"; String expected2 = "- Couldn't resolve reference to Stuff '_mystuff'."; String expected3 = "- Couldn't resolve reference to Stuff '_yourstuff'."; assertTrue(hoverInfo.startsWith(expected1)); assertTrue(hoverInfo.contains(expected2)); assertTrue(hoverInfo.contains(expected3)); }
Example 27
Source Project: xtext-eclipse Source File: AnnotationWithQuickFixesHoverTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void testAnnotations() { AnnotationWithQuickFixesHover.AnnotationInfo info = (AnnotationInfo) hover.getHoverInfo2( editor.getInternalSourceViewer(), new Region(modelAsText.indexOf("_mystuff"), 1)); assertNotNull(info); assertNotNull(info.annotation); assertEquals(3, info.getCompletionProposals().length); }
Example 28
Source Project: xtext-eclipse Source File: XtextProposalProvider.java License: Eclipse Public License 2.0 | 5 votes |
@Override public void completeTypeRef_Classifier(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Grammar grammar = GrammarUtil.getGrammar(model); ContentAssistContext.Builder myContextBuilder = context.copy(); myContextBuilder.setMatcher(new ClassifierPrefixMatcher(context.getMatcher(), classifierQualifiedNameConverter)); if (model instanceof TypeRef) { ICompositeNode node = NodeModelUtils.getNode(model); if (node != null) { int offset = node.getOffset(); Region replaceRegion = new Region(offset, context.getReplaceRegion().getLength() + context.getReplaceRegion().getOffset() - offset); myContextBuilder.setReplaceRegion(replaceRegion); myContextBuilder.setLastCompleteNode(node); StringBuilder availablePrefix = new StringBuilder(4); for (ILeafNode leaf : node.getLeafNodes()) { if (leaf.getGrammarElement() != null && !leaf.isHidden()) { if ((leaf.getTotalLength() + leaf.getTotalOffset()) < context.getOffset()) availablePrefix.append(leaf.getText()); else availablePrefix.append(leaf.getText().substring(0, context.getOffset() - leaf.getTotalOffset())); } if (leaf.getTotalOffset() >= context.getOffset()) break; } myContextBuilder.setPrefix(availablePrefix.toString()); } } ContentAssistContext myContext = myContextBuilder.toContext(); for (AbstractMetamodelDeclaration declaration : grammar.getMetamodelDeclarations()) { if (declaration.getEPackage() != null) { createClassifierProposals(declaration, model, myContext, acceptor); } } }
Example 29
Source Project: tlaplus Source File: TLAEditor.java License: MIT License | 5 votes |
public void gotoMarker(final IMarker marker) { // if the given marker happens to be of instance TLAtoPCalMarker, it // indicates that the user wants to go to the PCal equivalent of the // current TLA+ marker if (marker instanceof TLAtoPCalMarker) { final TLAtoPCalMarker tlaToPCalMarker = (TLAtoPCalMarker) marker; try { final pcal.Region region = tlaToPCalMarker.getRegion(); if (region != null) { selectAndReveal(region); return; } else { UIHelper.setStatusLineMessage("No valid TLA to PCal mapping found for current selection"); } } catch (BadLocationException e) { // not expected to happen e.printStackTrace(); } } // fall back to original marker if the TLAtoPCalMarker didn't work or no TLAtoPCalMarker // N.B even though this is marked deprecated, the recommended replacement of: // ((IGotoMarker)getAdapter(IGotoMarker.class)).gotoMarker(marker); // causes a stack overflow. // See: https://github.com/tlaplus/tlaplus/commit/28f6e2cf6328b84027762e828fb2f741b1a25377#r35904992 super.gotoMarker(marker); }
Example 30
Source Project: Pydev Source File: PyStringCodeCompletion.java License: Eclipse Public License 1.0 | 5 votes |
/** * @param ret OUT: this is where the completions are stored */ private void fillWithEpydocFields(CompletionRequest request, List<ICompletionProposalHandle> ret) { try { Region region = new Region(request.documentOffset - request.qlen, request.qlen); IImageHandle image = PyCodeCompletionImages.getImageForType(IToken.TYPE_EPYDOC); TemplateContext context = createContext(region, request.doc); char c = request.doc.getChar(request.documentOffset - request.qualifier.length() - 1); boolean createFields = c == '@' || c == ':'; if (createFields) { String lineContentsToCursor = PySelection.getLineContentsToCursor(request.doc, request.documentOffset - request.qualifier.length() - 1); if (lineContentsToCursor.trim().length() != 0) { //Only create if @param or :param is the first thing in the line. createFields = false; } } if (createFields) { //ok, looking for epydoc filters for (int i = 0; i < EPYDOC_FIELDS.length; i++) { String f = EPYDOC_FIELDS[i]; if (f.startsWith(request.qualifier)) { Template t = new Template(f, EPYDOC_FIELDS[i + 2], "", EPYDOC_FIELDS[i + 1], false); ret.add( CompletionProposalFactory.get().createPyTemplateProposalForTests( t, context, region, image, 5)); } i += 2; } } } catch (BadLocationException e) { //just ignore it } }