This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 226012
Collapse All | Expand All

(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/content/file/FileContent.java (-1 / +2 lines)
Lines 542-548 Link Here
542
        fileComponentInstantiations = Union2.createSecond(new WeakContainer<FileComponentInstantiations>(owner, fileInstantiationsKey));
542
        fileComponentInstantiations = Union2.createSecond(new WeakContainer<FileComponentInstantiations>(owner, fileInstantiationsKey));
543
        
543
        
544
        this.errors = createErrors(Collections.<ErrorDirectiveImpl>emptySet());
544
        this.errors = createErrors(Collections.<ErrorDirectiveImpl>emptySet());
545
        PersistentUtils.readErrorDirectives(this.errors, input);
545
        // ErrorDirectiveImpl does not have UID, so deserialize using containingFile directly
546
        PersistentUtils.readErrorDirectives(this.errors, file, input);
546
        parserErrorsCount = input.readInt();
547
        parserErrorsCount = input.readInt();
547
        
548
        
548
        this.fakeIncludeRegistrations = createFakeIncludes(Collections.<FakeIncludePair>emptyList());
549
        this.fakeIncludeRegistrations = createFakeIncludes(Collections.<FakeIncludePair>emptyList());
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/ErrorDirectiveImpl.java (-2 / +2 lines)
Lines 113-120 Link Here
113
    // serialization
113
    // serialization
114
    
114
    
115
    @SuppressWarnings("unchecked")
115
    @SuppressWarnings("unchecked")
116
    public ErrorDirectiveImpl(RepositoryDataInput input) throws IOException {
116
    public ErrorDirectiveImpl(FileImpl containingFile, RepositoryDataInput input) throws IOException {
117
        super(input);
117
        super(containingFile, input); // ErrorDirectiveImpl does not have UID, so deserialize using containingFile directly
118
        this.msg = PersistentUtils.readUTF(input, DefaultCache.getManager());
118
        this.msg = PersistentUtils.readUTF(input, DefaultCache.getManager());
119
        if (input.readBoolean()) {
119
        if (input.readBoolean()) {
120
            this.ppState = PersistentUtils.readPreprocState(input);
120
            this.ppState = PersistentUtils.readPreprocState(input);
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/OffsetableBase.java (-34 / +35 lines)
Lines 70-77 Link Here
70
 * @author Vladimir Kvashin
70
 * @author Vladimir Kvashin
71
 */
71
 */
72
public abstract class OffsetableBase implements CsmOffsetable, Disposable, CsmValidable {
72
public abstract class OffsetableBase implements CsmOffsetable, Disposable, CsmValidable {
73
    private /*final*/ CsmFile fileRef; // set in onDispose, used as marker of invalid object
73
    private final CsmFile fileRef;// we keep ref to file, because it owns disposing flag from project
74
    private final CsmUID<CsmFile> fileUID;
74
    private boolean isValid = true;
75
    
75
    
76
    private final int startPosition;
76
    private final int startPosition;
77
    private final int endPosition;
77
    private final int endPosition;
Lines 84-119 Link Here
84
84
85
    protected OffsetableBase(CsmFile file, int start, int end) {
85
    protected OffsetableBase(CsmFile file, int start, int end) {
86
        // Parameters.notNull("file can not be null", file); // NOI18N
86
        // Parameters.notNull("file can not be null", file); // NOI18N
87
        this.fileUID = UIDCsmConverter.fileToUID(file);
87
        this.fileRef = file;
88
        this.fileRef = null;// to prevent error with "final"
89
        if(end < start) {
88
        if(end < start) {
90
            if(CndUtils.isDebugMode()) {            
89
            if(CndUtils.isDebugMode()) {            
91
                CndUtils.assertTrueInConsole(false, "end < start for " + ((file != null)?file.getAbsolutePath():"null file") + ":[" + start + "-" + end + "]"); // NOI18N
90
                CndUtils.assertTrueInConsole(false, "end < start for " + ((file != null)?file.getAbsolutePath():"null file") + ":[" + start + "-" + end + "]"); // NOI18N
92
            }
91
            }
93
            end = start;
92
            end = start;
94
        }
93
        }
94
        CsmUID<CsmFile> fileUID = UIDCsmConverter.fileToUID(file);
95
        this.startPosition = PositionManager.createPositionID(fileUID, start, PositionManager.Position.Bias.FOWARD);
95
        this.startPosition = PositionManager.createPositionID(fileUID, start, PositionManager.Position.Bias.FOWARD);
96
        this.endPosition = PositionManager.createPositionID(fileUID, end, PositionManager.Position.Bias.BACKWARD);
96
        this.endPosition = PositionManager.createPositionID(fileUID, end, PositionManager.Position.Bias.BACKWARD);
97
    }
97
    }
98
98
99
    @Override
99
    @Override
100
    final public int getStartOffset() {
100
    final public int getStartOffset() {
101
        return PositionManager.getOffset(fileUID, startPosition);
101
        return PositionManager.getOffset(fileRef, startPosition);
102
    }
102
    }
103
    
103
    
104
    @Override
104
    @Override
105
    final public int getEndOffset() {
105
    final public int getEndOffset() {
106
        return endPosition != 0 ? PositionManager.getOffset(fileUID, endPosition) : PositionManager.getOffset(fileUID, startPosition);
106
        return endPosition != 0 ? PositionManager.getOffset(fileRef, endPosition) : PositionManager.getOffset(fileRef, startPosition);
107
    }
107
    }
108
108
109
    @Override
109
    @Override
110
    public final Position getStartPosition() {
110
    public final Position getStartPosition() {
111
        return PositionManager.getPosition(fileUID, startPosition);
111
        return PositionManager.getPosition(fileRef, startPosition);
112
    }
112
    }
113
    
113
    
114
    @Override
114
    @Override
115
    public final Position getEndPosition() {
115
    public final Position getEndPosition() {
116
        return PositionManager.getPosition(fileUID, endPosition);
116
        return PositionManager.getPosition(fileRef, endPosition);
117
    }
117
    }
118
    
118
    
119
    public static int getStartOffset(AST node) {
119
    public static int getStartOffset(AST node) {
Lines 155-166 Link Here
155
    
155
    
156
    @Override
156
    @Override
157
    public CsmFile getContainingFile() {
157
    public CsmFile getContainingFile() {
158
        return _getFile(true);
158
        return this.fileRef;
159
    }
159
    }
160
160
161
    @Override
161
    @Override
162
    public boolean isValid() {
162
    public boolean isValid() {
163
        return CsmBaseUtilities.isValid(_getFile(false)) && this.fileRef == null;
163
        return isValid && CsmBaseUtilities.isValid(this.fileRef);
164
    }
164
    }
165
    
165
    
166
    @Override
166
    @Override
Lines 179-216 Link Here
179
    }
179
    }
180
    
180
    
181
    private synchronized void onDispose() {
181
    private synchronized void onDispose() {
182
        if (fileRef == null) {
182
        this.isValid = false;
183
            // restore container from it's UID
183
    }    
184
            this.fileRef = UIDCsmConverter.UIDtoFile(fileUID);
185
            assert this.fileRef != null : "no object for UID " + fileUID;
186
        }
187
    }
188
    
189
    private synchronized CsmFile _getFile(boolean checkNull) {
190
        CsmFile file = this.fileRef;
191
        if (file == null) {
192
            file = UIDCsmConverter.UIDtoFile(fileUID);
193
            assert file != null || !checkNull: "no object for UID " + fileUID + " in object " + getClass() + ":" + getOffsetString();
194
        }
195
        return file;
196
    }
197
184
198
    public void write(RepositoryDataOutput output) throws IOException {
185
    public void write(RepositoryDataOutput output) throws IOException {
199
        output.writeInt(startPosition);
186
        output.writeInt(startPosition);
200
        output.writeInt(endPosition);
187
        output.writeInt(endPosition);
188
        CsmUID<CsmFile> fileUID = UIDCsmConverter.fileToUID(fileRef);
201
        // not null UID
189
        // not null UID
202
        assert this.fileUID != null;
190
        assert fileUID != null;
203
        UIDObjectFactory.getDefaultFactory().writeUID(this.fileUID, output);
191
        UIDObjectFactory.getDefaultFactory().writeUID(fileUID, output);
204
    }
192
    }
205
    
193
    
206
    protected OffsetableBase(RepositoryDataInput input) throws IOException {
194
    protected OffsetableBase(RepositoryDataInput input) throws IOException {
207
        startPosition = input.readInt();
195
        startPosition = input.readInt();
208
        endPosition = input.readInt();
196
        endPosition = input.readInt();
209
197
210
        this.fileUID = UIDObjectFactory.getDefaultFactory().readUID(input);
198
        CsmUID<CsmFile> fileUID = UIDObjectFactory.getDefaultFactory().readUID(input);
211
        // not null UID
199
        // not null UID
212
        assert this.fileUID != null;          
200
        assert fileUID != null;
213
        this.fileRef = null;
201
        this.fileRef = UIDCsmConverter.UIDtoFile(fileUID);
202
        this.isValid = (this.fileRef != null);
203
    }
204
205
    protected OffsetableBase(CsmFile containingFile, RepositoryDataInput input) throws IOException {
206
        // must be in sync with the above constructor
207
        startPosition = input.readInt();
208
        endPosition = input.readInt();
209
210
        CsmUID<CsmFile> fileUID = UIDObjectFactory.getDefaultFactory().readUID(input);
211
        // not null UID
212
        assert fileUID != null;
213
        this.fileRef = containingFile;
214
        this.isValid = (this.fileRef != null);
214
    }
215
    }
215
    
216
    
216
    // test trace method
217
    // test trace method
Lines 221-229 Link Here
221
    protected CharSequence getPositionString() {
222
    protected CharSequence getPositionString() {
222
        StringBuilder sb = new StringBuilder(); 
223
        StringBuilder sb = new StringBuilder(); 
223
        sb.append('[');
224
        sb.append('[');
224
        CsmFile containingFile = _getFile(false);
225
        CsmFile containingFile = this.fileRef;
225
        if (containingFile == null) {
226
        if (containingFile == null) {
226
            sb.append(" NO CONTAINER ").append(fileUID);// NOI18N
227
            sb.append(" NO CONTAINER ");// NOI18N
227
        } else {
228
        } else {
228
            sb.append(containingFile.getName());
229
            sb.append(containingFile.getName());
229
        }
230
        }
Lines 256-262 Link Here
256
            return false;
257
            return false;
257
        }
258
        }
258
        final OffsetableBase other = (OffsetableBase) obj;
259
        final OffsetableBase other = (OffsetableBase) obj;
259
        if (this.fileUID != other.fileUID && (this.fileUID == null || !this.fileUID.equals(other.fileUID))) {
260
        if ((this.fileRef == null || !this.fileRef.equals(other.fileRef))) {
260
            return false;
261
            return false;
261
        }
262
        }
262
        if (this.startPosition != other.startPosition) {
263
        if (this.startPosition != other.startPosition) {
Lines 271-277 Link Here
271
    @Override
272
    @Override
272
    public int hashCode() {
273
    public int hashCode() {
273
        int hash = 7;
274
        int hash = 7;
274
        hash = 47 * hash + (this.fileUID != null ? this.fileUID.hashCode() : 0);
275
        hash = 47 * hash + (this.fileRef != null ? this.fileRef.hashCode() : 0);
275
        hash = 47 * hash + this.startPosition;
276
        hash = 47 * hash + this.startPosition;
276
        hash = 47 * hash + this.endPosition;
277
        hash = 47 * hash + this.endPosition;
277
        return hash;
278
        return hash;
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/PositionManager.java (-2 / +19 lines)
Lines 71-79 Link Here
71
    }
71
    }
72
    
72
    
73
    public static CsmOffsetable.Position getPosition(CsmUID<CsmFile> uid, int posID) {
73
    public static CsmOffsetable.Position getPosition(CsmUID<CsmFile> uid, int posID) {
74
        CsmFile file = UIDCsmConverter.UIDtoFile(uid);
74
        return getPosition(UIDCsmConverter.UIDtoFile(uid), posID);
75
    }
76
77
    public static CsmOffsetable.Position getPosition(CsmFile file, int posID) {
75
        if (file instanceof FileImpl) {
78
        if (file instanceof FileImpl) {
76
            return new LazyOffsPositionImpl((FileImpl) file, getOffset(uid, posID));
79
            return new LazyOffsPositionImpl((FileImpl) file, getOffset(file, posID));
77
        } else {
80
        } else {
78
            return new PositionImpl(posID);
81
            return new PositionImpl(posID);
79
        }
82
        }
Lines 101-106 Link Here
101
//        }
104
//        }
102
    }
105
    }
103
106
107
    public static int getOffset(CsmFile file, int posID) {
108
        if (IMPL == Impl.trivial) {
109
            return posID;
110
        }
111
        throw new UnsupportedOperationException("Not yet implemented "); // NOI18N
112
    }
113
    
114
    public static int createPositionID(CsmFile file, int offset, Position.Bias bias) {
115
        if (IMPL == Impl.trivial) {
116
            return offset;
117
        }
118
        throw new UnsupportedOperationException("Not yet implemented "); // NOI18N
119
    }
120
    
104
    public static int createPositionID(CsmUID<CsmFile> uid, int offset, Position.Bias bias) {
121
    public static int createPositionID(CsmUID<CsmFile> uid, int offset, Position.Bias bias) {
105
        if (IMPL == Impl.trivial) {
122
        if (IMPL == Impl.trivial) {
106
            return offset;
123
            return offset;
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/repository/PersistentUtils.java (-2 / +4 lines)
Lines 83-88 Link Here
83
import org.netbeans.modules.cnd.modelimpl.csm.TypeBasedSpecializationParameterImpl;
83
import org.netbeans.modules.cnd.modelimpl.csm.TypeBasedSpecializationParameterImpl;
84
import org.netbeans.modules.cnd.modelimpl.csm.VariadicSpecializationParameterImpl;
84
import org.netbeans.modules.cnd.modelimpl.csm.VariadicSpecializationParameterImpl;
85
import org.netbeans.modules.cnd.modelimpl.csm.core.ErrorDirectiveImpl;
85
import org.netbeans.modules.cnd.modelimpl.csm.core.ErrorDirectiveImpl;
86
import org.netbeans.modules.cnd.modelimpl.csm.core.FileImpl;
86
import org.netbeans.modules.cnd.modelimpl.csm.deep.CompoundStatementImpl;
87
import org.netbeans.modules.cnd.modelimpl.csm.deep.CompoundStatementImpl;
87
import org.netbeans.modules.cnd.modelimpl.csm.deep.ExpandedExpressionBase;
88
import org.netbeans.modules.cnd.modelimpl.csm.deep.ExpandedExpressionBase;
88
import org.netbeans.modules.cnd.modelimpl.csm.deep.LazyTryCatchStatementImpl;
89
import org.netbeans.modules.cnd.modelimpl.csm.deep.LazyTryCatchStatementImpl;
Lines 116-125 Link Here
116
        //PersistentUtils.writeUTF(rootUrl, output);        
117
        //PersistentUtils.writeUTF(rootUrl, output);        
117
    }
118
    }
118
119
119
    public static void readErrorDirectives(Set<ErrorDirectiveImpl> errors, RepositoryDataInput input) throws IOException {
120
    public static void readErrorDirectives(Set<ErrorDirectiveImpl> errors, FileImpl containingFile, RepositoryDataInput input) throws IOException {
120
        int size = input.readInt();
121
        int size = input.readInt();
121
        for (int i = 0; i < size; i++) {
122
        for (int i = 0; i < size; i++) {
122
            ErrorDirectiveImpl offs = new ErrorDirectiveImpl(input);
123
            // ErrorDirectiveImpl does not have UID, so deserialize using containingFile directly
124
            ErrorDirectiveImpl offs = new ErrorDirectiveImpl(containingFile, input);
123
            errors.add(offs);
125
            errors.add(offs);
124
        }
126
        }
125
    }
127
    }

Return to bug 226012