Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormspector2008-01-15 04:58:37 -0500
committermspector2008-01-15 04:58:37 -0500
commite4f3dfee81b4da01e18b1a20139c7896fb08c6fa (patch)
treee9ca4b3d7f88e165e1c4664e7c0a3aa233f85591
parentcbc2e4cd23176cddc32db1bf669992f0db3235e8 (diff)
downloadorg.eclipse.pdt-EXPERIMENTAL_DLTK_AST_14012008.tar.gz
org.eclipse.pdt-EXPERIMENTAL_DLTK_AST_14012008.tar.xz
org.eclipse.pdt-EXPERIMENTAL_DLTK_AST_14012008.zip
Starting adaptation for DLTK (AST)EXPERIMENTAL_DLTK_AST_14012008
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/ASTUtil.java29
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/AbstractASTNode.java79
2 files changed, 108 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/ASTUtil.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/ASTUtil.java
new file mode 100644
index 000000000..655011259
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/ASTUtil.java
@@ -0,0 +1,29 @@
+package org.eclipse.php.internal.core.ast;
+
+import org.eclipse.php.internal.core.ast.nodes.ASTNode;
+
+public class ASTUtil {
+
+ /**
+ * For a given node, returns the outer node that surrounds it
+ * @param node AST node
+ * @return the enclosing node for the given node
+ */
+ public static ASTNode getEnclosingBodyNode(ASTNode node) {
+ do {
+ switch (node.getType()) {
+ case ASTNode.FUNCTION_DECLARATION:
+ return node;
+
+ case ASTNode.FIELD_DECLARATION:
+ return null;
+
+ case ASTNode.PROGRAM:
+ return node;
+
+ }
+ node = node.getParent();
+ } while (node != null);
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/AbstractASTNode.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/AbstractASTNode.java
new file mode 100644
index 000000000..7f794caa7
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/AbstractASTNode.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Zend Corporation and IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend and IBM - Initial implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.ast.nodes;
+
+import org.eclipse.dltk.ast.ASTVisitor;
+
+
+
+/**
+ * Abstract superclass of all Abstract Syntax Tree (AST) node types. <p>
+ * An AST node represents a PHP source code construct, such
+ * as a name, type, expression, statement, or declaration.<p>
+ * ASTs do not contain cycles. <p>
+ *
+ * @see Visitable
+ * @author Modhe S., Roy G. ,2007
+ * </p>
+ */
+public abstract class AbstractASTNode extends org.eclipse.dltk.ast.ASTNode implements ASTNode {
+
+ private ASTNode parent;
+
+ public AbstractASTNode(int start, int end) {
+ super(start, end);
+ }
+
+ public int getLength() {
+ return sourceEnd() - sourceStart();
+ }
+
+ public abstract int getType();
+
+ public String toString() {
+ final StringBuffer buffer = new StringBuffer();
+ toString(buffer, ""); //$NON-NLS-1$
+ return buffer.toString();
+ }
+
+ /**
+ * Appends the start, length parameters to the buffer
+ */
+ protected void appendInterval(StringBuffer buffer) {
+ buffer.append(" start='").append(sourceStart()).append("' length='").append(getLength()).append("'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ /**
+ * Formats a given string to an XML file
+ * @param input
+ * @return String the formatted string
+ */
+ protected static String getXmlStringValue(String input) {
+ String escapedString = input;
+ escapedString = escapedString.replaceAll("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
+ escapedString = escapedString.replaceAll(">", "&gt;"); //$NON-NLS-1$ //$NON-NLS-2$
+ escapedString = escapedString.replaceAll("<", "&lt;"); //$NON-NLS-1$ //$NON-NLS-2$
+ escapedString = escapedString.replaceAll("'", "&apos;"); //$NON-NLS-1$ //$NON-NLS-2$
+ return escapedString;
+ }
+
+ public ASTNode getParent() {
+ return parent;
+ }
+
+ public void setParent(ASTNode parent) {
+ this.parent = parent;
+ }
+
+ public final void traverse(ASTVisitor visitor) throws Exception {
+ // We don't implement it right now, since we are not going to use ASTVisitor from DLTK
+ }
+}

Back to the top