mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Bug 373695 - Quick fix fails to create local variable
This commit is contained in:
parent
dc01366f97
commit
c40a860ba3
2 changed files with 22 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2010 Tomasz Wesolowski
|
* Copyright (c) 2010, 2012 Tomasz Wesolowski
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Tomasz Wesolowski - initial API and implementation
|
* Tomasz Wesolowski - initial API and implementation
|
||||||
|
* Marc-Andre Laperle
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
|
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
|
||||||
|
|
||||||
|
@ -74,6 +75,9 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix {
|
||||||
HashMap<ITranslationUnit, ASTRewrite> cachedRewrites = new HashMap<ITranslationUnit, ASTRewrite>();
|
HashMap<ITranslationUnit, ASTRewrite> cachedRewrites = new HashMap<ITranslationUnit, ASTRewrite>();
|
||||||
for (IIndexName iname : declarations) {
|
for (IIndexName iname : declarations) {
|
||||||
ITranslationUnit declTU = CxxAstUtils.getTranslationUnitFromIndexName(iname);
|
ITranslationUnit declTU = CxxAstUtils.getTranslationUnitFromIndexName(iname);
|
||||||
|
if (declTU == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ASTRewrite rewrite;
|
ASTRewrite rewrite;
|
||||||
IASTTranslationUnit declAST;
|
IASTTranslationUnit declAST;
|
||||||
if (!cachedASTs.containsKey(declTU)) {
|
if (!cachedASTs.containsKey(declTU)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2011 Alena Laskavaia, Tomasz Wesolowski
|
* Copyright (c) 2009, 2012 Alena Laskavaia, Tomasz Wesolowski
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
* Tomasz Wesolowski - extension
|
* Tomasz Wesolowski - extension
|
||||||
|
* Marc-Andre Laperle
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.cxx;
|
package org.eclipse.cdt.codan.core.cxx;
|
||||||
|
|
||||||
|
@ -51,13 +52,11 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
|
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful functions for doing code analysis on c/c++ AST
|
* Useful functions for doing code analysis on c/c++ AST
|
||||||
|
@ -254,6 +253,10 @@ public final class CxxAstUtils {
|
||||||
for (IIndexName decl : declSet) {
|
for (IIndexName decl : declSet) {
|
||||||
// for now, just use the first overload found
|
// for now, just use the first overload found
|
||||||
ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
|
ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
|
||||||
|
if (tu == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
IASTTranslationUnit ast = null;
|
IASTTranslationUnit ast = null;
|
||||||
if(astCache.containsKey(tu)) {
|
if(astCache.containsKey(tu)) {
|
||||||
ast = astCache.get(tu);
|
ast = astCache.get(tu);
|
||||||
|
@ -305,10 +308,11 @@ public final class CxxAstUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ITranslationUnit getTranslationUnitFromIndexName(IIndexName decl) throws CoreException {
|
public static ITranslationUnit getTranslationUnitFromIndexName(IIndexName decl) throws CoreException {
|
||||||
Path path = new Path(decl.getFile().getLocation().getFullPath());
|
IIndexFile file = decl.getFile();
|
||||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
if (file != null) {
|
||||||
ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
|
return CoreModelUtil.findTranslationUnitForLocation(file.getLocation().getURI(), null);
|
||||||
return tu;
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,6 +354,10 @@ public final class CxxAstUtils {
|
||||||
// Check the declarations and use first suitable
|
// Check the declarations and use first suitable
|
||||||
for (IIndexName decl : declarations) {
|
for (IIndexName decl : declarations) {
|
||||||
ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
|
ITranslationUnit tu = getTranslationUnitFromIndexName(decl);
|
||||||
|
if (tu == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
IASTTranslationUnit ast = null;
|
IASTTranslationUnit ast = null;
|
||||||
if(astCache.containsKey(tu)) {
|
if(astCache.containsKey(tu)) {
|
||||||
ast = astCache.get(tu);
|
ast = astCache.get(tu);
|
||||||
|
|
Loading…
Add table
Reference in a new issue