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


Java ContextSensitiveImportRewriteContext类代码示例

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


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

示例1: createDeclaration

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private VariableDeclarationStatement createDeclaration(
    IVariableBinding binding, Expression intilizer) {
  VariableDeclaration original =
      ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
  VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
  fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
  fragment.setInitializer(intilizer);
  VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
  result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
  result.setType(
      ASTNodeFactory.newType(
          fAST,
          original,
          fImportRewriter,
          new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ExtractMethodRefactoring.java

示例2: getIteratorBasedForInitializer

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
/**
 * Generates the initializer for an iterator based <code>for</code> loop, which declares and
 * initializes the variable to loop over.
 *
 * @param rewrite the instance of {@link ASTRewrite}
 * @param loopVariableName the proposed name of the loop variable
 * @return a {@link VariableDeclarationExpression} to use as initializer
 */
private VariableDeclarationExpression getIteratorBasedForInitializer(
    ASTRewrite rewrite, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  IMethodBinding iteratorMethodBinding =
      Bindings.findMethodInHierarchy(
          fExpressionType, "iterator", new ITypeBinding[] {}); // $NON-NLS-1$
  // initializing fragment
  VariableDeclarationFragment varDeclarationFragment = ast.newVariableDeclarationFragment();
  varDeclarationFragment.setName(loopVariableName);
  MethodInvocation iteratorExpression = ast.newMethodInvocation();
  iteratorExpression.setName(ast.newSimpleName(iteratorMethodBinding.getName()));
  iteratorExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
  varDeclarationFragment.setInitializer(iteratorExpression);

  // declaration
  VariableDeclarationExpression varDeclarationExpression =
      ast.newVariableDeclarationExpression(varDeclarationFragment);
  varDeclarationExpression.setType(
      getImportRewrite()
          .addImport(
              iteratorMethodBinding.getReturnType(),
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));

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

示例3: InitializerTraversal

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
public InitializerTraversal(
    Expression initializer,
    HashSet<SimpleName> staticImportsInInitializer,
    Expression newLocation,
    HashSet<SimpleName> staticImportsInReference,
    CompilationUnitRewrite newLocationCuRewrite) {
  fInitializer = initializer;
  fInitializerRewrite = ASTRewrite.create(initializer.getAST());
  fStaticImportsInInitializer2 = staticImportsInInitializer;

  fNewLocation = newLocation;
  fStaticImportsInReference = staticImportsInReference;
  fNewLocationCuRewrite = newLocationCuRewrite;
  fNewLocationContext =
      new ContextSensitiveImportRewriteContext(
          fNewLocation, fNewLocationCuRewrite.getImportRewrite());

  perform(initializer);
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:InlineConstantRefactoring.java

示例4: getIteratorBasedForBodyAssignment

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的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

示例5: getForBodyAssignment

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的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

示例6: getIndexBasedForBodyAssignment

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的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

示例7: getRewrite

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
  AST ast = fTypeNode.getAST();

  ASTRewrite rewrite = ASTRewrite.create(ast);

  createImportRewrite((CompilationUnit) fTypeNode.getRoot());

  CodeGenerationSettings settings =
      JavaPreferencesSettings.getCodeGenerationSettings(getCompilationUnit().getJavaProject());
  if (!settings.createComments) {
    settings = null;
  }
  ImportRewriteContext importRewriteContext =
      new ContextSensitiveImportRewriteContext(fTypeNode, getImportRewrite());

  MethodDeclaration newMethodDecl =
      createNewMethodDeclaration(ast, fSuperConstructor, rewrite, importRewriteContext, settings);
  rewrite
      .getListRewrite(fTypeNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY)
      .insertFirst(newMethodDecl, null);

  addLinkedRanges(rewrite, newMethodDecl);

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

示例8: doAddField

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
  SimpleName node = fOriginalNode;
  boolean isInDifferentCU = false;

  ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
  if (newTypeDecl == null) {
    astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
    newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
    isInDifferentCU = true;
  }
  ImportRewrite imports = createImportRewrite(astRoot);
  ImportRewriteContext importRewriteContext =
      new ContextSensitiveImportRewriteContext(
          ASTResolving.findParentBodyDeclaration(node), imports);

  if (newTypeDecl != null) {
    AST ast = newTypeDecl.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(node.getIdentifier()));

    Type type = evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);

    FieldDeclaration newDecl = ast.newFieldDeclaration(fragment);
    newDecl.setType(type);
    newDecl
        .modifiers()
        .addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));

    if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
      fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
    }

    ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
    List<BodyDeclaration> decls =
        ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);

    int maxOffset = isInDifferentCU ? -1 : node.getStartPosition();

    int insertIndex = findFieldInsertIndex(decls, newDecl, maxOffset);

    ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
    listRewriter.insertAt(newDecl, insertIndex, null);

    ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
        getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());

    addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
    if (!isInDifferentCU) {
      addLinkedPosition(rewrite.track(node), true, KEY_NAME);
    }
    addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);

    if (fragment.getInitializer() != null) {
      addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
    }
    return rewrite;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:63,代码来源:NewVariableCorrectionProposal.java

