mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 477556 - Protect against NPE in ASTTranslationUnit.getAdapter
Change-Id: Ic8b101f6e298fd24277b27b3a43dab63b7c5410b
This commit is contained in:
parent
8640070d4b
commit
03e0264fc1
1 changed files with 8 additions and 9 deletions
|
@ -50,7 +50,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,16 +324,16 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
public final Object getAdapter(Class adapter) {
|
public final <T> T getAdapter(Class<T> adapter) {
|
||||||
if (adapter.isAssignableFrom(fLocationResolver.getClass())) {
|
if (adapter.isInstance(fLocationResolver)) {
|
||||||
return fLocationResolver;
|
return (T) fLocationResolver;
|
||||||
}
|
}
|
||||||
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
|
if (adapter.isInstance(fIndexFileSet)) {
|
||||||
return fIndexFileSet;
|
return (T) fIndexFileSet;
|
||||||
}
|
}
|
||||||
if (adapter.isAssignableFrom(LexerOptions.class)) {
|
if (fLocationResolver != null && adapter.isInstance(fLocationResolver.getLexerOptions())) {
|
||||||
return fLocationResolver.getLexerOptions();
|
return (T) fLocationResolver.getLexerOptions();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue