Java Code Examples for org.eclipse.jdt.internal.corext.util.Strings#convertIntoLines()
The following examples show how to use
org.eclipse.jdt.internal.corext.util.Strings#convertIntoLines() .
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: SourceProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String[] getBlocks(RangeMarker[] markers) throws BadLocationException { String[] result= new String[markers.length]; for (int i= 0; i < markers.length; i++) { RangeMarker marker= markers[i]; String content= fDocument.get(marker.getOffset(), marker.getLength()); String lines[]= Strings.convertIntoLines(content); Strings.trimIndentation(lines, fTypeRoot.getJavaProject(), false); if (fMarkerMode == STATEMENT_MODE && lines.length == 2 && isSingleControlStatementWithoutBlock()) { lines[1]= CodeFormatterUtil.createIndentString(1, fTypeRoot.getJavaProject()) + lines[1]; } result[i]= Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(fDocument)); } return result; }
Example 2
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
Example 3
Source File: PullUpMethodPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void setSourceViewerContents(String contents) { if (contents != null) { final IJavaProject project= fProcessor.getDestinationType().getJavaProject(); final String[] lines= Strings.convertIntoLines(contents); if (lines.length > 0) { final int indent= Strings.computeIndentUnits(lines[lines.length - 1], project); contents= Strings.changeIndent(contents, indent, project, "", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } } final IDocument document= (contents == null) ? new Document() : new Document(contents); JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document); fSourceViewer.setDocument(document); }
Example 4
Source File: JavaSourceHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the trimmed source lines. * * @param source the source string, could be <code>null</code> * @param javaElement the java element * @return the trimmed source lines or <code>null</code> */ private String[] getTrimmedSource(String source, IJavaElement javaElement) { if (source == null) return null; source= removeLeadingComments(source); String[] sourceLines= Strings.convertIntoLines(source); Strings.trimIndentation(sourceLines, javaElement.getJavaProject()); return sourceLines; }
Example 5
Source File: JavaHistoryActionImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static String trimTextBlock(String content, String delimiter, IJavaProject currentProject) { if (content != null) { String[] lines= Strings.convertIntoLines(content); if (lines != null) { Strings.trimIndentation(lines, currentProject); return Strings.concatenate(lines, delimiter); } } return null; }
Example 6
Source File: HierarchyProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected static String getUnindentedText(final String text, final ICompilationUnit declaringCu) throws JavaModelException { final String[] lines= Strings.convertIntoLines(text); Strings.trimIndentation(lines, declaringCu.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(declaringCu)); }
Example 7
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private String getAlignedSourceBlock(final ICompilationUnit unit, final String block) { Assert.isNotNull(block); final String[] lines= Strings.convertIntoLines(block); Strings.trimIndentation(lines, unit.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(fType.getJavaProject())); }
Example 8
Source File: SourceView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected Object computeInput(Object input) { if (fViewer == null || !(input instanceof ISourceReference)) return null; ISourceReference sourceRef= (ISourceReference)input; if (fLastOpenedElement != null && input instanceof IJavaElement && ((IJavaElement)input).getHandleIdentifier().equals(fLastOpenedElement.getHandleIdentifier())) { fLastOpenedElement= null; return null; } else { fLastOpenedElement= null; } String source; try { source= sourceRef.getSource(); } catch (JavaModelException ex) { return ""; //$NON-NLS-1$ } if (source == null) return ""; //$NON-NLS-1$ source= removeLeadingComments(source); String delim= StubUtility.getLineDelimiterUsed((IJavaElement) input); String[] sourceLines= Strings.convertIntoLines(source); if (sourceLines == null || sourceLines.length == 0) return ""; //$NON-NLS-1$ String firstLine= sourceLines[0]; boolean firstCharNotWhitespace= firstLine != null && firstLine.length() > 0 && !Character.isWhitespace(firstLine.charAt(0)); if (firstCharNotWhitespace) sourceLines[0]= ""; //$NON-NLS-1$ IJavaProject project; if (input instanceof IJavaElement) project= ((IJavaElement) input).getJavaProject(); else project= null; Strings.trimIndentation(sourceLines, project); if (firstCharNotWhitespace) sourceLines[0]= firstLine; return Strings.concatenate(sourceLines, delim); }
Example 9
Source File: ExtractInterfaceProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Normalizes the indentation of the specified text. * * @param code * the text to normalize * @return the normalized text * @throws JavaModelException * if an error occurs */ protected final String normalizeText(final String code) throws JavaModelException { Assert.isNotNull(code); final String[] lines= Strings.convertIntoLines(code); final IJavaProject project= fSubType.getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(project)); }