本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNodes.getParent方法的具体用法?Java ASTNodes.getParent怎么用?Java ASTNodes.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.dom.ASTNodes
的用法示例。
在下文中一共展示了ASTNodes.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLeftHandSideOfAssignment
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
static boolean isLeftHandSideOfAssignment(ASTNode node) {
Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
if (assignment != null) {
Expression leftHandSide = assignment.getLeftHandSide();
if (leftHandSide == node) {
return true;
}
if (ASTNodes.isParent(node, leftHandSide)) {
switch (leftHandSide.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return true;
case ASTNode.FIELD_ACCESS:
return node == ((FieldAccess) leftHandSide).getName();
case ASTNode.QUALIFIED_NAME:
return node == ((QualifiedName) leftHandSide).getName();
case ASTNode.SUPER_FIELD_ACCESS:
return node == ((SuperFieldAccess) leftHandSide).getName();
default:
return false;
}
}
}
return false;
}
示例2: considerBinding
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private boolean considerBinding(IBinding binding, ASTNode node) {
if (!(binding instanceof IVariableBinding)) return false;
boolean result =
Bindings.equals(fFieldBinding, ((IVariableBinding) binding).getVariableDeclaration());
if (!result || fEncapsulateDeclaringClass) return result;
if (binding instanceof IVariableBinding) {
AbstractTypeDeclaration type =
(AbstractTypeDeclaration) ASTNodes.getParent(node, AbstractTypeDeclaration.class);
if (type != null) {
ITypeBinding declaringType = type.resolveBinding();
return !Bindings.equals(fDeclaringClassBinding, declaringType);
}
}
return true;
}
示例3: canAddFinal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean canAddFinal(IBinding binding, ASTNode declNode) {
if (!(binding instanceof IVariableBinding)) return false;
IVariableBinding varbinding = (IVariableBinding) binding;
int modifiers = varbinding.getModifiers();
if (Modifier.isFinal(modifiers)
|| Modifier.isVolatile(modifiers)
|| Modifier.isTransient(modifiers)) return false;
ASTNode parent = ASTNodes.getParent(declNode, VariableDeclarationExpression.class);
if (parent != null && ((VariableDeclarationExpression) parent).fragments().size() > 1)
return false;
if (varbinding.isField() && !Modifier.isPrivate(modifiers)) return false;
if (varbinding.isParameter()) {
ASTNode varDecl = declNode.getParent();
if (varDecl instanceof MethodDeclaration) {
MethodDeclaration declaration = (MethodDeclaration) varDecl;
if (declaration.getBody() == null) return false;
}
}
return true;
}
示例4: checkInitialConditions
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的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;
}
示例5: isLeftHandSideOfAssignment
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean isLeftHandSideOfAssignment(ASTNode node) {
Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
if (assignment != null) {
Expression leftHandSide = assignment.getLeftHandSide();
if (leftHandSide == node) {
return true;
}
if (ASTNodes.isParent(node, leftHandSide)) {
switch (leftHandSide.getNodeType()) {
case ASTNode.SIMPLE_NAME:
return true;
case ASTNode.FIELD_ACCESS:
return node == ((FieldAccess) leftHandSide).getName();
case ASTNode.QUALIFIED_NAME:
return node == ((QualifiedName) leftHandSide).getName();
case ASTNode.SUPER_FIELD_ACCESS:
return node == ((SuperFieldAccess) leftHandSide).getName();
default:
return false;
}
}
}
return false;
}
示例6: getProblematicImport
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static ImportDeclaration getProblematicImport(IProblem problem, CompilationUnit astRoot) {
ASTNode coveringNode = new NodeFinder(astRoot, problem.getSourceStart(),
problem.getSourceEnd() - problem.getSourceStart()).getCoveringNode();
if (coveringNode != null) {
ASTNode importNode= ASTNodes.getParent(coveringNode, ASTNode.IMPORT_DECLARATION);
if (importNode instanceof ImportDeclaration) {
return (ImportDeclaration) importNode;
}
}
return null;
}
示例7: needsImport
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
return false; // no imports for anonymous, local, primitive types or parameters types
}
int modifiers= typeBinding.getModifiers();
if (Modifier.isPrivate(modifiers)) {
return false; // imports for privates are not required
}
ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref);
if (currTypeBinding == null) {
if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
return true; // reference in package-info.java
}
return false; // not in a type
}
if (!Modifier.isPublic(modifiers)) {
if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
return false; // not visible
}
}
ASTNode parent= ref.getParent();
while (parent instanceof Type) {
parent= parent.getParent();
}
if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) {
return true;
}
if (typeBinding.isMember()) {
if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY)) {
return false;
}
}
return true;
}
示例8: getEnclosingBodyDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public BodyDeclaration getEnclosingBodyDeclaration() {
ASTNode node = getFirstSelectedNode();
if (node == null) {
return null;
}
return (BodyDeclaration) ASTNodes.getParent(node, BodyDeclaration.class);
}
示例9: getEnclosingNode
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static ASTNode getEnclosingNode(ASTNode firstSelectedNode) {
ASTNode enclosingNode;
if (firstSelectedNode instanceof MethodReference) {
enclosingNode = firstSelectedNode;
} else {
enclosingNode = ASTResolving.findEnclosingLambdaExpression(firstSelectedNode);
if (enclosingNode != null) {
enclosingNode = ((LambdaExpression) enclosingNode).getBody();
} else {
enclosingNode = ASTNodes.getParent(firstSelectedNode, BodyDeclaration.class);
}
}
return enclosingNode;
}
示例10: getWritingConstructor
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private MethodDeclaration getWritingConstructor(SimpleName name) {
Assignment assignement = (Assignment) ASTNodes.getParent(name, Assignment.class);
if (assignement == null) return null;
ASTNode expression = assignement.getParent();
if (!(expression instanceof ExpressionStatement)) return null;
ASTNode block = expression.getParent();
if (!(block instanceof Block)) return null;
ASTNode methodDeclaration = block.getParent();
if (!(methodDeclaration instanceof MethodDeclaration)) return null;
return (MethodDeclaration) methodDeclaration;
}
示例11: getVariableDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static VariableDeclaration getVariableDeclaration(Name node) {
IBinding binding = node.resolveBinding();
if (binding == null && node.getParent() instanceof VariableDeclaration)
return (VariableDeclaration) node.getParent();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
CompilationUnit cu = (CompilationUnit) ASTNodes.getParent(node, CompilationUnit.class);
return ASTNodes.findVariableDeclaration(((IVariableBinding) binding), cu);
}
return null;
}
示例12: getMethodDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static MethodDeclaration getMethodDeclaration(
TextEdit edit, TextChange change, CompilationUnit cuNode) {
ASTNode decl =
RefactoringAnalyzeUtil.findSimpleNameNode(
RefactoringAnalyzeUtil.getNewTextRange(edit, change), cuNode);
return ((MethodDeclaration) ASTNodes.getParent(decl, MethodDeclaration.class));
}
示例13: isRecursiveReference
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private boolean isRecursiveReference() {
MethodDeclaration enclosingMethodDeclaration =
(MethodDeclaration) ASTNodes.getParent(fNode, MethodDeclaration.class);
if (enclosingMethodDeclaration == null) return false;
IMethodBinding enclosingMethodBinding = enclosingMethodDeclaration.resolveBinding();
if (enclosingMethodBinding == null) return false;
if (fNode instanceof MethodInvocation)
return enclosingMethodBinding == ((MethodInvocation) fNode).resolveMethodBinding();
if (fNode instanceof SuperMethodInvocation) {
IMethodBinding methodBinding = ((SuperMethodInvocation) fNode).resolveMethodBinding();
return isSameMethod(methodBinding, enclosingMethodBinding);
}
if (fNode instanceof ClassInstanceCreation)
return enclosingMethodBinding
== ((ClassInstanceCreation) fNode).resolveConstructorBinding();
if (fNode instanceof ConstructorInvocation)
return enclosingMethodBinding
== ((ConstructorInvocation) fNode).resolveConstructorBinding();
if (fNode instanceof SuperConstructorInvocation) {
return false; // Constructors don't override -> enclosing has not been changed -> no
// recursion
}
if (fNode instanceof EnumConstantDeclaration) {
return false; // cannot define enum constant inside enum constructor
}
Assert.isTrue(false);
return false;
}
示例14: getNamesDeclaredLocallyAtNewLocation
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private Set<String> getNamesDeclaredLocallyAtNewLocation() {
if (fNamesDeclaredLocallyAtNewLocation != null) return fNamesDeclaredLocallyAtNewLocation;
BodyDeclaration enclosingBodyDecl =
(BodyDeclaration) ASTNodes.getParent(fNewLocation, BodyDeclaration.class);
Assert.isTrue(!(enclosingBodyDecl instanceof AbstractTypeDeclaration));
return fNamesDeclaredLocallyAtNewLocation = getLocallyDeclaredNames(enclosingBodyDecl);
}
示例15: isDeclaredIn
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static boolean isDeclaredIn(
VariableDeclaration tempDeclaration, Class<? extends ASTNode> astNodeClass) {
ASTNode initializer = ASTNodes.getParent(tempDeclaration, astNodeClass);
if (initializer == null) return false;
ASTNode anonymous = ASTNodes.getParent(tempDeclaration, AnonymousClassDeclaration.class);
if (anonymous == null) return true;
// stupid code. Is to find out if the variable declaration isn't a field.
if (ASTNodes.isParent(anonymous, initializer)) return false;
return true;
}