Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zulus committed Jun 1, 2014
1 parent fc00211 commit fb1c967
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Expand Up @@ -33,6 +33,8 @@
import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
import org.eclipse.php.internal.core.compiler.ast.nodes.UseStatement;
import org.eclipse.php.internal.core.compiler.ast.visitor.PHPASTVisitor;
import org.eclipse.php.internal.core.model.PerFileModelAccessCache;
import org.eclipse.php.internal.core.typeinference.IModelAccessCache;
import org.eclipse.wst.sse.core.utils.StringUtils;

import com.dubture.doctrine.annotation.model.Annotation;
Expand Down Expand Up @@ -84,13 +86,15 @@ public class TemplateVariableVisitor extends PHPASTVisitor {
private ISourceModule source;

private AnnotationCommentParser parser;
private IModelAccessCache cache;

public TemplateVariableVisitor(List<UseStatement> useStatements, NamespaceDeclaration namespace, ISourceModule source) {
this.namespace = namespace;
this.useStatements = useStatements;

this.source = source;
this.parser = AnnotationUtils.createParser();
this.cache = new PerFileModelAccessCache(source);

bundle = ModelUtils.extractBundleName(namespace);
}
Expand Down Expand Up @@ -325,9 +329,9 @@ private void parseVariablesFromArray(ArrayCreation array, String viewPath) {
if (deferred.getName().equals(varRef.getName())) {

TemplateVariable tempVar = SymfonyModelAccess.getDefault()
.createTemplateVariableByReturnType(currentMethod,
.createTemplateVariableByReturnType(source, currentMethod,
callName, deferred.getClassName(), deferred.getNamespace(),
varRef.getName());
varRef.getName(), cache);

templateVariables.put(tempVar, viewPath);
break;
Expand Down Expand Up @@ -427,8 +431,8 @@ public boolean visit(Assignment s) throws Exception {
TemplateVariable tempVar = null;

tempVar = SymfonyModelAccess.getDefault()
.createTemplateVariableByReturnType(currentMethod, callName,
service.getClassName(), fqsn, var.getName());
.createTemplateVariableByReturnType(source, currentMethod, callName,
service.getClassName(), fqsn, var.getName(), cache);

if (tempVar != null) {

Expand All @@ -446,7 +450,7 @@ public boolean visit(Assignment s) throws Exception {
if (tempVar.getName().equals(varRef.getName())) {

TemplateVariable tVar = SymfonyModelAccess.getDefault()
.createTemplateVariableByReturnType(currentMethod, ref, tempVar.getClassName(), tempVar.getNamespace(), var.getName());
.createTemplateVariableByReturnType(source, currentMethod, ref, tempVar.getClassName(), tempVar.getNamespace(), var.getName(), cache);

if (tVar != null) {
deferredVariables.push(tVar);
Expand Down
Expand Up @@ -9,6 +9,7 @@
package com.dubture.symfony.core.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.eclipse.php.internal.core.compiler.ast.nodes.PHPMethodDeclaration;
import org.eclipse.php.internal.core.compiler.ast.visitor.PHPASTVisitor;
import org.eclipse.php.internal.core.model.PhpModelAccess;
import org.eclipse.php.internal.core.typeinference.IModelAccessCache;

import com.dubture.symfony.core.SymfonyLanguageToolkit;
import com.dubture.symfony.core.index.SymfonyElementResolver.TemplateField;
Expand Down Expand Up @@ -106,18 +108,27 @@ public static SymfonyModelAccess getDefault() {

return modelInstance;
}


public TemplateVariable createTemplateVariableByReturnType(PHPMethodDeclaration controllerMethod, SimpleReference callName,

public TemplateVariable createTemplateVariableByReturnType(ISourceModule sourceModule, PHPMethodDeclaration controllerMethod, SimpleReference callName,
String className, String namespace, String variableName) {
return createTemplateVariableByReturnType(sourceModule, controllerMethod, callName, className, namespace, variableName, null);
}

IDLTKSearchScope scope = SearchEngine.createWorkspaceScope(PHPLanguageToolkit.getDefault());

if (scope == null)
return null;

IType[] types = findTypes(namespace, className, MatchRule.EXACT, 0, 0, scope, null);

public TemplateVariable createTemplateVariableByReturnType(ISourceModule sourceModule, PHPMethodDeclaration controllerMethod, SimpleReference callName,
String className, String namespace, String variableName, IModelAccessCache cache) {
IType[] types = null;
if (cache != null) {
Collection<IType> typesList = cache.getTypes(sourceModule, className, namespace, null);
types = typesList.toArray(new IType[typesList.size()]);
} else {
IDLTKSearchScope scope = createSearchScope(sourceModule);

if (scope == null)
return null;

types = findTypes(namespace, className, MatchRule.EXACT, 0, 0, scope, null);
}
if (types.length != 1)
return null;

Expand Down

0 comments on commit fb1c967

Please sign in to comment.