@Override public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { DartX.todo("indent"); String partitioning = getConfiguredDocumentPartitioning(sourceViewer); if (DartPartitions.DART_DOC.equals(contentType) || DartPartitions.DART_MULTI_LINE_COMMENT.equals(contentType)) { return new IAutoEditStrategy[] {new DartDocAutoIndentStrategy(partitioning)}; } else if (DartPartitions.DART_MULTI_LINE_STRING.equals(contentType)) { return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new DartStringAutoIndentStrategy(partitioning) }; } else if (DartPartitions.DART_STRING.equals(contentType)) { return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new DartStringAutoIndentStrategy(partitioning) }; } else if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new DartAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; } else { return new IAutoEditStrategy[] { new DartAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; } }
@Override public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return array(LangUIPlugin_Actual.createAutoEditStrategy(sourceViewer, contentType)); } else { return super.getAutoEditStrategies(sourceViewer, contentType); } }
protected boolean isComment(int offset) { if (IDocument.DEFAULT_CONTENT_TYPE.equals(fContentType)) { return false; } if (fContentType.contains("_comment")) // $NON-NLS-1$ { return true; } // TODO Check the scope? return false; }
/* * (non-Javadoc) * * @see * com.aptana.editor.common.CompositeSubPartitionScanner#setLastToken(org * .eclipse.jface.text.rules.IToken) */ @Override public void setLastToken(IToken token) { super.setLastToken(token); if (token == null) { return; } if (!(token.getData() instanceof String)) { current = TYPE_DEFAULT; return; } String contentType = (String) token.getData(); if (HTMLSourceConfiguration.HTML_SCRIPT.equals(contentType) || SVGSourceConfiguration.SCRIPT.equals(contentType)) { if (!(token instanceof ExtendedToken && ((HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents())) || !HTMLUtils.isJavaScriptTag(((ExtendedToken) token).getContents())))) { current = TYPE_JS; super.setLastToken(null); } } else if (HTMLSourceConfiguration.HTML_STYLE.equals(contentType) || SVGSourceConfiguration.STYLE.equals(contentType)) { if (!(token instanceof ExtendedToken && HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents()))) { current = TYPE_CSS; super.setLastToken(null); } } else if (HTMLSourceConfiguration.HTML_SVG.equals(contentType)) { if (!(token instanceof ExtendedToken && HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents()))) { current = TYPE_SVG; super.setLastToken(null); } } else if (HTMLSourceConfiguration.DEFAULT.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { current = TYPE_DEFAULT; } else { for (int i = 0; i < subPartitionScanners.length; ++i) { if (subPartitionScanners[i].hasContentType(contentType)) { current = i; break; } } } }
/** * @param contentType * @return */ public ITokenScanner getScannerForContentType(String contentType) { if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return getLanguage() != null ? getCodeScanner(getLanguage()) : null; } else if (ICPartitions.C_CHARACTER.equals(contentType)) { return getStringScanner(); } else if (ICPartitions.C_STRING.equals(contentType)) { return getStringScanner(); } else if (ICPartitions.C_SINGLE_LINE_COMMENT.equals(contentType)) { return getSinglelineCommentScanner(); } else if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(contentType)) { return getSinglelineDocCommentScanner(getProject()); } else if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType)) { return getMultilineCommentScanner(); } else if (ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(contentType)) { return getMultilineDocCommentScanner(getProject()); } else if (ICPartitions.C_PREPROCESSOR.equals(contentType)) { return getPreprocessorScanner(getLanguage()); } return null; }
/* * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String) */ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { String partitioning = getConfiguredDocumentPartitioning(sourceViewer); if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)) return new IAutoEditStrategy[] {new JavaDocAutoIndentStrategy(partitioning)}; else if (IJavaPartitions.JAVA_STRING.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning) }; else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; else return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; }
@Override public IAutoEditStrategy[] getAutoEditStrategies( final ISourceViewer aSourceViewer, final String aContentType) { if (pAutoEditIndent == null) { pAutoEditIndent = new DefaultIndentLineAutoEditStrategy(); } if (pAutoEditLineWrap == null) { int maxLineLength = LineWrapUtil.get().getMaxLineLength(); pAutoEditLineWrap = new HardLineWrapAutoEdit(RestPartitionScanner.PARTITIONING, maxLineLength); } List<IAutoEditStrategy> strategies = new ArrayList<IAutoEditStrategy>(); strategies.add(pAutoEditIndent); // Only enable line wrapping in "default text" if (LineWrapUtil.get().isWrappingEnabled() && IDocument.DEFAULT_CONTENT_TYPE.equals(aContentType)) { strategies.add(pAutoEditLineWrap); } if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_TABS_TO_SPACES)) { // Automatic tabs to space conversion if (pAutoEditTabsToSpace == null) { pAutoEditTabsToSpace = new TabsToSpacesConverter(); pAutoEditTabsToSpace.setNumberOfSpacesPerTab(getTabWidth(aSourceViewer)); pAutoEditTabsToSpace.setLineTracker(new DefaultLineTracker()); } strategies.add(pAutoEditTabsToSpace); } return strategies.toArray(new IAutoEditStrategy[0]); }
/** * Returns a segmentation of the line of the given document appropriate for Bidi rendering. * * @param document the document * @param baseLevel the base level of the line * @param lineStart the offset of the line * @param lineText Text of the line to retrieve Bidi segments for * @return the line's Bidi segmentation * @throws BadLocationException in case lineOffset is not valid in document */ protected static int[] getBidiLineSegments( IDocument document, int baseLevel, int lineStart, String lineText) throws BadLocationException { if (lineText == null || document == null) return null; int lineLength = lineText.length(); if (lineLength <= 2) return null; // Have ICU compute embedding levels. Consume these levels to reduce // the Bidi impact, by creating selective segments (preceding // character runs with a level mismatching the base level). // XXX: Alternatively, we could apply TextLayout. Pros would be full // synchronization with the underlying StyledText's (i.e. native) Bidi // implementation. Cons are performance penalty because of // unavailability of such methods as isLeftToRight and getLevels. Bidi bidi = new Bidi(lineText, baseLevel); if (bidi.isLeftToRight()) // Bail out if this is not Bidi text. return null; IRegion line = document.getLineInformationOfOffset(lineStart); ITypedRegion[] linePartitioning = TextUtilities.computePartitioning( document, IJavaPartitions.JAVA_PARTITIONING, lineStart, line.getLength(), false); if (linePartitioning == null || linePartitioning.length < 1) return null; int segmentIndex = 1; int[] segments = new int[lineLength + 1]; byte[] levels = bidi.getLevels(); int nPartitions = linePartitioning.length; for (int partitionIndex = 0; partitionIndex < nPartitions; partitionIndex++) { ITypedRegion partition = linePartitioning[partitionIndex]; int lineOffset = partition.getOffset() - lineStart; // Assert.isTrue(lineOffset >= 0 && lineOffset < lineLength); if (lineOffset > 0 && isMismatchingLevel(levels[lineOffset], baseLevel) && isMismatchingLevel(levels[lineOffset - 1], baseLevel)) { // Indicate a Bidi segment at the partition start - provided // levels of both character at the current offset and its // preceding character mismatch the base paragraph level. // Partition end will be covered either by the start of the next // partition, a delimiter inside a next partition, or end of line. segments[segmentIndex++] = lineOffset; } if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) { int partitionEnd = Math.min(lineLength, lineOffset + partition.getLength()); while (++lineOffset < partitionEnd) { if (isMismatchingLevel(levels[lineOffset], baseLevel) && String.valueOf(lineText.charAt(lineOffset)).matches(BIDI_DELIMITERS)) { // For default content types, indicate a segment before // a delimiting character with a mismatching embedding // level. segments[segmentIndex++] = lineOffset; } } } } if (segmentIndex <= 1) return null; segments[0] = 0; if (segments[segmentIndex - 1] != lineLength) segments[segmentIndex++] = lineLength; if (segmentIndex == segments.length) return segments; int[] newSegments = new int[segmentIndex]; System.arraycopy(segments, 0, newSegments, 0, segmentIndex); return newSegments; }
protected void assertContentAssistResults( int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, boolean filterResults, int compareType) throws Exception { if (CTestPlugin.getDefault().isDebugging()) { System.out.println("\n\n\n\n\nTesting " + this.getClass().getName()); } // Call the CContentAssistProcessor ISourceViewer sourceViewer = EditorTestHelper.getSourceViewer((AbstractTextEditor) fEditor); String contentType = TextUtilities.getContentType( sourceViewer.getDocument(), ICPartitions.C_PARTITIONING, offset, true); boolean isCode = IDocument.DEFAULT_CONTENT_TYPE.equals(contentType); ContentAssistant assistant = new ContentAssistant(); CContentAssistProcessor processor = new CContentAssistProcessor(fEditor, assistant, contentType); long startTime = System.currentTimeMillis(); sourceViewer.setSelectedRange(offset, length); Object[] results = isCompletion ? (Object[]) processor.computeCompletionProposals(sourceViewer, offset) : (Object[]) processor.computeContextInformation(sourceViewer, offset); long endTime = System.currentTimeMillis(); assertTrue(results != null); if (filterResults) { if (isTemplate) { results = filterResultsKeepTemplates(results); } else { results = filterResults(results, isCode); } } String[] resultStrings = toStringArray(results, compareType); Arrays.sort(expected); Arrays.sort(resultStrings); if (CTestPlugin.getDefault().isDebugging()) { System.out.println("Time (ms): " + (endTime - startTime)); for (String proposal : resultStrings) { System.out.println("Result: " + proposal); } } boolean allFound = true; // for the time being, let's be optimistic for (String element : expected) { boolean found = false; for (String proposal : resultStrings) { if (element.equals(proposal)) { found = true; if (CTestPlugin.getDefault().isDebugging()) { System.out.println("Lookup success for " + element); } break; } } if (!found) { allFound = false; if (CTestPlugin.getDefault().isDebugging()) { System.out.println("Lookup failed for " + element); // $NON-NLS-1$ } } } if (!allFound) { assertEquals("Missing results!", toString(expected), toString(resultStrings)); } else if (doCheckExtraResults()) { assertEquals("Extra results!", toString(expected), toString(resultStrings)); } }