示例9: getNewType

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private Type getNewType(ASTRewrite rewrite) {
  AST ast = rewrite.getAST();
  Type newTypeNode = null;
  ITypeBinding binding = null;
  if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
    Expression value = ((MemberValuePair) fInvocationNode.getParent()).getValue();
    binding = value.resolveTypeBinding();
  } else if (fInvocationNode instanceof Expression) {
    binding = ((Expression) fInvocationNode).resolveTypeBinding();
  }
  if (binding != null) {
    ImportRewriteContext importRewriteContext =
        new ContextSensitiveImportRewriteContext(fInvocationNode, getImportRewrite());
    newTypeNode = getImportRewrite().addImport(binding, ast, importRewriteContext);
  }
  if (newTypeNode == null) {
    newTypeNode = ast.newSimpleType(ast.newSimpleName("String")); // $NON-NLS-1$
  }
  addLinkedPosition(rewrite.track(newTypeNode), false, KEY_TYPE);
  return newTypeNode;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:NewAnnotationMemberProposal.java

示例10: rewrite

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
protected void rewrite(FieldAccess node, ITypeBinding type) {
	Expression exp= node.getExpression();
	if (exp == null) {
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(node, fCuRewrite.getImportRewrite());
		Type result= fCuRewrite.getImportRewrite().addImport(type, fCuRewrite.getAST(), context);
		fCuRewrite.getImportRemover().registerAddedImport(type.getQualifiedName());
		exp= ASTNodeFactory.newName(fCuRewrite.getAST(), ASTFlattener.asString(result));
		fCuRewrite.getASTRewrite().set(node, FieldAccess.EXPRESSION_PROPERTY, exp,  fCuRewrite.createGroupDescription(REFERENCE_UPDATE));
		fNeedsImport= true;
	} else if (exp instanceof Name) {
		rewriteName((Name)exp, type);
	} else {
		rewriteExpression(node, exp, type);
	}
	fProcessed.add(node.getName());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:MoveStaticMemberAnalyzer.java

示例11: createParameterClassAwareContext

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
ContextSensitiveImportRewriteContext createParameterClassAwareContext(final boolean asTopLevelClass, final CompilationUnitRewrite cuRewrite, int position) {
	ContextSensitiveImportRewriteContext context= new ContextSensitiveImportRewriteContext(cuRewrite.getRoot(), position, cuRewrite.getImportRewrite()) {
		@Override
		public int findInContext(String qualifier, String name, int kind) {
			String parameterClassName= getClassName();
			if (kind == ImportRewriteContext.KIND_TYPE && parameterClassName.equals(name)) {
				String parameterClassQualifier= asTopLevelClass ? getPackage() : getEnclosingType();
				if (super.findInContext(qualifier, "", kind) == ImportRewriteContext.RES_NAME_FOUND) { //$NON-NLS-1$ // TODO: should be "*", not " "!
					if (parameterClassQualifier.equals(qualifier)) {
						return ImportRewriteContext.RES_NAME_FOUND;
					} else {
						return ImportRewriteContext.RES_NAME_CONFLICT;
					}
				}
			}
			return super.findInContext(qualifier, name, kind);
		}
	};
	return context;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ParameterObjectFactory.java

示例12: addMethodStubForAbstractMethod

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private void addMethodStubForAbstractMethod(final IMethod sourceMethod, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration typeToCreateStubIn, final ICompilationUnit newCu, final CompilationUnitRewrite rewriter, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws CoreException {
	final MethodDeclaration methodToCreateStubFor= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode);
	final AST ast= rewriter.getRoot().getAST();
	final MethodDeclaration newMethod= ast.newMethodDeclaration();
	newMethod.setBody(createMethodStub(methodToCreateStubFor, ast));
	newMethod.setConstructor(false);
	copyExtraDimensions(methodToCreateStubFor, newMethod);
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiersWithUpdatedVisibility(sourceMethod, JdtFlags.clearFlag(Modifier.NATIVE | Modifier.ABSTRACT, methodToCreateStubFor.getModifiers()), adjustments, new SubProgressMonitor(monitor, 1), false, status)));
	newMethod.setName(((SimpleName) ASTNode.copySubtree(ast, methodToCreateStubFor.getName())));
	final TypeVariableMaplet[] mapping= TypeVariableUtil.composeMappings(TypeVariableUtil.subTypeToSuperType(getDeclaringType(), getDestinationType()), TypeVariableUtil.superTypeToInheritedType(getDestinationType(), ((IType) typeToCreateStubIn.resolveBinding().getJavaElement())));
	copyReturnType(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
	copyParameters(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping);
	copyThrownExceptions(methodToCreateStubFor, newMethod);
	newMethod.setJavadoc(createJavadocForStub(typeToCreateStubIn.getName().getIdentifier(), methodToCreateStubFor, newMethod, newCu, rewriter.getASTRewrite()));
	ImportRewriteContext context= new ContextSensitiveImportRewriteContext(typeToCreateStubIn, rewriter.getImportRewrite());
	ImportRewriteUtil.addImports(rewriter, context, newMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
	rewriter.getASTRewrite().getListRewrite(typeToCreateStubIn, typeToCreateStubIn.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, typeToCreateStubIn.bodyDeclarations()), rewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_method_stub, SET_PULL_UP));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:PullUpRefactoringProcessor.java

示例13: createAbstractMethod

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private void createAbstractMethod(final IMethod sourceMethod, final CompilationUnitRewrite sourceRewriter, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration destination, final TypeVariableMaplet[] mapping, final CompilationUnitRewrite targetRewrite, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode);
	if (JavaModelUtil.is50OrHigher(sourceMethod.getJavaProject()) && (fSettings.overrideAnnotation || JavaCore.ERROR.equals(sourceMethod.getJavaProject().getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true)))) {
		final MarkerAnnotation annotation= sourceRewriter.getAST().newMarkerAnnotation();
		annotation.setTypeName(sourceRewriter.getAST().newSimpleName("Override")); //$NON-NLS-1$
		sourceRewriter.getASTRewrite().getListRewrite(oldMethod, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, sourceRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_override_annotation, SET_PULL_UP));
	}
	final MethodDeclaration newMethod= targetRewrite.getAST().newMethodDeclaration();
	newMethod.setBody(null);
	newMethod.setConstructor(false);
	copyExtraDimensions(oldMethod, newMethod);
	newMethod.setJavadoc(null);
	int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, Modifier.ABSTRACT | JdtFlags.clearFlag(Modifier.NATIVE | Modifier.FINAL, sourceMethod.getFlags()), adjustments, monitor, false, status);
	if (oldMethod.isVarargs())
		modifiers&= ~Flags.AccVarargs;
	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(targetRewrite.getAST(), modifiers));
	newMethod.setName(((SimpleName) ASTNode.copySubtree(targetRewrite.getAST(), oldMethod.getName())));
	copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
	copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping);
	copyThrownExceptions(oldMethod, newMethod);
	copyTypeParameters(oldMethod, newMethod);
	ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite());
	ImportRewriteUtil.addImports(targetRewrite, context, oldMethod, new HashMap<Name, String>(), new HashMap<Name, String>(), false);
	targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:PullUpRefactoringProcessor.java

