/** * 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()]); }
public IGoal[] init() { ClassVariableDeclarationGoal typedGoal = (ClassVariableDeclarationGoal) goal; IType[] types = typedGoal.getTypes(); if (types == null) { TypeContext context = (TypeContext) typedGoal.getContext(); types = PHPTypeInferenceUtils.getModelElements(context.getInstanceType(), context); } if (types == null) { return null; } IContext context = typedGoal.getContext(); IModelAccessCache cache = null; if (context instanceof IModelCacheContext) { cache = ((IModelCacheContext) context).getCache(); } String variableName = typedGoal.getVariableName(); final List<IGoal> subGoals = new LinkedList<IGoal>(); for (final IType type : types) { try { ITypeHierarchy hierarchy = null; if (cache != null) { hierarchy = cache.getSuperTypeHierarchy(type, null); } IField[] fields = PHPModelUtils.getTypeHierarchyField(type, hierarchy, variableName, true, null); Map<IType, IType> fieldDeclaringTypeSet = new HashMap<IType, IType>(); for (IField field : fields) { IType declaringType = field.getDeclaringType(); if (declaringType != null) { fieldDeclaringTypeSet.put(declaringType, type); ISourceModule sourceModule = declaringType.getSourceModule(); ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule); TypeDeclaration typeDeclaration = PHPModelUtils.getNodeByClass(moduleDeclaration, declaringType); if (typeDeclaration != null && field instanceof SourceRefElement) { SourceRefElement sourceRefElement = (SourceRefElement) field; ISourceRange sourceRange = sourceRefElement.getSourceRange(); ClassDeclarationSearcher searcher = new ClassDeclarationSearcher( sourceModule, typeDeclaration, sourceRange.getOffset(), sourceRange.getLength(), null, type, declaringType); try { moduleDeclaration.traverse(searcher); if (searcher.getResult() != null) { subGoals.add(new ExpressionTypeGoal(searcher.getContext(), searcher.getResult())); } } catch (Exception e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } } } if (subGoals.size() == 0) { getGoalFromStaticDeclaration(variableName, subGoals, type, null); } fieldDeclaringTypeSet.remove(type); if (subGoals.size() == 0 && !fieldDeclaringTypeSet.isEmpty()) { for (Iterator iterator = fieldDeclaringTypeSet.keySet().iterator(); iterator.hasNext(); ) { IType fieldDeclaringType = (IType) iterator.next(); getGoalFromStaticDeclaration( variableName, subGoals, fieldDeclaringType, fieldDeclaringTypeSet.get(fieldDeclaringType)); } } } catch (CoreException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } resolveMagicClassVariableDeclaration(types, variableName, cache); return subGoals.toArray(new IGoal[subGoals.size()]); }