/** * Runs the query to retrieve all global types * * @param context * @return * @throws BadLocationException */ protected IType[] getTypes(AbstractCompletionContext context) throws BadLocationException { String prefix = context.getPrefix(); if (prefix.startsWith("$")) { return EMPTY; } IDLTKSearchScope scope = createSearchScope(); if (context.getCompletionRequestor().isContextInformationMode()) { return PhpModelAccess.getDefault() .findTypes(prefix, MatchRule.EXACT, trueFlag, falseFlag, scope, null); } List<IType> result = new LinkedList<IType>(); if (prefix.length() > 1 && prefix.toUpperCase().equals(prefix)) { // Search by camel-case IType[] types = PhpModelAccess.getDefault() .findTypes(prefix, MatchRule.CAMEL_CASE, trueFlag, falseFlag, scope, null); result.addAll(Arrays.asList(types)); } IType[] types = PhpModelAccess.getDefault() .findTypes(null, prefix, MatchRule.PREFIX, trueFlag, falseFlag, scope, null); if (context instanceof NamespaceMemberContext) { for (IType type : types) { if (PHPModelUtils.getFullName(type).startsWith(prefix)) { result.add(type); } } } else { result.addAll(Arrays.asList(types)); } return (IType[]) result.toArray(new IType[result.size()]); }
/** * 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); } } } } }