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


Java NodeFinder.perform方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.NodeFinder.perform方法的典型用法代码示例。如果您正苦于以下问题:Java NodeFinder.perform方法的具体用法?Java NodeFinder.perform怎么用?Java NodeFinder.perform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.NodeFinder的用法示例。


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

示例1: addEdits

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
	super.addEdits(doc, root);

	// build a full AST
	CompilationUnit unit = SharedASTProvider.getInstance().getAST(getCompilationUnit(), null);

	ASTNode name= NodeFinder.perform(unit, fOffset, fLength);
	if (name instanceof SimpleName) {

		SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
		if (names != null) {
			for (int i= 0; i < names.length; i++) {
				SimpleName curr= names[i];
				root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
			}
			return;
		}
	}
	root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:RenameNodeCorrectionProposal.java

示例2: findConstantNameNode

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private Name findConstantNameNode() {
  ASTNode node =
      NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
  if (node == null) return null;
  if (node instanceof FieldAccess) node = ((FieldAccess) node).getName();
  if (!(node instanceof Name)) return null;
  Name name = (Name) node;
  IBinding binding = name.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return null;
  IVariableBinding variableBinding = (IVariableBinding) binding;
  if (!variableBinding.isField() || variableBinding.isEnumConstant()) return null;
  int modifiers = binding.getModifiers();
  if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) return null;

  return name;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:InlineConstantRefactoring.java

示例3: checkInitialConditions

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  if (fVisibility < 0)
    fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
  RefactoringStatus result = new RefactoringStatus();
  result.merge(Checks.checkAvailability(fField));
  if (result.hasFatalError()) return result;
  fRoot =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(fField.getCompilationUnit(), true, pm);
  ISourceRange sourceRange = fField.getNameRange();
  ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
  if (node == null) {
    return mappingErrorFound(result, node);
  }
  fFieldDeclaration =
      (VariableDeclarationFragment) ASTNodes.getParent(node, VariableDeclarationFragment.class);
  if (fFieldDeclaration == null) {
    return mappingErrorFound(result, node);
  }
  if (fFieldDeclaration.resolveBinding() == null) {
    if (!processCompilerError(result, node))
      result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
    return result;
  }
  computeUsedNames();
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:SelfEncapsulateFieldRefactoring.java

示例4: addEdits

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
  super.addEdits(doc, root);

  // build a full AST
  CompilationUnit unit =
      SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null);

  ASTNode name = NodeFinder.perform(unit, fOffset, fLength);
  if (name instanceof SimpleName) {

    SimpleName[] names = LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
    if (names != null) {
      for (int i = 0; i < names.length; i++) {
        SimpleName curr = names[i];
        root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
      }
      return;
    }
  }
  root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:RenameNodeCorrectionProposal.java

示例5: getHoverRegion

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
	if (!(getEditor() instanceof JavaEditor))
		return null;

	ITypeRoot je= getEditorInputJavaElement();
	if (je == null)
		return null;

	// Never wait for an AST in UI thread.
	CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
	if (ast == null)
		return null;

	ASTNode node= NodeFinder.perform(ast, offset, 1);
	if (node instanceof StringLiteral) {
		StringLiteral stringLiteral= (StringLiteral)node;
		return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
	} else if (node instanceof SimpleName) {
		SimpleName simpleName= (SimpleName)node;
		return new Region(simpleName.getStartPosition(), simpleName.getLength());
	}

	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:26,代码来源:NLSStringHover.java

示例6: findConstantNameNode

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private Name findConstantNameNode() {
	ASTNode node= NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
	if (node == null)
		return null;
	if (node instanceof FieldAccess)
		node= ((FieldAccess) node).getName();
	if (!(node instanceof Name))
		return null;
	Name name= (Name) node;
	IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return null;
	IVariableBinding variableBinding= (IVariableBinding) binding;
	if (!variableBinding.isField() || variableBinding.isEnumConstant())
		return null;
	int modifiers= binding.getModifiers();
	if (! (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)))
		return null;

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

示例7: findByProblems

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
	ArrayList<SimpleName> res= new ArrayList<>();

	ASTNode astRoot = parent.getRoot();
	if (!(astRoot instanceof CompilationUnit)) {
		return null;
	}

	IProblem[] problems= ((CompilationUnit) astRoot).getProblems();
	int nameNodeKind= getNameNodeProblemKind(problems, nameNode);
	if (nameNodeKind == 0) { // no problem on node
		return null;
	}

	int bodyStart= parent.getStartPosition();
	int bodyEnd= bodyStart + parent.getLength();

	String name= nameNode.getIdentifier();

	for (int i= 0; i < problems.length; i++) {
		IProblem curr= problems[i];
		int probStart= curr.getSourceStart();
		int probEnd= curr.getSourceEnd() + 1;

		if (probStart > bodyStart && probEnd < bodyEnd) {
			int currKind= getProblemKind(curr);
			if ((nameNodeKind & currKind) != 0) {
				ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart));
				if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
					res.add((SimpleName) node);
				}
			}
		}
	}
	return res.toArray(new SimpleName[res.size()]);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:LinkedNodeFinder.java

示例8: isSideEffectFree

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private static boolean isSideEffectFree(SimpleName simpleName, CompilationUnit completeRoot) {
	SimpleName nameNode= (SimpleName) NodeFinder.perform(completeRoot, simpleName.getStartPosition(), simpleName.getLength());
	SimpleName[] references= LinkedNodeFinder.findByBinding(completeRoot, nameNode.resolveBinding());
	for (int i= 0; i < references.length; i++) {
		if (hasSideEffect(references[i])) {
			return false;
		}
	}
	return true;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:UnusedCodeFix.java

示例9: visit

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
@Override
public boolean visit(Assignment node) {
	boolean result = super.visit(node);
	Selection selection = getSelection();
	ASTNode selectedNode = NodeFinder.perform(node, selection.getOffset(), selection.getLength());
	if ((selectedNode != null && SnippetFinder.isLeftHandSideOfAssignment(selectedNode)) || (selection.covers(node.getLeftHandSide()) && !selection.covers(node.getRightHandSide()))) {
		invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_leftHandSideOfAssignment, JavaStatusContext.create(fCUnit, node));
		return false;
	}
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:ExtractMethodAnalyzer.java

示例10: getASTNode

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
public static ASTNode getASTNode(int offset, int length, IEditorPart part) {
	IJavaElement activeEditorJavaInput = null;
	if (part != null) {
		IEditorInput editorInput = part.getEditorInput();
		if (editorInput != null) {
			activeEditorJavaInput = JavaUI
					.getEditorInputJavaElement(editorInput);
		}
	} else {
		activeEditorJavaInput = EditorUtility.getActiveEditorJavaInput();
		part = getActivePart();
	}

	if (activeEditorJavaInput != null
			&& activeEditorJavaInput.getElementType() == IJavaElement.COMPILATION_UNIT) {

		ICompilationUnit compilationUnit = (ICompilationUnit) activeEditorJavaInput;
		ASTParser parser = ASTParser.newParser(AST.JLS3);
		parser.setKind(ASTParser.K_COMPILATION_UNIT);
		parser.setSource(compilationUnit);
		parser.setResolveBindings(true);
		ASTNode root = parser.createAST(null);

		ASTNode node = NodeFinder.perform(root, offset, length);
		return node;
	}
	return null;
}
 
开发者ID:aroog,项目名称:code,代码行数:29,代码来源:ASTUtils.java

示例11: rewriteExpressions

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private void rewriteExpressions(CompilationUnit node, SearchMatch match,
		RefactoringStatus status, ASTRewrite astRewrite,
		ImportRewrite importRewrite) {
	final ASTNode result = NodeFinder.perform(node, match.getOffset(),
			match.getLength());
	final InfixExpression ie = Util.getInfixExpression(result);
	if (ie == null) // there is none.
		return;
	else if (Util.inNeedOfTransformation(ie.getOperator())) {
		// Get the fully qualified type name.
		final String fqn = this.getFullyQualifiedName(((Name) result)
				.resolveBinding().getJavaElement());
		this.rewriteInfixExpression(astRewrite, importRewrite, ie, fqn);
	}
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:16,代码来源:ConvertConstantsToEnumRefactoring.java

示例12: getClonesFromDecard

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private static Multimap<Integer, ASTNode> getClonesFromDecard(
		final String clusterFile, final File baseDirectory)
		throws IOException {
	final List<String> lines = FileUtils.readLines(new File(clusterFile));
	int id = 0;
	final Multimap<Integer, ASTNode> nodesInCluster = ArrayListMultimap
			.create();

	final JavaASTExtractor astExtractor = new JavaASTExtractor(false);

	for (final String line : lines) {
		if (line.length() == 0) {
			id++;
			continue;
		}
		final Matcher matcher = decardClone.matcher(line);
		checkArgument(matcher.find());
		final String filename = matcher.group(1);
		final int startingLine = Integer.parseInt(matcher.group(2));
		final int offestLine = Integer.parseInt(matcher.group(3));

		final File targetFile = new File(baseDirectory.getAbsolutePath()
				+ "/" + filename);
		final CompilationUnit fileAst = astExtractor.getAST(targetFile);
		final int start = fileAst.getPosition(startingLine, 0);
		final int end = fileAst.getPosition(startingLine + offestLine - 1,
				0);

		final ASTNode cloneNode = NodeFinder.perform(fileAst, start, end
				- start);
		nodesInCluster.put(id, cloneNode);
	}

	return nodesInCluster;
}
 
开发者ID:mast-group,项目名称:codemining-treelm,代码行数:36,代码来源:DeckardClonesInTsg.java

示例13: findByProblems

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
  ArrayList<SimpleName> res = new ArrayList<SimpleName>();

  ASTNode astRoot = parent.getRoot();
  if (!(astRoot instanceof CompilationUnit)) {
    return null;
  }

  IProblem[] problems = ((CompilationUnit) astRoot).getProblems();
  int nameNodeKind = getNameNodeProblemKind(problems, nameNode);
  if (nameNodeKind == 0) { // no problem on node
    return null;
  }

  int bodyStart = parent.getStartPosition();
  int bodyEnd = bodyStart + parent.getLength();

  String name = nameNode.getIdentifier();

  for (int i = 0; i < problems.length; i++) {
    IProblem curr = problems[i];
    int probStart = curr.getSourceStart();
    int probEnd = curr.getSourceEnd() + 1;

    if (probStart > bodyStart && probEnd < bodyEnd) {
      int currKind = getProblemKind(curr);
      if ((nameNodeKind & currKind) != 0) {
        ASTNode node = NodeFinder.perform(parent, probStart, (probEnd - probStart));
        if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
          res.add((SimpleName) node);
        }
      }
    }
  }
  return res.toArray(new SimpleName[res.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:LinkedNodeFinder.java

示例14: isSideEffectFree

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
private static boolean isSideEffectFree(SimpleName simpleName, CompilationUnit completeRoot) {
  SimpleName nameNode =
      (SimpleName)
          NodeFinder.perform(completeRoot, simpleName.getStartPosition(), simpleName.getLength());
  SimpleName[] references =
      LinkedNodeFinder.findByBinding(completeRoot, nameNode.resolveBinding());
  for (int i = 0; i < references.length; i++) {
    if (hasSideEffect(references[i])) return false;
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:UnusedCodeFix.java

示例15: findNode

import org.eclipse.jdt.core.dom.NodeFinder; //导入方法依赖的package包/类
public static ASTNode findNode(SearchMatch searchResult, CompilationUnit cuNode) {
  ASTNode selectedNode =
      NodeFinder.perform(cuNode, searchResult.getOffset(), searchResult.getLength());
  if (selectedNode == null) return null;
  if (selectedNode.getParent() == null) return null;
  return selectedNode;
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:ASTNodeSearchUtil.java


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