This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 207534
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java (-32 / +82 lines)
Lines 194-224 Link Here
194
            FunctionScopeImpl functionScope = (FunctionScopeImpl) currentScope;
194
            FunctionScopeImpl functionScope = (FunctionScopeImpl) currentScope;
195
            Expression expression = node.getExpression();
195
            Expression expression = node.getExpression();
196
            if (expression instanceof ClassInstanceCreation) {
196
            if (expression instanceof ClassInstanceCreation) {
197
                ClassInstanceCreation instanceCreation = (ClassInstanceCreation) expression;
197
                typeName = extractTypeName((ClassInstanceCreation) expression);
198
                ASTNodeInfo<ClassInstanceCreation> inf = ASTNodeInfo.create(instanceCreation);
199
                String pureTypeName = inf.getQualifiedName().toString();
200
                typeName = VariousUtils.qualifyTypeNames(pureTypeName, node.getStartOffset(), currentScope);
201
            } else if (expression instanceof VariableBase) {
198
            } else if (expression instanceof VariableBase) {
202
                typeName = VariousUtils.extractTypeFroVariableBase((VariableBase) expression);
199
                typeName = extractTypeName((VariableBase) expression, node);
203
                if (typeName != null) {
204
                    Collection<? extends VariableName> allVariables = VariousUtils.getAllVariables(functionScope, typeName);
205
                    Map<String,String> var2Type = new HashMap<String, String>();
206
                    for (VariableName variable : allVariables) {
207
                        String name = variable.getName();
208
                        String type = resolveVariableType(name, functionScope, node);
209
                        String qualifiedType = VariousUtils.qualifyTypeNames(type, node.getStartOffset(), currentScope);
210
                        if (qualifiedType == null) {
211
                            var2Type = Collections.emptyMap();
212
                            break;
213
                        }
214
                        var2Type.put(name, qualifiedType);
215
                    }
216
                    if (!var2Type.isEmpty()) {
217
                        typeName = VariousUtils.replaceVarNames(typeName, var2Type);
218
                    }
219
                }
220
            } else if (expression instanceof Scalar) {
200
            } else if (expression instanceof Scalar) {
221
                typeName = VariousUtils.extractVariableTypeFromExpression(expression, null);
201
                typeName = VariousUtils.extractVariableTypeFromExpression(expression, null);
202
            } else if (expression instanceof ArrayCreation) {
203
                ArrayCreation arrayCreation = (ArrayCreation) expression;
204
                List<ArrayElement> elements = arrayCreation.getElements();
205
                if (!elements.isEmpty()) {
206
                    for (ArrayElement arrayElement : elements) {
207
                        Expression value = arrayElement.getValue();
208
                        String type = null;
209
                        if (value instanceof ClassInstanceCreation) {
210
                            type = extractTypeName((ClassInstanceCreation) value);
211
                        } else if (value instanceof Scalar) {
212
                            type = VariousUtils.extractVariableTypeFromExpression(value, null);
213
                        } else if (value instanceof VariableBase) {
214
                            type = extractTypeName((VariableBase) value, node);
215
                        }
216
                        if (type != null) {
217
                            type += "[]"; //NOI18N
218
                            if (typeName == null) {
219
                                typeName = type;
220
                            } else {
221
                                typeName += "|" + type; //NOI18N
222
                            }
223
                        }
224
                     }
225
                }
222
            }
226
            }
223
227
224
            if (typeName != null) {
228
            if (typeName != null) {
Lines 237-245 Link Here
237
        }
241
        }
238
    }
242
    }
239
243
244
    private String extractTypeName(ClassInstanceCreation classInstanceCreation) {
245
        ASTNodeInfo<ClassInstanceCreation> inf = ASTNodeInfo.create(classInstanceCreation);
246
        String pureTypeName = inf.getQualifiedName().toString();
247
        return VariousUtils.qualifyTypeNames(pureTypeName, classInstanceCreation.getStartOffset(), modelBuilder.getCurrentScope());
248
    }
