本文整理匯總了Java中org.eclipse.jdt.core.dom.VariableDeclarationFragment.setInitializer方法的典型用法代碼示例。如果您正苦於以下問題:Java VariableDeclarationFragment.setInitializer方法的具體用法?Java VariableDeclarationFragment.setInitializer怎麽用?Java VariableDeclarationFragment.setInitializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.VariableDeclarationFragment
的用法示例。
在下文中一共展示了VariableDeclarationFragment.setInitializer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createDeclaration
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private VariableDeclarationStatement createDeclaration(
IVariableBinding binding, Expression intilizer) {
VariableDeclaration original =
ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
fragment.setInitializer(intilizer);
VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
result.setType(
ASTNodeFactory.newType(
fAST,
original,
fImportRewriter,
new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
return result;
}
示例2: createUnobservedInitStmt
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的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);
}
示例3: createUnobservedInitStmt
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的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);
}
示例4: variableDeclarationStatement
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
public VariableDeclarationStatement variableDeclarationStatement(String name, Type type, Expression initializer) {
VariableDeclarationFragment variableDeclarationFragment = variableDeclarationFragment(name);
variableDeclarationFragment.setInitializer(initializer);
VariableDeclarationStatement statement = ast.get().newVariableDeclarationStatement(variableDeclarationFragment);
statement.setType(type);
return statement;
}
示例5: createDeclaration
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) {
VariableDeclaration original = ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
fragment.setInitializer(intilizer);
VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
return result;
}
示例6: createNewFieldDeclaration
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
AST ast = getAST();
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
SimpleName variableName = ast.newSimpleName(fFieldName);
fragment.setName(variableName);
addLinkedName(rewrite, variableName, false);
List<Dimension> extraDimensions =
DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
fragment.extraDimensions().addAll(extraDimensions);
if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
fragment.setInitializer(initializer);
}
FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);
VariableDeclarationStatement vds = getTempDeclarationStatement();
Type type = (Type) rewrite.createCopyTarget(vds.getType());
fieldDeclaration.setType(type);
fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
return fieldDeclaration;
}
示例7: createTempDeclaration
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private VariableDeclarationStatement createTempDeclaration(Expression initializer)
throws CoreException {
AST ast = fCURewrite.getAST();
VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(ast.newSimpleName(fTempName));
vdf.setInitializer(initializer);
VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(vdf);
if (fDeclareFinal) {
vds.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
}
vds.setType(createTempType());
if (fLinkedProposalModel != null) {
ASTRewrite rewrite = fCURewrite.getASTRewrite();
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(rewrite.track(vdf.getName()), true);
String[] nameSuggestions = guessTempNames();
if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fTempName)) {
nameGroup.addProposal(fTempName, null, nameSuggestions.length + 1);
}
for (int i = 0; i < nameSuggestions.length; i++) {
nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
}
}
return vds;
}
示例8: getIteratorBasedForInitializer
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的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;
}
示例9: getForInitializer
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
/**
* Generates a {@link VariableDeclarationExpression}, which initializes the loop variable to
* iterate over an array.
*
* @param ast the current {@link AST} instance
* @param loopVariableName the name of the variable which should be initialized
* @return a filled {@link VariableDeclarationExpression}, declaring a int variable, which is
* initializes with 0
*/
private VariableDeclarationExpression getForInitializer(AST ast, SimpleName loopVariableName) {
// initializing fragment
VariableDeclarationFragment firstDeclarationFragment = ast.newVariableDeclarationFragment();
firstDeclarationFragment.setName(loopVariableName);
NumberLiteral startIndex = ast.newNumberLiteral();
firstDeclarationFragment.setInitializer(startIndex);
// declaration
VariableDeclarationExpression variableDeclaration =
ast.newVariableDeclarationExpression(firstDeclarationFragment);
PrimitiveType variableType = ast.newPrimitiveType(PrimitiveType.INT);
variableDeclaration.setType(variableType);
return variableDeclaration;
}
示例10: createCollectionInitStmt
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的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);
}
}
示例11: createMapInitStmt
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的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);
}
}
示例12: addInitializer
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
protected boolean addInitializer(VariableDeclarationFragment fragment, ASTNode declarationNode) {
ITypeBinding typeBinding = getTypeBinding(declarationNode);
if (typeBinding == null) {
return false;
}
Long id = fContext.getSerialVersionId(typeBinding);
if (id == null) {
return false;
}
fragment.setInitializer(fragment.getAST().newNumberLiteral(id.toString() + LONG_SUFFIX));
return true;
}
示例13: addInitializer
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
protected boolean addInitializer(final VariableDeclarationFragment fragment, final ASTNode declarationNode) {
Assert.isNotNull(fragment);
final Expression expression= fragment.getAST().newNumberLiteral(DEFAULT_EXPRESSION);
if (expression != null) {
fragment.setInitializer(expression);
}
return true;
}
示例14: addInitializer
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
@Override
protected boolean addInitializer(final VariableDeclarationFragment fragment, final ASTNode declarationNode) {
Assert.isNotNull(fragment);
try {
String id = computeId(declarationNode, new NullProgressMonitor());
fragment.setInitializer(fragment.getAST().newNumberLiteral(id));
} catch (InterruptedException exception) {
// Do nothing
}
return true;
}
示例15: createLiceseInLineField
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入方法依賴的package包/類
private FieldDeclaration createLiceseInLineField(AST ast) {
VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(ast.newSimpleName("COPYRIGHT"));
StringLiteral sl = ast.newStringLiteral();
sl.setLiteralValue(license_inline);
vdf.setInitializer(sl);
FieldDeclaration fd = ast.newFieldDeclaration(vdf);
fd.modifiers().addAll(ast.newModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL));
fd.setType(ast.newSimpleType(ast.newSimpleName("String")));
return fd;
}