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


Java TextUtilities类代码示例

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


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

示例1: isBlockCommented

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
private boolean isBlockCommented(int startLine, int endLine, String[] prefixes, IDocument document) {
	try {
		// check for occurrences of prefixes in the given lines
		for (int i = startLine; i <= endLine; i++) {
			IRegion line = document.getLineInformation(i);
			String text = document.get(line.getOffset(), line.getLength());
			int[] found = TextUtilities.indexOf(prefixes, text, 0);
			if (found[0] == -1) {
				// found a line which is not commented
				return false;
			}
			String s = document.get(line.getOffset(), found[0]);
			s = s.trim();
			if (s.length() != 0) {
				// found a line which is not commented
				return false;
			}
		}
		return true;
	} catch (BadLocationException x) {
		// should not happen
	}
	return false;
}
 
开发者ID:DarwinSPL,项目名称:DarwinSPL,代码行数:25,代码来源:DwprofileToggleCommentHandler.java

示例2: 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

示例3: 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

示例4: computeCompletionEngine

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(TypeScriptContentAssistInvocationContext context) {
	try {
		IResource resource = context.getResource();
		if (resource == null || !AngularProject.isAngularProject(resource.getProject())) {
			return null;
		}
		String partition = TextUtilities.getContentType(context.getDocument(),
				IJavaScriptPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
		if (partition.equals(IJavaScriptPartitions.JAVA_DOC)) {
			return null;
		} else {
			return ng2TemplateEngine;
		}
	} catch (BadLocationException x) {
		return null;
	}
}
 
开发者ID:angelozerr,项目名称:angular-eclipse,代码行数:19,代码来源:TypeScriptAngularTemplateCompletionProposalComputer.java

示例5: samePartition

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
private boolean samePartition(int beg, int len) throws BadLocationException {
	if (len == 0) return TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, cpos, false)
			.equals(IDocument.DEFAULT_CONTENT_TYPE);

	boolean begDef = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg, false)
			.equals(IDocument.DEFAULT_CONTENT_TYPE);
	boolean endDef = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg + len - 1, false)
			.equals(IDocument.DEFAULT_CONTENT_TYPE);

	if (begDef && endDef) {
		ITypedRegion begRegion = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg, false);
		ITypedRegion endRegion = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg + len - 1, false);
		if (begRegion.getOffset() == endRegion.getOffset()) return true;
	}
	return false;
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:17,代码来源:AbstractMarksHandler.java

