• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ASTNodeSearchUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getEnhancedForStatements

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private static Set<EnhancedForStatement> getEnhancedForStatements(IMethod method, IProgressMonitor pm)
		throws JavaModelException {
	ICompilationUnit iCompilationUnit = method.getCompilationUnit();

	// get the ASTParser of the method
	CompilationUnit compilationUnit = RefactoringASTParser.parseWithASTProvider(iCompilationUnit, true,
			new SubProgressMonitor(pm, 1));

	// get the method declaration ASTNode.
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(method, compilationUnit);

	final Set<EnhancedForStatement> statements = new LinkedHashSet<EnhancedForStatement>();
	// extract all enhanced for loop statements in the method.
	methodDeclarationNode.accept(new ASTVisitor() {

		@Override
		public boolean visit(EnhancedForStatement node) {
			statements.add(node);
			return super.visit(node);
		}
	});

	return statements;
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:25,代码来源:ForeachLoopToLambdaRefactoring.java


示例2: copyImportsToDestination

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void copyImportsToDestination(
    IImportContainer container,
    ASTRewrite rewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  ListRewrite listRewrite =
      rewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);

  IJavaElement[] importDeclarations = container.getChildren();
  for (int i = 0; i < importDeclarations.length; i++) {
    IImportDeclaration declaration = (IImportDeclaration) importDeclarations[i];

    ImportDeclaration sourceNode =
        ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
    ImportDeclaration copiedNode =
        (ImportDeclaration) ASTNode.copySubtree(rewrite.getAST(), sourceNode);

    if (getLocation() == IReorgDestination.LOCATION_BEFORE) {
      listRewrite.insertFirst(copiedNode, null);
    } else {
      listRewrite.insertLast(copiedNode, null);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ReorgPolicyFactory.java


示例3: copyImportToDestination

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void copyImportToDestination(
    IImportDeclaration declaration,
    ASTRewrite targetRewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  ImportDeclaration sourceNode =
      ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
  ImportDeclaration copiedNode =
      (ImportDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
  ListRewrite listRewrite =
      targetRewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);

  if (getJavaElementDestination() instanceof IImportDeclaration) {
    ImportDeclaration destinationNode =
        ASTNodeSearchUtil.getImportDeclarationNode(
            (IImportDeclaration) getJavaElementDestination(), destinationCuNode);
    insertRelative(copiedNode, destinationNode, listRewrite);
  } else {
    // dropped on container, we could be better here
    listRewrite.insertLast(copiedNode, null);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ReorgPolicyFactory.java


示例4: performFirstPass

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
/**
 * Performs the first pass of processing the affected compilation units.
 *
 * @param creator
 *            the constraints creator to use
 * @param units
 *            the compilation unit map (element type:
 *            <code>&lt;IJavaProject, Set&lt;ICompilationUnit&gt;&gt;</code>)
 * @param groups
 *            the search result group map (element type:
 *            <code>&lt;ICompilationUnit, SearchResultGroup&gt;</code>)
 * @param unit
 *            the compilation unit of the subtype
 * @param node
 *            the compilation unit node of the subtype
 * @param monitor
 *            the progress monitor to use
 */
protected final void performFirstPass(final SuperTypeConstraintsCreator creator, final Map<IJavaProject, Set<ICompilationUnit>> units, final Map<ICompilationUnit, SearchResultGroup> groups, final ICompilationUnit unit, final CompilationUnit node, final IProgressMonitor monitor) {
	try {
		monitor.beginTask("", 100); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.SuperTypeRefactoringProcessor_creating);
		node.accept(creator);
		monitor.worked(20);
		final SearchResultGroup group= groups.get(unit);
		if (group != null) {
			final ASTNode[] nodes= ASTNodeSearchUtil.getAstNodes(group.getSearchResults(), node);
			try {
				getMethodReferencingCompilationUnits(units, nodes);
				monitor.worked(40);
				getFieldReferencingCompilationUnits(units, nodes);
				monitor.worked(40);
			} catch (JavaModelException exception) {
				JavaPlugin.log(exception);
			}
		}
	} finally {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:SuperTypeRefactoringProcessor.java


示例5: copyImportsToDestination

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void copyImportsToDestination(IImportContainer container, ASTRewrite rewrite, CompilationUnit sourceCuNode, CompilationUnit destinationCuNode) throws JavaModelException {
	ListRewrite listRewrite= rewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);

	IJavaElement[] importDeclarations= container.getChildren();
	for (int i= 0; i < importDeclarations.length; i++) {
		IImportDeclaration declaration= (IImportDeclaration) importDeclarations[i];

		ImportDeclaration sourceNode= ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
		ImportDeclaration copiedNode= (ImportDeclaration) ASTNode.copySubtree(rewrite.getAST(), sourceNode);

		if (getLocation() == IReorgDestination.LOCATION_BEFORE) {
			listRewrite.insertFirst(copiedNode, null);
		} else {
			listRewrite.insertLast(copiedNode, null);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:ReorgPolicyFactory.java


示例6: getDestinationNode

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException {
	switch (destination.getElementType()) {
		case IJavaElement.INITIALIZER:
			return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target);
		case IJavaElement.FIELD:
			return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target);
		case IJavaElement.METHOD:
			return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target);
		case IJavaElement.TYPE:
			IType typeDestination= (IType) destination;
			if (typeDestination.isAnonymous()) {
				return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration();
			} else {
				return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target);
			}
		case IJavaElement.COMPILATION_UNIT:
			IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination);
			if (mainType != null) {
				return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target);
			}
			//$FALL-THROUGH$
		default:
			return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ReorgPolicyFactory.java


示例7: getFieldSource

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private static String getFieldSource(IField field, SourceTuple tuple) throws CoreException {
	if (Flags.isEnum(field.getFlags())) {
		String source= field.getSource();
		if (source != null)
			return source;
	} else {
		if (tuple.node == null) {
			ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
			parser.setSource(tuple.unit);
			tuple.node= (CompilationUnit) parser.createAST(null);
		}
		FieldDeclaration declaration= ASTNodeSearchUtil.getFieldDeclarationNode(field, tuple.node);
		if (declaration.fragments().size() == 1)
			return getSourceOfDeclararationNode(field, tuple.unit);
		VariableDeclarationFragment declarationFragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(field, tuple.node);
		IBuffer buffer= tuple.unit.getBuffer();
		StringBuffer buff= new StringBuffer();
		buff.append(buffer.getText(declaration.getStartPosition(), ((ASTNode) declaration.fragments().get(0)).getStartPosition() - declaration.getStartPosition()));
		buff.append(buffer.getText(declarationFragment.getStartPosition(), declarationFragment.getLength()));
		buff.append(";"); //$NON-NLS-1$
		return buff.toString();
	}
	return ""; //$NON-NLS-1$
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:TypedSource.java


示例8: AddDelegateMethodsContentProvider

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
AddDelegateMethodsContentProvider(CompilationUnit astRoot, IType type, IField[] fields) throws JavaModelException {

			final ITypeBinding binding= ASTNodes.getTypeBinding(astRoot, type);
			if (binding != null) {
				fDelegateEntries= StubUtility2.getDelegatableMethods(binding);

				List<IVariableBinding> expanded= new ArrayList<IVariableBinding>();
				for (int index= 0; index < fields.length; index++) {
					VariableDeclarationFragment fragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(fields[index], astRoot);
					if (fragment != null) {
						IVariableBinding variableBinding= fragment.resolveBinding();
						if (variableBinding != null)
							expanded.add(variableBinding);
					}
				}
				fExpanded= expanded.toArray(new IVariableBinding[expanded.size()]);
			}
		}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:AddDelegateMethodsAction.java


示例9: getRealMethodDeclarationNode

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
public static org.eclipse.jdt.core.dom.MethodDeclaration getRealMethodDeclarationNode(org.eclipse.jdt.core.IMethod sourceMethod, org.eclipse.jdt.core.dom.CompilationUnit cuUnit) throws JavaModelException {
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, cuUnit);
	if (isGenerated(methodDeclarationNode)) {
		IType declaringType = sourceMethod.getDeclaringType();
		Stack<IType> typeStack = new Stack<IType>();
		while (declaringType != null) {
			typeStack.push(declaringType);
			declaringType = declaringType.getDeclaringType();
		}
		
		IType rootType = typeStack.pop();
		org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = findTypeDeclaration(rootType, cuUnit.types());
		while (!typeStack.isEmpty() && typeDeclaration != null) {
			typeDeclaration = findTypeDeclaration(typeStack.pop(), typeDeclaration.bodyDeclarations());
		}
		
		if (typeStack.isEmpty() && typeDeclaration != null) {
			String methodName = sourceMethod.getElementName();
			for (Object declaration : typeDeclaration.bodyDeclarations()) {
				if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
					org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration = (org.eclipse.jdt.core.dom.MethodDeclaration) declaration;
					if (methodDeclaration.getName().toString().equals(methodName)) {
						return methodDeclaration;
					}
				}
			}
		}
	}
	return methodDeclarationNode;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:31,代码来源:PatchFixesHider.java


示例10: getMethodDeclaration

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private MethodDeclaration getMethodDeclaration(IMethod method, Optional<IProgressMonitor> pm)
		throws JavaModelException {
	ITypeRoot root = method.getCompilationUnit();
	CompilationUnit unit = this.getCompilationUnit(root,
			new SubProgressMonitor(pm.orElseGet(NullProgressMonitor::new), IProgressMonitor.UNKNOWN));
	MethodDeclaration declaration = ASTNodeSearchUtil.getMethodDeclarationNode(method, unit);
	return declaration;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:9,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java


示例11: resolveMethodBinding

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private IMethodBinding resolveMethodBinding(IMethod method, Optional<IProgressMonitor> monitor)
		throws JavaModelException {
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(method,
			getCompilationUnit(method.getTypeRoot(),
					new SubProgressMonitor(monitor.orElseGet(NullProgressMonitor::new), IProgressMonitor.UNKNOWN)));

	if (methodDeclarationNode != null)
		return methodDeclarationNode.resolveBinding();
	else
		return null;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:12,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java


示例12: resolveReturnTypeBinding

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private ITypeBinding resolveReturnTypeBinding(IMethod method, Optional<IProgressMonitor> monitor)
		throws JavaModelException {
	MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(method,
			getCompilationUnit(method.getTypeRoot(),
					new SubProgressMonitor(monitor.orElseGet(NullProgressMonitor::new), IProgressMonitor.UNKNOWN)));

	if (methodDeclarationNode != null) {
		Type returnType = methodDeclarationNode.getReturnType2();
		return returnType.resolveBinding();
	} else
		return null;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:13,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java


示例13: addDeclarationUpdate

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void addDeclarationUpdate(TextChangeManager manager) throws CoreException {

    if (getDelegateUpdating()) {
      // create the delegate
      CompilationUnitRewrite rewrite = new CompilationUnitRewrite(getDeclaringCU());
      rewrite.setResolveBindings(true);
      MethodDeclaration methodDeclaration =
          ASTNodeSearchUtil.getMethodDeclarationNode(getMethod(), rewrite.getRoot());
      DelegateMethodCreator creator = new DelegateMethodCreator();
      creator.setDeclaration(methodDeclaration);
      creator.setDeclareDeprecated(getDeprecateDelegates());
      creator.setSourceRewrite(rewrite);
      creator.setCopy(true);
      creator.setNewElementName(getNewElementName());
      creator.prepareDelegate();
      creator.createEdit();
      CompilationUnitChange cuChange = rewrite.createChange(true);
      if (cuChange != null) {
        cuChange.setKeepPreviewEdits(true);
        manager.manage(getDeclaringCU(), cuChange);
      }
    }

    String editName = RefactoringCoreMessages.RenameMethodRefactoring_update_declaration;
    ISourceRange nameRange = getMethod().getNameRange();
    ReplaceEdit replaceEdit =
        new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
    addTextEdit(manager.get(getDeclaringCU()), editName, replaceEdit);
  }
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:RenameNonVirtualMethodProcessor.java


示例14: addMethodDelegate

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void addMethodDelegate(IMethod getter, String newName, CompilationUnitRewrite rewrite)
    throws JavaModelException {
  MethodDeclaration declaration =
      ASTNodeSearchUtil.getMethodDeclarationNode(getter, rewrite.getRoot());
  DelegateCreator creator = new DelegateMethodCreator();
  creator.setDeclareDeprecated(fDelegateDeprecation);
  creator.setDeclaration(declaration);
  creator.setNewElementName(newName);
  creator.setSourceRewrite(rewrite);
  creator.prepareDelegate();
  creator.createEdit();
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:RenameFieldProcessor.java


示例15: createRenameChanges

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
/**
 * Creates the necessary changes for the renaming of the type parameter.
 *
 * @param monitor the progress monitor to display progress
 * @return the status of the operation
 * @throws CoreException if the change could not be generated
 */
private RefactoringStatus createRenameChanges(IProgressMonitor monitor) throws CoreException {
  Assert.isNotNull(monitor);
  RefactoringStatus status = new RefactoringStatus();
  try {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeParameterRefactoring_searching, 2);
    ICompilationUnit cu = fTypeParameter.getDeclaringMember().getCompilationUnit();
    CompilationUnit root = RefactoringASTParser.parseWithASTProvider(cu, true, null);
    CompilationUnitRewrite rewrite = new CompilationUnitRewrite(cu, root);
    IMember member = fTypeParameter.getDeclaringMember();
    ASTNode declaration = null;
    if (member instanceof IMethod) {
      declaration = ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, root);
    } else if (member instanceof IType) {
      declaration = ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, root);
    } else {
      JavaPlugin.logErrorMessage(
          "Unexpected sub-type of IMember: " + member.getClass().getName()); // $NON-NLS-1$
      Assert.isTrue(false);
    }
    monitor.worked(1);
    RenameTypeParameterVisitor visitor =
        new RenameTypeParameterVisitor(rewrite, fTypeParameter.getNameRange(), status);
    if (declaration != null) declaration.accept(visitor);
    fChange = visitor.getResult();
  } finally {
    monitor.done();
  }
  return status;
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:RenameTypeParameterProcessor.java


示例16: getNodesToDelete

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private static ASTNode[] getNodesToDelete(IJavaElement element, CompilationUnit cuNode)
    throws JavaModelException {
  // fields are different because you don't delete the whole declaration but only a fragment of it
  if (element.getElementType() == IJavaElement.FIELD) {
    if (JdtFlags.isEnum((IField) element))
      return new ASTNode[] {
        ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element, cuNode)
      };
    else
      return new ASTNode[] {
        ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) element, cuNode)
      };
  }
  if (element.getElementType() == IJavaElement.TYPE && ((IType) element).isLocal()) {
    IType type = (IType) element;
    if (type.isAnonymous()) {
      if (type.getParent().getElementType() == IJavaElement.FIELD) {
        EnumConstantDeclaration enumDecl =
            ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element.getParent(), cuNode);
        if (enumDecl != null && enumDecl.getAnonymousClassDeclaration() != null) {
          return new ASTNode[] {enumDecl.getAnonymousClassDeclaration()};
        }
      }
      ClassInstanceCreation creation =
          ASTNodeSearchUtil.getClassInstanceCreationNode(type, cuNode);
      if (creation != null) {
        if (creation.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) {
          return new ASTNode[] {creation.getParent()};
        } else if (creation.getLocationInParent()
            == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
          return new ASTNode[] {creation};
        }
        return new ASTNode[] {creation.getAnonymousClassDeclaration()};
      }
      return new ASTNode[0];
    } else {
      ASTNode[] nodes = ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
      // we have to delete the TypeDeclarationStatement
      nodes[0] = nodes[0].getParent();
      return nodes;
    }
  }
  return ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
}
 
开发者ID:eclipse,项目名称:che,代码行数:45,代码来源:ASTNodeDeleteUtil.java


示例17: getDestinationNode

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target)
    throws JavaModelException {
  switch (destination.getElementType()) {
    case IJavaElement.INITIALIZER:
      return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target);
    case IJavaElement.FIELD:
      return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target);
    case IJavaElement.METHOD:
      return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode(
          (IMethod) destination, target);
    case IJavaElement.TYPE:
      IType typeDestination = (IType) destination;
      if (typeDestination.isAnonymous()) {
        return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target)
            .getAnonymousClassDeclaration();
      } else {
        return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target);
      }
    case IJavaElement.COMPILATION_UNIT:
      IType mainType = JavaElementUtil.getMainType((ICompilationUnit) destination);
      if (mainType != null) {
        return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target);
      }
      // $FALL-THROUGH$
    default:
      return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:ReorgPolicyFactory.java


