use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project che by eclipse.
the class SemanticHighlightings method getBinding.
/**
* Extracts the binding from the token's simple name.
* Works around bug 62605 to return the correct constructor binding in a ClassInstanceCreation.
*
* @param token
* the token to extract the binding from
* @return the token's binding, or <code>null</code>
*/
private static IBinding getBinding(SemanticToken token) {
ASTNode node = token.getNode();
ASTNode normalized = ASTNodes.getNormalizedNode(node);
if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
// work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
return ((ClassInstanceCreation) normalized.getParent()).resolveConstructorBinding();
}
return token.getBinding();
}
use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project che by eclipse.
the class SourceProvider method updateImplicitReceivers.
private void updateImplicitReceivers(ASTRewrite rewriter, CallContext context) {
if (context.receiver == null)
return;
List<Expression> implicitReceivers = fAnalyzer.getImplicitReceivers();
for (Iterator<Expression> iter = implicitReceivers.iterator(); iter.hasNext(); ) {
ASTNode node = iter.next();
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(node, context.importer);
if (node instanceof MethodInvocation) {
final MethodInvocation inv = (MethodInvocation) node;
rewriter.set(inv, MethodInvocation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, (IMethodBinding) inv.getName().resolveBinding(), importRewriteContext), null);
} else if (node instanceof ClassInstanceCreation) {
final ClassInstanceCreation inst = (ClassInstanceCreation) node;
rewriter.set(inst, ClassInstanceCreation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, inst.resolveConstructorBinding(), importRewriteContext), null);
} else if (node instanceof ThisExpression) {
rewriter.replace(node, rewriter.createStringPlaceholder(context.receiver, ASTNode.METHOD_INVOCATION), null);
} else if (node instanceof FieldAccess) {
final FieldAccess access = (FieldAccess) node;
rewriter.set(access, FieldAccess.EXPRESSION_PROPERTY, createReceiver(rewriter, context, access.resolveFieldBinding(), importRewriteContext), null);
} else if (node instanceof SimpleName && ((SimpleName) node).resolveBinding() instanceof IVariableBinding) {
IVariableBinding vb = (IVariableBinding) ((SimpleName) node).resolveBinding();
if (vb.isField()) {
Expression receiver = createReceiver(rewriter, context, vb, importRewriteContext);
if (receiver != null) {
FieldAccess access = node.getAST().newFieldAccess();
ASTNode target = rewriter.createMoveTarget(node);
access.setName((SimpleName) target);
access.setExpression(receiver);
rewriter.replace(node, access, null);
}
}
}
}
}
use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project che by eclipse.
the class PotentialProgrammingProblemsFix method getDeclarationNode.
/**
* Returns the declaration node for the originally selected node.
* @param name the name of the node
*
* @return the declaration node
*/
private static ASTNode getDeclarationNode(SimpleName name) {
ASTNode parent = name.getParent();
if (!(parent instanceof AbstractTypeDeclaration)) {
parent = parent.getParent();
if (parent instanceof ParameterizedType || parent instanceof Type)
parent = parent.getParent();
if (parent instanceof ClassInstanceCreation) {
final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
parent = creation.getAnonymousClassDeclaration();
}
}
return parent;
}
use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project che by eclipse.
the class ASTNodeDeleteUtil method getNodesToDelete.
private static ASTNode[] getNodesToDelete(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
// fields are different because you don't delete the whole declaration but only a fragment of it
if (element.getElementType() == IJavaElement.FIELD) {
if (JdtFlags.isEnum((IField) element))
return new ASTNode[] { ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element, cuNode) };
else
return new ASTNode[] { ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) element, cuNode) };
}
if (element.getElementType() == IJavaElement.TYPE && ((IType) element).isLocal()) {
IType type = (IType) element;
if (type.isAnonymous()) {
if (type.getParent().getElementType() == IJavaElement.FIELD) {
EnumConstantDeclaration enumDecl = ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element.getParent(), cuNode);
if (enumDecl != null && enumDecl.getAnonymousClassDeclaration() != null) {
return new ASTNode[] { enumDecl.getAnonymousClassDeclaration() };
}
}
ClassInstanceCreation creation = ASTNodeSearchUtil.getClassInstanceCreationNode(type, cuNode);
if (creation != null) {
if (creation.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) {
return new ASTNode[] { creation.getParent() };
} else if (creation.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
return new ASTNode[] { creation };
}
return new ASTNode[] { creation.getAnonymousClassDeclaration() };
}
return new ASTNode[0];
} else {
ASTNode[] nodes = ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
// we have to delete the TypeDeclarationStatement
nodes[0] = nodes[0].getParent();
return nodes;
}
}
return ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
}
use of org.eclipse.jdt.core.dom.ClassInstanceCreation in project che by eclipse.
the class JavadocFinder method resolveBinding.
private static IBinding resolveBinding(ASTNode node) {
if (node instanceof SimpleName) {
SimpleName simpleName = (SimpleName) node;
// workaround for https://bugs.eclipse.org/62605 (constructor name resolves to type, not method)
ASTNode normalized = ASTNodes.getNormalizedNode(simpleName);
if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
ClassInstanceCreation cic = (ClassInstanceCreation) normalized.getParent();
IMethodBinding constructorBinding = cic.resolveConstructorBinding();
if (constructorBinding == null)
return null;
ITypeBinding declaringClass = constructorBinding.getDeclaringClass();
if (!declaringClass.isAnonymous())
return constructorBinding;
ITypeBinding superTypeDeclaration = declaringClass.getSuperclass().getTypeDeclaration();
return resolveSuperclassConstructor(superTypeDeclaration, constructorBinding);
}
return simpleName.resolveBinding();
} else if (node instanceof SuperConstructorInvocation) {
return ((SuperConstructorInvocation) node).resolveConstructorBinding();
} else if (node instanceof ConstructorInvocation) {
return ((ConstructorInvocation) node).resolveConstructorBinding();
} else {
return null;
}
}
Aggregations