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


Java TextEditGroup类代码示例

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


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

示例1: rewriteAST

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:AbstractSerialVersionOperation.java

示例2: handleManyMany

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
	ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
	if (fToReplace.length == replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
	} else if (fToReplace.length < replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
		for (int i= fToReplace.length; i < replacements.length; i++) {
			container.insertAfter(replacements[i], replacements[i - 1], description);
		}
	} else if (fToReplace.length > replacements.length) {
		int delta= fToReplace.length - replacements.length;
		for(int i= 0; i < delta; i++) {
			container.remove(fToReplace[i], description);
		}
		for (int i= delta, r= 0; i < fToReplace.length; i++, r++) {
			container.replace(fToReplace[i], replacements[r], description);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:ReplaceRewrite.java

示例3: handleOneMany

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
@Override
protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) {
	AST ast= fToReplace[0].getAST();
	// to replace == 1, but more than one replacement. Have to check if we
	// need to insert a block to not change structure
	if (ASTNodes.isControlStatementBody(fDescriptor)) {
		Block block= ast.newBlock();
		ListRewrite statements= fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
		for (int i= 0; i < replacements.length; i++) {
			statements.insertLast(replacements[i], description);
		}
		fRewrite.replace(fToReplace[0], block, description);
	} else {
		ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
		container.replace(fToReplace[0], replacements[0], description);
		for (int i= 1; i < replacements.length; i++) {
			container.insertAfter(replacements[i], replacements[i - 1], description);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:StatementRewrite.java

示例4: removePureTypeAnnotations

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
/**
 * Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
 * <code>node</code>'s <code>childListProperty</code>.
 * <p>
 * In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
 * the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
 *
 * @param node ASTNode
 * @param childListProperty child list property
 * @param rewrite rewrite that removes the nodes
 * @param editGroup the edit group in which to collect the corresponding text edits, or null if
 *            ungrouped
 */
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
	CompilationUnit root= (CompilationUnit) node.getRoot();
	if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
		return;
	}
	ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
	for (ASTNode child : children) {
		if (child instanceof Annotation) {
			Annotation annotation= (Annotation) child;
			if (isPureTypeAnnotation(annotation)) {
				listRewrite.remove(child, editGroup);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:31,代码来源:TypeAnnotationRewrite.java

示例5: addOverrideAnnotation

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
/**
 * Adds <code>@Override</code> annotation to <code>methodDecl</code> if not already present and
 * if requested by code style settings or compiler errors/warnings settings.
 *
 * @param settings the code generation style settings, may be <code>null</code>
 * @param project the Java project used to access the compiler settings
 * @param rewrite the ASTRewrite
 * @param imports the ImportRewrite
 * @param methodDecl the method declaration to add the annotation to
 * @param isDeclaringTypeInterface <code>true</code> if the type declaring the method overridden
 *            by <code>methodDecl</code> is an interface
 * @param group the text edit group, may be <code>null</code>
 */
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
		boolean isDeclaringTypeInterface, TextEditGroup group) {
	if (!JavaModelUtil.is50OrHigher(project)) {
		return;
	}
	if (isDeclaringTypeInterface) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
		{
			return; // not allowed in 1.5
		}
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
		{
			return; // user doesn't want to use 1.6 style
		}
	}
	if ((settings != null && settings.overrideAnnotation) || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true))) {
		createOverrideAnnotation(rewrite, imports, methodDecl, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:34,代码来源:StubUtility2.java

示例6: rewriteAST

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	IBinding binding= fUnusedName.resolveBinding();
	CompilationUnit root= (CompilationUnit) fUnusedName.getRoot();
	String displayString= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
	TextEditGroup group= createTextEditGroup(displayString, cuRewrite);

	if (binding.getKind() == IBinding.TYPE) {
		ITypeBinding decl= ((ITypeBinding) binding).getTypeDeclaration();
		ASTNode declaration= root.findDeclaringNode(decl);
		if (declaration.getParent() instanceof TypeDeclarationStatement) {
			declaration= declaration.getParent();
		}
		rewrite.remove(declaration, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:UnusedCodeFix.java

示例7: splitUpDeclarations

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
	if (sideEffects.size() > 0) {
		ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());

		Statement previousStatement= originalStatement;
		for (int i= 0; i < sideEffects.size(); i++) {
			Expression sideEffect= sideEffects.get(i);
			Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
			ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
			statementRewrite.insertAfter(wrapped, previousStatement, group);
			previousStatement= wrapped;
		}

		VariableDeclarationStatement newDeclaration= null;
		List<VariableDeclarationFragment> fragments= originalStatement.fragments();
		int fragIndex= fragments.indexOf(frag);
		ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
		while (fragmentIterator.hasNext()) {
			VariableDeclarationFragment currentFragment= fragmentIterator.next();
			VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
			if (newDeclaration == null) {
				newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
				Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
				newDeclaration.setType(copiedType);
			} else {
				newDeclaration.fragments().add(movedFragment);
			}
		}
		if (newDeclaration != null){
			statementRewrite.insertAfter(newDeclaration, previousStatement, group);
			if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
				rewrite.remove(originalStatement, group);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:UnusedCodeFix.java

示例8: removeVariableWithInitializer

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
private void removeVariableWithInitializer(ASTRewrite rewrite, ASTNode initializerNode, ASTNode statementNode, TextEditGroup group) {
	boolean performRemove= fForceRemove;
	if (!performRemove) {
		ArrayList<Expression> sideEffectNodes= new ArrayList<>();
		initializerNode.accept(new SideEffectFinder(sideEffectNodes));
		performRemove= sideEffectNodes.isEmpty();
	}
	if (performRemove) {
		removeStatement(rewrite, statementNode, group);
		fRemovedAssignmentsCount++;
	} else {
		ASTNode initNode = rewrite.createMoveTarget(initializerNode);
		ExpressionStatement statement = rewrite.getAST().newExpressionStatement((Expression) initNode);
		rewrite.replace(statementNode, statement, null);
		fAlteredAssignmentsCount++;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:UnusedCodeFix.java

示例9: replaceCast

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
private static void replaceCast(CastExpression castExpression, Expression replacement, ASTRewrite rewrite, TextEditGroup group) {
	boolean castEnclosedInNecessaryParentheses= castExpression.getParent() instanceof ParenthesizedExpression
			&& NecessaryParenthesesChecker.needsParentheses(castExpression, castExpression.getParent().getParent(), castExpression.getParent().getLocationInParent());

	ASTNode toReplace= castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
	ASTNode move;
	if (NecessaryParenthesesChecker.needsParentheses(replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
		if (replacement.getParent() instanceof ParenthesizedExpression) {
			move= rewrite.createMoveTarget(replacement.getParent());
		} else if (castEnclosedInNecessaryParentheses) {
			toReplace= castExpression;
			move= rewrite.createMoveTarget(replacement);
		} else {
			ParenthesizedExpression parentheses= replacement.getAST().newParenthesizedExpression();
			parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
			move= parentheses;
		}
	} else {
		move= rewrite.createMoveTarget(replacement);
	}
	rewrite.replace(toReplace, move, group);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:UnusedCodeFix.java

示例10: handleManyMany

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
  ListRewrite container =
      fRewrite.getListRewrite(
          fToReplace[0].getParent(), (ChildListPropertyDescriptor) fDescriptor);
  if (fToReplace.length == replacements.length) {
    for (int i = 0; i < fToReplace.length; i++) {
      container.replace(fToReplace[i], replacements[i], description);
    }
  } else if (fToReplace.length < replacements.length) {
    for (int i = 0; i < fToReplace.length; i++) {
      container.replace(fToReplace[i], replacements[i], description);
    }
    for (int i = fToReplace.length; i < replacements.length; i++) {
      container.insertAfter(replacements[i], replacements[i - 1], description);
    }
  } else if (fToReplace.length > replacements.length) {
    int delta = fToReplace.length - replacements.length;
    for (int i = 0; i < delta; i++) {
      container.remove(fToReplace[i], description);
    }
    for (int i = delta, r = 0; i < fToReplace.length; i++, r++) {
      container.replace(fToReplace[i], replacements[r], description);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ReplaceRewrite.java

示例11: replace

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
  ASTNode groupNode = getGroupRoot();

  List<Expression> allOperands = findGroupMembersInOrderFor(getGroupRoot());
  if (allOperands.size() == fOperands.size()) {
    if (replacement instanceof Name && groupNode.getParent() instanceof ParenthesizedExpression) {
      // replace including the parenthesized expression around it
      rewrite.replace(groupNode.getParent(), replacement, textEditGroup);
    } else {
      rewrite.replace(groupNode, replacement, textEditGroup);
    }
    return;
  }

  rewrite.replace(fOperands.get(0), replacement, textEditGroup);
  int first = allOperands.indexOf(fOperands.get(0));
  int after = first + fOperands.size();
  for (int i = first + 1; i < after; i++) {
    rewrite.remove(allOperands.get(i), textEditGroup);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:AssociativeInfixExpressionFragment.java

示例12: handleOneMany

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
@Override
protected void handleOneMany(ASTNode[] replacements, TextEditGroup description) {
  AST ast = fToReplace[0].getAST();
  // to replace == 1, but more than one replacement. Have to check if we
  // need to insert a block to not change structure
  if (ASTNodes.isControlStatementBody(fDescriptor)) {
    Block block = ast.newBlock();
    ListRewrite statements = fRewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
    for (int i = 0; i < replacements.length; i++) {
      statements.insertLast(replacements[i], description);
    }
    fRewrite.replace(fToReplace[0], block, description);
  } else {
    ListRewrite container =
        fRewrite.getListRewrite(
            fToReplace[0].getParent(), (ChildListPropertyDescriptor) fDescriptor);
    container.replace(fToReplace[0], replacements[0], description);
    for (int i = 1; i < replacements.length; i++) {
      container.insertAfter(replacements[i], replacements[i - 1], description);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:StatementRewrite.java

示例13: rewriteAST

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  TextEditGroup group = createTextEditGroup(getDescription(), cuRewrite);
  AST ast = rewrite.getAST();

  FieldAccess fieldAccess = ast.newFieldAccess();

  ThisExpression thisExpression = ast.newThisExpression();
  if (fQualifier != null) thisExpression.setQualifier(ast.newName(fQualifier));

  fieldAccess.setExpression(thisExpression);
  fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));

  rewrite.replace(fName, fieldAccess, group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:CodeStyleFix.java

示例14: rewriteAST

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  String label;
  if (fBodyProperty == IfStatement.THEN_STATEMENT_PROPERTY) {
    label = FixMessages.CodeStyleFix_ChangeIfToBlock_desription;
  } else if (fBodyProperty == IfStatement.ELSE_STATEMENT_PROPERTY) {
    label = FixMessages.CodeStyleFix_ChangeElseToBlock_description;
  } else {
    label = FixMessages.CodeStyleFix_ChangeControlToBlock_description;
  }

  TextEditGroup group = createTextEditGroup(label, cuRewrite);
  ASTNode moveTarget = rewrite.createMoveTarget(fBody);
  Block replacingBody = cuRewrite.getRoot().getAST().newBlock();
  replacingBody.statements().add(moveTarget);
  rewrite.set(fControlStatement, fBodyProperty, replacingBody, group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:ControlStatementsFix.java

示例15: rewriteAST

import org.eclipse.text.edits.TextEditGroup; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(
    CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedProposalPositions)
    throws CoreException {
  AST ast = cuRewrite.getAST();
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  Modifier newModifier = ast.newModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  TextEditGroup textEditGroup =
      createTextEditGroup(
          CorrectionMessages.UnimplementedCodeFix_TextEditGroup_label, cuRewrite);
  rewrite
      .getListRewrite(fTypeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY)
      .insertLast(newModifier, textEditGroup);

  LinkedProposalPositionGroup group =
      new LinkedProposalPositionGroup("modifier"); // $NON-NLS-1$
  group.addPosition(rewrite.track(newModifier), !linkedProposalPositions.hasLinkedPositions());
  linkedProposalPositions.addPositionGroup(group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:UnimplementedCodeFix.java


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