org.eclipse.jdt.core.dom.AnonymousClassDeclaration Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.AnonymousClassDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Visitor.java    From RefactoringMiner with MIT License 6 votes vote down vote up
private DefaultMutableTreeNode insertNode(AnonymousClassDeclaration childAnonymous) {
	Enumeration enumeration = root.postorderEnumeration();
	AnonymousClassDeclarationObject anonymousObject = new AnonymousClassDeclarationObject(cu, filePath, childAnonymous);
	DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(anonymousObject);
	
	DefaultMutableTreeNode parentNode = root;
	while(enumeration.hasMoreElements()) {
		DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)enumeration.nextElement();
		AnonymousClassDeclarationObject currentAnonymous = (AnonymousClassDeclarationObject)currentNode.getUserObject();
		if(currentAnonymous != null && isParent(childAnonymous, currentAnonymous.getAstNode())) {
			parentNode = currentNode;
			break;
		}
	}
	parentNode.add(childNode);
	return childNode;
}
 
Example #2
Source File: ExtractMethodInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getLabel(ASTNode node) {
	if (node instanceof AbstractTypeDeclaration) {
		return ((AbstractTypeDeclaration)node).getName().getIdentifier();
	} else if (node instanceof AnonymousClassDeclaration) {
		if (node.getLocationInParent() == ClassInstanceCreation.ANONYMOUS_CLASS_DECLARATION_PROPERTY) {
			ClassInstanceCreation creation= (ClassInstanceCreation)node.getParent();
			return Messages.format(
				RefactoringMessages.ExtractMethodInputPage_anonymous_type_label,
				BasicElementLabels.getJavaElementName(ASTNodes.asString(creation.getType())));
		} else if (node.getLocationInParent() == EnumConstantDeclaration.ANONYMOUS_CLASS_DECLARATION_PROPERTY) {
			EnumConstantDeclaration decl= (EnumConstantDeclaration)node.getParent();
			return decl.getName().getIdentifier();
		}
	}
	return "UNKNOWN"; //$NON-NLS-1$
}
 
Example #3
Source File: ScopeAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean addOuterDeclarationsForLocalType(ITypeBinding localBinding, int flags, IBindingRequestor requestor) {
	ASTNode node= fRoot.findDeclaringNode(localBinding);
	if (node == null) {
		return false;
	}

	if (node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration) {
		if (addLocalDeclarations(node.getParent(), flags, requestor))
			return true;

		ITypeBinding parentTypeBinding= Bindings.getBindingOfParentType(node.getParent());
		if (parentTypeBinding != null) {
			if (addTypeDeclarations(parentTypeBinding, flags, requestor))
				return true;
		}

	}
	return false;
}
 
Example #4
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final EnumConstantDeclaration node) {
  Javadoc _javadoc = node.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    node.getJavadoc().accept(this);
  }
  this.appendModifiers(node, node.modifiers());
  node.getName().accept(this);
  boolean _isEmpty = node.arguments().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    this.addProblem(node, "Enum constant cannot have any arguments");
    this.appendToBuffer("(");
    this.visitAllSeparatedByComma(node.arguments());
    this.appendToBuffer(")");
  }
  AnonymousClassDeclaration _anonymousClassDeclaration = node.getAnonymousClassDeclaration();
  boolean _tripleNotEquals_1 = (_anonymousClassDeclaration != null);
  if (_tripleNotEquals_1) {
    this.addProblem(node, "Enum constant cannot have any anonymous class declarations");
    node.getAnonymousClassDeclaration().accept(this);
  }
  return false;
}
 
Example #5
Source File: DOMFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(AnonymousClassDeclaration node) {
	ASTNode name;
	ASTNode parent = node.getParent();
	switch (parent.getNodeType()) {
		case ASTNode.CLASS_INSTANCE_CREATION:
			name = ((ClassInstanceCreation) parent).getType();
			if (name.getNodeType() == ASTNode.PARAMETERIZED_TYPE) {
				name = ((ParameterizedType) name).getType();
			}
			break;
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			name = ((EnumConstantDeclaration) parent).getName();
			break;
		default:
			return true;
	}
	if (found(node, name) && this.resolveBinding)
		this.foundBinding = node.resolveBinding();
	return true;
}
 
