import net.sourceforge.phpdt.core.compiler.CharOperation;
import net.sourceforge.phpdt.core.compiler.IProblem;
+import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
+import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.AnonymousLocalTypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.Argument;
+import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.ExplicitConstructorCall;
+import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
+import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.NameReference;
+import net.sourceforge.phpdt.internal.compiler.ast.QualifiedAllocationExpression;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
import net.sourceforge.phpdt.internal.compiler.env.ISourceType;
import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation;
import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
import net.sourceforge.phpdt.internal.core.util.CommentRecorderParser;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AnonymousLocalTypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
-import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.LocalTypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.MemberTypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedAllocationExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
/**
* A source element parser extracts structural and reference information
/**
* An ast visitor that visits local type declarations.
*/
- public class LocalDeclarationVisitor extends AbstractSyntaxTreeVisitorAdapter {
- // public boolean visit(
- // AnonymousLocalTypeDeclaration anonymousTypeDeclaration,
- // BlockScope scope) {
- // notifySourceElementRequestor(anonymousTypeDeclaration, sourceType ==
- // null);
- // return false; // don't visit members as this was done during
- // notifySourceElementRequestor(...)
- // }
- public boolean visit(LocalTypeDeclaration typeDeclaration, BlockScope scope) {
- notifySourceElementRequestor(typeDeclaration, sourceType == null);
- return false; // don't visit members as this was done during
- // notifySourceElementRequestor(...)
- }
- public boolean visit(MemberTypeDeclaration typeDeclaration, ClassScope scope) {
- notifySourceElementRequestor(typeDeclaration, sourceType == null);
- return false; // don't visit members as this was done during
- // notifySourceElementRequestor(...)
- }
-
+ public class LocalDeclarationVisitor extends ASTVisitor {
+ public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) {
+ notifySourceElementRequestor(typeDeclaration, sourceType == null);
+ return false; // don't visit members as this was done during notifySourceElementRequestor(...)
+ }
+ public boolean visit(TypeDeclaration typeDeclaration, ClassScope scope) {
+ notifySourceElementRequestor(typeDeclaration, sourceType == null);
+ return false; // don't visit members as this was done during notifySourceElementRequestor(...)
+ }
+
}
public SourceElementParser(final ISourceElementRequestor requestor, IProblemFactory problemFactory, CompilerOptions options) {
// we want to notify all syntax error with the acceptProblem API
// To do so, we define the record method of the ProblemReporter
- super(new ProblemReporter(DefaultErrorHandlingPolicies.exitAfterAllProblems(), options, problemFactory) {
+ super( new ProblemReporter(DefaultErrorHandlingPolicies.exitAfterAllProblems(), options, problemFactory) {
public void record(IProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) {
unitResult.record(problem, referenceContext);
- requestor.acceptProblem(problem);
+ if (requestor!=null) {
+ requestor.acceptProblem(problem);
+ }
}
});
// true);
* @deprecated use SourceElementParser(ISourceElementRequestor,
* IProblemFactory, CompilerOptions)
*/
- //public SourceElementParser(
- // final ISourceElementRequestor requestor,
- // IProblemFactory problemFactory) {
- // this(requestor, problemFactory, new CompilerOptions());
- //}
- //public SourceElementParser(
- // final ISourceElementRequestor requestor,
- // IProblemFactory problemFactory,
- // CompilerOptions options,
- // boolean reportLocalDeclarations) {
- // this(requestor, problemFactory, options);
- // if (reportLocalDeclarations) {
- // this.localDeclarationVisitor = new LocalDeclarationVisitor();
- // }
- //}
+ public SourceElementParser(
+ final ISourceElementRequestor requestor,
+ IProblemFactory problemFactory) {
+ this(requestor, problemFactory, new CompilerOptions());
+ }
+ public SourceElementParser(
+ final ISourceElementRequestor requestor,
+ IProblemFactory problemFactory,
+ CompilerOptions options,
+ boolean reportLocalDeclarations) {
+ this(requestor, problemFactory, options);
+ if (reportLocalDeclarations) {
+ this.localDeclarationVisitor = new LocalDeclarationVisitor();
+ }
+ }
//public void checkAnnotation() {
// int firstCommentIndex = scanner.commentPtr;
//
// new SingleNameReference(
// identifierStack[identifierPtr],
// identifierPositionStack[identifierPtr--]);
- // ref.bits &= ~AstNode.RestrictiveFlagMASK;
+ // ref.bits &= ~ASTNode.RestrictiveFlagMASK;
// ref.bits |= LOCAL | FIELD;
// if (reportReferenceInfo) {
// this.addUnknownRef(ref);
// (int) (identifierPositionStack[identifierPtr + 1] >> 32),
// // sourceStart
// (int) identifierPositionStack[identifierPtr + length]); // sourceEnd
- // ref.bits &= ~AstNode.RestrictiveFlagMASK;
+ // ref.bits &= ~ASTNode.RestrictiveFlagMASK;
// ref.bits |= LOCAL | FIELD;
// if (reportReferenceInfo) {
// this.addUnknownRef(ref);
// }
// collect the top level ast nodes
int length = 0;
- AstNode[] nodes = null;
+ ASTNode[] nodes = null;
if (sourceType == null) {
if (isInRange) {
requestor.enterCompilationUnit();
// (currentPackage == null ? 0 : 1)
// + (imports == null ? 0 : imports.length)
// + (types == null ? 0 : types.length);
- // nodes = new AstNode[length];
+ // nodes = new ASTNode[length];
length = (imports == null ? 0 : imports.length) + types.size();
- nodes = new AstNode[length];
+ nodes = new ASTNode[length];
int index = 0;
// if (currentPackage != null) {
// nodes[index++] = currentPackage;
}
for (int i = 0, max = types.size(); i < max; i++) {
- nodes[index++] = (AstNode) types.get(i);
+ nodes[index++] = (ASTNode) types.get(i);
}
}
} else {
ArrayList types = parsedUnit.types;
if (types != null) {
length = types.size();
- nodes = new AstNode[length];
+ nodes = new ASTNode[length];
for (int i = 0, max = types.size(); i < max; i++) {
- nodes[i] = (AstNode) types.get(i);
+ nodes[i] = (ASTNode) types.get(i);
}
}
}
if (nodes != null && length > 0) {
quickSort(nodes, 0, length - 1);
for (int i = 0; i < length; i++) {
- AstNode node = nodes[i];
+ ASTNode node = nodes[i];
if (node instanceof ImportReference) {
ImportReference importRef = (ImportReference)node;
// if (node == parsedUnit.currentPackage) {
// }
}
public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence) {
- //// public void notifySourceElementRequestor(AstNode typeDeclaration,
+ //// public void notifySourceElementRequestor(ASTNode typeDeclaration,
// boolean notifyTypePresence) {
// range check
FieldDeclaration[] fields = typeDeclaration.fields;
AbstractMethodDeclaration[] methods = typeDeclaration.methods;
- MemberTypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
+ TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
int fieldCount = fields == null ? 0 : fields.length;
int methodCount = methods == null ? 0 : methods.length;
int memberTypeCount = memberTypes == null ? 0 : memberTypes.length;
return null;
}
+ public CompilationUnitDeclaration parseCompletionUnit(ICompilationUnit unit, boolean fullParse) {
+
+ // boolean old = diet;
+ // if (fullParse) {
+ // unknownRefs = new NameReference[10];
+ // unknownRefsCounter = 0;
+ // }
+
+ try {
+ // diet = true;
+ this.reportReferenceInfo = fullParse;
+ CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.options.maxProblemsPerUnit);
+ CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult, false);
+// if (scanner.recordLineSeparator) {
+// requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
+// }
+// int initialStart = this.scanner.initialPosition;
+// int initialEnd = this.scanner.eofPosition;
+// // if (this.localDeclarationVisitor != null || fullParse){
+// // diet = false;
+// // this.getMethodBodies(parsedUnit);
+// // }
+// this.scanner.resetTo(initialStart, initialEnd);
+// notifySourceElementRequestor(parsedUnit);
+ return parsedUnit;
+ } catch (AbortCompilation e) {
+ // ignore this exception
+ } finally {
+ // diet = old;
+ }
+ return null;
+ }
//public void parseTypeMemberDeclarations(
// ISourceType sourceType,
// ICompilationUnit sourceUnit,
/**
* Sort the given ast nodes by their positions.
*/
- private static void quickSort(AstNode[] sortedCollection, int left, int right) {
+ private static void quickSort(ASTNode[] sortedCollection, int left, int right) {
int original_left = left;
int original_right = right;
- AstNode mid = sortedCollection[(left + right) / 2];
+ ASTNode mid = sortedCollection[(left + right) / 2];
do {
while (sortedCollection[left].sourceStart < mid.sourceStart) {
left++;
right--;
}
if (left <= right) {
- AstNode tmp = sortedCollection[left];
+ ASTNode tmp = sortedCollection[left];
sortedCollection[left] = sortedCollection[right];
sortedCollection[right] = tmp;
left++;
}
private void visitIfNeeded(AbstractMethodDeclaration method) {
- if (this.localDeclarationVisitor != null && (method.bits & AstNode.HasLocalTypeMASK) != 0) {
+ if (this.localDeclarationVisitor != null && (method.bits & ASTNode.HasLocalTypeMASK) != 0) {
if (method.statements != null) {
int statementsLength = method.statements.length;
for (int i = 0; i < statementsLength; i++)
//private void visitIfNeeded(FieldDeclaration field) {
// if (this.localDeclarationVisitor != null
- // && (field.bits & AstNode.HasLocalTypeMASK) != 0) {
+ // && (field.bits & ASTNode.HasLocalTypeMASK) != 0) {
// if (field.initialization != null) {
// field.initialization.traverse(this.localDeclarationVisitor, null);
// }
//
//private void visitIfNeeded(Initializer initializer) {
// if (this.localDeclarationVisitor != null
- // && (initializer.bits & AstNode.HasLocalTypeMASK) != 0) {
+ // && (initializer.bits & ASTNode.HasLocalTypeMASK) != 0) {
// if (initializer.block != null) {
// initializer.block.traverse(this.localDeclarationVisitor, null);
// }