Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry BLIND2019-10-30 06:26:54 -0400
committerThierry BLIND2019-10-30 06:26:54 -0400
commit524607d02e63d72e4fba25f67565054c5104fdfe (patch)
tree5ac759cd4ed0057a1cd16ef613827655872efb66
parent6eb44d845c789202c5bb529e609d5f1d71cb54e4 (diff)
downloadorg.eclipse.pdt-524607d02e63d72e4fba25f67565054c5104fdfe.tar.gz
org.eclipse.pdt-524607d02e63d72e4fba25f67565054c5104fdfe.tar.xz
org.eclipse.pdt-524607d02e63d72e4fba25f67565054c5104fdfe.zip
Bug 551505 - support var comments using the PHPDoc block syntax
Change-Id: I4d0e52bd4ee62040b0b16cdf3abf9efa3aa9765f Signed-off-by: Thierry BLIND <thierryblind@msn.com>
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/PHPModuleDeclaration.java9
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/visitor/ValidatorVisitor.java39
2 files changed, 48 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/PHPModuleDeclaration.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/PHPModuleDeclaration.java
index 5a4640c19..fd8dfea09 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/PHPModuleDeclaration.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/PHPModuleDeclaration.java
@@ -147,14 +147,23 @@ public class PHPModuleDeclaration extends ModuleDeclaration {
this.hasErrors = hasErrors;
}
+ /**
+ * Naturally sorted by order of appearance in the file.
+ */
public List<VarComment> getVarComments() {
return varComments;
}
+ /**
+ * Naturally sorted by order of appearance in the file.
+ */
public List<PHPDocBlock> getPHPDocBlocks() {
return phpDocBlocks;
}
+ /**
+ * Naturally sorted by order of appearance in the file.
+ */
public List<Comment> getCommentList() {
return commentList;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/visitor/ValidatorVisitor.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/visitor/ValidatorVisitor.java
index 1eecb31a8..e8e71ddb2 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/visitor/ValidatorVisitor.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/visitor/ValidatorVisitor.java
@@ -39,6 +39,7 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.php.core.PHPVersion;
import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.core.compiler.ast.nodes.*;
+import org.eclipse.php.core.compiler.ast.nodes.PHPDocTag.TagKind;
import org.eclipse.php.core.compiler.ast.validator.IValidatorExtension;
import org.eclipse.php.core.compiler.ast.validator.IValidatorVisitor;
import org.eclipse.php.core.compiler.ast.visitor.PHPASTVisitor;
@@ -97,8 +98,10 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
private Map<String, UsePartInfo> usePartInfo = new LinkedHashMap<>();
private Map<String, Boolean> elementExists = new HashMap<>();
private NamespaceDeclaration currentNamespace;
+ private IPHPDocAwareDeclaration currentDeclaration;
private Set<String> typeDeclared = new HashSet<>();
private ArrayList<VarComment> varComments = new ArrayList<>();
+ private ArrayList<PHPDocBlock> docBlocks = new ArrayList<>();
private boolean hasNamespace;
private ISourceModule sourceModule;
private PHPVersion version;
@@ -146,6 +149,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
if (s instanceof PHPModuleDeclaration) {
// See also VariableReferenceEvaluator.init().
varComments.addAll(((PHPModuleDeclaration) s).getVarComments());
+ docBlocks.addAll(((PHPModuleDeclaration) s).getPHPDocBlocks());
}
return super.visit(s);
}
@@ -162,6 +166,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(NamespaceDeclaration s) throws Exception {
+ currentDeclaration = s;
hasNamespace = true;
currentNamespace = s;
fNamespaceDeclarations.push(s);
@@ -184,6 +189,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(PHPMethodDeclaration s) throws Exception {
+ currentDeclaration = s;
if (s.getPHPDoc() != null) {
s.getPHPDoc().traverse(this);
}
@@ -192,6 +198,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(PHPFieldDeclaration s) throws Exception {
+ currentDeclaration = s;
if (s.getPHPDoc() != null) {
s.getPHPDoc().traverse(this);
}
@@ -280,6 +287,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(ClassDeclaration s) throws Exception {
+ currentDeclaration = s;
checkReservedWord(s, "class"); //$NON-NLS-1$
checkUnimplementedMethods(s, s.getRef());
if (s.getSuperClass() != null) {
@@ -314,6 +322,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(InterfaceDeclaration s) throws Exception {
+ currentDeclaration = s;
checkReservedWord(s, "interface"); //$NON-NLS-1$
if (s.getSuperClasses() == null) {
return super.visit(s);
@@ -462,6 +471,16 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
}
/**
+ * Fake VarComment visitor (visit the @var tags inside a PHPDocBlock).
+ */
+ private boolean visitVarTags(PHPDocBlock s) throws Exception {
+ for (PHPDocTag phpDocTag : s.getTags(TagKind.VAR)) {
+ visit(phpDocTag);
+ }
+ return false;
+ }
+
+ /**
* Fake VarComment visitor.
*/
private boolean visit(VarComment varComment) throws Exception {
@@ -492,6 +511,25 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
visit(varComment);
itr.remove();
}
+ if (currentDeclaration instanceof ASTNode) {
+ // currentDeclaration.sourceStart() is the minimal position to look
+ // for PHPDocBlocks, to avoid getting out of current declaration
+ // block
+ minPos = Math.max(minPos, ((ASTNode) currentDeclaration).sourceStart());
+ }
+ Iterator<PHPDocBlock> itr2 = docBlocks.iterator();
+ while (itr2.hasNext()) {
+ PHPDocBlock docBlock = itr2.next();
+ if (docBlock.sourceStart() < minPos) {
+ itr2.remove();
+ continue;
+ }
+ if (docBlock.sourceEnd() > maxPos) {
+ break;
+ }
+ visitVarTags(docBlock);
+ itr2.remove();
+ }
}
@Override
@@ -973,6 +1011,7 @@ public class ValidatorVisitor extends PHPASTVisitor implements IValidatorVisitor
@Override
public boolean visit(ConstantDeclaration s) throws Exception {
+ currentDeclaration = s;
validateConstantExpression(s.getConstantValue(), false);
return super.visit(s);
}

Back to the top