Example #6
Source File: AddUnimplementedConstructorsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new add unimplemented constructors operation.
 *
 * @param astRoot the compilation unit AST node
 * @param type the type to add the methods to
 * @param constructorsToImplement the method binding keys to implement
 * @param insertPos the insertion point, or <code>-1</code>
 * @param imports <code>true</code> if the import edits should be applied, <code>false</code> otherwise
 * @param apply <code>true</code> if the resulting edit should be applied, <code>false</code> otherwise
 * @param save <code>true</code> if the changed compilation unit should be saved, <code>false</code> otherwise
 */
public AddUnimplementedConstructorsOperation(CompilationUnit astRoot, ITypeBinding type, IMethodBinding[] constructorsToImplement, int insertPos, final boolean imports, final boolean apply, final boolean save) {
	if (astRoot == null || !(astRoot.getJavaElement() instanceof ICompilationUnit)) {
		throw new IllegalArgumentException("AST must not be null and has to be created from a ICompilationUnit"); //$NON-NLS-1$
	}
	if (type == null) {
		throw new IllegalArgumentException("The type must not be null"); //$NON-NLS-1$
	}
	ASTNode node= astRoot.findDeclaringNode(type);
	if (!(node instanceof AnonymousClassDeclaration || node instanceof AbstractTypeDeclaration)) {
		throw new IllegalArgumentException("type has to map to a type declaration in the AST"); //$NON-NLS-1$
	}

	fType= type;
	fInsertPos= insertPos;
	fASTRoot= astRoot;
	fConstructorsToImplement= constructorsToImplement;
	fSave= save;
	fApply= apply;
	fImports= imports;

	fCreateComments= StubUtility.doAddComments(astRoot.getJavaElement().getJavaProject());
	fVisibility= Modifier.PUBLIC;
	fOmitSuper= false;
}
 
Example #7
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the type binding of the node's type context or null if the node is inside
 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
 * 
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
	StructuralPropertyDescriptor lastLocation= null;

	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
			if (lastLocation == decl.getBodyDeclarationsProperty()
					|| lastLocation == decl.getJavadocProperty()) {
				return decl.resolveBinding();
			} else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
				return decl.resolveBinding();
			}
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration) node).resolveBinding();
		}
		lastLocation= node.getLocationInParent();
		node= node.getParent();
	}
	return null;
}
 
Example #8
Source File: UnimplementedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isTypeBindingNull(ASTNode typeNode) {
	if (typeNode instanceof AbstractTypeDeclaration) {
		AbstractTypeDeclaration abstractTypeDeclaration= (AbstractTypeDeclaration) typeNode;
		if (abstractTypeDeclaration.resolveBinding() == null)
			return true;

		return false;
	} else if (typeNode instanceof AnonymousClassDeclaration) {
		AnonymousClassDeclaration anonymousClassDeclaration= (AnonymousClassDeclaration) typeNode;
		if (anonymousClassDeclaration.resolveBinding() == null)
			return true;

		return false;
	} else if (typeNode instanceof EnumConstantDeclaration) {
		return false;
	} else {
		return true;
	}
}
 
Example #9
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(AnonymousClassDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	Type type;
	if (binding != null)
		type = importer.createTypeFromTypeBinding(binding);
	else {
		type = importer.createTypeNamedInUnknownNamespace("");
		logNullBinding("anonymous type declaration", node.getParent().toString().replaceAll("\n", " "),
				((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition()));
	}
	importer.ensureTypeFromAnonymousDeclaration(type, node);
	type.setIsStub(false);
	importer.createSourceAnchor(type, node);
	importer.pushOnContainerStack(type);
	return true;
}
 
Example #10
Source File: SnippetFinder.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static List<Match> perform(ASTNode start, ASTNode[] snippet) {
	Assert.isTrue(start instanceof AbstractTypeDeclaration || start instanceof AnonymousClassDeclaration);
	SnippetFinder finder = new SnippetFinder(snippet);
	start.accept(finder);
	for (Iterator<Match> iter = finder.fResult.iterator(); iter.hasNext();) {
		Match match = iter.next();
		ASTNode[] nodes = match.getNodes();
		// doesn't match if the candidate is the left hand side of an
		// assignment and the snippet consists of a single node.
		// Otherwise y= i; i= z; results in y= e(); e()= z;
		if (nodes.length == 1 && isLeftHandSideOfAssignment(nodes[0])) {
			iter.remove();
		}
	}
	return finder.fResult;
}
 
Example #11
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static String getUniqueMethodName(ASTNode astNode, String suggestedName) throws JavaModelException {
	while (astNode != null && !(astNode instanceof TypeDeclaration || astNode instanceof AnonymousClassDeclaration)) {
		astNode = astNode.getParent();
	}
	if (astNode instanceof TypeDeclaration) {
		ITypeBinding typeBinding = ((TypeDeclaration) astNode).resolveBinding();
		if (typeBinding == null) {
			return suggestedName;
		}
		IType type = (IType) typeBinding.getJavaElement();
		if (type == null) {
			return suggestedName;
		}
		IMethod[] methods = type.getMethods();

		int suggestedPostfix = 2;
		String resultName = suggestedName;
		while (suggestedPostfix < 1000) {
			if (!hasMethod(methods, resultName)) {
				return resultName;
			}
			resultName = suggestedName + suggestedPostfix++;
		}
	}
	return suggestedName;
}
 
Example #12
Source File: SourceAssistProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static IType getSelectionType(IInvocationContext context) {
	ICompilationUnit unit = context.getCompilationUnit();
	ASTNode node = context.getCoveredNode();
	if (node == null) {
		node = context.getCoveringNode();
	}

	ITypeBinding typeBinding = null;
	while (node != null && !(node instanceof CompilationUnit)) {
		if (node instanceof AbstractTypeDeclaration) {
			typeBinding = ((AbstractTypeDeclaration) node).resolveBinding();
			break;
		} else if (node instanceof AnonymousClassDeclaration) { // Anonymous
			typeBinding = ((AnonymousClassDeclaration) node).resolveBinding();
			break;
		}

		node = node.getParent();
	}

	if (typeBinding != null && typeBinding.getJavaElement() instanceof IType) {
		return (IType) typeBinding.getJavaElement();
	}

	return unit.findPrimaryType();
}
 
Example #13
Source File: AnonymousTypeCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private IBinding getEnclosingDeclaration(ASTNode node) {
	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			return ((AbstractTypeDeclaration) node).resolveBinding();
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration) node).resolveBinding();
		} else if (node instanceof MethodDeclaration) {
			return ((MethodDeclaration) node).resolveBinding();
		} else if (node instanceof FieldDeclaration) {
			List<?> fragments = ((FieldDeclaration) node).fragments();
			if (fragments.size() > 0) {
				return ((VariableDeclarationFragment) fragments.get(0)).resolveBinding();
			}
		} else if (node instanceof VariableDeclarationFragment) {
			IVariableBinding variableBinding = ((VariableDeclarationFragment) node).resolveBinding();
			if (variableBinding.getDeclaringMethod() != null || variableBinding.getDeclaringClass() != null) {
				return variableBinding;
				// workaround for incomplete wiring of DOM bindings: keep searching when variableBinding is unparented
			}
		}
		node = node.getParent();
	}
	return null;
}
 
Example #14
Source File: ReplaceTypeCodeWithStateStrategy.java    From JDeodorant with MIT License 6 votes vote down vote up
private Set<MethodDeclaration> getMethodDeclarationsWithinAnonymousClassDeclarations(FieldDeclaration fieldDeclaration) {
	Set<MethodDeclaration> methods = new LinkedHashSet<MethodDeclaration>();
	List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
	for(VariableDeclarationFragment fragment : fragments) {
		Expression expression = fragment.getInitializer();
		if(expression != null && expression instanceof ClassInstanceCreation) {
			ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)expression;
			AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
			if(anonymousClassDeclaration != null) {
				List<BodyDeclaration> bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
				for(BodyDeclaration bodyDeclaration : bodyDeclarations) {
					if(bodyDeclaration instanceof MethodDeclaration)
						methods.add((MethodDeclaration)bodyDeclaration);
				}
			}
		}
	}
	return methods;
}
 
