/** * Adds the self function with the relevant data to the proposals array * * @param context * @param reporter * @throws BadLocationException */ protected void addSelf(AbstractCompletionContext context, ICompletionReporter reporter) throws BadLocationException { String prefix = context.getPrefix(); SourceRange replaceRange = getReplacementRange(context); if (CodeAssistUtils.startsWithIgnoreCase("self", prefix)) { if (!context.getCompletionRequestor().isContextInformationMode() || prefix.length() == 4) { // "self".length() String suffix = getSuffix(context); // get the class data for "self". In case of null, the self // function will not be added IType selfClassData = CodeAssistUtils.getSelfClassData(context.getSourceModule(), context.getOffset()); if (selfClassData != null) { try { IMethod ctor = null; for (IMethod method : selfClassData.getMethods()) { if (method.isConstructor()) { ctor = method; break; } } if (ctor != null) { ISourceRange sourceRange = selfClassData.getSourceRange(); FakeMethod ctorMethod = new FakeMethod( (ModelElement) selfClassData, "self", sourceRange.getOffset(), sourceRange.getLength(), sourceRange.getOffset(), sourceRange.getLength()) { public boolean isConstructor() throws ModelException { return true; } }; ctorMethod.setParameters(ctor.getParameters()); reporter.reportMethod(ctorMethod, suffix, replaceRange); } else { ISourceRange sourceRange = selfClassData.getSourceRange(); reporter.reportMethod( new FakeMethod( (ModelElement) selfClassData, "self", sourceRange.getOffset(), sourceRange.getLength(), sourceRange.getOffset(), sourceRange.getLength()), "()", replaceRange); } } catch (ModelException e) { PHPCorePlugin.log(e); } } } } }