249
250
    private String extractTypeName(VariableBase variableBase, ReturnStatement node) {
251
        String typeName = VariousUtils.extractTypeFroVariableBase(variableBase);
252
        if (typeName != null) {
253
            ScopeImpl currentScope = modelBuilder.getCurrentScope();
254
            Collection<? extends VariableName> allVariables = VariousUtils.getAllVariables((FunctionScope) currentScope, typeName);
255
            Map<String,String> var2Type = new HashMap<String, String>();
256
            for (VariableName variable : allVariables) {
257
                String name = variable.getName();
258
                String type = resolveVariableType(name, (FunctionScope) currentScope, node);
259
                String qualifiedType = VariousUtils.qualifyTypeNames(type, variableBase.getStartOffset(), modelBuilder.getCurrentScope());
260
                if (qualifiedType == null) {
261
                    var2Type = Collections.emptyMap();
262
                    break;
263
                }
264
                var2Type.put(name, qualifiedType);
265
            }
266
            if (!var2Type.isEmpty()) {
267
                typeName = VariousUtils.replaceVarNames(typeName, var2Type);
268
            }
269
        }
270
        return typeName;
271
    }
272
240
    private static Set<String> recursionDetection = new HashSet<String>();//#168868
273
    private static Set<String> recursionDetection = new HashSet<String>();//#168868
241
274
242
    private String resolveVariableType(String varName, FunctionScopeImpl varScope, ReturnStatement node) {
275
    private String resolveVariableType(String varName, FunctionScope varScope, ReturnStatement node) {
243
        try {
276
        try {
244
            if (varName != null && recursionDetection.add(varName)) {
277
            if (varName != null && recursionDetection.add(varName)) {
245
                if (varName.equalsIgnoreCase("$this") && varScope instanceof MethodScope) {//NOI18N
278
                if (varName.equalsIgnoreCase("$this") && varScope instanceof MethodScope) {//NOI18N
Lines 249-266 Link Here
249
                if (var != null) {
282
                if (var != null) {
250
                    AssignmentImpl assignment = var.findVarAssignment(node.getStartOffset());
283
                    AssignmentImpl assignment = var.findVarAssignment(node.getStartOffset());
251
                    if (assignment != null) {
284
                    if (assignment != null) {
252
                        String typeName = assignment.typeNameFromUnion();
285
                        List<AssignmentImpl> varAssignments = new LinkedList<AssignmentImpl>();
253
                        if (typeName != null) {
286
                        if (assignment.isArrayAccess()) {
254
                            if (!typeName.contains("@")) {//NOI18N
287
                            varAssignments.addAll(var.getVarAssignments());
255
                                return typeName;
288
                        } else {
256
                            } else {
289
                            varAssignments.add((VarAssignmentImpl) assignment);
257
                                String variableName = getName(typeName, VariousUtils.Kind.VAR, true);
290
                        }
258
                                if (variableName != null && !variableName.equalsIgnoreCase(varName)) {
291
                        List<String> typeNames = new LinkedList<String>();
259
                                    return resolveVariableType(variableName, varScope, node);
292
                        for (AssignmentImpl varAssignment : varAssignments) {
293
                            String typeName = varAssignment.typeNameFromUnion();
294
                            if (varAssignment.isArrayAccess()) {
295
                                typeName += "[]"; //NOI18N
296
                            }
297
                            if (typeName != null) {
298
                                if (!typeName.contains("@")) {//NOI18N
299
                                    typeNames.add(typeName);
300
                                } else {
301
                                    String variableName = getName(typeName, VariousUtils.Kind.VAR, true);
302
                                    if (variableName != null && !variableName.equalsIgnoreCase(varName)) {
303
                                        typeNames.add(resolveVariableType(variableName, varScope, node));
304
                                    }
305
                                    typeNames.add(typeName);
260
                                }
306
                                }
261
                                return typeName;
262
                            }
307
                            }
263
                        }
308
                        }
309
                        String allTypeNames = ""; //NOI18N
310
                        for (String type : typeNames) {
311
                            allTypeNames += ("|" + type); //NOI18N
312
                        }
313
                        return allTypeNames.substring(1);
264
                    }
314
                    }
265
                }
315
                }
266
            }
316
            }

Return to bug 207534