use of org.eclipse.jdt.core.dom.AST in project che by eclipse.
the class NewAnnotationMemberProposal method getNewType.
private Type getNewType(ASTRewrite rewrite) {
AST ast = rewrite.getAST();
Type newTypeNode = null;
ITypeBinding binding = null;
if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
Expression value = ((MemberValuePair) fInvocationNode.getParent()).getValue();
binding = value.resolveTypeBinding();
} else if (fInvocationNode instanceof Expression) {
binding = ((Expression) fInvocationNode).resolveTypeBinding();
}
if (binding != null) {
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(fInvocationNode, getImportRewrite());
newTypeNode = getImportRewrite().addImport(binding, ast, importRewriteContext);
}
if (newTypeNode == null) {
//$NON-NLS-1$
newTypeNode = ast.newSimpleType(ast.newSimpleName("String"));
}
addLinkedPosition(rewrite.track(newTypeNode), false, KEY_TYPE);
return newTypeNode;
}
use of org.eclipse.jdt.core.dom.AST in project che by eclipse.
the class NewCUUsingWizardProposal method getPossibleSuperTypeBinding.
// private NewTypeWizardPage getPage(NewElementWizard wizard) {
// IWizardPage[] pages= wizard.getPages();
// Assert.isTrue(pages.length > 0 && pages[0] instanceof NewTypeWizardPage);
// return (NewTypeWizardPage) pages[0];
// }
//
// private NewElementWizard createWizard(StructuredSelection selection) {
// switch (fTypeKind) {
// case K_CLASS: {
// NewClassWizardPage page= new NewClassWizardPage();
// page.init(selection);
// configureWizardPage(page);
// return new NewClassCreationWizard(page, true);
// }
// case K_INTERFACE: {
// NewInterfaceWizardPage page= new NewInterfaceWizardPage();
// page.init(selection);
// configureWizardPage(page);
// return new NewInterfaceCreationWizard(page, true);
// }
// case K_ENUM: {
// NewEnumWizardPage page= new NewEnumWizardPage();
// page.init(selection);
// configureWizardPage(page);
// return new NewEnumCreationWizard(page, true);
// }
// case K_ANNOTATION: {
// NewAnnotationWizardPage page= new NewAnnotationWizardPage();
// page.init(selection);
// configureWizardPage(page);
// return new NewAnnotationCreationWizard(page, true);
// }
// }
// throw new IllegalArgumentException();
// }
//
// private void configureWizardPage(NewTypeWizardPage page) {
// fillInWizardPageName(page);
// fillInWizardPageSuperTypes(page);
// }
//
// /**
// * Fill-in the "Package" and "Name" fields.
// * @param page the wizard page.
// */
// private void fillInWizardPageName(NewTypeWizardPage page) {
// // allow to edit when there are type parameters
// page.setTypeName(fTypeNameWithParameters, fTypeNameWithParameters.indexOf('<') != -1);
//
// boolean isInEnclosingType= fTypeContainer instanceof IType;
// if (isInEnclosingType) {
// page.setEnclosingType((IType) fTypeContainer, true);
// } else {
// page.setPackageFragment((IPackageFragment) fTypeContainer, true);
// }
// page.setEnclosingTypeSelection(isInEnclosingType, true);
// }
//
// /**
// * Fill-in the "Super Class" and "Super Interfaces" fields.
// * @param page the wizard page.
// */
// private void fillInWizardPageSuperTypes(NewTypeWizardPage page) {
// ITypeBinding type= getPossibleSuperTypeBinding(fNode);
// type= Bindings.normalizeTypeBinding(type);
// if (type != null) {
// if (type.isArray()) {
// type= type.getElementType();
// }
// if (type.isTopLevel() || type.isMember()) {
// if (type.isClass() && (fTypeKind == K_CLASS)) {
// page.setSuperClass(type.getQualifiedName(), true);
// } else if (type.isInterface()) {
// List<String> superInterfaces= new ArrayList<String>();
// superInterfaces.add(type.getQualifiedName());
// page.setSuperInterfaces(superInterfaces, true);
// }
// }
// }
// }
private ITypeBinding getPossibleSuperTypeBinding(ASTNode node) {
if (fTypeKind == K_ANNOTATION) {
return null;
}
AST ast = node.getAST();
node = ASTNodes.getNormalizedNode(node);
ASTNode parent = node.getParent();
switch(parent.getNodeType()) {
case ASTNode.METHOD_DECLARATION:
if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
//$NON-NLS-1$
return ast.resolveWellKnownType("java.lang.Exception");
}
break;
case ASTNode.THROW_STATEMENT:
//$NON-NLS-1$
return ast.resolveWellKnownType("java.lang.Exception");
case ASTNode.SINGLE_VARIABLE_DECLARATION:
if (parent.getLocationInParent() == CatchClause.EXCEPTION_PROPERTY) {
//$NON-NLS-1$
return ast.resolveWellKnownType("java.lang.Exception");
}
break;
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
case ASTNode.FIELD_DECLARATION:
// no guessing for LHS types, cannot be a supertype of a known type
return null;
case ASTNode.PARAMETERIZED_TYPE:
// Inheritance doesn't help: A<X> z= new A<String>(); ->
return null;
}
ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
if (binding != null && !binding.isRecovered()) {
return binding;
}
return null;
}
use of org.eclipse.jdt.core.dom.AST in project che by eclipse.
the class NewDefiningMethodProposal method addNewParameters.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#addNewParameters(org.eclipse.jdt.core
* .dom.rewrite.ASTRewrite, java.util.List, java.util.List)
*/
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params) throws CoreException {
AST ast = rewrite.getAST();
ImportRewrite importRewrite = getImportRewrite();
ITypeBinding[] bindings = fMethod.getParameterTypes();
IJavaProject project = getCompilationUnit().getJavaProject();
String[][] paramNames = StubUtility.suggestArgumentNamesWithProposals(project, fParamNames);
for (int i = 0; i < bindings.length; i++) {
ITypeBinding curr = bindings[i];
String[] proposedNames = paramNames[i];
SingleVariableDeclaration newParam = ast.newSingleVariableDeclaration();
newParam.setType(importRewrite.addImport(curr, ast));
newParam.setName(ast.newSimpleName(proposedNames[0]));
params.add(newParam);
//$NON-NLS-1$
String groupId = "arg_name_" + i;
addLinkedPosition(rewrite.track(newParam.getName()), false, groupId);
for (int k = 0; k < proposedNames.length; k++) {
addLinkedPositionProposal(groupId, proposedNames[k], null);
}
}
}
use of org.eclipse.jdt.core.dom.AST in project che by eclipse.
the class NewDefiningMethodProposal method getNewName.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#getNewName(org.eclipse.jdt.core.dom.rewrite.ASTRewrite)
*/
@Override
protected SimpleName getNewName(ASTRewrite rewrite) {
AST ast = rewrite.getAST();
SimpleName nameNode = ast.newSimpleName(fMethod.getName());
return nameNode;
}
use of org.eclipse.jdt.core.dom.AST in project che by eclipse.
the class NewDefiningMethodProposal method addNewExceptions.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#addNewExceptions(org.eclipse.jdt.core.dom.rewrite.ASTRewrite, java.util.List)
*/
@Override
protected void addNewExceptions(ASTRewrite rewrite, List<Type> exceptions) throws CoreException {
AST ast = rewrite.getAST();
ImportRewrite importRewrite = getImportRewrite();
ITypeBinding[] bindings = fMethod.getExceptionTypes();
for (int i = 0; i < bindings.length; i++) {
Type newType = importRewrite.addImport(bindings[i], ast);
exceptions.add(newType);
//$NON-NLS-1$
addLinkedPosition(rewrite.track(newType), false, "exc_type_" + i);
}
}
Aggregations