本文整理匯總了Java中org.eclipse.jdt.core.dom.VariableDeclarationFragment類的典型用法代碼示例。如果您正苦於以下問題:Java VariableDeclarationFragment類的具體用法?Java VariableDeclarationFragment怎麽用?Java VariableDeclarationFragment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
VariableDeclarationFragment類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了VariableDeclarationFragment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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);
}
示例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: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
Type fieldType = fieldDeclaration.getType();
int fieldModifiers = fieldDeclaration.getModifiers();
Visibility visibility = getVisibility(fieldModifiers);
// boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
for (VariableDeclarationFragment fragment : fragments) {
String fieldName = fragment.getName().getIdentifier();
final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
attribute.setStatic(isStatic);
attribute.setVisibility(visibility);
attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));
Expression expression = fragment.getInitializer();
if (expression != null) {
//attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
}
attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
}
return true;
}
示例6: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
public boolean visit(VariableDeclarationStatement vds) {
if (mtbStack.isEmpty()) // not part of a method
return true;
// make local variable declaration
for (Object ovdf : vds.fragments()) {
VariableDeclarationFragment vdf = (VariableDeclarationFragment) ovdf;
try {
facts.add(Fact.makeLocalVarFact(getQualifiedName(mtbStack
.peek()), getQualifiedName(vds.getType()
.resolveBinding()), vdf.getName().getIdentifier(), vdf
.getInitializer().toString()));
} catch (Exception e) {
System.err.println("Cannot resolve variable declaration \""
+ vdf.getName().toString() + "\"");
}
}
return true;
}
示例7: locationNeedsParentheses
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例8: rewriteAST
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
final ASTRewrite rewrite = cuRewrite.getASTRewrite();
VariableDeclarationFragment fragment = null;
for (int i = 0; i < fNodes.length; i++) {
final ASTNode node = fNodes[i];
final AST ast = node.getAST();
fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(NAME_FIELD));
final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));
if (!addInitializer(fragment, node)) {
continue;
}
if (fragment.getInitializer() != null) {
final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
if (node instanceof AbstractTypeDeclaration) {
rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
} else if (node instanceof AnonymousClassDeclaration) {
rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
} else if (node instanceof ParameterizedType) {
final ParameterizedType type = (ParameterizedType) node;
final ASTNode parent = type.getParent();
if (parent instanceof ClassInstanceCreation) {
final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
if (anonymous != null) {
rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
}
}
} else {
Assert.isTrue(false);
}
addLinkedPositions(rewrite, fragment, positionGroups);
}
final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
declaration.setJavadoc(doc);
}
}
if (fragment == null) {
return;
}
positionGroups.setEndPosition(rewrite.track(fragment));
}
示例9: 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;
}
示例10: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration node) {
int modifiers = node.getModifiers();
if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
List<VariableDeclarationFragment> fragments = node.fragments();
for (VariableDeclarationFragment varDeclFrag : fragments) {
IVariableBinding varBinding = varDeclFrag.resolveBinding();
String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
final TACVariable fieldVar = new TACVariable(varBinding);
if(!enclosingClass.equals(Config.MAINCLASS)){
context.addEncapsulatedVariable(fieldVar);
}
}
}
}
return super.visit(node);
}
示例11: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
@Override
public boolean visit(VariableDeclarationFragment param) {
ASTNode parent = param.getParent();
if (parent instanceof VariableDeclarationStatement) {
VariableDeclarationStatement statement = (VariableDeclarationStatement) parent;
ASTNode annotation = getAnnotation(statement.modifiers(), "Domain");
if (annotation != null) {
ListRewrite paramRewrite = rewrite.getListRewrite(statement,
VariableDeclarationStatement.MODIFIERS2_PROPERTY);
paramRewrite.remove(annotation, null);
}
}
return super.visit(param);
}
示例12: hasFieldInitializers
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
private static boolean hasFieldInitializers(TypeDeclaration typeDecl) {
boolean returnFlag = false;
for (FieldDeclaration fd : typeDecl.getFields()) {
// Skip over primitive types
if (fd.getType().isPrimitiveType() ) {
continue;
}
if (fd.fragments().size() > 0)
if (fd.fragments().get(0) instanceof VariableDeclarationFragment) {
VariableDeclarationFragment vdf = (VariableDeclarationFragment) fd.fragments().get(0);
if (vdf.getInitializer() != null)
returnFlag = true;
}
}
return returnFlag;
}
示例13: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
@Override
public boolean visit(VariableDeclarationFragment node) {
if (isDeclarationTarget(DeclarationType.FIELD_DECLARATION)) {
IVariableBinding variableBinding = node.resolveBinding();
if (variableBinding != null) {
if (variableBinding.isField()) {
variableFound = variableBinding.getName();
if (matchTypeDeclaration()
&& TraceUtility
.match(variableToFind, variableFound)) {
TraceUtility.selectInEditor(node);
setEnclosingDeclaration(node);
}
}
}
}
return super.visit(node);
}
示例14: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
public boolean visit(VariableDeclarationStatement vds)
{
if (this.mtbStack.isEmpty()) {
return true;
}
for (Object ovdf : vds.fragments())
{
VariableDeclarationFragment vdf = (VariableDeclarationFragment)ovdf;
try
{
this.facts.add(Fact.makeLocalVarFact(getQualifiedName(
(IMethodBinding)this.mtbStack.peek()), getQualifiedName(vds.getType()
.resolveBinding()), vdf.getName().getIdentifier(), vdf
.getInitializer().toString()));
}
catch (Exception e)
{
System.err.println("Cannot resolve variable declaration \"" +
vdf.getName().toString() + "\"");
}
}
return true;
}
示例15: visit
import org.eclipse.jdt.core.dom.VariableDeclarationFragment; //導入依賴的package包/類
public boolean visit(VariableDeclarationStatement vds)
{
if (this.mtbStack.isEmpty()) {
return true;
}
for (Object ovdf : vds.fragments())
{
VariableDeclarationFragment vdf = (VariableDeclarationFragment)ovdf;
try
{
this.facts.add(Fact.makeLocalVarFact(getQualifiedName(
(IMethodBinding)this.mtbStack.peek()), getQualifiedName(vds.getType()
.resolveBinding()), vdf.getName().getIdentifier(), vdf
.getInitializer().toString()));
}
catch (Exception localException)
{
System.err.println("Cannot resolve variable declaration \"" +
vdf.getName().toString() + "\"");
}
}
return true;
}