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


Java IJavaPartitions类代码示例

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


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

示例1: getCurrentIndent

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
/**
 * Returns the indentation of the line <code>line</code> in <code>document</code>. The returned
 * string may contain pairs of leading slashes that are considered part of the indentation. The
 * space before the asterix in a javadoc-like comment is not considered part of the indentation.
 *
 * @param document the document
 * @param line the line
 * @return the indentation of <code>line</code> in <code>document</code>
 * @throws BadLocationException if the document is changed concurrently
 */
private static String getCurrentIndent(IDocument document, int line) throws BadLocationException {
  IRegion region = document.getLineInformation(line);
  int from = region.getOffset();
  int endOffset = region.getOffset() + region.getLength();

  // go behind line comments
  int to = from;
  while (to < endOffset - 2 && document.get(to, 2).equals(SLASHES)) to += 2;

  while (to < endOffset) {
    char ch = document.getChar(to);
    if (!Character.isWhitespace(ch)) break;
    to++;
  }

  // don't count the space before javadoc like, asterix-style comment lines
  if (to > from && to < endOffset - 1 && document.get(to - 1, 2).equals(" *")) { // $NON-NLS-1$
    String type =
        TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, to, true);
    if (type.equals(IJavaPartitions.JAVA_DOC)
        || type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT)) to--;
  }

  return document.get(from, to - from);
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:IndentUtil.java

示例2: handleSmartTrigger

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset)
    throws BadLocationException {
  DocumentCommand cmd = new DocumentCommand() {};

  cmd.offset = referenceOffset;
  cmd.length = 0;
  cmd.text = Character.toString(trigger);
  cmd.doit = true;
  cmd.shiftsCaret = true;
  cmd.caretOffset = getReplacementOffset() + getCursorPosition();

  SmartSemicolonAutoEditStrategy strategy =
      new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING);
  strategy.customizeDocumentCommand(document, cmd);

  replace(document, cmd.offset, cmd.length, cmd.text);
  setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length());
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:AbstractJavaCompletionProposal.java

示例3: getValidPositionForPartition

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
/**
 * Returns a valid insert location (except for whitespace) in <code>partition</code> or -1 if
 * there is no valid insert location. An valid insert location is right after any java string or
 * character partition, or at the end of a java default partition, but never behind <code>
 * maxOffset</code>. Comment partitions or empty java partitions do never yield valid insert
 * positions.
 *
 * @param doc the document being modified
 * @param partition the current partition
 * @param maxOffset the maximum offset to consider
 * @return a valid insert location in <code>partition</code>, or -1 if there is no valid insert
 *     location
 */
private static int getValidPositionForPartition(
    IDocument doc, ITypedRegion partition, int maxOffset) {
  final int INVALID = -1;

  if (IJavaPartitions.JAVA_DOC.equals(partition.getType())) return INVALID;
  if (IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(partition.getType())) return INVALID;
  if (IJavaPartitions.JAVA_SINGLE_LINE_COMMENT.equals(partition.getType())) return INVALID;

  int endOffset = Math.min(maxOffset, partition.getOffset() + partition.getLength());

  if (IJavaPartitions.JAVA_CHARACTER.equals(partition.getType())) return endOffset;
  if (IJavaPartitions.JAVA_STRING.equals(partition.getType())) return endOffset;
  if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) {
    try {
      if (doc.get(partition.getOffset(), endOffset - partition.getOffset()).trim().length() == 0)
        return INVALID;
      else return endOffset;
    } catch (BadLocationException e) {
      return INVALID;
    }
  }
  // default: we don't know anything about the partition - assume valid
  return endOffset;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:SmartSemicolonAutoEditStrategy.java

示例4: createPatternViewer

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected SourceViewer createPatternViewer(Composite parent) {
	IDocument document= new Document();
	JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
	JavaSourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new JavaSourcePreviewerUpdater(viewer, configuration, store);

	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);

	viewer.setEditable(false);
	return viewer;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:JavaTemplatesPage.java

示例5: setPreferenceStore

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected void setPreferenceStore(IPreferenceStore store) {
	super.setPreferenceStore(store);
	SourceViewerConfiguration sourceViewerConfiguration= getSourceViewerConfiguration();
	if (sourceViewerConfiguration == null || sourceViewerConfiguration instanceof JavaSourceViewerConfiguration) {
		JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
		setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING));
	}

	if (getSourceViewer() instanceof JavaSourceViewer)
		((JavaSourceViewer)getSourceViewer()).setPreferenceStore(store);

	fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
	fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
	fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
	fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
	fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
	fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
	fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
	fMarkExceptions= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
	fMarkImplementors= store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS);
	fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
	fMarkBreakContinueTargets= store.getBoolean(PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:JavaEditor.java

示例6: isValidSelection

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
/**
* Computes the partition type at the selection start and checks whether the proposal category
* has any computers for this partition.
*
* @param selection the selection
* @return <code>true</code> if there are any computers for the selection
*/
  private boolean isValidSelection(ISelection selection) {
  	if (!(selection instanceof ITextSelection))
  		return false;
  	int offset= ((ITextSelection) selection).getOffset();

  	IDocument document= getDocument();
  	if (document == null)
  		return false;

  	String contentType;
  	try {
       contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
      } catch (BadLocationException x) {
      	return false;
      }

      return fCategory.hasComputers(contentType);
  }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:SpecificContentAssistAction.java

示例7: runInternal

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException {
	int selectionOffset= selection.getOffset();
	int selectionEndOffset= selectionOffset + selection.getLength();
	List<Edit> edits= new LinkedList<Edit>();
	ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false);

	handleFirstPartition(partition, edits, factory, selectionOffset);

	while (partition.getOffset() + partition.getLength() < selectionEndOffset) {
		partition= handleInteriorPartition(partition, edits, factory, docExtension);
	}

	handleLastPartition(partition, edits, factory, selectionEndOffset);

	executeEdits(edits);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:AddBlockCommentAction.java

示例8: handleSmartTrigger

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset) throws BadLocationException {
	DocumentCommand cmd= new DocumentCommand() {
	};

	cmd.offset= referenceOffset;
	cmd.length= 0;
	cmd.text= Character.toString(trigger);
	cmd.doit= true;
	cmd.shiftsCaret= true;
	cmd.caretOffset= getReplacementOffset() + getCursorPosition();

	SmartSemicolonAutoEditStrategy strategy= new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING);
	strategy.customizeDocumentCommand(document, cmd);

	replace(document, cmd.offset, cmd.length, cmd.text);
	setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:AbstractJavaCompletionProposal.java

