junichi11 commented on a change in pull request #994: [NETBEANS-1438] :
stackoverflowerror opening .js files
URL: https://github.com/apache/incubator-netbeans/pull/994#discussion_r229274397
##########
File path:
webcommon/javascript2.model/src/org/netbeans/modules/javascript2/model/api/ModelUtils.java
##########
@@ -1173,75 +1177,84 @@ public static boolean hasDeclaredProperty(JsObject
jsObject) {
* @return
*/
public static TypeUsage createResolvedType(JsObject parent, TypeUsage
typeHere) {
- deepCRT = 0;
+ int invokeCount = 0;
String fqn = getFQNFromType(typeHere);
- return resolveTypes(parent, fqn, typeHere.getOffset());
+ List<TypeUsage> alreadyResolved = new ArrayList<>();
+ return resolveTypes(parent, fqn, typeHere.getOffset(),
alreadyResolved, invokeCount);
}
/* @return TypeUsage with generated typename string
*/
- private static TypeUsage resolveTypes(JsObject parent, String fqn, int
offset) {
+ private static TypeUsage resolveTypes(JsObject parent, String fqn, int
offset, List<TypeUsage> alreadyResolved, int invokeCount) {
- deepCRT++;
+ invokeCount++;
String name = fqn;
StringBuilder props = new StringBuilder();
int indx = fqn.indexOf(".");
if (indx != -1) {
name = fqn.substring(0, indx);
props.append(fqn.substring(indx + 1));
}
- List<TypeUsage> localResolved = new ArrayList<TypeUsage>();
+ List<TypeUsage> localResolved = new ArrayList<>();
resolveAssignments(parent, name, offset, localResolved, props);
- boolean typeResolved = false;
- for (TypeUsage type : localResolved) {
- if (type.isResolved()) {
- String newObjectName = type.getType();
- JsObject object = ModelUtils.searchJsObjectByName(parent,
newObjectName);
- if ((object != null) && (object != parent)) {
- String partfqn = props.toString();
- if (!partfqn.trim().equals("")) {
- String[] tokens = partfqn.split("\\.");
- for (int i = 0; i < tokens.length; i++) {
- object = ModelUtils.searchJsObjectByName(parent,
newObjectName);
- for (JsObject prop :
object.getProperties().values()) {
- if ((prop.getName().equals(tokens[i])) &&
(prop.isDeclared())) {
- if ((prop.getAssignmentCount() > 0) &&
(deepCRT < MAX_RECURSION_DEEP_RESOLVING_ASSIGNMENTS)) {
- for (TypeUsage type1 :
prop.getAssignments()) {
- return resolveTypes(object,
String.join(".", Arrays.copyOfRange(tokens, i, tokens.length)), offset);
- }
- } else {
- object = prop;
- newObjectName = newObjectName + "." +
prop.getName();
- if (i == tokens.length - 1) {
- typeResolved = true;
+ List<TypeUsage> diff = localResolved.stream().filter(type ->
!alreadyResolved.contains(type)).collect(Collectors.toList());
+ if (diff.size() > 0) {
+ alreadyResolved.addAll(diff);
+ boolean typeResolved = false;
+ for (TypeUsage type : localResolved) {
+ if (type.isResolved()) {
+ String newObjectName = type.getType();
+ JsObject object = ModelUtils.searchJsObjectByName(parent,
newObjectName);
+ if ((object != null) && (object != parent)) {
+ String partfqn = props.toString();
+ if (!partfqn.trim().equals("")) {
+ String[] tokens = partfqn.split("\\.");
+ for (int i = 0; i < tokens.length; i++) {
+ object =
ModelUtils.searchJsObjectByName(parent, newObjectName);
+ for (JsObject prop :
object.getProperties().values()) {
+ if ((prop.getName().equals(tokens[i])) &&
(prop.isDeclared())) {
+ if (prop.getAssignmentCount() > 0) {
+ if (invokeCount ==
MAX_RECURSION_DEEP_RESOLVING_ASSIGNMENTS) {
+ LOG.log(Level.WARNING,
"StackOverFlowError : {0} : {1}",
+ new
Object[]{object.getFullyQualifiedName(),
+
object.getFileObject()});
+ }
+ for (TypeUsage type1 :
prop.getAssignments()) {
Review comment:
Need this check? (Here is within the `if (prop.getAssignmentCount() > 0)`
block and `type1` is not used.)
If need it, should write like this?
```java
if (!prop.getAssignments().isEmpty()) {
...
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists