List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration FRAGMENTS_PROPERTY
ChildListPropertyDescriptor FRAGMENTS_PROPERTY
To view the source code for org.eclipse.jdt.core.dom FieldDeclaration FRAGMENTS_PROPERTY.
Click Source Link
From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJAbstractType.java
License:Open Source License
protected List<JNode> getMembers() { List<JNode> members = new ArrayList<JNode>(); ListRewrite listRewrite = rewriter.getListRewrite(getASTNode(), getASTNode().getBodyDeclarationsProperty()); @SuppressWarnings("unchecked") List<BodyDeclaration> bodyDeclarations = listRewrite.getRewrittenList(); for (BodyDeclaration declaration : bodyDeclarations) { // for field declarations use variable declaration fragments instead if (declaration instanceof FieldDeclaration) { FieldDeclaration fieldDeclaration = (FieldDeclaration) declaration; ListRewrite fragmentslistRewrite = rewriter.getListRewrite(fieldDeclaration, FieldDeclaration.FRAGMENTS_PROPERTY); List<?> fragments = fragmentslistRewrite.getRewrittenList(); for (Object fragment : fragments) { JNode node = getFacadeHelper().convertToNode(fragment); if (node != null) { members.add(node);/* ww w . java 2 s . c om*/ } } } else { JNode node = getFacadeHelper().convertToNode(declaration); if (node != null) { members.add(node); } } } return members; }
From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJField.java
License:Open Source License
/** * Ensures that the field wrapped by this ASTJField have only 1 variable in the declaration. * <p>//from www . j av a 2 s.c o m * If required, this method creates a new field declaration, and sets rewritten AST node * to it. The ASTNode of all annotations of the new field is updated to use the original node. * <p> * Note that the no changes are added to the rewriter or wrapped object until {@link #performSplit()} is called. * <p> * This method must be called when field is created to ensure that annotations are unique for each <code>ASTJField</code>. * * @see #performSplit() */ protected void prepareSplit() { // check number of fragments ListRewrite listRewrite = rewriter.getListRewrite(originalFieldDeclaration, FieldDeclaration.FRAGMENTS_PROPERTY); List<?> fragments = listRewrite.getRewrittenList(); if (splitPerformed || fragments.size() <= 1) { splitPerformed = true; return; } // create a copy of declaration FieldDeclaration newDeclaration = (FieldDeclaration) ASTNode.copySubtree(originalFieldDeclaration.getAST(), originalFieldDeclaration); // set original node of annotations (to allow get methods to work correctly) @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()) { Annotation annotation = (Annotation) modifier; Annotation originalAnnotation = (Annotation) originalModifier; ASTJAnnotation astjAnnotation = (ASTJAnnotation) getFacadeHelper().convertToNode(annotation); astjAnnotation.setRewriter(getRewriter()); astjAnnotation.setASTNode(originalAnnotation); } } // new declaration will not have fragments until performSplit() is called newDeclaration.fragments().clear(); setASTNode(newDeclaration); }
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 ww w . ja 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; }
From source file:org.eclipse.wb.internal.core.eval.evaluators.SimpleNameEvaluator.java
License:Open Source License
private Object evaluateAsAssignment(EvaluationContext context, SimpleName simpleName) throws Exception { ExpressionValue value = ExecutionFlowUtils2.getValue(context.getFlowDescription(), simpleName); if (value != null) { Expression expression = value.getExpression(); // field declaration without initializer if (expression.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY && expression.getParent().getLocationInParent() == FieldDeclaration.FRAGMENTS_PROPERTY) { return null; }// w w w . j a v a 2 s. c o m // parameter of method without invocation if (expression.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY) { SingleVariableDeclaration parameter = (SingleVariableDeclaration) expression.getParent(); MethodDeclaration methodDeclaration = AstNodeUtils.getEnclosingMethod(parameter); return context.evaluateUnknownParameter(methodDeclaration, parameter); } // normal Expression return AstEvaluationEngine.evaluate(context, expression); } // no value throw new DesignerException(ICoreExceptionConstants.EVAL_NO_SIMPLE_NAME_FOUND, simpleName.getIdentifier()); }
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
License:Open Source License
/** * Replaces {@link Type} in {@link VariableDeclarationStatement} with new type.<br> * We use this method in morphing.// w w w . j av a2s . c om * * @param declaration * the fragment from {@link VariableDeclarationStatement}. {@link FieldDeclaration} * should have only one fragment. * @param newTypeName * the fully qualified name of type to use. */ public void replaceVariableType(VariableDeclaration declaration, String newTypeName) throws Exception { Type type; VariableDeclarationStatement declarationStatement = null; FieldDeclaration fieldDeclaration = null; if (declaration.getLocationInParent() == VariableDeclarationStatement.FRAGMENTS_PROPERTY) { declarationStatement = (VariableDeclarationStatement) declaration.getParent(); type = declarationStatement.getType(); } else if (declaration.getLocationInParent() == FieldDeclaration.FRAGMENTS_PROPERTY) { fieldDeclaration = (FieldDeclaration) declaration.getParent(); type = fieldDeclaration.getType(); } else { throw new IllegalArgumentException("Unknown argument: " + declaration.getClass()); } // do replace { Type newType = getParser().parseQualifiedType(type.getStartPosition(), newTypeName); // replace Type source replaceSubstring(type, newTypeName); // replace Type node if (declarationStatement != null) { declarationStatement.setType(newType); } if (fieldDeclaration != null) { fieldDeclaration.setType(newType); } resolveImports(newType); } }
From source file:org.moe.natjgen.FieldEditor.java
License:Apache License
private VariableDeclarationFragment getFirstFragment() { ListRewrite lrw = getRewrite().getListRewrite(fieldDecl, FieldDeclaration.FRAGMENTS_PROPERTY); return (VariableDeclarationFragment) lrw.getRewrittenList().get(0); }