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


Java LinkedPositionGroup类代码示例

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


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

示例1: controlUndoBehavior

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
private boolean controlUndoBehavior(int offset, int length) {
	LinkedPosition position = fModel.findPosition(new LinkedPosition(fCurrentTarget.getViewer().getDocument(),
			offset, length, LinkedPositionGroup.NO_STOP));
	if (position != null) {

		// if the last position is not the same and there is an open
		// change: close it.
		if (!position.equals(fPreviousPosition))
			endCompoundChangeIfNeeded();

		beginCompoundChangeIfNeeded();
	}

	fPreviousPosition = position;
	return fPreviousPosition != null;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:17,代码来源:TweakedLinkedModeUI.java

示例2: selectionChanged

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
public void selectionChanged(SelectionChangedEvent event) {
	ISelection selection = event.getSelection();
	if (selection instanceof ITextSelection) {
		ITextSelection textsel = (ITextSelection) selection;
		if (event.getSelectionProvider() instanceof ITextViewer) {
			IDocument doc = ((ITextViewer) event.getSelectionProvider()).getDocument();
			if (doc != null) {
				int offset = textsel.getOffset();
				int length = textsel.getLength();
				if (offset >= 0 && length >= 0) {
					LinkedPosition find = new LinkedPosition(doc, offset, length, LinkedPositionGroup.NO_STOP);
					LinkedPosition pos = fModel.findPosition(find);
					if (pos == null && fExitPosition != null && fExitPosition.includes(find))
						pos = fExitPosition;

					if (pos != null)
						switchPosition(pos, false, false);
				}
			}
		}
	}
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:23,代码来源:TweakedLinkedModeUI.java

示例3: doExit

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:22,代码来源:LinkedNamesAssistProposal.java

示例4: setUpLinkedMode

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
	 * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will
	 * exit the mode when <code>closingCharacter</code> is typed and an exit position at
	 * <code>getCursorPosition() + 1</code>.
	 *
	 * @param document the document
	 */
	protected void setUpLinkedMode(IDocument document) {
		try {
			LinkedPositionGroup group= new LinkedPositionGroup();
			group.addPosition(new LinkedPosition(document, getSelectionStart(), getSelectionLength(), LinkedPositionGroup.NO_STOP));

			LinkedModeModel model= new LinkedModeModel();
			model.addGroup(group);
			model.forceInstall();

			LinkedModeUI ui= new LinkedModeUI(model, viewer);
//			ui.setSimpleMode(true);
			ui.setExitPolicy(new ExitPolicy(exitChars));
			ui.setExitPosition(viewer, getCursorPosition() + getReplacementOffset(), 0, Integer.MAX_VALUE);
			ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
			ui.enter();
		} catch (BadLocationException e) {
			log.info(e.getMessage(), e);
		}
	}
 
开发者ID:cplutte,项目名称:bts,代码行数:27,代码来源:ConfigurableCompletionProposal.java

示例5: doExit

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF);
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0,
				LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					// skip backspace at beginning of linked position
					event.doit = false;
				}
			} else /* event.character == SWT.DEL */{
				if (offset + 1 > position.getOffset() + position.getLength()) {
					// skip delete at end of linked position
					event.doit = false;
				}
			}
		}
	}
	return null; // don't change behavior
}
 
开发者ID:cplutte,项目名称:bts,代码行数:22,代码来源:RenameLinkedMode.java

示例6: generateIteratorBasedForRewrite

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Helper to generate an iterator based <code>for</code> loop to iterate over an {@link Iterable}.
 *
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);
  ForStatement loopStatement = ast.newForStatement();

  ITypeBinding loopOverType = extractElementType(ast);

  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));

  MethodInvocation loopExpression = ast.newMethodInvocation();
  loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
  SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
  loopExpression.setExpression(expressionName);

  loopStatement.setExpression(loopExpression);

  Block forLoopBody = ast.newBlock();
  Assignment assignResolvedVariable =
      getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
  forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:GenerateForLoopAssistProposal.java

示例7: getIteratorBasedForBodyAssignment

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Generates the Assignment in an iterator based for, used in the first statement of an iterator
 * based <code>for</code> loop body, to retrieve the next element of the {@link Iterable}
 * instance.
 *
 * @param rewrite the current instance of {@link ASTRewrite}
 * @param loopOverType the {@link ITypeBinding} of the loop variable
 * @param loopVariableName the name of the loop variable
 * @return an {@link Assignment}, which retrieves the next element of the {@link Iterable} using
 *     the active {@link Iterator}
 */
