use of org.eclipse.jdt.core.dom.ConstructorInvocation in project che by eclipse.
the class ASTNodeSearchUtil method getAstNode.
public static ASTNode getAstNode(CompilationUnit cuNode, int start, int length) {
SelectionAnalyzer analyzer = new SelectionAnalyzer(Selection.createFromStartLength(start, length), true);
cuNode.accept(analyzer);
//XXX workaround for jdt core feature 23527
ASTNode node = analyzer.getFirstSelectedNode();
if (node == null && analyzer.getLastCoveringNode() instanceof SuperConstructorInvocation)
node = analyzer.getLastCoveringNode().getParent();
else if (node == null && analyzer.getLastCoveringNode() instanceof ConstructorInvocation)
node = analyzer.getLastCoveringNode().getParent();
if (node == null)
return null;
ASTNode parentNode = node.getParent();
if (parentNode instanceof MethodDeclaration) {
MethodDeclaration md = (MethodDeclaration) parentNode;
if (!(node instanceof SimpleName) && md.isConstructor() && md.getBody() != null && md.getBody().statements().size() > 0 && (md.getBody().statements().get(0) instanceof ConstructorInvocation || md.getBody().statements().get(0) instanceof SuperConstructorInvocation) && ((ASTNode) md.getBody().statements().get(0)).getLength() == length + 1)
return (ASTNode) md.getBody().statements().get(0);
}
if (parentNode instanceof SuperConstructorInvocation) {
if (parentNode.getLength() == length + 1)
return parentNode;
}
if (parentNode instanceof ConstructorInvocation) {
if (parentNode.getLength() == length + 1)
return parentNode;
}
return node;
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation 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;
}
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation in project che by eclipse.
the class IntroduceFactoryRefactoring method getCtorCallAt.
/**
* Look "in the vicinity" of the given range to find the <code>ClassInstanceCreation</code>
* node that this search hit identified. Necessary because the <code>SearchEngine</code>
* doesn't always cough up text extents that <code>NodeFinder.perform()</code> agrees with.
* @param start
* @param length
* @param unitAST
* @return return a {@link ClassInstanceCreation} or a {@link MethodRef} or <code>null</code> if this is really a constructor->constructor call (e.g. "this(...)")
* @throws CoreException
*/
private ASTNode getCtorCallAt(int start, int length, CompilationUnit unitAST) throws CoreException {
ICompilationUnit unitHandle = ASTCreator.getCu(unitAST);
ASTNode node = NodeFinder.perform(unitAST, start, length);
if (node == null)
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, Messages.format(RefactoringCoreMessages.IntroduceFactory_noASTNodeForConstructorSearchHit, new Object[] { Integer.toString(start), Integer.toString(start + length), BasicElementLabels.getJavaCodeString(unitHandle.getSource().substring(start, start + length)), BasicElementLabels.getFileName(unitHandle) }), null));
if (node instanceof ClassInstanceCreation) {
if (((ClassInstanceCreation) node).getAnonymousClassDeclaration() != null) {
// Cannot replace anonymous inner class, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=250660
fConstructorVisibility = Modifier.PROTECTED;
return null;
}
return node;
} else if (node instanceof VariableDeclaration) {
Expression init = ((VariableDeclaration) node).getInitializer();
if (init instanceof ClassInstanceCreation) {
return init;
} else if (init != null)
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, Messages.format(RefactoringCoreMessages.IntroduceFactory_unexpectedInitializerNodeType, new Object[] { BasicElementLabels.getJavaCodeString(init.toString()), BasicElementLabels.getFileName(unitHandle) }), null));
else
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, Messages.format(RefactoringCoreMessages.IntroduceFactory_noConstructorCallNodeInsideFoundVarbleDecl, BasicElementLabels.getJavaCodeString(node.toString())), null));
} else if (node instanceof ConstructorInvocation) {
// to another flavor on the same class.
return null;
} else if (node instanceof SuperConstructorInvocation) {
// This is a call we can bypass; it's from one constructor flavor
// to another flavor on the same class.
fConstructorVisibility = Modifier.PROTECTED;
return null;
} else if (node instanceof ExpressionStatement) {
Expression expr = ((ExpressionStatement) node).getExpression();
if (expr instanceof ClassInstanceCreation)
return expr;
else
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, Messages.format(RefactoringCoreMessages.IntroduceFactory_unexpectedASTNodeTypeForConstructorSearchHit, new Object[] { BasicElementLabels.getJavaCodeString(expr.toString()), BasicElementLabels.getFileName(unitHandle) }), null));
} else if (node instanceof SimpleName && (node.getParent() instanceof MethodDeclaration || node.getParent() instanceof AbstractTypeDeclaration)) {
// We seem to have been given a hit for an implicit call to the base-class constructor.
// Do nothing with this (implicit) call, but have to make sure we make the derived class
// doesn't lose access to the base-class constructor (so make it 'protected', not 'private').
fConstructorVisibility = Modifier.PROTECTED;
return null;
} else if (node instanceof MethodRef) {
return node;
} else
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, Messages.format(RefactoringCoreMessages.IntroduceFactory_unexpectedASTNodeTypeForConstructorSearchHit, new Object[] { BasicElementLabels.getJavaElementName(node.getClass().getName() + "('" + node.toString() + "')"), BasicElementLabels.getFileName(unitHandle) }), //$NON-NLS-1$ //$NON-NLS-2$
null));
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation in project che by eclipse.
the class InlineMethodRefactoring method setCurrentMode.
public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException {
if (fCurrentMode == mode)
return new RefactoringStatus();
Assert.isTrue(getInitialMode() == Mode.INLINE_SINGLE);
fCurrentMode = mode;
if (mode == Mode.INLINE_SINGLE) {
if (fInitialNode instanceof MethodInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (MethodInvocation) fInitialNode);
else if (fInitialNode instanceof SuperMethodInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (SuperMethodInvocation) fInitialNode);
else if (fInitialNode instanceof ConstructorInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (ConstructorInvocation) fInitialNode);
else
throw new IllegalStateException(String.valueOf(fInitialNode));
} else {
fTargetProvider = TargetProvider.create(fSourceProvider.getDeclaration());
}
return fTargetProvider.checkActivation();
}
use of org.eclipse.jdt.core.dom.ConstructorInvocation in project whole by wholeplatform.
the class CompilationUnitBuilder method newConstructorInvocation.
public ConstructorInvocation newConstructorInvocation(Expression arg0) {
ConstructorInvocation callExp = newConstructorInvocation();
callExp.arguments().add(arg0);
return callExp;
}
Aggregations