1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 513428 - Ensure PDOM implementations of IASTFileLocation.getFileName() do not return null

Change-Id: I1adb158bd8efc23300bf5c212d6ed4f532a19205
This commit is contained in:
Nathan Ridge 2017-04-27 01:54:34 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 917061f98a
commit a44996a200
6 changed files with 84 additions and 89 deletions

View file

@ -18,7 +18,7 @@ package org.eclipse.cdt.core.dom.ast;
*/
public interface IASTFileLocation extends IASTNodeLocation {
/**
* The name of the file.
* The name of the file. Should not be null.
*
* @return the name of the file
*/

View file

@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2017 Nathan Ridge.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
/**
* Implementation of IASTFileLocation for use by PDOM types.
* This implementation just stores the fields which need to be computed by the caller
* at constructor time.
*/
public class PDOMASTFileLocation implements IASTFileLocation {
private String fFilename;
private int fNodeOffset;
private int fNodeLength;
public PDOMASTFileLocation(String filename, int nodeOffset, int nodeLength) {
fFilename = filename;
fNodeOffset = nodeOffset;
fNodeLength = nodeLength;
}
@Override
public IASTFileLocation asFileLocation() {
return this;
}
@Override
public String getFileName() {
return fFilename;
}
@Override
public int getNodeOffset() {
return fNodeOffset;
}
@Override
public int getNodeLength() {
return fNodeLength;
}
@Override
public int getStartingLineNumber() {
return 0;
}
@Override
public int getEndingLineNumber() {
return 0;
}
@Override
public IASTPreprocessorIncludeStatement getContextInclusionStatement() {
return null;
}
}

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
@ -46,7 +45,7 @@ import org.eclipse.core.runtime.IPath;
* Represents macro definitions. They are stored with the file and with a PDOMMacroContainer.
* The latter also contains the references to all macros with the same name.
*/
public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation {
public class PDOMMacro implements IIndexMacro, IPDOMBinding {
private static final int CONTAINER = 0;
private static final int FILE = 4;
private static final int PARAMETERS= 8;
@ -288,7 +287,7 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation {
}
@Override
public String getFileName() {
public IASTFileLocation getFileLocation() {
try {
IIndexFile file = getFile();
if (file == null) {
@ -298,39 +297,17 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation {
// how to implement this. Existing implementations return
// the absolute path, so here we attempt to do the same.
IPath location = IndexLocationFactory.getAbsolutePath(file.getLocation());
return location != null ? location.toOSString() : null;
if (location == null) {
return null;
}
String filename = location.toOSString();
return new PDOMASTFileLocation(filename, getNodeOffset(), getNodeLength());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
@Override
public int getStartingLineNumber() {
return 0;
}
@Override
public int getEndingLineNumber() {
return 0;
}
@Override
public IASTPreprocessorIncludeStatement getContextInclusionStatement() {
return null;
}
@Override
public IASTFileLocation asFileLocation() {
return this;
}
@Override
public IASTFileLocation getFileLocation() {
return this;
}
@Override
public int getNodeLength() {
try {
return fLinkage.getDB().getShort(fRecord + NAME_LENGTH);
@ -340,7 +317,6 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation {
}
}
@Override
public int getNodeOffset() {
try {
return fLinkage.getDB().getInt(fRecord + NAME_OFFSET);

View file

@ -75,7 +75,7 @@ class PDOMMacroDefinitionName implements IIndexFragmentName {
@Override
public IASTFileLocation getFileLocation() {
return fMacro;
return fMacro.getFileLocation();
}
@Override

View file

@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
@ -31,7 +30,7 @@ import org.eclipse.core.runtime.IPath;
/**
* Represents declarations, definitions and references to bindings, except for macros.
*/
public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFileLocation {
public final class PDOMMacroReferenceName implements IIndexFragmentName {
private final PDOMLinkage linkage;
private final long record;
@ -206,11 +205,6 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil
@Override
public IASTFileLocation getFileLocation() {
return this;
}
@Override
public String getFileName() {
try {
IIndexFile file = getFile();
if (file == null) {
@ -220,33 +214,17 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil
// how to implement this. Existing implementations return
// the absolute path, so here we attempt to do the same.
IPath location = IndexLocationFactory.getAbsolutePath(file.getLocation());
return location != null ? location.toOSString() : null;
if (location == null) {
return null;
}
String filename = location.toOSString();
return new PDOMASTFileLocation(filename, getNodeOffset(), getNodeLength());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
@Override
public int getStartingLineNumber() {
return 0;
}
@Override
public int getEndingLineNumber() {
return 0;
}
@Override
public IASTPreprocessorIncludeStatement getContextInclusionStatement() {
return null;
}
@Override
public IASTFileLocation asFileLocation() {
return this;
}
@Override
public int getNodeLength() {
try {

View file

@ -17,7 +17,6 @@ import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
@ -30,7 +29,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
public final class PDOMName implements IIndexFragmentName {
private final PDOMLinkage linkage;
private final long record;
@ -332,11 +331,6 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
@Override
public IASTFileLocation getFileLocation() {
return this;
}
@Override
public String getFileName() {
try {
IIndexFile file = getFile();
if (file == null) {
@ -346,33 +340,17 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
// how to implement this. Existing implementations return
// the absolute path, so here we attempt to do the same.
IPath location = IndexLocationFactory.getAbsolutePath(file.getLocation());
return location != null ? location.toOSString() : null;
if (location == null) {
return null;
}
String filename = location.toOSString();
return new PDOMASTFileLocation(filename, getNodeOffset(), getNodeLength());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
@Override
public int getStartingLineNumber() {
return 0;
}
@Override
public int getEndingLineNumber() {
return 0;
}
@Override
public IASTPreprocessorIncludeStatement getContextInclusionStatement() {
return null;
}
@Override
public IASTFileLocation asFileLocation() {
return this;
}
@Override
public int getNodeLength() {
try {