Java Code Examples for org.eclipse.jdt.internal.corext.util.Strings#concatenate()

The following examples show how to use org.eclipse.jdt.internal.corext.util.Strings#concatenate() . 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 vote down vote up
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 vote down vote up
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: JavaSourceHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Deprecated
public String getHoverInfo(ITextViewer textViewer, IRegion region) {
	IJavaElement[] result= getJavaElementsAt(textViewer, region);

	fUpwardShiftInLines= 0;
	fBracketHoverStatus= null;

	if (result == null || result.length == 0) {
		return getBracketHoverInfo(textViewer, region);
	}

	if (result.length > 1)
		return null;

	IJavaElement curr= result[0];
	if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) {
		try {
			String source= ((ISourceReference) curr).getSource();

			String[] sourceLines= getTrimmedSource(source, curr);
			if (sourceLines == null)
				return null;

			String delim= StubUtility.getLineDelimiterUsed(curr);
			source= Strings.concatenate(sourceLines, delim);

			return source;
		} catch (JavaModelException ex) {
			//do nothing
		}
	}
	return null;
}
 
Example 4
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 5
Source File: HierarchyProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 6
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 7
Source File: SourceView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@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 8
Source File: ExtractInterfaceProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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));
}