private Assignment getIteratorBasedForBodyAssignment(
    ASTRewrite rewrite, ITypeBinding loopOverType, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  Assignment assignResolvedVariable = ast.newAssignment();

  // left hand side
  SimpleName resolvedVariableName =
      resolveLinkedVariableNameWithProposals(
          rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
  VariableDeclarationFragment resolvedVariableDeclarationFragment =
      ast.newVariableDeclarationFragment();
  resolvedVariableDeclarationFragment.setName(resolvedVariableName);
  VariableDeclarationExpression resolvedVariableDeclaration =
      ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
  resolvedVariableDeclaration.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

  // right hand side
  MethodInvocation invokeIteratorNextExpression = ast.newMethodInvocation();
  invokeIteratorNextExpression.setName(ast.newSimpleName("next")); // $NON-NLS-1$
  SimpleName currentElementName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(currentElementName),
      LinkedPositionGroup.NO_STOP,
      currentElementName.getIdentifier());
  invokeIteratorNextExpression.setExpression(currentElementName);
  assignResolvedVariable.setRightHandSide(invokeIteratorNextExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
开发者ID:eclipse,项目名称:che,代码行数:49,代码来源:GenerateForLoopAssistProposal.java

示例8: getForBodyAssignment

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Creates an {@link Assignment} as first expression appearing in a <code>for</code> loop's body.
 * This Assignment declares a local variable and initializes it using the array's current element
 * identified by the loop index.
 *
 * @param rewrite the current {@link ASTRewrite} instance
 * @param loopVariableName the name of the index variable in String representation
 * @return a completed {@link Assignment} containing the mentioned declaration and initialization
 */
private Assignment getForBodyAssignment(ASTRewrite rewrite, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  ITypeBinding loopOverType = extractElementType(ast);

  Assignment assignResolvedVariable = ast.newAssignment();

  // left hand side
  SimpleName resolvedVariableName =
      resolveLinkedVariableNameWithProposals(
          rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
  VariableDeclarationFragment resolvedVariableDeclarationFragment =
      ast.newVariableDeclarationFragment();
  resolvedVariableDeclarationFragment.setName(resolvedVariableName);
  VariableDeclarationExpression resolvedVariableDeclaration =
      ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
  resolvedVariableDeclaration.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

  // right hand side
  ArrayAccess access = ast.newArrayAccess();
  access.setArray((Expression) rewrite.createCopyTarget(fCurrentExpression));
  SimpleName indexName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(indexName), LinkedPositionGroup.NO_STOP, indexName.getIdentifier());
  access.setIndex(indexName);
  assignResolvedVariable.setRightHandSide(access);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
开发者ID:eclipse,项目名称:che,代码行数:46,代码来源:GenerateForLoopAssistProposal.java

示例9: getLinkedInfixExpression

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Creates an {@link InfixExpression} which is linked to the group of the variableToIncrement.
 *
 * @param rewrite the current {@link ASTRewrite} instance
 * @param variableToIncrement the name of the variable to generate the {@link InfixExpression} for
 * @param rightHandSide the right hand side expression which shall be included in the {@link
 *     InfixExpression}
 * @param operator the {@link org.eclipse.jdt.core.dom.InfixExpression.Operator} to use in the
 *     {@link InfixExpression} to create
 * @return a filled, new {@link InfixExpression} instance
 */
private InfixExpression getLinkedInfixExpression(
    ASTRewrite rewrite,
    String variableToIncrement,
    Expression rightHandSide,
    InfixExpression.Operator operator) {
  AST ast = rewrite.getAST();
  InfixExpression loopExpression = ast.newInfixExpression();
  SimpleName name = ast.newSimpleName(variableToIncrement);
  addLinkedPosition(rewrite.track(name), LinkedPositionGroup.NO_STOP, name.getIdentifier());
  loopExpression.setLeftOperand(name);

  loopExpression.setOperator(operator);

  loopExpression.setRightOperand(rightHandSide);
  return loopExpression;
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:GenerateForLoopAssistProposal.java

示例10: getIndexBasedForBodyAssignment

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Creates an {@link Assignment} as first expression appearing in an index based <code>for</code>
 * loop's body. This Assignment declares a local variable and initializes it using the {@link
 * List}'s current element identified by the loop index.
 *
 * @param rewrite the current {@link ASTRewrite} instance
 * @param loopVariableName the name of the index variable in String representation
 * @return a completed {@link Assignment} containing the mentioned declaration and initialization
 */
private Expression getIndexBasedForBodyAssignment(
    ASTRewrite rewrite, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  ITypeBinding loopOverType = extractElementType(ast);

  Assignment assignResolvedVariable = ast.newAssignment();

  // left hand side
  SimpleName resolvedVariableName =
      resolveLinkedVariableNameWithProposals(
          rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
  VariableDeclarationFragment resolvedVariableDeclarationFragment =
      ast.newVariableDeclarationFragment();
  resolvedVariableDeclarationFragment.setName(resolvedVariableName);
  VariableDeclarationExpression resolvedVariableDeclaration =
      ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
  resolvedVariableDeclaration.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

  // right hand side
  MethodInvocation invokeGetExpression = ast.newMethodInvocation();
  invokeGetExpression.setName(ast.newSimpleName("get")); // $NON-NLS-1$
  SimpleName indexVariableName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(indexVariableName),
      LinkedPositionGroup.NO_STOP,
      indexVariableName.getIdentifier());
  invokeGetExpression.arguments().add(indexVariableName);
  invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
  assignResolvedVariable.setRightHandSide(invokeGetExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
开发者ID:eclipse,项目名称:che,代码行数:50,代码来源:GenerateForLoopAssistProposal.java

示例11: setUpLinkedMode

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will
 * exit the mode when <code>closingCharacter</code> is typed and an exit position at
 * <code>getCursorPosition() + 1</code>.
 *
 * @param document the document
 * @param closingCharacter the exit character
 */
protected void setUpLinkedMode(IDocument document, char closingCharacter) {
	if (getTextViewer() != null && autocloseBrackets()) {
		int offset= getReplacementOffset() + getCursorPosition();
		int exit= getReplacementOffset() + getReplacementString().length();
		try {
			LinkedPositionGroup group= new LinkedPositionGroup();
			group.addPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP));

			LinkedModeModel model= new LinkedModeModel();
			model.addGroup(group);
			model.forceInstall();

			LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer());
			ui.setSimpleMode(true);
			ui.setExitPolicy(new ExitPolicy(closingCharacter, document));
			ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE);
			ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
			ui.enter();
		} catch (BadLocationException x) {
			JavaPlugin.log(x);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:AbstractJavaCompletionProposal.java

示例12: getIteratorBasedForBodyAssignment

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
/**
 * Generates the Assignment in an iterator based for, used in the first statement of an iterator
 * based <code>for</code> loop body, to retrieve the next element of the {@link Iterable}
 * instance.
 * 
 * @param rewrite the current instance of {@link ASTRewrite}
 * @param loopOverType the {@link ITypeBinding} of the loop variable
 * @param loopVariableName the name of the loop variable
 * @return an {@link Assignment}, which retrieves the next element of the {@link Iterable} using
 *         the active {@link Iterator}
 */
private Assignment getIteratorBasedForBodyAssignment(ASTRewrite rewrite, ITypeBinding loopOverType, SimpleName loopVariableName) {
	AST ast= rewrite.getAST();
	Assignment assignResolvedVariable= ast.newAssignment();

	// left hand side
	SimpleName resolvedVariableName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
	VariableDeclarationFragment resolvedVariableDeclarationFragment= ast.newVariableDeclarationFragment();
	resolvedVariableDeclarationFragment.setName(resolvedVariableName);
	VariableDeclarationExpression resolvedVariableDeclaration= ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
	resolvedVariableDeclaration.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
	assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

	// right hand side
	MethodInvocation invokeIteratorNextExpression= ast.newMethodInvocation();
	invokeIteratorNextExpression.setName(ast.newSimpleName("next")); //$NON-NLS-1$
	SimpleName currentElementName= ast.newSimpleName(loopVariableName.getIdentifier());
	addLinkedPosition(rewrite.track(currentElementName), LinkedPositionGroup.NO_STOP, currentElementName.getIdentifier());
	invokeIteratorNextExpression.setExpression(currentElementName);
	assignResolvedVariable.setRightHandSide(invokeIteratorNextExpression);

	assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

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

示例13: doExit

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:LinkedNamesAssistProposal.java

示例14: startLinkedEdit

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
private void startLinkedEdit(List<IRegion> selections, ITextViewer viewer, Point originalSelection)
		throws BadLocationException {
	final LinkedPositionGroup linkedPositionGroup = new LinkedPositionGroup();
	for (IRegion selection : selections) {
		linkedPositionGroup.addPosition(new LinkedPosition(viewer.getDocument(), selection.getOffset(), selection
				.getLength()));
	}

	LinkedModeModel model = new LinkedModeModel();
	model.addGroup(linkedPositionGroup);
	model.forceInstall();
	//FIXME can add a listener here to listen for the end of linked mode
	//model.addLinkingListener(null);

	LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
	ui.setExitPolicy(new DeleteBlockingExitPolicy(viewer.getDocument()));
	ui.enter();

	// by default the text being edited is selected so restore original selection
	viewer.setSelectedRange(originalSelection.x, originalSelection.y);
}
 
开发者ID:caspark,项目名称:eclipse-multicursor,代码行数:22,代码来源:SelectNextOccurrenceHandler.java

示例15: getLinkedModeModel

import org.eclipse.jface.text.link.LinkedPositionGroup; //导入依赖的package包/类
protected LinkedModeModel getLinkedModeModel(ITextViewer viewer) throws BadLocationException {
	Indexable<SourceRange> sourceSubElements = proposal.getSourceSubElements();
	if(sourceSubElements == null || sourceSubElements.isEmpty()) {
		return null;
	}
	
	LinkedModeModel model = new LinkedModeModel();
	
	IDocument document = viewer.getDocument();
	int replaceOffset = getReplaceOffset();
	
	firstLinkedModeGroupPosition = -1;
	
	for (SourceRange sr : sourceSubElements) {
		LinkedPositionGroup group = new LinkedPositionGroup();
		int posOffset = replaceOffset + sr.getOffset();
		group.addPosition(new LinkedPosition(document, posOffset, sr.getLength()));
		if(firstLinkedModeGroupPosition == -1) {
			firstLinkedModeGroupPosition = posOffset;
		}
		model.addGroup(group);
	}
	
	return model;
}
 
开发者ID:GoClipse,项目名称:goclipse,代码行数:26,代码来源:LangCompletionProposal.java


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