X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java index 21df17c..7dc0c65 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java @@ -23,10 +23,10 @@ import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope; 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.ASTNode; 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; @@ -40,6 +40,8 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedAllocationExpre import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference; +import org.eclipse.core.resources.IResource; + /** * A source element parser extracts structural and reference information * from a piece of source. @@ -105,10 +107,12 @@ public class SourceElementParser extends CommentRecorderParser {//extends 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); @@ -514,7 +518,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends // new SingleNameReference( // identifierStack[identifierPtr], // identifierPositionStack[identifierPtr--]); - // ref.bits &= ~AstNode.RestrictiveFlagMASK; + // ref.bits &= ~ASTNode.RestrictiveFlagMASK; // ref.bits |= LOCAL | FIELD; // if (reportReferenceInfo) { // this.addUnknownRef(ref); @@ -541,7 +545,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends // (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); @@ -584,7 +588,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends // } // collect the top level ast nodes int length = 0; - AstNode[] nodes = null; + ASTNode[] nodes = null; if (sourceType == null) { if (isInRange) { requestor.enterCompilationUnit(); @@ -598,9 +602,9 @@ public class SourceElementParser extends CommentRecorderParser {//extends // (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; @@ -612,7 +616,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends } for (int i = 0, max = types.size(); i < max; i++) { - nodes[index++] = (AstNode) types.get(i); + nodes[index++] = (ASTNode) types.get(i); } } } else { @@ -620,9 +624,9 @@ public class SourceElementParser extends CommentRecorderParser {//extends 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); } } } @@ -631,7 +635,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends 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) { @@ -910,7 +914,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends // } } public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence) { - //// public void notifySourceElementRequestor(AstNode typeDeclaration, + //// public void notifySourceElementRequestor(ASTNode typeDeclaration, // boolean notifyTypePresence) { // range check @@ -1115,6 +1119,38 @@ public class SourceElementParser extends CommentRecorderParser {//extends 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, @@ -1207,10 +1243,10 @@ public class SourceElementParser extends CommentRecorderParser {//extends /** * 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++; @@ -1219,7 +1255,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends right--; } if (left <= right) { - AstNode tmp = sortedCollection[left]; + ASTNode tmp = sortedCollection[left]; sortedCollection[left] = sortedCollection[right]; sortedCollection[right] = tmp; left++; @@ -1263,7 +1299,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends } 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++) @@ -1274,7 +1310,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends //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); // } @@ -1283,7 +1319,7 @@ public class SourceElementParser extends CommentRecorderParser {//extends // //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); // }