本文整理汇总了Java中org.eclipse.jdt.core.dom.NodeFinder类的典型用法代码示例。如果您正苦于以下问题:Java NodeFinder类的具体用法?Java NodeFinder怎么用?Java NodeFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeFinder类属于org.eclipse.jdt.core.dom包,在下文中一共展示了NodeFinder类的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));
}
示例2: initAST
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
private void initAST(IProgressMonitor pm) {
if (fCompilationUnitNode == null) {
fCompilationUnitNode = RefactoringASTParser.parseWithASTProvider(fCu, true, pm);
}
if (fAnonymousInnerClassNode == null) {
fAnonymousInnerClassNode =
getAnonymousInnerClass(
NodeFinder.perform(fCompilationUnitNode, fSelectionStart, fSelectionLength));
}
if (fAnonymousInnerClassNode != null) {
final AbstractTypeDeclaration declaration =
(AbstractTypeDeclaration)
ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class);
if (declaration instanceof TypeDeclaration) {
final AbstractTypeDeclaration[] nested = ((TypeDeclaration) declaration).getTypes();
fClassNamesUsed = new HashSet<String>(nested.length);
for (int index = 0; index < nested.length; index++)
fClassNamesUsed.add(nested[index].getName().getIdentifier());
} else fClassNamesUsed = Collections.emptySet();
}
}
示例3: 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;
}
示例4: getTargetNode
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
/**
* Finds and returns the <code>ASTNode</code> for the given source text selection, if it is an
* entire constructor call or the class name portion of a constructor call or constructor
* declaration, or null otherwise.
*
* @param unit The compilation unit in which the selection was made
* @param offset The textual offset of the start of the selection
* @param length The length of the selection in characters
* @return ClassInstanceCreation or MethodDeclaration
*/
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
ASTNode node = ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return node;
if (node.getNodeType() == ASTNode.METHOD_DECLARATION
&& ((MethodDeclaration) node).isConstructor()) return node;
// we have some sub node. Make sure its the right child of the parent
StructuralPropertyDescriptor location = node.getLocationInParent();
ASTNode parent = node.getParent();
if (location == ClassInstanceCreation.TYPE_PROPERTY) {
return parent;
} else if (location == MethodDeclaration.NAME_PROPERTY
&& ((MethodDeclaration) parent).isConstructor()) {
return parent;
}
return null;
}
示例5: 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;
}
示例6: 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));
}
示例7: checkInitialConditions
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask(RefactoringCoreMessages.MoveMembersRefactoring_checking, 1);
RefactoringStatus result= new RefactoringStatus();
result.merge(checkDeclaringType());
pm.worked(1);
if (result.hasFatalError())
return result;
fSource= new CompilationUnitRewrite(fMembersToMove[0].getCompilationUnit());
fSourceBinding= (ITypeBinding)((SimpleName)NodeFinder.perform(fSource.getRoot(), fMembersToMove[0].getDeclaringType().getNameRange())).resolveBinding();
fMemberBindings= getMemberBindings();
if (fSourceBinding == null || hasUnresolvedMemberBinding()) {
result.addFatalError(Messages.format(
RefactoringCoreMessages.MoveMembersRefactoring_compile_errors,
BasicElementLabels.getFileName(fSource.getCu())));
}
fMemberDeclarations= getASTMembers(result);
return result;
} finally {
pm.done();
}
}
示例8: getASTMembers
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
private BodyDeclaration[] getASTMembers(RefactoringStatus status) throws JavaModelException {
BodyDeclaration[] result= new BodyDeclaration[fMembersToMove.length];
for (int i= 0; i < fMembersToMove.length; i++) {
IMember member= fMembersToMove[i];
ASTNode node= NodeFinder.perform(fSource.getRoot(), member.getNameRange());
result[i]= (BodyDeclaration)ASTNodes.getParent(node, BodyDeclaration.class);
//Fix for bug 42383: exclude multiple VariableDeclarationFragments ("int a=1, b=2")
//ReferenceAnalyzer#visit(FieldDeclaration node) depends on fragments().size() != 1 !
if (result[i] instanceof FieldDeclaration
&& ((FieldDeclaration) result[i]).fragments().size() != 1) {
status.addFatalError(RefactoringCoreMessages.MoveMembersRefactoring_multi_var_fields);
return result;
}
}
//Sorting members is important for field declarations referring to previous fields.
Arrays.sort(result, new Comparator<BodyDeclaration>() {
public int compare(BodyDeclaration o1, BodyDeclaration o2) {
return o1.getStartPosition() - o2.getStartPosition();
}
});
return result;
}
示例9: createExceptionInfoList
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
private RefactoringStatus createExceptionInfoList() {
if (fExceptionInfos == null || fExceptionInfos.isEmpty()) {
fExceptionInfos= new ArrayList<ExceptionInfo>(0);
try {
ASTNode nameNode= NodeFinder.perform(fBaseCuRewrite.getRoot(), fMethod.getNameRange());
if (nameNode == null || !(nameNode instanceof Name) || !(nameNode.getParent() instanceof MethodDeclaration))
return null;
MethodDeclaration methodDeclaration= (MethodDeclaration) nameNode.getParent();
List<Type> exceptions= methodDeclaration.thrownExceptionTypes();
List<ExceptionInfo> result= new ArrayList<ExceptionInfo>(exceptions.size());
for (int i= 0; i < exceptions.size(); i++) {
Type type= exceptions.get(i);
ITypeBinding typeBinding= type.resolveBinding();
if (typeBinding == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_no_exception_binding);
IJavaElement element= typeBinding.getJavaElement();
result.add(ExceptionInfo.createInfoForOldException(element, typeBinding));
}
fExceptionInfos= result;
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
}
return null;
}
示例10: 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;
}
示例11: 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:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:22,代码来源:RenameNodeCorrectionProposal.java
示例12: getTargetNode
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
/**
* Finds and returns the <code>ASTNode</code> for the given source text
* selection, if it is an entire constructor call or the class name portion
* of a constructor call or constructor declaration, or null otherwise.
* @param unit The compilation unit in which the selection was made
* @param offset The textual offset of the start of the selection
* @param length The length of the selection in characters
* @return ClassInstanceCreation or MethodDeclaration
*/
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
ASTNode node= ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
return node;
if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration)node).isConstructor())
return node;
// we have some sub node. Make sure its the right child of the parent
StructuralPropertyDescriptor location= node.getLocationInParent();
ASTNode parent= node.getParent();
if (location == ClassInstanceCreation.TYPE_PROPERTY) {
return parent;
} else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration)parent).isConstructor()) {
return parent;
}
return null;
}
示例13: initDomAST
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
private void initDomAST() {
if (isReadOnly())
return;
ASTParser parser= ASTParser.newParser(AST.JLS4);
parser.setSource(getCompilationUnit());
parser.setResolveBindings(true);
org.eclipse.jdt.core.dom.ASTNode domAst = parser.createAST(new NullProgressMonitor());
// org.eclipse.jdt.core.dom.AST ast = domAst.getAST();
NodeFinder nf = new NodeFinder(domAst, getCompletionOffset(), 1);
org.eclipse.jdt.core.dom.ASTNode cv = nf.getCoveringNode();
bodyDeclaration = ASTResolving.findParentBodyDeclaration(cv);
parentDeclaration = ASTResolving.findParentType(cv);
domInitialized = true;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:19,代码来源:JavaStatementPostfixContext.java
示例14: getConstantValueFromActiveEditor
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
/**
* Returns the constant value for a field that is referenced by the currently active type.
* This method does may not run in the main UI thread.
* <p>
* XXX: This method was part of the JavadocHover#getConstantValue(IField field, IRegion hoverRegion)
* method (lines 299-314).
* </p>
* @param activeType the type that is currently active
* @param field the field that is being referenced (usually not declared in <code>activeType</code>)
* @param selection the region in <code>activeType</code> that contains the field reference
* @param monitor a progress monitor
*
* @return the constant value for the given field or <code>null</code> if none
* @since 3.4
*/
private static Object getConstantValueFromActiveEditor(ITypeRoot activeType, IField field, ITextSelection selection, IProgressMonitor monitor) {
Object constantValue= null;
CompilationUnit unit= SharedASTProvider.getAST(activeType, SharedASTProvider.WAIT_ACTIVE_ONLY, monitor);
if (unit == null)
return null;
ASTNode node= NodeFinder.perform(unit, selection.getOffset(), selection.getLength());
if (node != null && node.getNodeType() == ASTNode.SIMPLE_NAME) {
IBinding binding= ((SimpleName)node).resolveBinding();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
IVariableBinding variableBinding= (IVariableBinding)binding;
if (field.equals(variableBinding.getJavaElement())) {
constantValue= variableBinding.getConstantValue();
}
}
}
return constantValue;
}
示例15: generateSetterMethod
import org.eclipse.jdt.core.dom.NodeFinder; //导入依赖的package包/类
/**
* Generates a new setter method for the specified field
*
* @param field the field
* @param astRewrite the AST rewrite to use
* @param rewrite the list rewrite to use
* @throws CoreException if an error occurs
* @throws OperationCanceledException if the operation has been cancelled
*/
private void generateSetterMethod(final IField field, ASTRewrite astRewrite, final ListRewrite rewrite) throws CoreException, OperationCanceledException {
final IType type= field.getDeclaringType();
final String name= GetterSetterUtil.getSetterName(field, null);
final IMethod existing= JavaModelUtil.findMethod(name, new String[] { field.getTypeSignature()}, false, type);
if (existing == null || !querySkipExistingMethods(existing)) {
IJavaElement sibling= null;
if (existing != null) {
sibling= StubUtility.findNextSibling(existing);
removeExistingAccessor(existing, rewrite);
} else
sibling= fInsert;
ASTNode insertion= StubUtility2.getNodeToInsertBefore(rewrite, sibling);
addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion);
if (Flags.isFinal(field.getFlags())) {
ASTNode fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class);
if (fieldDecl != null) {
ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null);
}
}
}
}