Example #15
Source File: ReplaceTypeCodeWithStateStrategy.java    From JDeodorant with MIT License 6 votes vote down vote up
private Set<MethodDeclaration> getMethodDeclarationsWithinAnonymousClassDeclarations(MethodDeclaration methodDeclaration) {
	Set<MethodDeclaration> methods = new LinkedHashSet<MethodDeclaration>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Expression> classInstanceCreations = expressionExtractor.getClassInstanceCreations(methodDeclaration.getBody());
	for(Expression expression : classInstanceCreations) {
		ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)expression;
		AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
		if(anonymousClassDeclaration != null) {
			List<BodyDeclaration> bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
			for(BodyDeclaration bodyDeclaration : bodyDeclarations) {
				if(bodyDeclaration instanceof MethodDeclaration)
					methods.add((MethodDeclaration)bodyDeclaration);
			}
		}
	}
	return methods;
}
 
Example #16
Source File: TestQ15.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnonymousClassDeclaration node) {
	if (methods2 > 0) {
		classes ++;
		if (maxMethods < methods2)
			maxMethods = methods2;
		if (minMethods > methods2)
			minMethods = methods2;
	}
	
	methods2 = methodsStack.pop();
}
 
Example #17
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final ClassInstanceCreation node) {
	Assert.isNotNull(node);
	if (node.getParent() instanceof ClassInstanceCreation) {
		final AnonymousClassDeclaration declaration= node.getAnonymousClassDeclaration();
		if (declaration != null)
			visit(declaration);
		return false;
	}
	return super.visit(node);
}
 
Example #18
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isInsideSubclassOfDeclaringType(ASTNode node) {
	Assert.isTrue((node instanceof ClassInstanceCreation) || (node instanceof SuperConstructorInvocation));
	final AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(node, AbstractTypeDeclaration.class);
	Assert.isNotNull(declaration);

	final AnonymousClassDeclaration anonymous= (AnonymousClassDeclaration) ASTNodes.getParent(node, AnonymousClassDeclaration.class);
	boolean isAnonymous= anonymous != null && ASTNodes.isParent(anonymous, declaration);
	if (isAnonymous)
		return anonymous != null && isSubclassBindingOfEnclosingType(anonymous.resolveBinding());
	return isSubclassBindingOfEnclosingType(declaration.resolveBinding());
}
 
Example #19
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final void endVisit(final AnonymousClassDeclaration node) {
	Assert.isNotNull(node);
	if (fAnonymousClass > 0)
		fAnonymousClass--;
	super.endVisit(node);
}
 
Example #20
Source File: ExtractStatementsVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean isStartNodeNestedUnderAnonymousClassDeclaration(AnonymousClassDeclaration node) {
	ASTNode parent = startNode.getParent();
	while(parent != null) {
		if(parent.equals(node)) {
			return true;
		}
		parent = parent.getParent();
	}
	return false;
}
 
Example #21
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The node's enclosing method declaration or <code>null</code> if
 * the node is not inside a method and is not a method declaration itself.
 * 
 * @param node a node
 * @return the enclosing method declaration or <code>null</code>
 */
public static MethodDeclaration findParentMethodDeclaration(ASTNode node) {
	while (node != null) {
		if (node instanceof MethodDeclaration) {
			return (MethodDeclaration) node;
		} else if (node instanceof BodyDeclaration || node instanceof AnonymousClassDeclaration || node instanceof LambdaExpression) {
			return null;
		}
		node= node.getParent();
	}
	return null;
}
 
Example #22
Source File: Testq12.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof EnumDeclaration
			|| node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface())
		return false;
	if (node instanceof TypeDeclaration || node instanceof AnonymousClassDeclaration) {
		methodsStack.push(methods2);
		methods2 = 0;
	}
	return true;
}
 
