List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration delete
public final void delete()
From source file:ch.acanda.eclipse.pmd.java.resolution.design.SingularFieldQuickFix.java
License:Open Source License
/** * Updates the field declaration. If the replaced field was the only fragment, the entire field declaration is * removed. Otherwise the field declaration stays and only the respective fragment is removed. *///w ww . j ava 2 s . co m private void updateFieldDeclaration(final VariableDeclarationFragment node) { final FieldDeclaration fieldDeclaration = (FieldDeclaration) node.getParent(); @SuppressWarnings("unchecked") final List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments(); if (fragments.size() > 1) { for (final VariableDeclarationFragment fragment : fragments) { if (fragment.getName().getIdentifier().equals(node.getName().getIdentifier())) { fragment.delete(); } } } else { fieldDeclaration.delete(); } }
From source file:edu.buffalo.cse.green.relationship.alternateassociation.AssociationRemover.java
License:Open Source License
/** * @see edu.buffalo.cse.green.relationships.RelationshipRemover#finish() *//*from w ww .j av a 2 s . c om*/ protected void finish() { for (ExpressionStatement exp : lEXP) { Block block = (Block) exp.getParent(); exp.delete(); MethodDeclaration mdc = (MethodDeclaration) block.getParent(); processAddInvocations(block); for (SingleVariableDeclaration varDec : (AbstractList<SingleVariableDeclaration>) mdc.parameters()) { IBinding binding = varDec.getName().resolveBinding(); if (binding.getJavaElement().equals(lPAR.get(0))) { varDec.delete(); break; } } lPAR.remove(0); } for (IField field : lFIE) { for (Object element : _typeInfo.bodyDeclarations()) { BodyDeclaration dec = (BodyDeclaration) element; if (dec.getNodeType() == FIELD_DECLARATION) { FieldDeclaration fieldDec = (FieldDeclaration) dec; List<VariableDeclarationFragment> fragments = (AbstractList<VariableDeclarationFragment>) fieldDec .fragments(); for (VariableDeclarationFragment fragment : fragments) { IField dField = (IField) fragment.getName().resolveBinding().getJavaElement(); if (field.equals(dField)) { fieldDec.delete(); break; } } } } } }
From source file:edu.buffalo.cse.green.relationship.composition.CompositionRemover.java
License:Open Source License
/** * @see edu.buffalo.cse.green.relationships.RelationshipRemover#finish() *///from w w w .j a v a 2s .c o m protected void finish() { for (ExpressionStatement exp : lEXP) { Block block = (Block) exp.getParent(); exp.delete(); processAddInvocations(block); } for (IField field : lFIE) { for (FieldDeclaration fieldDec : _typeInfo.getFields()) { List<VariableDeclarationFragment> fragments = (AbstractList<VariableDeclarationFragment>) fieldDec .fragments(); for (VariableDeclarationFragment fragment : fragments) { IField dField = (IField) fragment.getName().resolveBinding().getJavaElement(); if (field.equals(dField)) { fieldDec.delete(); break; } } } } }
From source file:org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor.java
License:Apache License
/** * Find the generated fields and delete them *///from www . j ava 2 s. c om @Override public boolean visit(FieldDeclaration node) { if (isGenerated(node)) { List<Annotation> annotations = retrieveAnnotations(node); if (!annotations.isEmpty()) { VariableDeclarationFragment variable = (VariableDeclarationFragment) node.fragments().get(0); fieldAnnotations.put(variable.getName().getIdentifier(), annotations); } node.delete(); } return false; }
From source file:sourcecodefilter.ExitCode.java
License:Open Source License
@SuppressWarnings("unchecked") private static void removeNonSerializedFieldsAndUnusedMethodsIn(ConverterRelevantCatroidSource source) { final List<AbstractTypeDeclaration> types = source.getSourceAst().types(); assert types.size() > 0; // TODO: add abstraction for field and method iteration for (AbstractTypeDeclaration abstractTypeDecl : types) { Set<FieldDeclaration> nonTransientFields = new HashSet<FieldDeclaration>(); // using AbstractTypeDeclaration to cover regular Types and Enums for (BodyDeclaration bodyDecl : new ArrayList<BodyDeclaration>(abstractTypeDecl.bodyDeclarations())) { if (bodyDecl.getNodeType() == ASTNode.FIELD_DECLARATION) { FieldDeclaration fieldDecl = (FieldDeclaration) bodyDecl; assert fieldDecl.fragments().size() == 1 : String .format("Unsupported multi field declaration: '%s'", fieldDecl.toString()); String fieldName = ((VariableDeclarationFragment) fieldDecl.fragments().get(0)).getName() .getIdentifier(); if (source.isRemovedField(fieldName)) { fieldDecl.delete(); } else if (Modifier.isTransient(fieldDecl.getModifiers()) && !(source.isPreservedField(fieldName))) { fieldDecl.delete();/*from w w w. ja v a2 s . c o m*/ } else { nonTransientFields.add(fieldDecl); } } } for (BodyDeclaration bodyDecl : new ArrayList<BodyDeclaration>(abstractTypeDecl.bodyDeclarations())) { if (bodyDecl.getNodeType() == ASTNode.METHOD_DECLARATION) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDecl; if (!methodDeclaration.isConstructor()) { // removeOverrideAnnotation(methodDeclaration); final String methodName = methodDeclaration.getName().getIdentifier(); if (methodName.equals("init")) { Block body = methodDeclaration.getBody(); for (Iterator<Statement> iterator2 = body.statements().iterator(); iterator2 .hasNext();) { iterator2.next(); iterator2.remove(); } } else if (source.isRemovedMethod(methodName)) { methodDeclaration.delete(); } else if (!(source.isPreservedMethod(methodName))) { if (!(isRelatedToNonTransientFields(methodName, nonTransientFields)) || isOverriding(methodDeclaration)) { methodDeclaration.delete(); } } } } } } }