本文整理汇总了Java中org.eclipse.jdt.core.dom.ClassInstanceCreation.setType方法的典型用法代码示例。如果您正苦于以下问题:Java ClassInstanceCreation.setType方法的具体用法?Java ClassInstanceCreation.setType怎么用?Java ClassInstanceCreation.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.ClassInstanceCreation
的用法示例。
在下文中一共展示了ClassInstanceCreation.setType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCollectionInitStmt
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void createCollectionInitStmt(final CaptureLog log, final int logRecNo)
{
final int oid = log.objectIds.get(logRecNo);
final Object[] params = log.params.get(logRecNo);
String collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
final Class<?> collType = getClassForName(collTypeName);
final String varName;
// -- determine if an alternative collection must be used for code generation
final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
if(isPrivate || ! hasDefaultConstructor(collType))
{
if(Set.class.isAssignableFrom(collType))
{
collTypeName = HashSet.class.getName();
}
else if (List.class.isAssignableFrom(collType))
{
collTypeName = ArrayList.class.getName();
}
else if(Queue.class.isAssignableFrom(collType))
{
collTypeName = ArrayDeque.class.getName();
}
else
{
throw new RuntimeException("Collection " + collType + " is not supported");
}
}
// -- create code for instantiating collection
varName = this.createNewVarName(oid, collTypeName);
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
final SimpleName varNameExpr = ast.newSimpleName(varName);
vd.setName(varNameExpr);
final ClassInstanceCreation ci = ast.newClassInstanceCreation();
ci.setType(this.createAstType(collTypeName, ast));
vd.setInitializer(ci);
final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
stmt.setType(this.createAstType(collTypeName, ast));
methodBlock.statements().add(stmt);
// --- create code for filling the collection
Integer paramOID;
MethodInvocation mi;
for(int i = 0; i < params.length; i++)
{
mi = ast.newMethodInvocation();
mi.setName(ast.newSimpleName("add"));
paramOID = (Integer) params[i];
if(paramOID == null)
{
mi.arguments().add(ast.newNullLiteral());
}
else
{
mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
}
methodBlock.statements().add(mi);
}
}
示例2: createMapInitStmt
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
public void createMapInitStmt(final CaptureLog log, final int logRecNo) {
final int oid = log.objectIds.get(logRecNo);
final Object[] params = log.params.get(logRecNo);
String collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
final Class<?> collType = getClassForName(collTypeName);
final String varName;
// -- determine if an alternative collection must be used for code generation
final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
if(isPrivate || ! hasDefaultConstructor(collType))
{
collTypeName = HashMap.class.getName();
}
// -- create code for instantiating collection
varName = this.createNewVarName(oid, collTypeName);
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
final SimpleName varNameExpr = ast.newSimpleName(varName);
vd.setName(varNameExpr);
final ClassInstanceCreation ci = ast.newClassInstanceCreation();
ci.setType(this.createAstType(collTypeName, ast));
vd.setInitializer(ci);
final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
stmt.setType(this.createAstType(collTypeName, ast));
methodBlock.statements().add(stmt);
// --- create code for filling the collection
Integer valueOID;
Integer keyOID;
MethodInvocation mi;
for(int i = 0; i + 1< params.length; i+=2)
{
mi = ast.newMethodInvocation();
mi.setName(ast.newSimpleName("put"));
keyOID = (Integer) params[i];
mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(keyOID)));
valueOID = (Integer) params[i + 1];
if(valueOID == null)
{
mi.arguments().add(ast.newNullLiteral());
}
else
{
mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(valueOID)));
}
methodBlock.statements().add(mi);
}
}
示例3: createReturnBlock
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
public Block createReturnBlock(AST ast, TypeDeclaration builderType, String withName, String parameterName) {
Block builderMethodBlock = ast.newBlock();
ReturnStatement returnStatement = ast.newReturnStatement();
ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
MethodInvocation withMethodInvocation = ast.newMethodInvocation();
withMethodInvocation.setExpression(newClassInstanceCreation);
withMethodInvocation.setName(ast.newSimpleName(withName));
withMethodInvocation.arguments().add(ast.newSimpleName(parameterName));
returnStatement.setExpression(withMethodInvocation);
builderMethodBlock.statements().add(returnStatement);
return builderMethodBlock;
}
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:16,代码来源:NewBuilderAndWithMethodCallCreationFragment.java
示例4: createNewClassInstanceCreation
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private ASTNode createNewClassInstanceCreation(
CompilationUnitRewrite rewrite, ITypeBinding[] parameters) {
AST ast = fAnonymousInnerClassNode.getAST();
ClassInstanceCreation newClassCreation = ast.newClassInstanceCreation();
newClassCreation.setAnonymousClassDeclaration(null);
Type type = null;
SimpleName newNameNode = ast.newSimpleName(fClassName);
if (parameters.length > 0) {
final ParameterizedType parameterized =
ast.newParameterizedType(ast.newSimpleType(newNameNode));
for (int index = 0; index < parameters.length; index++)
parameterized
.typeArguments()
.add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
type = parameterized;
} else type = ast.newSimpleType(newNameNode);
newClassCreation.setType(type);
copyArguments(rewrite, newClassCreation);
addArgumentsForLocalsUsedInInnerClass(newClassCreation);
addLinkedPosition(KEY_TYPE_NAME, newNameNode, rewrite.getASTRewrite(), true);
return newClassCreation;
}
示例5: setCtorTypeArguments
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
/**
* Sets the type being instantiated in the given constructor call, including specifying any
* necessary type arguments.
*
* @param newCtorCall the constructor call to modify
* @param ctorTypeName the simple name of the type being instantiated
* @param ctorOwnerTypeParameters the formal type parameters of the type being instantiated
* @param ast utility object used to create AST nodes
*/
private void setCtorTypeArguments(
ClassInstanceCreation newCtorCall,
String ctorTypeName,
ITypeBinding[] ctorOwnerTypeParameters,
AST ast) {
if (ctorOwnerTypeParameters.length == 0) // easy, just a simple type
newCtorCall.setType(ASTNodeFactory.newType(ast, ctorTypeName));
else {
Type baseType = ast.newSimpleType(ast.newSimpleName(ctorTypeName));
ParameterizedType newInstantiatedType = ast.newParameterizedType(baseType);
List<Type> newInstTypeArgs = newInstantiatedType.typeArguments();
for (int i = 0; i < ctorOwnerTypeParameters.length; i++) {
Type typeArg = ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());
newInstTypeArgs.add(typeArg);
}
newCtorCall.setType(newInstantiatedType);
}
}
示例6: initialize
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
protected void initialize() {
super.initialize();
fBuilderVariableName= createNameSuggestion(getContext().is50orHigher() ? "builder" : "buffer", NamingConventions.VK_LOCAL); //$NON-NLS-1$ //$NON-NLS-2$
fBuffer= new StringBuffer();
VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment();
fragment.setName(fAst.newSimpleName(fBuilderVariableName));
ClassInstanceCreation classInstance= fAst.newClassInstanceCreation();
Name typeName= addImport(getContext().is50orHigher() ? "java.lang.StringBuilder" : "java.lang.StringBuffer"); //$NON-NLS-1$ //$NON-NLS-2$
classInstance.setType(fAst.newSimpleType(typeName));
fragment.setInitializer(classInstance);
VariableDeclarationStatement vStatement= fAst.newVariableDeclarationStatement(fragment);
vStatement.setType(fAst.newSimpleType((Name)ASTNode.copySubtree(fAst, typeName)));
toStringMethod.getBody().statements().add(vStatement);
}
示例7: createNewClassInstanceCreation
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private ASTNode createNewClassInstanceCreation(CompilationUnitRewrite rewrite, ITypeBinding[] parameters) {
AST ast= fAnonymousInnerClassNode.getAST();
ClassInstanceCreation newClassCreation= ast.newClassInstanceCreation();
newClassCreation.setAnonymousClassDeclaration(null);
Type type= null;
SimpleName newNameNode= ast.newSimpleName(fClassName);
if (parameters.length > 0) {
final ParameterizedType parameterized= ast.newParameterizedType(ast.newSimpleType(newNameNode));
for (int index= 0; index < parameters.length; index++)
parameterized.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
type= parameterized;
} else
type= ast.newSimpleType(newNameNode);
newClassCreation.setType(type);
copyArguments(rewrite, newClassCreation);
addArgumentsForLocalsUsedInInnerClass(newClassCreation);
addLinkedPosition(KEY_TYPE_NAME, newNameNode, rewrite.getASTRewrite(), true);
return newClassCreation;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:22,代码来源:ConvertAnonymousToNestedRefactoring.java
示例8: setCtorTypeArguments
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
/**
* Sets the type being instantiated in the given constructor call, including
* specifying any necessary type arguments.
* @param newCtorCall the constructor call to modify
* @param ctorTypeName the simple name of the type being instantiated
* @param ctorOwnerTypeParameters the formal type parameters of the type being
* instantiated
* @param ast utility object used to create AST nodes
*/
private void setCtorTypeArguments(ClassInstanceCreation newCtorCall, String ctorTypeName, ITypeBinding[] ctorOwnerTypeParameters, AST ast) {
if (ctorOwnerTypeParameters.length == 0) // easy, just a simple type
newCtorCall.setType(ASTNodeFactory.newType(ast, ctorTypeName));
else {
Type baseType= ast.newSimpleType(ast.newSimpleName(ctorTypeName));
ParameterizedType newInstantiatedType= ast.newParameterizedType(baseType);
List<Type> newInstTypeArgs= newInstantiatedType.typeArguments();
for(int i= 0; i < ctorOwnerTypeParameters.length; i++) {
Type typeArg= ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());
newInstTypeArgs.add(typeArg);
}
newCtorCall.setType(newInstantiatedType);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:26,代码来源:IntroduceFactoryRefactoring.java
示例9: createMemberAccessExpression
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@Override
protected Expression createMemberAccessExpression(Object member, boolean ignoreArraysCollections, boolean ignoreNulls) {
ITypeBinding type= getMemberType(member);
if (!getContext().is50orHigher() && type.isPrimitive()) {
String nonPrimitiveType= null;
String typeName= type.getName();
if (typeName.equals("byte"))nonPrimitiveType= "java.lang.Byte"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("short"))nonPrimitiveType= "java.lang.Short"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("char"))nonPrimitiveType= "java.lang.Character"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("int"))nonPrimitiveType= "java.lang.Integer"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("long"))nonPrimitiveType= "java.lang.Long"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("float"))nonPrimitiveType= "java.lang.Float"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("double"))nonPrimitiveType= "java.lang.Double"; //$NON-NLS-1$ //$NON-NLS-2$
if (typeName.equals("boolean"))nonPrimitiveType= "java.lang.Boolean"; //$NON-NLS-1$ //$NON-NLS-2$
ClassInstanceCreation classInstance= fAst.newClassInstanceCreation();
classInstance.setType(fAst.newSimpleType(addImport(nonPrimitiveType)));
classInstance.arguments().add(super.createMemberAccessExpression(member, true, true));
return classInstance;
}
return super.createMemberAccessExpression(member, ignoreArraysCollections, ignoreNulls);
}
示例10: createBody
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
public Block createBody(AST ast, TypeDeclaration originalType) {
ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(originalType.getName().toString())));
newClassInstanceCreation.arguments().add(ast.newThisExpression());
ReturnStatement statement = ast.newReturnStatement();
statement.setExpression(newClassInstanceCreation);
Block block = ast.newBlock();
block.statements().add(statement);
return block;
}
示例11: createReturnBlock
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
public Block createReturnBlock(AST ast, TypeDeclaration builderType) {
Block builderMethodBlock = ast.newBlock();
ReturnStatement returnStatement = ast.newReturnStatement();
ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
returnStatement.setExpression(newClassInstanceCreation);
builderMethodBlock.statements().add(returnStatement);
return builderMethodBlock;
}
示例12: after
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void after(CaptureLog log)
{
if(this.isXStreamNeeded)
{
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] { "com", "thoughtworks", "xstream", "XStream" }));
cu.imports().add(id);
// create XSTREAM constant: private static final XStream XSTREAM = new XStream();
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
vd.setName(ast.newSimpleName("XSTREAM"));
final ClassInstanceCreation ci = ast.newClassInstanceCreation();
ci.setType(this.createAstType("XStream", ast));
vd.setInitializer(ci);
final FieldDeclaration xstreamConst = ast.newFieldDeclaration(vd);
xstreamConst.setType(this.createAstType("XStream", ast));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
td.bodyDeclarations().add(xstreamConst);
this.isXStreamNeeded = false;
}
//-- creates utility method to set field value via reflections
if(this.isSetFieldMethodNeeded)
{
this.createSetFieldMethod(td, cu, ast);
this.isSetFieldMethodNeeded = false;
}
//-- creates utility method to get field value via reflections
if(this.isGetFieldMethodNeeded)
{
this.createGetFieldMethod(td, cu, ast);
this.isGetFieldMethodNeeded = false;
}
//-- creates utility method to call method via reflections
if(this.isCallMethodMethodNeeded)
{
this.createCallMethod(td, cu, ast);
this.isCallMethodMethodNeeded = false;
}
//-- creates utility method to call constructor via reflections
if(this.isNewInstanceMethodNeeded)
{
this.createNewInstanceMethod(td, cu, ast);
this.isNewInstanceMethodNeeded = false;
}
}
示例13: createDefaultExpression
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
public Expression createDefaultExpression(List<Expression> invocationArguments, ParameterInfo addedInfo, List<ParameterInfo> parameterInfos, MethodDeclaration enclosingMethod, boolean isRecursive, CompilationUnitRewrite cuRewrite) {
final AST ast= cuRewrite.getAST();
final ASTRewrite rewrite= cuRewrite.getASTRewrite();
if (isRecursive && canReuseParameterObject(invocationArguments, addedInfo, parameterInfos, enclosingMethod)) {
return ast.newSimpleName(addedInfo.getNewName());
}
ClassInstanceCreation classCreation= ast.newClassInstanceCreation();
int startPosition= enclosingMethod != null ? enclosingMethod.getStartPosition() : cuRewrite.getRoot().getStartPosition();
ContextSensitiveImportRewriteContext context= fParameterObjectFactory.createParameterClassAwareContext(fCreateAsTopLevel, cuRewrite, startPosition);
classCreation.setType(fParameterObjectFactory.createType(fCreateAsTopLevel, cuRewrite, startPosition));
List<Expression> constructorArguments= classCreation.arguments();
for (Iterator<ParameterInfo> iter= parameterInfos.iterator(); iter.hasNext();) {
ParameterInfo pi= iter.next();
if (isValidField(pi)) {
if (pi.isOldVarargs()) {
boolean isLastParameter= !iter.hasNext();
constructorArguments.addAll(computeVarargs(invocationArguments, pi, isLastParameter, cuRewrite, context));
} else {
Expression exp= invocationArguments.get(pi.getOldIndex());
importNodeTypes(exp, cuRewrite, context);
constructorArguments.add(moveNode(exp, rewrite));
}
}
}
return classCreation;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:IntroduceParameterObjectProcessor.java
示例14: buildChainedToString
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private MethodInvocation buildChainedToString(ASTRewrite rewrite, StringToCharVisitor visitor, AST ast) {
ClassInstanceCreation newStringBuilder = ast.newClassInstanceCreation();
newStringBuilder.setType(ast.newSimpleType(ast.newName("StringBuilder"))); // doesn't need to be qualified because
// it's java.lang
Expression lastExpression = newStringBuilder;
for (Expression expr : visitor.nodesBeingConcatenated) {
MethodInvocation newAppend = ast.newMethodInvocation();
// chains the call
newAppend.setExpression(lastExpression);
Expression fixedExpr = fixSingleLengthString(expr, ast);
if (fixedExpr == expr) {
// if it wasn't fixed, we have to make a moveTarget
newAppend.arguments().add((Expression) rewrite.createMoveTarget(expr));
} else {
// if it was fixed, it doesn't need a move target
newAppend.arguments().add(fixedExpr);
}
newAppend.setName(ast.newSimpleName("append"));
lastExpression = newAppend;
}
MethodInvocation toString = ast.newMethodInvocation();
toString.setExpression(lastExpression);
toString.setName(ast.newSimpleName("toString"));
return toString;
}
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:30,代码来源:UseCharacterParameterizedMethodResolution.java
示例15: addParameterInfo
import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private void addParameterInfo(CompilationUnitRewrite cuRewrite) throws JavaModelException {
ITypeBinding typeBinding= Bindings.normalizeForDeclarationUse(fSelectedExpression.resolveTypeBinding(), fSelectedExpression.getAST());
String name= fParameterName != null ? fParameterName : guessedParameterName();
Expression expression= fSelectedExpression instanceof ParenthesizedExpression ? ((ParenthesizedExpression)fSelectedExpression).getExpression() : fSelectedExpression;
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(fSelectedExpression, importRewrite);
String typeName= importRewrite.addImport(typeBinding, importRewriteContext);
String defaultValue= null;
if (expression instanceof ClassInstanceCreation && typeBinding.isParameterizedType()) {
ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) expression;
Type cicType= classInstanceCreation.getType();
if (cicType instanceof ParameterizedType && ((ParameterizedType) cicType).typeArguments().size() == 0) {
// expand the diamond:
AST ast= cuRewrite.getAST();
Type type= importRewrite.addImport(typeBinding, ast, importRewriteContext);
classInstanceCreation.setType(type); // Should not touch the original AST ...
defaultValue= ASTNodes.asFormattedString(classInstanceCreation, 0, StubUtility.getLineDelimiterUsed(cuRewrite.getCu()), cuRewrite.getCu().getJavaProject().getOptions(true));
classInstanceCreation.setType(cicType); // ... so let's restore it right away.
}
}
if (defaultValue == null) {
defaultValue= fSourceCU.getBuffer().getText(expression.getStartPosition(), expression.getLength());
}
fParameter= ParameterInfo.createInfoForAddedParameter(typeBinding, typeName, name, defaultValue);
if (fArguments == null) {
List<ParameterInfo> parameterInfos= fChangeSignatureProcessor.getParameterInfos();
int parametersCount= parameterInfos.size();
if (parametersCount > 0 && parameterInfos.get(parametersCount - 1).isOldVarargs())
parameterInfos.add(parametersCount - 1, fParameter);
else
parameterInfos.add(fParameter);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:IntroduceParameterRefactoring.java