List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration getJavadocProperty
public final ChildPropertyDescriptor getJavadocProperty()
From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJField.java
License:Open Source License
/** * If required, separates the variable declaration fragment into a new {@link FieldDeclaration} * object. If this declaration does not need to be split, reverts the changes made by {@link #prepareSplit()}. * <p>/*from w w w .j a v a2 s .c o m*/ * New field declaration will have only one variable declaration fragment. * New declaration is added to the {@link ASTRewrite}. * The attributes of this ASTJField are updated to reference elements of the new declaration. * Only the javadoc, variable initializer, and annotations are copied as String, all other attributes are copied * using {@link ASTNode#copySubtree(org.eclipse.jdt.core.dom.AST, ASTNode)}. All * formatting except for Javadoc, initializer, and annotations is lost. * If field declaration wrapped by ASTJField has only one variable declaration * fragment left, no changes are made. * <p> * Note that this method must be called after {@link #prepareSplit()} and before any * changes are made to the nodes. * * @see #prepareSplit() */ protected void performSplit() { if (!splitPerformed && getASTNode() != originalFieldDeclaration) { ListRewrite listRewrite = rewriter.getListRewrite(originalFieldDeclaration, FieldDeclaration.FRAGMENTS_PROPERTY); List<?> fragments = listRewrite.getRewrittenList(); // perform split if there is more than 1 fragment if (fragments.size() > 1) { FieldDeclaration newDeclaration = getASTNode(); // set javadoc if (originalFieldDeclaration.getJavadoc() != null) { String javadocString = getFacadeHelper() .applyFormatRules(getFacadeHelper().toString(originalFieldDeclaration.getJavadoc())); setTrackedNodeProperty(newDeclaration, javadocString, newDeclaration.getJavadocProperty(), ASTNode.JAVADOC); } // set initializer if (variableDeclarationFragment.getInitializer() != null) { if (initializer == UNITIALIZED_STRING) { initializer = getFacadeHelper().applyFormatRules( getFacadeHelper().toString(variableDeclarationFragment.getInitializer())); } setTrackedNodeProperty(variableDeclarationFragment, initializer, VariableDeclarationFragment.INITIALIZER_PROPERTY, ASTNode.JAVADOC); } // set annotations contents @SuppressWarnings("unchecked") Iterator<IExtendedModifier> newModifiersIterator = newDeclaration.modifiers().iterator(); @SuppressWarnings("unchecked") Iterator<IExtendedModifier> originalModifiersIterator = originalFieldDeclaration.modifiers() .iterator(); for (; newModifiersIterator.hasNext() && originalModifiersIterator.hasNext();) { IExtendedModifier modifier = newModifiersIterator.next(); IExtendedModifier originalModifier = originalModifiersIterator.next(); if (originalModifier.isAnnotation()) { ASTJAnnotation astjAnnotation = (ASTJAnnotation) getFacadeHelper().convertToNode(modifier); astjAnnotation.trackAndReplace(astjAnnotation.getRewrittenASTNode(), getFacadeHelper().applyFormatRules(getFacadeHelper().toString(originalModifier))); } } // insert new declaration before this one listRewrite = rewriter.getListRewrite(originalFieldDeclaration.getParent(), (ChildListPropertyDescriptor) originalFieldDeclaration.getLocationInParent()); listRewrite.insertBefore(newDeclaration, originalFieldDeclaration, null); // update the wrapped object setWrappedObject(newDeclaration); // delete variable fragment from old declaration removeNodeFromListProperty(originalFieldDeclaration, variableDeclarationFragment, FieldDeclaration.FRAGMENTS_PROPERTY); // add variable fragment to new declaration ListRewrite newListRewrite = rewriter.getListRewrite(newDeclaration, FieldDeclaration.FRAGMENTS_PROPERTY); newListRewrite.insertFirst(variableDeclarationFragment, null); } else { // only 1 fragment left - revert the changes revertPrepareSplit(); } } // split is performed splitPerformed = true; }