001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.core.jdom;
011:
012: import org.eclipse.jdt.internal.core.jdom.*;
013:
014: /**
015: * Standard implementation of <code>IDOMFactory</code>, and the only means
016: * of creating JDOMs and document fragments.
017: * <p>
018: * This class may be instantiated; it is not intended to be subclassed.
019: * </p>
020: * @deprecated The JDOM was made obsolete by the addition in 2.0 of the more
021: * powerful, fine-grained DOM/AST API found in the
022: * org.eclipse.jdt.core.dom package.
023: */
024: public class DOMFactory implements IDOMFactory {
025: String lineSeparator;
026:
027: /**
028: * Creates a new DOM factory.
029: */
030: public DOMFactory() {
031: // constructor is explicitly API
032: this .lineSeparator = org.eclipse.jdt.internal.core.util.Util
033: .getLineSeparator(null, null/*take the workspace line separator as no project is available*/);
034: }
035:
036: /* (non-Javadoc)
037: * Method declared on IDOMFactory.
038: */
039: public IDOMCompilationUnit createCompilationUnit() {
040: return (new DOMBuilder()).createCompilationUnit();
041: }
042:
043: /* (non-Javadoc)
044: * Method declared on IDOMFactory.
045: */
046: public IDOMCompilationUnit createCompilationUnit(char[] sourceCode,
047: String name) {
048: if (sourceCode == null) {
049: return null;
050: }
051: return (new SimpleDOMBuilder()).createCompilationUnit(
052: sourceCode, name.toCharArray());
053: }
054:
055: /* (non-Javadoc)
056: * Method declared on IDOMFactory.
057: */
058: public IDOMCompilationUnit createCompilationUnit(String sourceCode,
059: String name) {
060: if (sourceCode == null) {
061: return null;
062: }
063: return (new SimpleDOMBuilder()).createCompilationUnit(
064: sourceCode.toCharArray(), name.toCharArray());
065: }
066:
067: /* (non-Javadoc)
068: * Method declared on IDOMFactory.
069: */
070: public IDOMField createField() {
071: return createField("Object aField;" + this .lineSeparator); //$NON-NLS-1$
072: }
073:
074: /* (non-Javadoc)
075: * Method declared on IDOMFactory.
076: */
077: public IDOMField createField(String sourceCode) {
078: if (sourceCode == null) {
079: return null;
080: }
081: return (new DOMBuilder()).createField(sourceCode.toCharArray());
082: }
083:
084: /* (non-Javadoc)
085: * Method declared on IDOMFactory.
086: */
087: public IDOMImport createImport() {
088: return (new DOMBuilder()).createImport();
089: }
090:
091: /* (non-Javadoc)
092: * Method declared on IDOMFactory.
093: */
094: public IDOMImport createImport(String sourceCode) {
095: if (sourceCode == null) {
096: return null;
097: }
098: return (new DOMBuilder())
099: .createImport(sourceCode.toCharArray());
100: }
101:
102: /* (non-Javadoc)
103: * Method declared on IDOMFactory.
104: */
105: public IDOMInitializer createInitializer() {
106: return createInitializer("static {}" + this .lineSeparator); //$NON-NLS-1$
107: }
108:
109: /* (non-Javadoc)
110: * Method declared on IDOMFactory.
111: */
112: public IDOMInitializer createInitializer(String sourceCode) {
113: if (sourceCode == null) {
114: return null;
115: }
116: return (new DOMBuilder()).createInitializer(sourceCode
117: .toCharArray());
118: }
119:
120: /* (non-Javadoc)
121: * Method declared on IDOMFactory.
122: */
123: public IDOMMethod createMethod() {
124: return createMethod("public void newMethod() {" + this .lineSeparator + "}" + this .lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
125: }
126:
127: /* (non-Javadoc)
128: * Method declared on IDOMFactory.
129: */
130: public IDOMMethod createMethod(String sourceCode) {
131: if (sourceCode == null) {
132: return null;
133: }
134: return (new DOMBuilder())
135: .createMethod(sourceCode.toCharArray());
136: }
137:
138: /* (non-Javadoc)
139: * Method declared on IDOMFactory.
140: */
141: public IDOMPackage createPackage() {
142: return (new DOMBuilder()).createPackage();
143: }
144:
145: /* (non-Javadoc)
146: * Method declared on IDOMFactory.
147: */
148: public IDOMPackage createPackage(String sourceCode) {
149: if (sourceCode == null) {
150: return null;
151: }
152: return (new DOMBuilder()).createPackage(sourceCode
153: .toCharArray());
154: }
155:
156: /* (non-Javadoc)
157: * Method declared on IDOMFactory.
158: */
159: public IDOMType createType() {
160: return createType("public class AClass {" + this .lineSeparator + "}" + this .lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
161: }
162:
163: /* (non-Javadoc)
164: * Method declared on IDOMFactory.
165: */
166: public IDOMType createClass() {
167: return createType("public class AClass {" + this .lineSeparator + "}" + this .lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
168: }
169:
170: /* (non-Javadoc)
171: * Method declared on IDOMFactory.
172: */
173: public IDOMType createInterface() {
174: return createType("public interface AnInterface {" + this .lineSeparator + "}" + this .lineSeparator); //$NON-NLS-2$ //$NON-NLS-1$
175: }
176:
177: /* (non-Javadoc)
178: * Method declared on IDOMFactory.
179: */
180: public IDOMType createType(String sourceCode) {
181: if (sourceCode == null) {
182: return null;
183: }
184: return (new DOMBuilder()).createType(sourceCode.toCharArray());
185: }
186: }
|