当前位置: 首页>>代码示例>>Java>>正文


Java TextUtilities.getDefaultLineDelimiter方法代码示例

本文整理汇总了Java中org.eclipse.jface.text.TextUtilities.getDefaultLineDelimiter方法的典型用法代码示例。如果您正苦于以下问题:Java TextUtilities.getDefaultLineDelimiter方法的具体用法?Java TextUtilities.getDefaultLineDelimiter怎么用?Java TextUtilities.getDefaultLineDelimiter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jface.text.TextUtilities的用法示例。


在下文中一共展示了TextUtilities.getDefaultLineDelimiter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateReplacementString

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
 * @param document
 * @param offset
 * @param importRewrite
 * @param completionSnippetsSupported
 * @return
 * @throws CoreException
 * @throws BadLocationException
 */
public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported) throws CoreException, BadLocationException {
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

	String stub;
	if (fIsGetter) {
		String getterName= GetterSetterUtil.getGetterName(fField, null);
		stub = GetterSetterUtil.getGetterStub(fField, getterName, true, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub = GetterSetterUtil.getSetterStub(fField, setterName, true, flags);
	}

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
	String replacement = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, 0, lineDelim, fField.getJavaProject());

	if (replacement.endsWith(lineDelim)) {
		replacement = replacement.substring(0, replacement.length() - lineDelim.length());
	}

	return replacement;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:GetterSetterCompletionProposal.java

示例2: addEdits

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
	try {
		String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
		final IJavaProject project= getCompilationUnit().getJavaProject();
		IRegion region= document.getLineInformationOfOffset(fInsertPosition);

		String lineContent= document.get(region.getOffset(), region.getLength());
		String indentString= Strings.getIndentString(lineContent, project);
		String str= Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
		InsertEdit edit= new InsertEdit(fInsertPosition, str);
		rootEdit.addChild(edit);
		if (fComment.charAt(fComment.length() - 1) != '\n') {
			rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
			rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
		}
	} catch (BadLocationException e) {
		throw new CoreException(StatusFactory.newErrorStatus("Invalid edit", e));
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:JavadocTagsSubProcessor.java

示例3: evaluate

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  TemplateTranslator translator = new TemplateTranslator();
  TemplateBuffer buffer = translator.translate(template);

  getContextType().resolve(buffer, this);

  //		IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
  boolean useCodeFormatter =
      true; // prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

  IJavaProject project = getJavaProject();
  JavaFormatter formatter =
      new JavaFormatter(
          TextUtilities.getDefaultLineDelimiter(getDocument()),
          getIndentation(),
          useCodeFormatter,
          project);
  formatter.format(buffer, this);

  return buffer;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:JavaDocContext.java

示例4: appendMethodNameReplacement

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
 * Appends everything up to the method name including the opening parenthesis.
 *
 * <p>In case of {@link org.eclipse.jdt.core.CompletionProposal#METHOD_REF_WITH_CASTED_RECEIVER}
 * it add cast.
 *
 * @param buffer the string buffer
 * @since 3.4
 */
protected void appendMethodNameReplacement(StringBuffer buffer) {
  if (fProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
    String coreCompletion = String.valueOf(fProposal.getCompletion());
    String lineDelimiter = TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument());
    String replacement =
        CodeFormatterUtil.format(
            CodeFormatter.K_EXPRESSION,
            coreCompletion,
            0,
            lineDelimiter,
            fInvocationContext.getProject());
    buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1));
  }

  if (fProposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION)
    buffer.append(fProposal.getName());

  FormatterPrefs prefs = getFormatterPrefs();
  if (prefs.beforeOpeningParen) buffer.append(SPACE);
  buffer.append(LPAREN);
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:JavaMethodCompletionProposal.java

示例5: addEdits

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
  try {
    String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);
    final IJavaProject project = getCompilationUnit().getJavaProject();
    IRegion region = document.getLineInformationOfOffset(fInsertPosition);

    String lineContent = document.get(region.getOffset(), region.getLength());
    String indentString = Strings.getIndentString(lineContent, project);
    String str = Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
    InsertEdit edit = new InsertEdit(fInsertPosition, str);
    rootEdit.addChild(edit);
    if (fComment.charAt(fComment.length() - 1) != '\n') {
      rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
      rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
    }
  } catch (BadLocationException e) {
    throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:JavadocTagsSubProcessor.java

示例6: processFix

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
public IRegion processFix(IDocument document, IMarker marker) throws CoreException {
    int line = (int) marker.getAttribute(IMarker.LINE_NUMBER);
    try {
        String indent = getIndent(document, line);
        // getLineOffset() is zero-based, and imarkerLine is one-based.
        int endOfCurrLine = document.getLineInformation(line - 1).getOffset()
                + document.getLineInformation(line - 1).getLength();
        // should be fine for first and last lines in the doc as well
        String replacementText = indent + "type: object";
        String delim = TextUtilities.getDefaultLineDelimiter(document);
        document.replace(endOfCurrLine, 0, delim + replacementText);
        return new Region(endOfCurrLine + delim.length(), replacementText.length());
    } catch (BadLocationException e) {
        throw new CoreException(createStatus(e, "Cannot process the IMarker"));
    }
}
 
开发者ID:RepreZen,项目名称:KaiZen-OpenAPI-Editor,代码行数:18,代码来源:QuickFixer.java

示例7: evaluate

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
	TemplateTranslator translator= new TemplateTranslator();
	TemplateBuffer buffer= translator.translate(template);

	getContextType().resolve(buffer, this);

	IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
	boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

	IJavaProject project= getJavaProject();
	JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
	formatter.format(buffer, this);

	return buffer;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:JavaDocContext.java

示例8: appendMethodNameReplacement

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
 * Appends everything up to the method name including
 * the opening parenthesis.
 * <p>
 * In case of {@link CompletionProposal#METHOD_REF_WITH_CASTED_RECEIVER}
 * it add cast.
 * </p>
 *
 * @param buffer the string buffer
 * @since 3.4
 */
protected void appendMethodNameReplacement(StringBuffer buffer) {
	if (fProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
		String coreCompletion= String.valueOf(fProposal.getCompletion());
		String lineDelimiter= TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument());
		String replacement= CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, coreCompletion, 0, lineDelimiter, fInvocationContext.getProject());
		buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1));
	}

	if (fProposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION)
		buffer.append(fProposal.getName());

	FormatterPrefs prefs= getFormatterPrefs();
	if (prefs.beforeOpeningParen)
		buffer.append(SPACE);
	buffer.append(LPAREN);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:JavaMethodCompletionProposal.java