Example #23
Source File: ExtractMethodAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(AnonymousClassDeclaration node) {
	boolean result= super.visit(node);
	if (isFirstSelectedNode(node)) {
		invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_anonymous_type, JavaStatusContext.create(fCUnit, node));
		return false;
	}
	return result;
}
 
Example #24
Source File: TestQ10.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof EnumDeclaration|| node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface())
		return false;
	if (node instanceof TypeDeclaration || node instanceof AnonymousClassDeclaration){
		methodsStack.push(methods2);
		methods2 = 0;
	}
	return true;
}
 
Example #25
Source File: TestQ13.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface()) {
		methodsStack.push(methods2);
		methods2 = 0;
		interfaces++;
		return true;
	}
	if (node instanceof TypeDeclaration || node instanceof AnonymousClassDeclaration
			|| node instanceof EnumDeclaration) {
		return false;
	}
	return true;
}
 
Example #26
Source File: LambdaExpressionsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static boolean isFunctionalAnonymous(ClassInstanceCreation node) {
	ITypeBinding typeBinding= node.resolveTypeBinding();
	if (typeBinding == null)
		return false;
	ITypeBinding[] interfaces= typeBinding.getInterfaces();
	if (interfaces.length != 1)
		return false;
	if (interfaces[0].getFunctionalInterfaceMethod() == null)
		return false;

	AnonymousClassDeclaration anonymTypeDecl= node.getAnonymousClassDeclaration();
	if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null)
		return false;
	
	List<BodyDeclaration> bodyDeclarations= anonymTypeDecl.bodyDeclarations();
	// cannot convert if there are fields or additional methods
	if (bodyDeclarations.size() != 1)
		return false;
	BodyDeclaration bodyDeclaration= bodyDeclarations.get(0);
	if (!(bodyDeclaration instanceof MethodDeclaration))
		return false;

	MethodDeclaration methodDecl= (MethodDeclaration) bodyDeclaration;
	IMethodBinding methodBinding= methodDecl.resolveBinding();

	if (methodBinding == null)
		return false;
	// generic lambda expressions are not allowed
	if (methodBinding.isGenericMethod())
		return false;

	// lambda cannot refer to 'this'/'super' literals
	if (SuperThisReferenceFinder.hasReference(methodDecl))
		return false;
	
	if (!isInTargetTypeContext(node))
		return false;
	
	return true;
}
 
Example #27
Source File: TestQ19.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof EnumDeclaration|| node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface())
		return false;
	if (node instanceof TypeDeclaration || node instanceof AnonymousClassDeclaration){
		fieldsStack.push(fieds2);
		fieds2 = 0;
	}
	return true;
}
 
Example #28
Source File: TestQ16.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnonymousClassDeclaration node) {
	if (methods2 > 0) {
		classes++;
		if (maxMethods < methods2)
			maxMethods = methods2;
		if (minMethods > methods2)
			minMethods = methods2;
	}

	methods2 = methodsStack.pop();
}
 
Example #29
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the type binding of the node's enclosing type declaration.
 * 
 * @param node an AST node
 * @return the type binding of the node's parent type declaration, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentType(ASTNode node) {
	while (node != null) {
		if (node instanceof AbstractTypeDeclaration) {
			return ((AbstractTypeDeclaration) node).resolveBinding();
		} else if (node instanceof AnonymousClassDeclaration) {
			return ((AnonymousClassDeclaration) node).resolveBinding();
		}
		node= node.getParent();
	}
	return null;
}
 
Example #30
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
private DefaultMutableTreeNode findNode(AnonymousClassDeclaration anonymous) {
	Enumeration enumeration = root.postorderEnumeration();
	
	while(enumeration.hasMoreElements()) {
		DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)enumeration.nextElement();
		AnonymousClassDeclarationObject currentAnonymous = (AnonymousClassDeclarationObject)currentNode.getUserObject();
		if(currentAnonymous != null && currentAnonymous.getAstNode().equals(anonymous)) {
			return currentNode;
		}
	}
	return null;
}