示例9: computeCompletionEngine

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
	try {
		String partition= TextUtilities.getContentType(context.getDocument(), IJavaPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
		if (partition.equals(IJavaPartitions.JAVA_DOC))
			return fJavadocTemplateEngine;
		else {
			CompletionContext coreContext= context.getCoreContext();
			if (coreContext != null) {
				int tokenLocation= coreContext.getTokenLocation();
				if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
					return fJavaMembersTemplateEngine;
				}
				if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
					return fJavaStatementsTemplateEngine;
				}
			}
			return fJavaTemplateEngine;
		}
	} catch (BadLocationException x) {
		return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:TemplateCompletionProposalComputer.java

示例10: createViewer

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected SourceViewer createViewer(Composite parent) {
	IDocument document= new Document();
	JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
	SourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new JavaSourcePreviewerUpdater(viewer, configuration, store);

	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);

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

示例11: JavaTextViewer

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
JavaTextViewer(Composite parent) {
	fSourceViewer= new SourceViewer(parent, null, SWT.LEFT_TO_RIGHT | SWT.H_SCROLL | SWT.V_SCROLL);
	JavaTextTools tools= JavaCompareUtilities.getJavaTextTools();
	if (tools != null) {
		IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
		fSourceViewer.configure(new JavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING));
	}

	fSourceViewer.setEditable(false);

	String symbolicFontName= JavaMergeViewer.class.getName();
	Font font= JFaceResources.getFont(symbolicFontName);
	if (font != null)
		fSourceViewer.getTextWidget().setFont(font);

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

示例12: installJavaStuff

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
/**
 * Installs a java partitioner with <code>document</code>.
 *
 * @param document the document
 */
private static void installJavaStuff(Document document) {
  String[] types =
      new String[] {
        IJavaPartitions.JAVA_DOC,
        IJavaPartitions.JAVA_MULTI_LINE_COMMENT,
        IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
        IJavaPartitions.JAVA_STRING,
        IJavaPartitions.JAVA_CHARACTER,
        IDocument.DEFAULT_CONTENT_TYPE
      };
  FastPartitioner partitioner = new FastPartitioner(new FastJavaPartitionScanner(), types);
  partitioner.connect(document);
  document.setDocumentPartitioner(IJavaPartitions.JAVA_PARTITIONING, partitioner);
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:JavaFormatter.java

示例13: computeCompletionEngine

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
  try {
    String partition =
        TextUtilities.getContentType(
            context.getDocument(),
            IJavaPartitions.JAVA_PARTITIONING,
            context.getInvocationOffset(),
            true);
    if (partition.equals(IJavaPartitions.JAVA_DOC)) return fJavadocTemplateEngine;
    else {
      CompletionContext coreContext = context.getCoreContext();
      if (coreContext != null) {
        int tokenLocation = coreContext.getTokenLocation();
        if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
          return fJavaMembersTemplateEngine;
        }
        if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
          return fJavaStatementsTemplateEngine;
        }
      }
      return fJavaTemplateEngine;
    }
  } catch (BadLocationException x) {
    return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:TemplateCompletionProposalComputer.java

示例14: doSetInput

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
protected void doSetInput(IEditorInput input) throws CoreException {
  IJavaProject javaProject = EditorUtility.getJavaProject(input);

  if (javaProject != null && GWTNature.isGWTProject(javaProject.getProject())) {
    // Use GWT partitioning if the compilation unit is in a GWT project
    inputPartitioning = GWTPartitions.GWT_PARTITIONING;
  } else {
    // Otherwise, use Java partitioning to emulate the Java editor
    inputPartitioning = IJavaPartitions.JAVA_PARTITIONING;
  }

  super.doSetInput(input);
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:15,代码来源:GWTJavaEditor.java

示例15: getConfiguredDocumentPartitioning

import org.eclipse.jdt.ui.text.IJavaPartitions; //导入依赖的package包/类
@Override
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
  try {
    ITextEditor editor = getEditor();
    return ((GWTJavaEditor) editor).getInputPartitioning();
  } catch (Exception e) {
    GWTPluginLog.logError(e);
    return IJavaPartitions.JAVA_PARTITIONING;
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:11,代码来源:GWTSourceViewerConfiguration.java


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