示例9: addEdits

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
	try {
		String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
		final IJavaProject project= getCompilationUnit().getJavaProject();
		IRegion region= document.getLineInformationOfOffset(fInsertPosition);

		String lineContent= document.get(region.getOffset(), region.getLength());
		String indentString= Strings.getIndentString(lineContent, project);
		String str= Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
		InsertEdit edit= new InsertEdit(fInsertPosition, str);
		rootEdit.addChild(edit);
		if (fComment.charAt(fComment.length() - 1) != '\n') {
			rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
			rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
		}
	} catch (BadLocationException e) {
		throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:21,代码来源:JavadocTagsSubProcessor.java

示例10: updateReplacementString

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
public String updateReplacementString(IDocument document, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {
	String newBody = createNewBody(impRewrite);
	if (newBody == null) {
		return null;
	}
	StringBuffer buf = new StringBuffer("new A()"); //$NON-NLS-1$
	buf.append(newBody);
	// use the code formatter
	String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
	final IJavaProject project = fCompilationUnit.getJavaProject();
	IRegion lineInfo = document.getLineInformationOfOffset(fReplacementOffset);
	Map<String, String> options = project != null ? project.getOptions(true) : JavaCore.getOptions();
	String replacementString = CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, buf.toString(), 0, lineDelim, options);
	int lineEndOffset = lineInfo.getOffset() + lineInfo.getLength();
	int p = offset;
	if (p < document.getLength()) {
		char ch = document.getChar(p);
		while (p < lineEndOffset) {
			if (ch == '(' || ch == ')' || ch == ';' || ch == ',') {
				break;
			}
			ch = document.getChar(++p);
		}
		if (ch != ';' && ch != ',' && ch != ')') {
			replacementString = replacementString + ';';
		}
	}
	int beginIndex = replacementString.indexOf('(');
	replacementString = replacementString.substring(beginIndex);
	return replacementString;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:AnonymousTypeCompletionProposal.java

示例11: getLineDelimiter

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
String getLineDelimiter(IDocument document)
{
	InstanceScope scope = EclipseUtil.instanceScope();
	IEclipsePreferences node = scope.getNode(Platform.PI_RUNTIME);
	String separator = node.get(Platform.PREF_LINE_SEPARATOR, StringUtil.EMPTY);
	if (StringUtil.isEmpty(separator))
	{
		separator = TextUtilities.getDefaultLineDelimiter(document);
	}

	return separator;
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:13,代码来源:FindBarDecorator.java

示例12: evaluate

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
	public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
		clear();

		if (!canEvaluate(template))
			throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);

		TemplateTranslator translator= new TemplateTranslator() {
			@Override
			protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets) {
//				TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
//				return resolver.createVariable();

				MultiVariable variable= new JavaVariable(type, name, offsets);
				fVariables.put(name, variable);
				return variable;
			}
		};
		TemplateBuffer buffer= translator.translate(template);

		getContextType().resolve(buffer, this);

		rewriteImports();

		IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
		boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

		IJavaProject project= getJavaProject();
		JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
		formatter.format(buffer, this);

		clear();

		return buffer;
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:JavaContext.java

示例13: SpellCheckIterator

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
 * Creates a new spell check iterator.
 *
 * @param document the document containing the specified partition
 * @param region the region to spell check
 * @param locale the locale to use for spell checking
 * @param breakIterator the break-iterator
 */
public SpellCheckIterator(IDocument document, IRegion region, Locale locale, BreakIterator breakIterator) {
	fOffset= region.getOffset();
	fWordIterator= breakIterator;
	fDelimiter= TextUtilities.getDefaultLineDelimiter(document);

	String content;
	try {

		content= document.get(region.getOffset(), region.getLength());
		if (content.startsWith(NLSElement.TAG_PREFIX))
			content= ""; //$NON-NLS-1$

	} catch (Exception exception) {
		content= ""; //$NON-NLS-1$
	}
	fContent= content;

	fWordIterator.setText(content);
	fPredecessor= fWordIterator.first();
	fSuccessor= fWordIterator.next();

	final BreakIterator iterator= BreakIterator.getSentenceInstance(locale);
	iterator.setText(content);

	int offset= iterator.current();
	while (offset != BreakIterator.DONE) {

		fSentenceBreaks.add(new Integer(offset));
		offset= iterator.next();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:40,代码来源:SpellCheckIterator.java

示例14: rewriteAST

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
 * Performs the rewrite: The rewrite events are translated to the corresponding in text changes.
 * The given options can be null in which case the global options {@link JavaCore#getOptions() JavaCore.getOptions()}
 * will be used.
 *
 * @param document Document which describes the code of the AST that is passed in in the
 * constructor. This document is accessed read-only.
 * @param options the given options
 * @throws IllegalArgumentException if the rewrite fails
 * @return Returns the edit describing the text changes.
 */
public TextEdit rewriteAST(IDocument document, Map options) {
	TextEdit result = new MultiTextEdit();

	final CompilationUnit rootNode = getRootNode();
	if (rootNode != null) {
		TargetSourceRangeComputer xsrComputer = new TargetSourceRangeComputer() {
			/**
			 * This implementation of
			 * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)}
			 * is specialized to work in the case of internal AST rewriting, where the
			 * original AST has been modified from its original form. This means that
			 * one cannot trust that the root of the given node is the compilation unit.
			 */
			public SourceRange computeSourceRange(ASTNode node) {
				int extendedStartPosition = rootNode.getExtendedStartPosition(node);
				int extendedLength = rootNode.getExtendedLength(node);
				return new SourceRange(extendedStartPosition, extendedLength);
			}
		};
		char[] content= document.get().toCharArray();
		LineInformation lineInfo= LineInformation.create(document);
		String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
		List comments= rootNode.getCommentList();

		Map currentOptions = options == null ? JavaCore.getOptions() : options;
		ASTRewriteAnalyzer visitor = new ASTRewriteAnalyzer(content, lineInfo, lineDelim, result, this.eventStore, this.nodeStore, comments, currentOptions, xsrComputer, (RecoveryScannerData)rootNode.getStatementsRecoveryData());
		rootNode.accept(visitor);
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:42,代码来源:InternalASTRewrite.java

示例15: updateReplacementString

import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {

	CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(fField.getJavaProject());
	boolean addComments= settings.createComments;
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

	String stub;
	if (fIsGetter) {
		String getterName= GetterSetterUtil.getGetterName(fField, null);
		stub= GetterSetterUtil.getGetterStub(fField, getterName, addComments, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub= GetterSetterUtil.getSetterStub(fField, setterName, addComments, flags);
	}

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);

	IRegion region= document.getLineInformationOfOffset(getReplacementOffset());
	int lineStart= region.getOffset();
	int indent= Strings.computeIndentUnits(document.get(lineStart, getReplacementOffset() - lineStart), settings.tabWidth, settings.indentWidth);

	String replacement= CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, indent, lineDelim, fField.getJavaProject());

	if (replacement.endsWith(lineDelim)) {
		replacement= replacement.substring(0, replacement.length() - lineDelim.length());
	}

	setReplacementString(Strings.trimLeadingTabsAndSpaces(replacement));
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:33,代码来源:GetterSetterCompletionProposal.java


注:本文中的org.eclipse.jface.text.TextUtilities.getDefaultLineDelimiter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。