示例18: copyPackageDeclarationToDestination

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void copyPackageDeclarationToDestination(
    IPackageDeclaration declaration,
    ASTRewrite targetRewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  if (destinationCuNode.getPackage() != null) return;
  PackageDeclaration sourceNode =
      ASTNodeSearchUtil.getPackageDeclarationNode(declaration, sourceCuNode);
  PackageDeclaration copiedNode =
      (PackageDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
  targetRewrite.set(destinationCuNode, CompilationUnit.PACKAGE_PROPERTY, copiedNode, null);
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:ReorgPolicyFactory.java


示例19: checkMethodBody

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
protected static RefactoringStatus checkMethodBody(IMethod method, IProgressMonitor pm) {
	RefactoringStatus status = new RefactoringStatus();

	ITypeRoot root = method.getCompilationUnit();
	CompilationUnit unit = RefactoringASTParser.parseWithASTProvider(root, false, new SubProgressMonitor(pm, 1));

	MethodDeclaration declaration;
	try {
		declaration = ASTNodeSearchUtil.getMethodDeclarationNode(method, unit);
		if (declaration != null) {
			Block body = declaration.getBody();

			if (body != null) {
				@SuppressWarnings("rawtypes")
				List statements = body.statements();

				if (!statements.isEmpty()) {
					// TODO for now.
					addWarning(status, Messages.ForEachLoopToLambdaRefactoring_NoMethodsWithStatements, method);
				}
			}
		}
	} catch (JavaModelException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	return status;
}
 
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:30,代码来源:ForeachLoopToLambdaRefactoring.java


示例20: addDeclarationUpdate

import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; //导入依赖的package包/类
private void addDeclarationUpdate(TextChangeManager manager) throws CoreException {

		if (getDelegateUpdating()) {
			// create the delegate
			CompilationUnitRewrite rewrite= new CompilationUnitRewrite(getDeclaringCU());
			rewrite.setResolveBindings(true);
			MethodDeclaration methodDeclaration= ASTNodeSearchUtil.getMethodDeclarationNode(getMethod(), rewrite.getRoot());
			DelegateMethodCreator creator= new DelegateMethodCreator();
			creator.setDeclaration(methodDeclaration);
			creator.setDeclareDeprecated(getDeprecateDelegates());
			creator.setSourceRewrite(rewrite);
			creator.setCopy(true);
			creator.setNewElementName(getNewElementName());
			creator.prepareDelegate();
			creator.createEdit();
			CompilationUnitChange cuChange= rewrite.createChange(true);
			if (cuChange != null) {
				cuChange.setKeepPreviewEdits(true);
				manager.manage(getDeclaringCU(), cuChange);
			}
		}

		String editName= RefactoringCoreMessages.RenameMethodRefactoring_update_declaration;
		ISourceRange nameRange= getMethod().getNameRange();
		ReplaceEdit replaceEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
		addTextEdit(manager.get(getDeclaringCU()), editName, replaceEdit);
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:RenameNonVirtualMethodProcessor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ForgeRegistry类代码示例发布时间:2022-05-23
下一篇:
Java TileEntitySkull类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap