synchronized from quantum plugin
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / SourceElementParser.java
index b689763..b66cb71 100644 (file)
@@ -16,12 +16,13 @@ import net.sourceforge.phpdt.core.compiler.CharOperation;
 import net.sourceforge.phpdt.core.compiler.IProblem;
 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.impl.ReferenceContext;
 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
 import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope;
-import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
 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;
@@ -59,7 +60,7 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
  * Any (parsing) problem encountered is also provided.
  */
 
-public class SourceElementParser extends UnitParser {
+public class SourceElementParser  extends CommentRecorderParser {//extends UnitParser {
        
        ISourceElementRequestor requestor;
        int fieldCount;
@@ -67,7 +68,7 @@ public class SourceElementParser extends UnitParser {
        int lastFieldEndPosition;
        ISourceType sourceType;
        boolean reportReferenceInfo;
-       char[][] typeNames;
+       char[][] typeNames; 
        char[][] superTypeNames;
        int nestedTypeIndex;
        static final char[] JAVA_LANG_OBJECT = "java.lang.Object".toCharArray(); //$NON-NLS-1$
@@ -99,14 +100,14 @@ public class LocalDeclarationVisitor extends AbstractSyntaxTreeVisitorAdapter {
 
 public SourceElementParser(
        final ISourceElementRequestor requestor, 
-       IProblemFactory problemFactory) {
-//     CompilerOptions options) {
+       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, 
+               options, 
                problemFactory) {
                public void record(IProblem problem, CompilationResult unitResult, ReferenceContext referenceContext) {
                        unitResult.record(problem, referenceContext);
@@ -119,7 +120,7 @@ public SourceElementParser(
        typeNames = new char[4][];
        superTypeNames = new char[4][];
        nestedTypeIndex = 0;
-//     this.options = options;
+       this.options = options;
 }
 
 /** @deprecated use SourceElementParser(ISourceElementRequestor, IProblemFactory, CompilerOptions) */
@@ -812,18 +813,18 @@ public void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclara
                requestor.exitMethod(methodDeclaration.declarationSourceEnd);
        }
 }
-///*
-//* Update the bodyStart of the corresponding parse node
-//*/
-//public void notifySourceElementRequestor(FieldDeclaration fieldDeclaration) {
-//     
-//     // range check
-//     boolean isInRange = 
-//                             scanner.initialPosition <= fieldDeclaration.declarationSourceStart
-//                             && scanner.eofPosition >= fieldDeclaration.declarationSourceEnd;
-//
-//     if (fieldDeclaration.isField()) {
-//             int fieldEndPosition = fieldDeclaration.declarationSourceEnd;
+/*
+* Update the bodyStart of the corresponding parse node
+*/
+public void notifySourceElementRequestor(FieldDeclaration fieldDeclaration) {
+       
+       // range check
+       boolean isInRange = 
+                               scanner.initialPosition <= fieldDeclaration.declarationSourceStart
+                               && scanner.eofPosition >= fieldDeclaration.declarationSourceEnd;
+
+       if (fieldDeclaration.isField()) {
+               int fieldEndPosition = fieldDeclaration.declarationSourceEnd;
 //             if (fieldDeclaration instanceof SourceFieldDeclaration) {
 //                     fieldEndPosition = ((SourceFieldDeclaration) fieldDeclaration).fieldEndPosition;
 //                     if (fieldEndPosition == 0) {
@@ -831,19 +832,19 @@ public void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclara
 //                             fieldEndPosition = fieldDeclaration.declarationSourceEnd;
 //                     }
 //             }
-//             if (isInRange) {
-//                     int modifiers = fieldDeclaration.modifiers;
-//                     boolean deprecated = (modifiers & AccDeprecated) != 0; // remember deprecation so as to not lose it below
-//                     requestor.enterField(
-//                             fieldDeclaration.declarationSourceStart, 
-//                             deprecated ? (modifiers & AccJustFlag) | AccDeprecated : modifiers & AccJustFlag, 
-//                             returnTypeName(fieldDeclaration.type), 
-//                             fieldDeclaration.name, 
-//                             fieldDeclaration.sourceStart, 
-//                             fieldDeclaration.sourceEnd); 
-//             }
+               if (isInRange) {
+                       int modifiers = fieldDeclaration.modifiers;
+                       boolean deprecated = (modifiers & AccDeprecated) != 0; // remember deprecation so as to not lose it below
+                       requestor.enterField(
+                               fieldDeclaration.declarationSourceStart, 
+                               deprecated ? (modifiers & AccJustFlag) | AccDeprecated : modifiers & AccJustFlag, 
+                               returnTypeName(fieldDeclaration.type), 
+                               fieldDeclaration.name, 
+                               fieldDeclaration.sourceStart, 
+                               fieldDeclaration.sourceEnd); 
+               }
 //             this.visitIfNeeded(fieldDeclaration);
-//             if (isInRange){
+               if (isInRange){
 //                     requestor.exitField(
 //                             // filter out initializations that are not a constant (simple check)
 //                             (fieldDeclaration.initialization == null 
@@ -859,9 +860,14 @@ public void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclara
 //                                     fieldDeclaration.initialization.sourceStart, 
 //                             fieldEndPosition,
 //                             fieldDeclaration.declarationSourceEnd);
-//             }
-//
-//     } else {
+                       requestor.exitField(
+                                       // filter out initializations that are not a constant (simple check)
+                                       -1, 
+                                       fieldEndPosition,
+                                       fieldDeclaration.declarationSourceEnd);
+               }
+
+       } else {
 //             if (isInRange){
 //                     requestor.enterInitializer(
 //                             fieldDeclaration.declarationSourceStart,
@@ -871,8 +877,8 @@ public void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclara
 //             if (isInRange){
 //                     requestor.exitInitializer(fieldDeclaration.declarationSourceEnd);
 //             }
-//     }
-//}
+       }
+}
 //public void notifySourceElementRequestor(
 //     ImportReference importReference, 
 //     boolean isPackage) {
@@ -1018,7 +1024,7 @@ public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolea
                switch (nextDeclarationType) {
                        case 0 :
                                fieldIndex++;
-//                             notifySourceElementRequestor(nextFieldDeclaration);
+                               notifySourceElementRequestor(nextFieldDeclaration);
                                break;
                        case 1 :
                                methodIndex++;
@@ -1071,36 +1077,41 @@ public void parseCompilationUnit (
 //             diet = old;
        }
 }
-public void parseCompilationUnit(
-       ICompilationUnit unit, 
-       boolean needReferenceInfo) {
-//     boolean old = diet;
-//     if (needReferenceInfo) {
-//             unknownRefs = new NameReference[10];
-//             unknownRefsCounter = 0;
-//     }
+public CompilationUnitDeclaration parseCompilationUnit(
+               ICompilationUnit unit, 
+               boolean fullParse) {
+                       
+//             boolean old = diet;
+//             if (fullParse) {
+//                     unknownRefs = new NameReference[10];
+//                     unknownRefsCounter = 0;
+//             }
 
-       try {
-//             diet = true;
-               reportReferenceInfo = needReferenceInfo;
-               CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, 10); //this.options.maxProblemsPerUnit);
-               CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult, false);
-               if (scanner.recordLineSeparator) {
-                       requestor.acceptLineSeparatorPositions(scanner.getLineEnds());
+               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;
                }
-               int initialStart = this.scanner.initialPosition;
-               int initialEnd = this.scanner.eofPosition;
-//             if (this.localDeclarationVisitor != null || needReferenceInfo){
-//                     diet = false;
-//                     this.getMethodBodies(parsedUnit);
-//             }
-               this.scanner.resetTo(initialStart, initialEnd);
-               notifySourceElementRequestor(parsedUnit);
-       } catch (AbortCompilation e) {
-       } finally {
-//             diet = old;
+               return null;
        }
-}
+
 //public void parseTypeMemberDeclarations(
 //     ISourceType sourceType, 
 //     ICompilationUnit sourceUnit, 
@@ -1289,5 +1300,19 @@ private void visitIfNeeded(AbstractMethodDeclaration method) {
 //     if (compilationUnit == null) return;
 //     super.reportSyntaxError(act, currentKind,stateStackTop);
 //}
-
+protected CompilationUnitDeclaration endParse(int act) {
+//     if (sourceType != null) {
+//             if (sourceType.isInterface()) {
+//                     consumeInterfaceDeclaration();
+//             } else {
+//                     consumeClassDeclaration();
+//             }
+//     }
+       if (compilationUnit != null) {
+               CompilationUnitDeclaration result = super.endParse(act);
+               return result;
+       } else {
+               return null;
+       }               
+}
 }