示例14: createDeclaration

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) {
	VariableDeclaration original= ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
	VariableDeclarationFragment fragment= fAST.newVariableDeclarationFragment();
	fragment.setName((SimpleName)ASTNode.copySubtree(fAST, original.getName()));
	fragment.setInitializer(intilizer);
	VariableDeclarationStatement result= fAST.newVariableDeclarationStatement(fragment);
	result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
	result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:ExtractMethodRefactoring.java

示例15: rewriteAST

import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	TextEditGroup group= createTextEditGroup(FixMessages.TypeParametersFix_insert_inferred_type_arguments_description, cuRewrite);

	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	ImportRewrite importRewrite= cuRewrite.getImportRewrite();
	AST ast= cuRewrite.getRoot().getAST();

	for (int i= 0; i < fCreatedTypes.length; i++) {
		ParameterizedType createdType= fCreatedTypes[i];

		ITypeBinding[] typeArguments= createdType.resolveBinding().getTypeArguments();
		ContextSensitiveImportRewriteContext importContext= new ContextSensitiveImportRewriteContext(cuRewrite.getRoot(), createdType.getStartPosition(), importRewrite);

		ListRewrite argumentsRewrite= rewrite.getListRewrite(createdType, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);
		for (int j= 0; j < typeArguments.length; j++) {
			ITypeBinding typeArgument= typeArguments[j];
			Type argumentNode= importRewrite.addImport(typeArgument, ast, importContext);
			argumentsRewrite.insertLast(argumentNode, group);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:TypeParametersFix.java


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