if (region == null) {
return null;
}
IModelElement input = EditorUtility.getEditorInputModelElement(editor,
false);
if (input == null) {
return null;
}
PHPVersion phpVersion = ProjectOptions.getPhpVersion(input
.getScriptProject().getProject());
boolean namespacesSupported = phpVersion.isGreaterThan(PHPVersion.PHP5); // PHP
// 5.3
// and
// greater
IDocument document = textViewer.getDocument();
int offset = region.getOffset();
try {
IRegion wordRegion = findWord(document, offset, namespacesSupported);
if (wordRegion == null)
return null;
try {
String text = document.get(wordRegion.getOffset(),
wordRegion.getLength());
if (text.equals(NEW)) {
return null;
}
} catch (BadLocationException e) {
}
IModelElement[] elements = null;
elements = ((ICodeAssist) input).codeSelect(wordRegion.getOffset(),
wordRegion.getLength());
if ((elements == null || elements.length == 0)
&& input instanceof ISourceModule) {
elements = PHPModelUtils.getTypeInString((ISourceModule) input,
wordRegion);
}
if (elements != null && elements.length > 0) {
final IHyperlink link;
if (elements.length == 1) {
link = new ModelElementHyperlink(wordRegion, elements[0],
new OpenAction(editor));
} else {
link = new ModelElementHyperlink(wordRegion,
new ModelElementArray(elements), new OpenAction(
editor) {
public void selectAndOpen(
IModelElement[] elements) {
if (elements == null
|| elements.length == 0) {
IEditorStatusLine statusLine = null;
if (editor != null)
statusLine = (IEditorStatusLine) editor
.getAdapter(IEditorStatusLine.class);
if (statusLine != null)
statusLine
.setMessage(
true,
ActionMessages.OpenAction_error_messageBadSelection,
null);
getShell().getDisplay().beep();
return;
}
IModelElement element = elements[0];
if (elements.length > 1) {
element = OpenActionUtil
.selectModelElement(
elements,
getShell(),
ActionMessages.OpenAction_error_title,
ActionMessages.OpenAction_select_element);
if (element == null)
return;
}
int type = element.getElementType();
if (type == IModelElement.SCRIPT_PROJECT
|| type == IModelElement.PROJECT_FRAGMENT
|| type == IModelElement.SCRIPT_FOLDER)
element = EditorUtility
.getEditorInputModelElement(