IStructuredDocument document) {
// Find the first PHP script region:
IStructuredDocumentRegion sdRegion = document
.getFirstStructuredDocumentRegion();
IPhpScriptRegion phpScriptRegion = null;
ITextRegion textRegion = null;
String docBlock = null;
while (sdRegion != null && docBlock == null) {
ITextRegion region = sdRegion.getFirstRegion();
if (region.getType() == PHPRegionContext.PHP_OPEN) {
// File's content starts with '<?PHP' tag
region = sdRegion.getRegionAtCharacterOffset(region.getEnd()
+ sdRegion.getStart());
if (region != null
&& region.getType() == PHPRegionContext.PHP_CONTENT) {
phpScriptRegion = (IPhpScriptRegion) region;
try {
docBlock = CodeGeneration.getFileComment(data, null);
} catch (CoreException e) {
Logger.logException(
"Generating default phpdoc comment", e); //$NON-NLS-1$
docBlock = createDefaultComment(null);
}
break;
}
} else if (region.getType() == DOMRegionContext.XML_DECLARATION_OPEN) {
// File's content starts with HTML code
region = sdRegion.getRegionAtCharacterOffset(region.getEnd()
+ sdRegion.getStart());
if (region != null) {
phpScriptRegion = null;
textRegion = (ITextRegion) region;
docBlock = createPHPScopeFileDocBlock(data
.getScriptProject());
break;
}
}
sdRegion = sdRegion.getNext();
}
if (phpScriptRegion != null || textRegion != null) {
try {
int offset = 0;
if (phpScriptRegion == null && textRegion != null) {
// File's content starts with HTML code
offset = 0;
} else if (phpScriptRegion != null) {
// File's content starts with '<?php' tag
textRegion = phpScriptRegion.getPhpToken(0);
int lineDelimiterLength = document.getLineDelimiter(
document.getLineOfOffset(textRegion.getStart()))
.length();
offset = textRegion.getStart() + sdRegion.getStartOffset()
+ phpScriptRegion.getStart() + lineDelimiterLength;
} else {
assert false;// we shouldn't get here ...
}
if (data instanceof AbstractSourceModule)