use of org.eclipse.jdt.core.dom.StructuralPropertyDescriptor in project flux by eclipse.
the class Bindings method getBindingOfParentTypeContext.
/**
* 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;
}
use of org.eclipse.jdt.core.dom.StructuralPropertyDescriptor in project processing by processing.
the class CompletionGenerator method findClosestParentNode.
protected static ASTNode findClosestParentNode(int lineNumber, ASTNode node) {
// Base.loge("Props of " + node.getClass().getName());
for (StructuralPropertyDescriptor prop : (Iterable<StructuralPropertyDescriptor>) node.structuralPropertiesForType()) {
if (prop.isChildProperty() || prop.isSimpleProperty()) {
if (node.getStructuralProperty(prop) != null) {
// .println(node.getStructuralProperty(prop) + " -> " + (prop));
if (node.getStructuralProperty(prop) instanceof ASTNode) {
ASTNode cnode = (ASTNode) node.getStructuralProperty(prop);
// log("Looking at " + getNodeAsString(cnode)+ " for line num " + lineNumber);
int cLineNum = ((CompilationUnit) cnode.getRoot()).getLineNumber(cnode.getStartPosition() + cnode.getLength());
if (getLineNumber(cnode) <= lineNumber && lineNumber <= cLineNum) {
return findClosestParentNode(lineNumber, cnode);
}
}
}
} else if (prop.isChildListProperty()) {
List<ASTNode> nodelist = (List<ASTNode>) node.getStructuralProperty(prop);
for (ASTNode cnode : nodelist) {
int cLineNum = ((CompilationUnit) cnode.getRoot()).getLineNumber(cnode.getStartPosition() + cnode.getLength());
// log("Looking at " + getNodeAsString(cnode)+ " for line num " + lineNumber);
if (getLineNumber(cnode) <= lineNumber && lineNumber <= cLineNum) {
return findClosestParentNode(lineNumber, cnode);
}
}
}
}
return node;
}
use of org.eclipse.jdt.core.dom.StructuralPropertyDescriptor in project AutoRefactor by JnRouvignac.
the class UseDiamondOperatorRefactoring method parentAllowsDiamondOperator.
private boolean parentAllowsDiamondOperator(ClassInstanceCreation node) {
final ASTNode parentInfo = getFirstParentOfType(node, ParenthesizedExpression.class);
final StructuralPropertyDescriptor locationInParent = parentInfo.getLocationInParent();
switch(parentInfo.getParent().getNodeType()) {
case ASSIGNMENT:
return Assignment.RIGHT_HAND_SIDE_PROPERTY.equals(locationInParent);
case METHOD_INVOCATION:
// FIXME some of them can be refactored
return false;
case RETURN_STATEMENT:
return ReturnStatement.EXPRESSION_PROPERTY.equals(locationInParent);
case VARIABLE_DECLARATION_FRAGMENT:
return VariableDeclarationFragment.INITIALIZER_PROPERTY.equals(locationInParent);
default:
return false;
}
}
Aggregations