示例6: checkPartition

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
private int checkPartition(IDocument doc, int beg, int len) {
	try {
		boolean begCmt = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg, false)
				.equals(Partitions.COMMENT);
		boolean endCmt = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg + len - 1, false)
				.equals(Partitions.COMMENT);

		if (begCmt && endCmt) {
			ITypedRegion begPar = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg, false);
			ITypedRegion endPar = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg + len - 1, false);
			if (begPar.getOffset() == endPar.getOffset()) return SAME;
			return DIFF;
		}
		if ((begCmt && !endCmt) || (!begCmt && endCmt)) return LAPD;
		return NONE;
	} catch (BadLocationException e) {
		Log.error("Bad comment partitioning " + e.getMessage());
		return UNKN;
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:21,代码来源:ToggleHiddenCommentHandler.java

示例7: removeComment

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
private void removeComment(IDocument doc, int offset) {
	try {
		IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
		undoMgr.beginCompoundChange();

		ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
		int beg = par.getOffset();
		int len = par.getLength();

		String comment = doc.get(beg, len);
		int eLen = markerLen(comment);
		int bLen = eLen + 1;

		MultiTextEdit edit = new MultiTextEdit();
		edit.addChild(new DeleteEdit(beg, bLen));
		edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
		edit.apply(doc);
		undoMgr.endCompoundChange();
	} catch (MalformedTreeException | BadLocationException e) {
		Log.error("Failure removing comment " + e.getMessage());
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:23,代码来源:ToggleHiddenCommentHandler.java

示例8: customizeDocumentCommand

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
@Override
public void customizeDocumentCommand(final IDocument doc, final DocumentCommand cmd) {
	if (cmd.length != 0 || cmd.text == null) return;

	try {
		if (TextUtilities.endsWith(doc.getLegalLineDelimiters(), cmd.text) != -1) {
			if (AutoEdit.isBlankLine(doc, cmd.offset)) {
				int beg = AutoEdit.getLineOffset(doc, cmd.offset);
				int len = cmd.offset - beg;

				DeleteEdit blanks = new DeleteEdit(beg, len);
				blanks.apply(doc);
				cmd.offset = beg;

			} else {
				autoIndent(doc, cmd, false);	// return entered
			}

		} else if (evaluateInsertPoint(doc, cmd)) {
			autoIndent(doc, cmd, true);		// insert point exceeds limit
		} else if (evaluateLineWidth(doc, cmd)) {
			wrapLines(doc, cmd);			// line end exceeds limit
		}
	} catch (BadLocationException e) {}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:26,代码来源:LineWrapEditStrategy.java

示例9: computeCompletionEngine

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(TypeScriptContentAssistInvocationContext context) {
	try {
		if (!TypeScriptResourceUtil.isTsxOrJsxFile(context.getResource())) {
			return null;
		}
		String partition = TextUtilities.getContentType(context.getDocument(),
				IJavaScriptPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
		if (partition.equals(IJavaScriptPartitions.JAVA_DOC)) {
			return null;
		} else if (partition.equals(IJSXPartitions.JSX)) {
			return null;
		} else {
			return reactTemplateEngine;
		}
	} catch (BadLocationException x) {
		return null;
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:20,代码来源:ReactTemplateCompletionProposalComputer.java

示例10: createMethodTags

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
private String createMethodTags(IDocument document, DocumentCommand command, String indentation,
		String lineDelimiter, IFunction method) throws CoreException, BadLocationException {
	IRegion partition = TextUtilities.getPartition(document, fPartitioning, command.offset, false);
	IFunction inheritedMethod = getInheritedMethod(method);
	String comment = CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
	if (comment != null) {
		comment = comment.trim();
		boolean javadocComment = comment.startsWith("/**"); //$NON-NLS-1$
		if (!isFirstComment(document, command, method, javadocComment))
			return null;
		boolean isJavaDoc = partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
		if (javadocComment == isJavaDoc) {
			return prepareTemplateComment(comment, indentation, method.getJavaScriptProject(), lineDelimiter);
		}
	}
	return null;
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:18,代码来源:JSDocAutoIndentStrategy.java

示例11: customizeDocumentCommand

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {

		if (!isSmartMode())
			return;

		if (command.text != null) {
			if (command.length == 0) {
				String[] lineDelimiters = document.getLegalLineDelimiters();
				int index = TextUtilities.endsWith(lineDelimiters, command.text);
				if (index > -1) {
					// ends with line delimiter
					if (lineDelimiters[index].equals(command.text))
						// just the line delimiter
						indentAfterNewLine(document, command);
					return;
				}
			}

			if (command.text.equals("/")) { //$NON-NLS-1$
				indentAfterCommentEnd(document, command);
				return;
			}
		}
	}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:25,代码来源:JSDocAutoIndentStrategy.java

示例12: findExtendedDoubleClickSelection

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
@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() + 1 || offset == region.getOffset() + region.getLength() - 1) {
			return getSelectedRegion(document, region);
		}
	} catch (BadLocationException e) {
		return null;
	}
	return null;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:17,代码来源:AbstractPartitionDoubleClickSelector.java

示例13: internalCustomizeDocumentCommand

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
@Override
protected void internalCustomizeDocumentCommand(IDocument document, DocumentCommand command)
		throws BadLocationException {
	if (command.length != 0)
		return;
	String[] lineDelimiters = document.getLegalLineDelimiters();
	int delimiterIndex = TextUtilities.startsWith(lineDelimiters, command.text);
	if (delimiterIndex != -1) {
		MultiLineTerminalsEditStrategy bestStrategy = null;
		IRegion bestStart = null;
		for(MultiLineTerminalsEditStrategy strategy: strategies) {
			IRegion candidate = strategy.findStartTerminal(document, command.offset);
			if (candidate != null) {
				if (bestStart == null || bestStart.getOffset() < candidate.getOffset()) {
					bestStrategy = strategy;
					bestStart = candidate;
				}
			}
		}
		if (bestStrategy != null) {
			bestStrategy.internalCustomizeDocumentCommand(document, command);
		}
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:25,代码来源:CompoundMultiLineTerminalsEditStrategy.java

示例14: 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

示例15: getBlocks

import org.eclipse.jface.text.TextUtilities; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:SourceProvider.java


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