if (editorElement != null) {
ISourceModule sourceModule = ((ModelElement) editorElement)
.getSourceModule();
ASTParser parser = ASTParser.newParser(sourceModule);
Program program;
try {
program = parser.createAST(null);
program.recordModifications();
AST ast = program.getAST();
IDocument document = ((PHPStructuredEditor) targetEditor)
.getDocument();
for (int i = 0; i < fileNames.length; ++i) {
// resolve the relative path from include path
String relativeLocationFromIncludePath = getFileName(
fileNames[i], sourceModule);
if (relativeLocationFromIncludePath != null) {
Include include = ast.newInclude(ast.newScalar("'" //$NON-NLS-1$
+ relativeLocationFromIncludePath.toString()
+ "'"), Include.IT_REQUIRE_ONCE); //$NON-NLS-1$
program.statements().add(i,
ast.newExpressionStatement(include));
TextEdit edits = program.rewrite(document, null);
edits.apply(document);
}
}