diff --git a/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java b/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java --- a/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java +++ b/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java @@ -194,31 +194,35 @@ FunctionScopeImpl functionScope = (FunctionScopeImpl) currentScope; Expression expression = node.getExpression(); if (expression instanceof ClassInstanceCreation) { - ClassInstanceCreation instanceCreation = (ClassInstanceCreation) expression; - ASTNodeInfo inf = ASTNodeInfo.create(instanceCreation); - String pureTypeName = inf.getQualifiedName().toString(); - typeName = VariousUtils.qualifyTypeNames(pureTypeName, node.getStartOffset(), currentScope); + typeName = extractTypeName((ClassInstanceCreation) expression); } else if (expression instanceof VariableBase) { - typeName = VariousUtils.extractTypeFroVariableBase((VariableBase) expression); - if (typeName != null) { - Collection allVariables = VariousUtils.getAllVariables(functionScope, typeName); - Map var2Type = new HashMap(); - for (VariableName variable : allVariables) { - String name = variable.getName(); - String type = resolveVariableType(name, functionScope, node); - String qualifiedType = VariousUtils.qualifyTypeNames(type, node.getStartOffset(), currentScope); - if (qualifiedType == null) { - var2Type = Collections.emptyMap(); - break; - } - var2Type.put(name, qualifiedType); - } - if (!var2Type.isEmpty()) { - typeName = VariousUtils.replaceVarNames(typeName, var2Type); - } - } + typeName = extractTypeName((VariableBase) expression, node); } else if (expression instanceof Scalar) { typeName = VariousUtils.extractVariableTypeFromExpression(expression, null); + } else if (expression instanceof ArrayCreation) { + ArrayCreation arrayCreation = (ArrayCreation) expression; + List elements = arrayCreation.getElements(); + if (!elements.isEmpty()) { + for (ArrayElement arrayElement : elements) { + Expression value = arrayElement.getValue(); + String type = null; + if (value instanceof ClassInstanceCreation) { + type = extractTypeName((ClassInstanceCreation) value); + } else if (value instanceof Scalar) { + type = VariousUtils.extractVariableTypeFromExpression(value, null); + } else if (value instanceof VariableBase) { + type = extractTypeName((VariableBase) value, node); + } + if (type != null) { + type += "[]"; //NOI18N + if (typeName == null) { + typeName = type; + } else { + typeName += "|" + type; //NOI18N + } + } + } + } } if (typeName != null) { @@ -237,9 +241,38 @@ } } + private String extractTypeName(ClassInstanceCreation classInstanceCreation) { + ASTNodeInfo inf = ASTNodeInfo.create(classInstanceCreation); + String pureTypeName = inf.getQualifiedName().toString(); + return VariousUtils.qualifyTypeNames(pureTypeName, classInstanceCreation.getStartOffset(), modelBuilder.getCurrentScope()); + } + + private String extractTypeName(VariableBase variableBase, ReturnStatement node) { + String typeName = VariousUtils.extractTypeFroVariableBase(variableBase); + if (typeName != null) { + ScopeImpl currentScope = modelBuilder.getCurrentScope(); + Collection allVariables = VariousUtils.getAllVariables((FunctionScope) currentScope, typeName); + Map var2Type = new HashMap(); + for (VariableName variable : allVariables) { + String name = variable.getName(); + String type = resolveVariableType(name, (FunctionScope) currentScope, node); + String qualifiedType = VariousUtils.qualifyTypeNames(type, variableBase.getStartOffset(), modelBuilder.getCurrentScope()); + if (qualifiedType == null) { + var2Type = Collections.emptyMap(); + break; + } + var2Type.put(name, qualifiedType); + } + if (!var2Type.isEmpty()) { + typeName = VariousUtils.replaceVarNames(typeName, var2Type); + } + } + return typeName; + } + private static Set recursionDetection = new HashSet();//#168868 - private String resolveVariableType(String varName, FunctionScopeImpl varScope, ReturnStatement node) { + private String resolveVariableType(String varName, FunctionScope varScope, ReturnStatement node) { try { if (varName != null && recursionDetection.add(varName)) { if (varName.equalsIgnoreCase("$this") && varScope instanceof MethodScope) {//NOI18N @@ -249,18 +282,35 @@ if (var != null) { AssignmentImpl assignment = var.findVarAssignment(node.getStartOffset()); if (assignment != null) { - String typeName = assignment.typeNameFromUnion(); - if (typeName != null) { - if (!typeName.contains("@")) {//NOI18N - return typeName; - } else { - String variableName = getName(typeName, VariousUtils.Kind.VAR, true); - if (variableName != null && !variableName.equalsIgnoreCase(varName)) { - return resolveVariableType(variableName, varScope, node); + List varAssignments = new LinkedList(); + if (assignment.isArrayAccess()) { + varAssignments.addAll(var.getVarAssignments()); + } else { + varAssignments.add((VarAssignmentImpl) assignment); + } + List typeNames = new LinkedList(); + for (AssignmentImpl varAssignment : varAssignments) { + String typeName = varAssignment.typeNameFromUnion(); + if (varAssignment.isArrayAccess()) { + typeName += "[]"; //NOI18N + } + if (typeName != null) { + if (!typeName.contains("@")) {//NOI18N + typeNames.add(typeName); + } else { + String variableName = getName(typeName, VariousUtils.Kind.VAR, true); + if (variableName != null && !variableName.equalsIgnoreCase(varName)) { + typeNames.add(resolveVariableType(variableName, varScope, node)); + } + typeNames.add(typeName); } - return typeName; } } + String allTypeNames = ""; //NOI18N + for (String type : typeNames) { + allTypeNames += ("|" + type); //NOI18N + } + return allTypeNames.substring(1); } } }