private static Integer[] createOffsetArray(IType[] types) throws ModelException { List result = new ArrayList(); for (int i = 0; i < types.length; i++) { IType iType = types[i]; addOffset(result, iType.getNameRange().getOffset()); addOffset(result, iType.getSourceRange().getOffset() + iType.getSourceRange().getLength()); addMemberOffsetList(result, iType.getMethods()); addMemberOffsetList(result, iType.getFields()); // addMemberOffsetList(result, iType.getInitializers()); } return (Integer[]) result.toArray(new Integer[result.size()]); }
public void apply(ICompletionReporter reporter) throws BadLocationException { ICompletionContext context = getContext(); if (!(context instanceof NamespaceMemberContext)) { return; } NamespaceMemberContext concreteContext = (NamespaceMemberContext) context; String prefix = concreteContext.getPrefix(); String suffix = getSuffix(concreteContext); ISourceRange replaceRange = getReplacementRange(concreteContext); for (IType ns : concreteContext.getNamespaces()) { try { for (IMethod method : ns.getMethods()) { if (StringUtils.startsWithIgnoreCase(method.getElementName(), prefix)) { reporter.reportMethod(method, suffix, replaceRange); } } } catch (ModelException e) { PHPCorePlugin.log(e); } } }
/** * 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); } } } } }