本文整理匯總了Java中org.eclipse.jdt.core.dom.MethodInvocation.setName方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInvocation.setName方法的具體用法?Java MethodInvocation.setName怎麽用?Java MethodInvocation.setName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.MethodInvocation
的用法示例。
在下文中一共展示了MethodInvocation.setName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createUnobservedInitStmt
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void createUnobservedInitStmt(CaptureLog log, int logRecNo)
{
PostProcessor.notifyRecentlyProcessedLogRecNo(logRecNo);
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = log.objectIds.get(logRecNo);
// final String type = log.oidClassNames.get(log.oidRecMapping.get(oid));
final Object value = log.params.get(logRecNo)[0];
this.isXStreamNeeded = true;
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
// handling because there must always be a new instantiation statement for pseudo inits
this.oidToVarMapping.remove(oid);
vd.setName(ast.newSimpleName(this.createNewVarName(oid, log.oidClassNames.get(log.oidRecMapping.get(oid)), true)));
final MethodInvocation methodInvocation = ast.newMethodInvocation();
final Name name = ast.newSimpleName("XSTREAM");
methodInvocation.setExpression(name);
methodInvocation.setName(ast.newSimpleName("fromXML"));
final StringLiteral xmlParam = ast.newStringLiteral();
xmlParam.setLiteralValue((String) value);
methodInvocation.arguments().add(xmlParam);
// final CastExpression castExpr = ast.newCastExpression();
// castExpr.setType(this.createAstType(type, ast));
// castExpr.setExpression(methodInvocation);
// vd.setInitializer(castExpr);
vd.setInitializer(methodInvocation);
final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
vs.setType(this.createAstType("Object", ast));
methodBlock.statements().add(vs);
}
示例2: createUnobservedInitStmt
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = this.log.objectIds.get(logRecNo);
final String type = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
final Object value = this.log.params.get(logRecNo)[0];
this.isXStreamNeeded = true;
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
// handling because there must always be a new instantiation statement for pseudo inits
this.oidToVarMapping.remove(oid);
vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));
final MethodInvocation methodInvocation = ast.newMethodInvocation();
final Name name = ast.newSimpleName("XSTREAM");
methodInvocation.setExpression(name);
methodInvocation.setName(ast.newSimpleName("fromXML"));
final StringLiteral xmlParam = ast.newStringLiteral();
xmlParam.setLiteralValue((String) value);
methodInvocation.arguments().add(xmlParam);
final CastExpression castExpr = ast.newCastExpression();
castExpr.setType(this.createAstType(type, ast));
castExpr.setExpression(methodInvocation);
vd.setInitializer(castExpr);
final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
vs.setType(this.createAstType(type, ast));
methodBlock.statements().add(vs);
}
示例3: createInvocation
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private MethodInvocation createInvocation(AST ast, Expression operand, String operator) {
Expression receiver = getReceiver(operand);
MethodInvocation invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(fSetter));
if (receiver != null)
invocation.setExpression((Expression) fRewriter.createCopyTarget(receiver));
InfixExpression argument = ast.newInfixExpression();
invocation.arguments().add(argument);
if ("++".equals(operator)) { // $NON-NLS-1$
argument.setOperator(InfixExpression.Operator.PLUS);
} else if ("--".equals(operator)) { // $NON-NLS-1$
argument.setOperator(InfixExpression.Operator.MINUS);
} else {
Assert.isTrue(false, "Should not happen"); // $NON-NLS-1$
}
MethodInvocation getter = ast.newMethodInvocation();
getter.setName(ast.newSimpleName(fGetter));
if (receiver != null) getter.setExpression((Expression) fRewriter.createCopyTarget(receiver));
argument.setLeftOperand(getter);
argument.setRightOperand(ast.newNumberLiteral("1")); // $NON-NLS-1$
fReferencingGetter = true;
fReferencingSetter = true;
return invocation;
}
示例4: getIteratorBasedForInitializer
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
* Generates the initializer for an iterator based <code>for</code> loop, which declares and
* initializes the variable to loop over.
*
* @param rewrite the instance of {@link ASTRewrite}
* @param loopVariableName the proposed name of the loop variable
* @return a {@link VariableDeclarationExpression} to use as initializer
*/
private VariableDeclarationExpression getIteratorBasedForInitializer(
ASTRewrite rewrite, SimpleName loopVariableName) {
AST ast = rewrite.getAST();
IMethodBinding iteratorMethodBinding =
Bindings.findMethodInHierarchy(
fExpressionType, "iterator", new ITypeBinding[] {}); // $NON-NLS-1$
// initializing fragment
VariableDeclarationFragment varDeclarationFragment = ast.newVariableDeclarationFragment();
varDeclarationFragment.setName(loopVariableName);
MethodInvocation iteratorExpression = ast.newMethodInvocation();
iteratorExpression.setName(ast.newSimpleName(iteratorMethodBinding.getName()));
iteratorExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
varDeclarationFragment.setInitializer(iteratorExpression);
// declaration
VariableDeclarationExpression varDeclarationExpression =
ast.newVariableDeclarationExpression(varDeclarationFragment);
varDeclarationExpression.setType(
getImportRewrite()
.addImport(
iteratorMethodBinding.getReturnType(),
ast,
new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
return varDeclarationExpression;
}
示例5: createCollectionInitStmt
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的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);
}
}
示例6: createMapInitStmt
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的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);
}
}
示例7: createStaticMethodInvocation
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
public MethodInvocation createStaticMethodInvocation(AST ast, String className, String methodName) {
SimpleName typeName = ast.newSimpleName(className);
MethodInvocation methodInvocation = ast.newMethodInvocation();
methodInvocation.setName(ast.newSimpleName(methodName));
methodInvocation.setExpression(typeName);
return methodInvocation;
}
示例8: createReturnBlock
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的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
示例9: rewriteInfixExpression
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private RefactoringStatus rewriteInfixExpression(ASTRewrite astRewrite,
ImportRewrite importRewrite, InfixExpression ie,
String fullyQualifiedTypeName) {
final RefactoringStatus status = new RefactoringStatus();
final AST ast = ie.getAST();
final Expression leftExpCopy = (Expression) ASTNode.copySubtree(ast,
ie.getLeftOperand());
final Expression rightExpCopy = (Expression) ASTNode.copySubtree(ast,
ie.getRightOperand());
final NumberLiteral zero = ast.newNumberLiteral();
astRewrite.replace(ie.getRightOperand(), zero, null);
final MethodInvocation newInvocation = ast.newMethodInvocation();
newInvocation.setExpression(leftExpCopy);
newInvocation.setName(ast.newSimpleName("compareTo")); //$NON-NLS-1$
newInvocation.arguments().add(rightExpCopy);
astRewrite.replace(ie.getLeftOperand(), newInvocation, null);
if (((ASTNode) newInvocation.arguments().get(0)).getNodeType() == ASTNode.SIMPLE_NAME
&& this.fieldsToRefactor.contains(((SimpleName) ie
.getRightOperand()).resolveBinding().getJavaElement()))
this.rewriteReference(astRewrite, importRewrite,
(SimpleName) newInvocation.arguments().get(0),
fullyQualifiedTypeName);
if (((ASTNode) newInvocation.getExpression()).getNodeType() == ASTNode.SIMPLE_NAME
&& this.fieldsToRefactor.contains(((SimpleName) ie
.getLeftOperand()).resolveBinding().getJavaElement()))
this.rewriteReference(astRewrite, importRewrite,
(SimpleName) newInvocation.getExpression(),
fullyQualifiedTypeName);
return status;
}
開發者ID:ponder-lab,項目名稱:Constants-to-Enum-Eclipse-Plugin,代碼行數:38,代碼來源:ConvertConstantsToEnumRefactoring.java
示例10: generateIteratorBasedForRewrite
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
* Helper to generate an iterator based <code>for</code> loop to iterate over an {@link Iterable}.
*
* @param ast the {@link AST} instance to rewrite the loop to
* @return the complete {@link ASTRewrite} object
*/
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
ASTRewrite rewrite = ASTRewrite.create(ast);
ForStatement loopStatement = ast.newForStatement();
ITypeBinding loopOverType = extractElementType(ast);
SimpleName loopVariableName =
resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));
MethodInvocation loopExpression = ast.newMethodInvocation();
loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
addLinkedPosition(
rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
loopExpression.setExpression(expressionName);
loopStatement.setExpression(loopExpression);
Block forLoopBody = ast.newBlock();
Assignment assignResolvedVariable =
getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例11: getIteratorBasedForBodyAssignment
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
* Generates the Assignment in an iterator based for, used in the first statement of an iterator
* based <code>for</code> loop body, to retrieve the next element of the {@link Iterable}
* instance.
*
* @param rewrite the current instance of {@link ASTRewrite}
* @param loopOverType the {@link ITypeBinding} of the loop variable
* @param loopVariableName the name of the loop variable
* @return an {@link Assignment}, which retrieves the next element of the {@link Iterable} using
* the active {@link Iterator}
*/
private Assignment getIteratorBasedForBodyAssignment(
ASTRewrite rewrite, ITypeBinding loopOverType, SimpleName loopVariableName) {
AST ast = rewrite.getAST();
Assignment assignResolvedVariable = ast.newAssignment();
// left hand side
SimpleName resolvedVariableName =
resolveLinkedVariableNameWithProposals(
rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
VariableDeclarationFragment resolvedVariableDeclarationFragment =
ast.newVariableDeclarationFragment();
resolvedVariableDeclarationFragment.setName(resolvedVariableName);
VariableDeclarationExpression resolvedVariableDeclaration =
ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
resolvedVariableDeclaration.setType(
getImportRewrite()
.addImport(
loopOverType,
ast,
new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);
// right hand side
MethodInvocation invokeIteratorNextExpression = ast.newMethodInvocation();
invokeIteratorNextExpression.setName(ast.newSimpleName("next")); // $NON-NLS-1$
SimpleName currentElementName = ast.newSimpleName(loopVariableName.getIdentifier());
addLinkedPosition(
rewrite.track(currentElementName),
LinkedPositionGroup.NO_STOP,
currentElementName.getIdentifier());
invokeIteratorNextExpression.setExpression(currentElementName);
assignResolvedVariable.setRightHandSide(invokeIteratorNextExpression);
assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);
return assignResolvedVariable;
}
示例12: generateIndexBasedForRewrite
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
* Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
* implementation.
*
* @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
* @return an applicable {@link ASTRewrite} instance
*/
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
ASTRewrite rewrite = ASTRewrite.create(ast);
ForStatement loopStatement = ast.newForStatement();
SimpleName loopVariableName =
resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
loopStatement.initializers().add(getForInitializer(ast, loopVariableName));
MethodInvocation listSizeExpression = ast.newMethodInvocation();
listSizeExpression.setName(ast.newSimpleName("size")); // $NON-NLS-1$
Expression listExpression = (Expression) rewrite.createCopyTarget(fCurrentExpression);
listSizeExpression.setExpression(listExpression);
loopStatement.setExpression(
getLinkedInfixExpression(
rewrite,
loopVariableName.getIdentifier(),
listSizeExpression,
InfixExpression.Operator.LESS));
loopStatement
.updaters()
.add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));
Block forLoopBody = ast.newBlock();
forLoopBody
.statements()
.add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例13: getIndexBasedForBodyAssignment
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
* Creates an {@link Assignment} as first expression appearing in an index based <code>for</code>
* loop's body. This Assignment declares a local variable and initializes it using the {@link
* List}'s current element identified by the loop index.
*
* @param rewrite the current {@link ASTRewrite} instance
* @param loopVariableName the name of the index variable in String representation
* @return a completed {@link Assignment} containing the mentioned declaration and initialization
*/
private Expression getIndexBasedForBodyAssignment(
ASTRewrite rewrite, SimpleName loopVariableName) {
AST ast = rewrite.getAST();
ITypeBinding loopOverType = extractElementType(ast);
Assignment assignResolvedVariable = ast.newAssignment();
// left hand side
SimpleName resolvedVariableName =
resolveLinkedVariableNameWithProposals(
rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
VariableDeclarationFragment resolvedVariableDeclarationFragment =
ast.newVariableDeclarationFragment();
resolvedVariableDeclarationFragment.setName(resolvedVariableName);
VariableDeclarationExpression resolvedVariableDeclaration =
ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
resolvedVariableDeclaration.setType(
getImportRewrite()
.addImport(
loopOverType,
ast,
new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);
// right hand side
MethodInvocation invokeGetExpression = ast.newMethodInvocation();
invokeGetExpression.setName(ast.newSimpleName("get")); // $NON-NLS-1$
SimpleName indexVariableName = ast.newSimpleName(loopVariableName.getIdentifier());
addLinkedPosition(
rewrite.track(indexVariableName),
LinkedPositionGroup.NO_STOP,
indexVariableName.getIdentifier());
invokeGetExpression.arguments().add(indexVariableName);
invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
assignResolvedVariable.setRightHandSide(invokeGetExpression);
assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);
return assignResolvedVariable;
}
示例14: instrumentStart
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Statement instrumentStart(final CodeSection codeSection, final AST nodeFactory) {
final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
final MethodInvocation startInvocation = nodeFactory.newMethodInvocation();
startInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
"remote", "MeasurementCentral"));
startInvocation.setName(nodeFactory.newSimpleName("startResourceDemand"));
startInvocation.arguments().add(nodeFactory.newNumberLiteral("" + this.identifier.getIdOf(codeSection)));
return nodeFactory.newExpressionStatement(startInvocation);
}
示例15: instrumentEnd
import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public Statement instrumentEnd(final CodeSection codeSection, final AST nodeFactory) {
final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
final MethodInvocation endInvocation = nodeFactory.newMethodInvocation();
endInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
"remote", "MeasurementCentral"));
endInvocation.setName(nodeFactory.newSimpleName("stopResourceDemand"));
return nodeFactory.newExpressionStatement(endInvocation);
}