aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Maksimczyk2014-01-26 11:19:56 (EST)
committerMarek Maksimczyk2014-02-06 15:47:34 (EST)
commit0be0c8386e0e840af876f895a543205942c88f86 (patch)
tree254ebb2be8cb4b5f46503262400824e1efb3a86e
parent18960b0617374ae7abbf957c228487fb9f956a12 (diff)
downloadorg.eclipse.pdt-0be0c8386e0e840af876f895a543205942c88f86.zip
org.eclipse.pdt-0be0c8386e0e840af876f895a543205942c88f86.tar.gz
org.eclipse.pdt-0be0c8386e0e840af876f895a543205942c88f86.tar.bz2
Add posibility of blocks without brackled and colon in AST Block node.refs/changes/49/21649/1
There were only two type of block with brackles "{}" and with colon ":", in namespace block may no need any of this. Backward compatibility was kept. Signed-off-by: Marek Maksimczyk <marek.maksimczyk@mandos.net.pl>
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/Block.java57
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteFlattener.java15
2 files changed, 58 insertions, 14 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/Block.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/Block.java
index a66e1e0..35d2bca 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/Block.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/Block.java
@@ -35,14 +35,21 @@ public class Block extends Statement {
private final ASTNode.NodeList<Statement> statements = new ASTNode.NodeList<Statement>(STATEMENTS_PROPERTY);
private boolean isCurly;
-
+
+ private static enum BodyStartSymbol {
+ NONE, BRACKLET, COLON
+ };
+
+ private BodyStartSymbol bodyStartSymbol = BodyStartSymbol.NONE;
+
/**
* The "statements" structural property of this node type.
*/
- public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY =
- new ChildListPropertyDescriptor(Block.class, "statements", Statement.class, CYCLE_RISK); //$NON-NLS-1$
- public static final SimplePropertyDescriptor IS_CURLY_PROPERTY =
- new SimplePropertyDescriptor(Block.class, "isCurly", Boolean.class, OPTIONAL); //$NON-NLS-1$
+ public static final ChildListPropertyDescriptor STATEMENTS_PROPERTY = new ChildListPropertyDescriptor(
+ Block.class, "statements", Statement.class, CYCLE_RISK); //$NON-NLS-1$
+
+ public static final SimplePropertyDescriptor IS_CURLY_PROPERTY = new SimplePropertyDescriptor(
+ Block.class, "isCurly", Boolean.class, OPTIONAL); //$NON-NLS-1$
/**
* A list of property descriptors (element type:
@@ -130,19 +137,51 @@ public class Block extends Statement {
public boolean isCurly() {
return isCurly;
}
-
+
/**
* is this a curly block or an old (ie - : endblock) style
*
- * @param isCurly the assignment operator
- * @exception IllegalArgumentException if the argument is incorrect
- */
+ * @param isCurly
+ * the assignment operator
+ * @exception IllegalArgumentException
+ * if the argument is incorrect
+ *
+ * @deprecated <code>setBracketAsBodyStartSymbol</code>,
+ * <code>setColonAsBodyStartSymbol</code> or
+ * <code>clearBodyStartSymbol</code> should be use instead of
+ * this method.
+ */
public void setIsCurly(boolean isCurly) {
preValueChange(IS_CURLY_PROPERTY);
this.isCurly = isCurly;
+ if (isCurly == true) {
+ setBracketAsBodyStartSymbol();
+ } else {
+ setColonAsBodyStartSymbol();
+ }
postValueChange(IS_CURLY_PROPERTY);
}
+ public boolean isBracketed() {
+ return bodyStartSymbol == BodyStartSymbol.BRACKLET;
+ }
+
+ public void setBracketAsBodyStartSymbol() {
+ bodyStartSymbol = BodyStartSymbol.BRACKLET;
+ }
+
+ public boolean isColon() {
+ return bodyStartSymbol == BodyStartSymbol.COLON;
+ }
+
+ public void setColonAsBodyStartSymbol() {
+ bodyStartSymbol = BodyStartSymbol.COLON;
+ }
+
+ public void clearBodyStartSymbol() {
+ bodyStartSymbol = BodyStartSymbol.NONE;
+ }
+
/**
* @deprecated use {@link #statements()}
*/
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteFlattener.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteFlattener.java
index 1438eb5..d827882 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteFlattener.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteFlattener.java
@@ -215,17 +215,17 @@ public class ASTRewriteFlattener extends AbstractVisitor {
}
public boolean visit(Block block) {
- if (block.isCurly()) {
+ if (block.isBracketed()) {
result.append("{\n"); //$NON-NLS-1$
- } else {
+ } else if (block.isColon()) {
result.append(":\n"); //$NON-NLS-1$
}
visitList(block, Block.STATEMENTS_PROPERTY, null);
- if (block.isCurly()) {
+ if (block.isBracketed()) {
result.append("}\n"); //$NON-NLS-1$
- } else {
+ } else if (block.isColon()) {
StructuralPropertyDescriptor locationInParent = block
.getLocationInParent();
if (locationInParent == IfStatement.TRUE_STATEMENT_PROPERTY) {
@@ -501,9 +501,14 @@ public class ASTRewriteFlattener extends AbstractVisitor {
public boolean visit(NamespaceDeclaration namespaceDeclaration) {
result.append("namespace "); //$NON-NLS-1$
- namespaceDeclaration.childrenAccept(this);
+ namespaceDeclaration.getName().accept(this);
if (namespaceDeclaration.getBody() == null) {
result.append(";\n"); //$NON-NLS-1$
+ } else {
+ if (namespaceDeclaration.getBody().isBracketed() != true) {
+ result.append(";\n"); //$NON-NLS-1$
+ }
+ namespaceDeclaration.getBody().accept(this);
}
return false;
}