/** * Search for magic variables using the @property tag * * @param types * @param variableName * @param cache */ private void resolveMagicClassVariableDeclaration( IType[] types, String variableName, IModelAccessCache cache) { for (IType type : types) { resolveMagicClassVariableDeclaration(variableName, type, cache); try { if (evaluated.isEmpty() && type.getSuperClasses() != null && type.getSuperClasses().length > 0) { ITypeHierarchy hierarchy = null; if (cache != null) { hierarchy = cache.getSuperTypeHierarchy(type, null); } IType[] superClasses = PHPModelUtils.getSuperClasses(type, hierarchy); for (int i = 0; i < superClasses.length /* && evaluated.isEmpty() */; i++) { IType superClass = superClasses[i]; resolveMagicClassVariableDeclaration(variableName, superClass, cache); } } } catch (ModelException e) { e.printStackTrace(); } } }
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()]); }