mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Reworked refactoring: moved rename refactoring into ui-plugin (bug 220741), applied patch for extract constant (bug 181493).
This commit is contained in:
parent
8c518b15d3
commit
73869d3e94
132 changed files with 18106 additions and 415 deletions
|
@ -19,13 +19,13 @@ import org.eclipse.cdt.core.index.IIndexManager;
|
|||
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
|
||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.CTextFileChange;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
|
||||
public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
||||
|
||||
|
@ -63,8 +63,8 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
|||
changegenartor.generateChange(unit);
|
||||
Document doc = new Document(source);
|
||||
for(Change curChange : ((CompositeChange)changegenartor.getChange()).getChildren()){
|
||||
if (curChange instanceof CTextFileChange) {
|
||||
CTextFileChange textChange = (CTextFileChange) curChange;
|
||||
if (curChange instanceof TextFileChange) {
|
||||
TextFileChange textChange = (TextFileChange) curChange;
|
||||
textChange.getEdit().apply(doc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests",
|
||||
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests,org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.astwriter;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
|
||||
|
@ -54,7 +54,7 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.index.provider;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
|
||||
|
@ -72,7 +72,7 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.internal.errorparsers;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter.align;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter.scanner;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter.scanner;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.utils,
|
||||
org.eclipse.cdt.utils.cdtvariables,
|
||||
org.eclipse.cdt.utils.coff,
|
||||
|
|
|
@ -12,13 +12,27 @@ package org.eclipse.cdt.internal.core.dom.rewrite;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
|
||||
public class ASTRewriteAnalyzer {
|
||||
private static ICTextFileChangeFactory sFileChangeFactory;
|
||||
|
||||
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore) {
|
||||
ChangeGenerator rewriter = new ChangeGenerator(modificationStore);
|
||||
rewriter.generateChange(root);
|
||||
return rewriter.getChange();
|
||||
}
|
||||
|
||||
public static void setCTextFileChangeFactory(ICTextFileChangeFactory factory) {
|
||||
sFileChangeFactory= factory;
|
||||
}
|
||||
|
||||
public static TextFileChange createCTextFileChange(IFile file) {
|
||||
if (sFileChangeFactory == null) {
|
||||
return new TextFileChange(file.getName(), file);
|
||||
}
|
||||
return sFileChangeFactory.createCTextFileChange(file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
|
||||
/**
|
||||
* Factory to create CTextFileChanges. Allows for creating ui-dependent objects in the core plugin.
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface ICTextFileChangeFactory {
|
||||
|
||||
/**
|
||||
* Creates a text file change for the given file.
|
||||
*/
|
||||
TextFileChange createCTextFileChange(IFile file);
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.ChangeDescriptor;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup;
|
||||
import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
import org.eclipse.text.edits.MalformedTreeException;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class CTextFileChange extends Change {
|
||||
|
||||
private TextFileChange change;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param file
|
||||
*/
|
||||
public CTextFileChange(String name, IFile file) {
|
||||
change = new TextFileChange(name, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModifiedElement() {
|
||||
return change.getModifiedElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return change.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeValidationData(IProgressMonitor pm) {
|
||||
change.initializeValidationData(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change perform(IProgressMonitor pm) throws CoreException {
|
||||
return change.perform(pm);
|
||||
}
|
||||
|
||||
public void setEdit(TextEdit edit) {
|
||||
change.setEdit(edit);
|
||||
}
|
||||
|
||||
public TextEdit getEdit() {
|
||||
return change.getEdit();
|
||||
}
|
||||
|
||||
public void addTextEditGroup(TextEditBasedChangeGroup group) {
|
||||
change.addChangeGroup(group);
|
||||
}
|
||||
|
||||
public String getCurrentContent(IProgressMonitor pm) throws CoreException{
|
||||
return change.getCurrentContent(pm);
|
||||
}
|
||||
|
||||
public String getPreviewContent(IProgressMonitor pm) throws CoreException{
|
||||
return change.getPreviewContent(pm);
|
||||
}
|
||||
public String getTextType() {
|
||||
return change.getTextType();
|
||||
}
|
||||
|
||||
public IFile getFile() {
|
||||
return change.getFile();
|
||||
}
|
||||
|
||||
public void addChangeGroup(TextEditBasedChangeGroup group) {
|
||||
change.addChangeGroup(group);
|
||||
}
|
||||
|
||||
public void addEdit(TextEdit edit) throws MalformedTreeException {
|
||||
change.addEdit(edit);
|
||||
}
|
||||
|
||||
public void addTextEditChangeGroup(TextEditChangeGroup group) {
|
||||
change.addTextEditChangeGroup(group);
|
||||
}
|
||||
|
||||
public void addTextEditGroup(TextEditGroup group) {
|
||||
change.addTextEditGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
change.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return change.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class adapter) {
|
||||
return change.getAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getAffectedObjects() {
|
||||
return change.getAffectedObjects();
|
||||
}
|
||||
|
||||
public String getCurrentContent(IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
|
||||
return change.getCurrentContent(region, expandRegionToFullLine, surroundingLines, pm);
|
||||
}
|
||||
|
||||
public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
|
||||
return change.getCurrentDocument(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeDescriptor getDescriptor() {
|
||||
return change.getDescriptor();
|
||||
}
|
||||
|
||||
public boolean getKeepPreviewEdits() {
|
||||
return change.getKeepPreviewEdits();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change getParent() {
|
||||
return change.getParent();
|
||||
}
|
||||
|
||||
public String getPreviewContent(TextEditBasedChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
|
||||
return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
|
||||
}
|
||||
|
||||
public String getPreviewContent(TextEditChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
|
||||
return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
|
||||
}
|
||||
|
||||
public IDocument getPreviewDocument(IProgressMonitor pm) throws CoreException {
|
||||
return change.getPreviewDocument(pm);
|
||||
}
|
||||
|
||||
public TextEdit getPreviewEdit(TextEdit original) {
|
||||
return change.getPreviewEdit(original);
|
||||
}
|
||||
|
||||
public TextEdit[] getPreviewEdits(TextEdit[] originals) {
|
||||
return change.getPreviewEdits(originals);
|
||||
}
|
||||
|
||||
public int getSaveMode() {
|
||||
return change.getSaveMode();
|
||||
}
|
||||
|
||||
public TextEditChangeGroup[] getTextEditChangeGroups() {
|
||||
return change.getTextEditChangeGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return change.hashCode();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean hasOneGroupCategory(List groupCategories) {
|
||||
return change.hasOneGroupCategory(groupCategories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return change.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
|
||||
return change.isValid(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
change.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setKeepPreviewEdits(boolean keep) {
|
||||
change.setKeepPreviewEdits(keep);
|
||||
}
|
||||
|
||||
public void setSaveMode(int saveMode) {
|
||||
change.setSaveMode(saveMode);
|
||||
}
|
||||
|
||||
public void setTextType(String type) {
|
||||
change.setTextType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return change.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
|||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
|
||||
|
@ -40,6 +41,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
import org.eclipse.text.edits.DeleteEdit;
|
||||
import org.eclipse.text.edits.InsertEdit;
|
||||
import org.eclipse.text.edits.MultiTextEdit;
|
||||
|
@ -98,8 +100,7 @@ public class ChangeGenerator extends CPPASTVisitor {
|
|||
rootNode.accept(pathProvider);
|
||||
for (IFile currentFile : changes.keySet()) {
|
||||
|
||||
CTextFileChange subchange = new CTextFileChange(currentFile
|
||||
.getName(), currentFile);
|
||||
TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile);
|
||||
subchange.setEdit(changes.get(currentFile));
|
||||
change.add(subchange);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="ui"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#Fri Feb 15 10:15:35 CET 2008
|
||||
#Wed Feb 27 13:20:15 CET 2008
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.4
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
|
@ -16,7 +16,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
|||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
|
@ -79,7 +79,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
|
|||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.4
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
|
@ -151,7 +151,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
|||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
|
||||
|
|
|
@ -10,6 +10,7 @@ Export-Package: org.eclipse.cdt.ui.testplugin,
|
|||
org.eclipse.cdt.ui.tests,
|
||||
org.eclipse.cdt.ui.tests.DOMAST,
|
||||
org.eclipse.cdt.ui.tests.chelp,
|
||||
org.eclipse.cdt.ui.tests.refactoring.rename,
|
||||
org.eclipse.cdt.ui.tests.text,
|
||||
org.eclipse.cdt.ui.tests.text.contentassist,
|
||||
org.eclipse.cdt.ui.tests.text.selection
|
||||
|
@ -33,7 +34,7 @@ Require-Bundle: org.eclipse.jface.text,
|
|||
org.eclipse.core.expressions,
|
||||
org.eclipse.cdt.make.core,
|
||||
com.ibm.icu,
|
||||
org.eclipse.cdt.refactoring.tests
|
||||
org.eclipse.ltk.core.refactoring;bundle-version="3.4.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Vendor: Eclipse.org
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
|
|
|
@ -198,4 +198,21 @@
|
|||
</owner>
|
||||
</extension>
|
||||
|
||||
<extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
|
||||
<renameParticipant
|
||||
class="org.eclipse.cdt.ui.tests.refactoring.rename.TestRenameParticipant"
|
||||
name="TestRenameParticipant"
|
||||
id="org.eclipse.cdt.ui.tests.TestRenameParticipant">
|
||||
<enablement>
|
||||
<with variable="affectedNatures">
|
||||
<iterate operator="or">
|
||||
<equals value="org.eclipse.cdt.core.cnature"/>
|
||||
</iterate>
|
||||
</with>
|
||||
<with variable="element">
|
||||
<instanceof value="org.eclipse.cdt.core.dom.ast.IBinding"/>
|
||||
</with>
|
||||
</enablement>
|
||||
</renameParticipant>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,370 @@
|
|||
//!ExtractConstantInt
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
void bar();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
void bar();
|
||||
static const int theAnswer = 42;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return //$42$//;
|
||||
}
|
||||
|
||||
void A::bar()
|
||||
{
|
||||
int a = 42;
|
||||
int b = 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
||||
void A::bar()
|
||||
{
|
||||
int a = theAnswer;
|
||||
int b = theAnswer;
|
||||
}
|
||||
|
||||
//!ExtractConstantFloat
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
float foo();
|
||||
void bar();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
float foo();
|
||||
void bar();
|
||||
static const float theAnswer = 42.0;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
float A::foo()
|
||||
{
|
||||
return //$42.0$//;
|
||||
}
|
||||
|
||||
void A::bar()
|
||||
{
|
||||
float a = 42.0;
|
||||
float b = 42.0;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
float A::foo()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
||||
void A::bar()
|
||||
{
|
||||
float a = theAnswer;
|
||||
float b = theAnswer;
|
||||
}
|
||||
|
||||
//!ExtractConstantStaticInt
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
static const int a = 42;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
static const int a = 42;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
int bar()
|
||||
{
|
||||
return //$42$//;
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const int theAnswer = 42;
|
||||
}
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
||||
int bar()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
||||
|
||||
//!replaceNumberProtected
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
|
||||
//@.config
|
||||
visibility=protected
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
protected:
|
||||
static const int theAnswer = 42;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return //$42$//;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
||||
//!replaceNumberPrivate
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
|
||||
//@.config
|
||||
visibility=private
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
private:
|
||||
static const int theAnswer = 42;
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return //$42$//;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
return theAnswer;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//!before the class
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.utils.TranslationUnitHelperTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
offset_unix=27
|
||||
offset_win=30
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
void foo();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
|
||||
//!before a typedef
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.utils.TranslationUnitHelperTest
|
||||
//@.config
|
||||
filename=A.h
|
||||
offset_unix=0
|
||||
offset_win=0
|
||||
//@A.h
|
||||
typedef int nummere;
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
};
|
||||
|
|
@ -15,10 +15,10 @@ package org.eclipse.cdt.ui.tests;
|
|||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.refactoring.tests.RenameRegressionTests;
|
||||
import org.eclipse.cdt.ui.tests.buildconsole.BuildConsoleTests;
|
||||
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.search.SearchTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.text.TextTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.text.contentassist.ContentAssistTestSuite;
|
||||
|
@ -36,14 +36,14 @@ public class AutomatedSuite extends TestSuite {
|
|||
* Returns the suite. This is required to
|
||||
* use the JUnit Launcher.
|
||||
*/
|
||||
public static Test suite() {
|
||||
public static Test suite() throws Exception {
|
||||
return new AutomatedSuite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the test suite.
|
||||
*/
|
||||
public AutomatedSuite() {
|
||||
public AutomatedSuite() throws Exception {
|
||||
|
||||
// tests from package org.eclipse.cdt.ui.tests.text
|
||||
addTest(TextTestSuite.suite());
|
||||
|
@ -65,9 +65,6 @@ public class AutomatedSuite extends TestSuite {
|
|||
|
||||
// tests from package org.eclipse.cdt.ui.tests.text.contentAssist2
|
||||
addTest(ContentAssist2TestSuite.suite());
|
||||
|
||||
// tests from the refactoring plugin
|
||||
addTest(RenameRegressionTests.suite());
|
||||
|
||||
// tests from package org.eclipse.cdt.ui.tests.text.selection
|
||||
addTest(SelectionTestSuite.suite());
|
||||
|
@ -77,6 +74,9 @@ public class AutomatedSuite extends TestSuite {
|
|||
|
||||
// tests from package org.eclipse.cdt.ui.tests.search
|
||||
addTest(SearchTestSuite.suite());
|
||||
|
||||
// tests from package org.eclipse.cdt.ui.tests.refactoring
|
||||
addTest(RefactoringTestSuite.suite());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Messages {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.tests.refactoring.messages"; //$NON-NLS-1$
|
||||
|
||||
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return RESOURCE_BUNDLE.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.ILogListener;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public abstract class RefactoringBaseTest extends BaseTestFramework implements ILogListener{
|
||||
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
|
||||
|
||||
protected TreeMap<String, TestSourceFile> fileMap = new TreeMap<String, TestSourceFile>();
|
||||
protected String fileWithSelection;
|
||||
protected TextSelection selection;
|
||||
|
||||
protected RefactoringBaseTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public RefactoringBaseTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name);
|
||||
for (TestSourceFile file : files) {
|
||||
fileMap.put(file.getName(), file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract void runTest() throws Throwable;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
for (TestSourceFile testFile : fileMap.values()) {
|
||||
if(testFile.getSource().length() > 0) {
|
||||
importFile(testFile.getName(), testFile.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
|
||||
StringBuffer code = getCodeFromIFile(file2);
|
||||
assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
|
||||
protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
|
||||
for (String fileName : testResourceFiles.keySet()) {
|
||||
TestSourceFile file = testResourceFiles.get(fileName);
|
||||
IFile iFile = project.getFile(new Path(fileName));
|
||||
StringBuffer code = getCodeFromIFile(iFile);
|
||||
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
StringBuffer code = new StringBuffer();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
code.append(line);
|
||||
code.append('\n');
|
||||
}
|
||||
br.close();
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
System.gc();
|
||||
fileManager.closeAllFiles();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void logging(IStatus status, String plugin) {
|
||||
Throwable ex = status.getException();
|
||||
StringBuffer stackTrace = new StringBuffer();
|
||||
if(ex != null) {
|
||||
stackTrace.append('\n');
|
||||
for(StackTraceElement ste : ex.getStackTrace()) {
|
||||
stackTrace.append(ste.toString());
|
||||
}
|
||||
}
|
||||
fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setFileWithSelection(String fileWithSelection) {
|
||||
this.fileWithSelection = fileWithSelection;
|
||||
}
|
||||
|
||||
public void setSelection(TextSelection selection) {
|
||||
this.selection = selection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public abstract class RefactoringTest extends RefactoringBaseTest {
|
||||
|
||||
private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$
|
||||
|
||||
protected String fileName;
|
||||
|
||||
public RefactoringTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
initializeConfiguration(files);
|
||||
for (TestSourceFile file : files) {
|
||||
fileMap.put(file.getName(), file);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void configureRefactoring(Properties refactoringProperties);
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
|
||||
CTestPlugin.getDefault().getLog().addLogListener(this);
|
||||
CCorePlugin.getIndexManager().reindex(cproject);
|
||||
boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR);
|
||||
assertTrue(joined);
|
||||
}
|
||||
|
||||
private void initializeConfiguration(Vector<TestSourceFile> files) {
|
||||
TestSourceFile configFile = null;
|
||||
|
||||
for (TestSourceFile currentFile : files) {
|
||||
if (currentFile.getName().equals(CONFIG_FILE_NAME)) {
|
||||
configFile = currentFile;
|
||||
}
|
||||
}
|
||||
|
||||
Properties refactoringProperties = new Properties();
|
||||
|
||||
try {
|
||||
if(configFile != null) {
|
||||
refactoringProperties.load(new ByteArrayInputStream(configFile.getSource().getBytes()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Property initialization failed
|
||||
}
|
||||
|
||||
initCommonFields(refactoringProperties);
|
||||
configureRefactoring(refactoringProperties);
|
||||
files.remove(configFile);
|
||||
|
||||
}
|
||||
|
||||
private void initCommonFields(Properties refactoringProperties) {
|
||||
fileName = refactoringProperties.getProperty("filename", "A.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
protected void assertConditionsOk(RefactoringStatus conditions) {
|
||||
assertTrue(conditions.isOK() ? "OK" : "Error or Warning in initial Conditions: " + conditions.getEntries()[0].getMessage() //$NON-NLS-1$ //$NON-NLS-2$
|
||||
, conditions.isOK());
|
||||
}
|
||||
|
||||
protected void assertConditionsWarning(RefactoringStatus conditions, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Warning in Condition expected", conditions.hasWarning()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = conditions.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isWarning()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals(number + " Warnings expected found " + count, count, number); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void assertConditionsInfo(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Info in Condition expected", status.hasInfo()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isInfo()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals(number + " Infos expected found " + count, number, count); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void assertConditionsError(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Error in Condition expected", status.hasError()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isError()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals(number + " Errors expected found " + count, number, count); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void assertConditionsFatalError(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Fatal Error in Condition expected", status.hasFatalError()); //$NON-NLS-1$
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isFatalError()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals(number + " Fatal Errors expected found " + count, number, count); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void assertConditionsFatalError(RefactoringStatus conditions) {
|
||||
assertTrue("Fatal Error in Condition expected", conditions.hasFatalError()); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class RefactoringTestSuite extends TestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new RefactoringTestSuite();
|
||||
suite.addTest(RenameRegressionTests.suite());
|
||||
suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTests", "resources/refactoring/ExtractConstant.rts"));
|
||||
suite.addTest(UtilTestSuite.suite());
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class RefactoringTester extends TestSuite{
|
||||
|
||||
enum MatcherState{skip, inTest, inSource, inExpectedResult}
|
||||
|
||||
private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
|
||||
|
||||
public static Test suite(String name, String file)throws Exception {
|
||||
BufferedReader in = createReader(file);
|
||||
|
||||
ArrayList<RefactoringBaseTest> testCases = createTests(in);
|
||||
in.close();
|
||||
return createSuite(testCases, name);
|
||||
}
|
||||
|
||||
protected static BufferedReader createReader(String file) throws IOException {
|
||||
Bundle bundle = CTestPlugin.getDefault().getBundle();
|
||||
Path path = new Path(file);
|
||||
String file2 = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
|
||||
return new BufferedReader(new FileReader(file2));
|
||||
}
|
||||
|
||||
private static ArrayList<RefactoringBaseTest> createTests(BufferedReader inputReader) throws Exception {
|
||||
|
||||
String line;
|
||||
Vector<TestSourceFile> files = new Vector<TestSourceFile>();
|
||||
TestSourceFile actFile = null;
|
||||
MatcherState matcherState = MatcherState.skip;
|
||||
ArrayList<RefactoringBaseTest> testCases = new ArrayList<RefactoringBaseTest>();
|
||||
String testName = null;
|
||||
String className = null;
|
||||
boolean bevorFirstTest = true;
|
||||
|
||||
while ((line = inputReader.readLine()) != null){
|
||||
|
||||
if(lineMatchesBeginOfTest(line)) {
|
||||
if(!bevorFirstTest) {
|
||||
RefactoringBaseTest test = createTestClass(className, testName, files);
|
||||
testCases.add(test);
|
||||
files = new Vector<TestSourceFile>();
|
||||
className = null;
|
||||
testName = null;
|
||||
}
|
||||
matcherState = MatcherState.inTest;
|
||||
testName = getNameOfTest(line);
|
||||
bevorFirstTest = false;
|
||||
continue;
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
matcherState = MatcherState.inExpectedResult;
|
||||
continue;
|
||||
}else if (lineMatchesFileName(line)) {
|
||||
matcherState = MatcherState.inSource;
|
||||
actFile = new TestSourceFile(getFileName(line));
|
||||
files.add(actFile);
|
||||
continue;
|
||||
}else if(lineMatchesClassName(line)) {
|
||||
className = getNameOfClass(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(matcherState) {
|
||||
case inSource:
|
||||
if(actFile != null) {
|
||||
actFile.addLineToSource(line);
|
||||
}
|
||||
break;
|
||||
case inExpectedResult:
|
||||
if(actFile != null) {
|
||||
actFile.addLineToExpectedSource(line);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefactoringBaseTest test = createTestClass(className, testName, files);
|
||||
testCases.add(test);
|
||||
return testCases;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static RefactoringBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
|
||||
|
||||
|
||||
try {
|
||||
Class<?> refClass = Class.forName(className);
|
||||
Class<?> paratypes[] = new Class[2];
|
||||
paratypes[0] = testName.getClass();
|
||||
paratypes[1] = files.getClass();
|
||||
Constructor<?> ct = refClass.getConstructor(paratypes);
|
||||
Object arglist[] = new Object[2];
|
||||
arglist[0] = testName;
|
||||
arglist[1] = files;
|
||||
RefactoringBaseTest test = (RefactoringBaseTest) ct.newInstance(arglist);
|
||||
for (TestSourceFile file : files) {
|
||||
TextSelection sel = file.getSelection();
|
||||
if(sel != null) {
|
||||
test.setFileWithSelection(file.getName());
|
||||
test.setSelection(sel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return test;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.UnknownTestClass")); //$NON-NLS-1$
|
||||
} catch (SecurityException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.SecurityException"), e); //$NON-NLS-1$
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.ConstructorError")); //$NON-NLS-1$
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.IllegalArgument"), e); //$NON-NLS-1$
|
||||
} catch (InstantiationException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.InstantiationException"), e); //$NON-NLS-1$
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.IllegalAccessException"), e); //$NON-NLS-1$
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new Exception(Messages.getString("RefactoringTester.InvocationTargetException"), e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFileName(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getNameOfClass(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfTest(String line) {
|
||||
return createMatcherFromString(testRegexp, line).find();
|
||||
}
|
||||
|
||||
private static boolean lineMatchesClassName(String line) {
|
||||
return createMatcherFromString(classRegexp, line).find();
|
||||
}
|
||||
|
||||
private static boolean lineMatchesFileName(String line) {
|
||||
return createMatcherFromString(fileRegexp, line).find();
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
}
|
||||
|
||||
private static String getNameOfTest(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return Messages.getString("RefactoringTester.NotNamed"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfResult(String line) {
|
||||
return createMatcherFromString(resultRegexp, line).find();
|
||||
}
|
||||
|
||||
private static TestSuite createSuite(ArrayList<RefactoringBaseTest> testCases, String name) {
|
||||
TestSuite suite = new TestSuite(name);
|
||||
Iterator<RefactoringBaseTest> it = testCases.iterator();
|
||||
while(it.hasNext()) {
|
||||
RefactoringBaseTest subject =it.next();
|
||||
suite.addTest(subject);
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
public class TestHelper {
|
||||
|
||||
public static String unifyNewLines(String code) {
|
||||
String replacement = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
return code.replaceAll("(\n)|(\r\n)", replacement); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class TestSourceFile {
|
||||
|
||||
private static final String REPLACEMENT = ""; //$NON-NLS-1$
|
||||
private String name;
|
||||
private StringBuffer source = new StringBuffer();
|
||||
private StringBuffer expectedSource = new StringBuffer();
|
||||
private String separator = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
private int selectionStart = -1;
|
||||
private int selectionEnd = -1;
|
||||
|
||||
protected static final String selectionStartRegex = "//\\$"; //$NON-NLS-1$
|
||||
protected static final String selectionEndRegex = "\\$//"; //$NON-NLS-1$
|
||||
protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
public TestSourceFile(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
public String getExpectedSource() {
|
||||
String exp = expectedSource.toString();
|
||||
if(exp.length() == 0) {
|
||||
return getSource();
|
||||
}else {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getSource() {
|
||||
return source.toString();
|
||||
}
|
||||
|
||||
public void addLineToSource(String code) {
|
||||
Matcher start = createMatcherFromString(selectionStartLineRegex, code);
|
||||
if(start.matches()) {
|
||||
selectionStart = start.start(2) + source.length();
|
||||
code = code.replaceAll(selectionStartRegex, REPLACEMENT);
|
||||
}
|
||||
Matcher end = createMatcherFromString(selectionEndLineRegex, code);
|
||||
if(end.matches()) {
|
||||
selectionEnd = end.start(2) + source.length();
|
||||
code = code.replaceAll(selectionEndRegex, REPLACEMENT);
|
||||
}
|
||||
source.append(code);
|
||||
source.append(separator);
|
||||
}
|
||||
|
||||
public void addLineToExpectedSource(String code) {
|
||||
expectedSource.append(code);
|
||||
expectedSource.append(separator);
|
||||
}
|
||||
|
||||
public TextSelection getSelection() {
|
||||
if(selectionStart < 0 || selectionEnd <0 ) {
|
||||
return null;
|
||||
}else {
|
||||
return new TextSelection(selectionStart, selectionEnd -selectionStart);
|
||||
}
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.extractconstant;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*/
|
||||
public class ExtractConstantRefactoringTest extends RefactoringTest {
|
||||
|
||||
|
||||
protected VisibilityEnum visibility;
|
||||
|
||||
public ExtractConstantRefactoringTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
IFile refFile = project.getFile(fileName);
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
ExtractConstantRefactoring refactoring = new ExtractConstantRefactoring( refFile, selection, info, true);
|
||||
RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||
assertConditionsOk(checkInitialConditions);
|
||||
info.setName("theAnswer"); //$NON-NLS-1$
|
||||
info.setVisibility(visibility);
|
||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||
assertConditionsOk(finalConditions);
|
||||
createChange.perform(NULL_PROGRESS_MONITOR);
|
||||
|
||||
compareFiles(fileMap);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureRefactoring(Properties refactoringProperties) {
|
||||
visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_public.toString())); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
RefactoringTester.UnknownTestClass=Unknown TestClass. Make sure the test's sourcefile specifies a valid test class.
|
||||
RefactoringTester.SecurityException=Security Exception during Test creation
|
||||
RefactoringTester.ConstructorError=Test class does not provied required constructor.
|
||||
RefactoringTester.IllegalArgument=IllegalArgumentException during Test creation
|
||||
RefactoringTester.InstantiationException=InstantiationException during Test creation
|
||||
RefactoringTester.IllegalAccessException=IllegalAccessException during Test creation
|
||||
RefactoringTester.InvocationTargetException=InvocationTargetException during Test creation
|
||||
RefactoringTester.NotNamed=Not Named
|
|
@ -0,0 +1,268 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
|
||||
import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
import org.eclipse.search.internal.core.text.FileCharSequenceProvider;
|
||||
import org.eclipse.text.edits.MultiTextEdit;
|
||||
import org.eclipse.text.edits.ReplaceEdit;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
|
||||
/**
|
||||
* @author markus.schorn@windriver.com
|
||||
*/
|
||||
public class RefactoringTests extends BaseTestFramework {
|
||||
private int fBufferSize;
|
||||
|
||||
public RefactoringTests() {
|
||||
}
|
||||
|
||||
public RefactoringTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fBufferSize= FileCharSequenceProvider.BUFFER_SIZE;
|
||||
FileCharSequenceProvider.BUFFER_SIZE= 1024*4;
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
||||
FileCharSequenceProvider.BUFFER_SIZE= fBufferSize;
|
||||
}
|
||||
|
||||
protected void assertTotalChanges(int numChanges, Change changes) throws Exception {
|
||||
assertTotalChanges(numChanges, 0, 0, changes);
|
||||
}
|
||||
|
||||
protected void assertTotalChanges(int numChanges, int potChanges, int commentCh,
|
||||
Change changes) throws Exception {
|
||||
int count[]= {0,0,0};
|
||||
if( changes != null ) {
|
||||
countChanges( changes, count);
|
||||
}
|
||||
assertEquals( numChanges, count[0] );
|
||||
assertEquals("potential changes: ", potChanges, count[1]); //$NON-NLS-1$
|
||||
assertEquals("comment changes: ", commentCh, count[2]); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void countChanges(Change change, int[] count) {
|
||||
if( change instanceof CompositeChange ){
|
||||
Change [] children = ((CompositeChange) change).getChildren();
|
||||
for( int i = 0; i < children.length; i++ ){
|
||||
countChanges( children[i], count);
|
||||
}
|
||||
} else if( change instanceof TextFileChange ){
|
||||
TextFileChange tfc= (TextFileChange) change;
|
||||
TextEditChangeGroup[] tecgs= tfc.getTextEditChangeGroups();
|
||||
for (int i = 0; i < tecgs.length; i++) {
|
||||
TextEditChangeGroup group = tecgs[i];
|
||||
countChanges(group, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void countChanges(TextEditChangeGroup edit, int[] count) {
|
||||
String name= edit.getName();
|
||||
if (name.indexOf("potential") != -1) { //$NON-NLS-1$
|
||||
count[1]++;
|
||||
}
|
||||
else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
|
||||
count[2]++;
|
||||
}
|
||||
else {
|
||||
count[0]++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText) throws Exception {
|
||||
assertChange(changes, file, startOffset, numChars, newText, false);
|
||||
}
|
||||
|
||||
protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText, boolean potential) throws Exception {
|
||||
boolean found = false;
|
||||
if( changes != null && changes instanceof CompositeChange ){
|
||||
found = checkCompositeChange( (CompositeChange) changes, file, startOffset, numChars, newText, potential);
|
||||
}
|
||||
|
||||
if( !found ) {
|
||||
fail ("Rename at offset " + startOffset + " in \"" + file.getLocation() + "\" not found."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
assertFalse( true );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkCompositeChange(CompositeChange composite, IFile file, int startOffset, int numChars, String newText, boolean potential) {
|
||||
boolean found = false;
|
||||
Change [] children = composite.getChildren();
|
||||
for( int i = 0; i < children.length; i++ ){
|
||||
if( children[i] instanceof CompositeChange )
|
||||
found = checkCompositeChange( (CompositeChange) children[i], file, startOffset, numChars, newText, potential);
|
||||
else if( children[i] instanceof TextFileChange ){
|
||||
TextFileChange tuChange = (TextFileChange) children[i];
|
||||
if( tuChange.getFile().toString().equals( file.toString() ) ){
|
||||
found = checkTranslationUnitChange( tuChange, startOffset, numChars, newText, potential );
|
||||
}
|
||||
}
|
||||
if( found )
|
||||
return found;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private boolean checkTranslationUnitChange(TextFileChange change, int startOffset, int numChars, String newText, boolean potential) {
|
||||
TextEditChangeGroup[] groups= change.getTextEditChangeGroups();
|
||||
for (int i = 0; i < groups.length; i++) {
|
||||
TextEditGroup group = groups[i].getTextEditGroup();
|
||||
if ((group.getName().indexOf("potential") != -1) == potential) { //$NON-NLS-1$
|
||||
TextEdit[] edits= group.getTextEdits();
|
||||
if (checkTextEdits(edits, startOffset, numChars, newText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkTextEdit(TextEdit edit, int startOffset, int numChars, String newText) {
|
||||
if (edit instanceof MultiTextEdit) {
|
||||
if (checkTextEdits(((MultiTextEdit) edit).getChildren(),
|
||||
startOffset, numChars, newText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (edit instanceof ReplaceEdit) {
|
||||
if (checkReplaceEdit((ReplaceEdit) edit, startOffset, numChars, newText ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkTextEdits(TextEdit[] edits, int startOffset, int numChars, String newText) {
|
||||
for (int i = 0; i < edits.length; i++) {
|
||||
TextEdit edit = edits[i];
|
||||
if (checkTextEdit(edit, startOffset, numChars, newText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkReplaceEdit(ReplaceEdit edit, int startOffset, int numChars, String newText) {
|
||||
return ( edit.getOffset() == startOffset && edit.getLength() == numChars && edit.getText().equals( newText ) );
|
||||
}
|
||||
|
||||
protected IFile createCppFwdDecls(String fileName) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write( "class class_fwd; \n"); //$NON-NLS-1$
|
||||
writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$
|
||||
writer.write( "union union_fwd; \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_proto(); \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_proto_ov(); \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_proto_ov(int); \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_proto_ov(int*); \n"); //$NON-NLS-1$
|
||||
writer.write( "extern int extern_var; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
return importFile(fileName, contents );
|
||||
}
|
||||
|
||||
protected IFile createCFwdDecls(String fileName) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$
|
||||
writer.write( "union union_fwd; \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_proto(); \n"); //$NON-NLS-1$
|
||||
writer.write( "extern int extern_var; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
return importFile(fileName, contents );
|
||||
}
|
||||
|
||||
protected IFile createCppDefs(String fileName) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write( "class class_def { \n"); //$NON-NLS-1$
|
||||
writer.write( "public: \n"); //$NON-NLS-1$
|
||||
writer.write( " int member; \n"); //$NON-NLS-1$
|
||||
writer.write( " static int static_member; \n"); //$NON-NLS-1$
|
||||
writer.write( " void method(int par); \n"); //$NON-NLS-1$
|
||||
writer.write( " void static_method(int par); \n"); //$NON-NLS-1$
|
||||
writer.write( " int method_ov(); \n"); //$NON-NLS-1$
|
||||
writer.write( " int method_ov(int); \n"); //$NON-NLS-1$
|
||||
writer.write( " int method_ov(int*); \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "struct struct_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " int st_member; \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "union union_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " int un_member; \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$
|
||||
writer.write( "namespace namespace_def{}; \n"); //$NON-NLS-1$
|
||||
writer.write( "enum enum_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " enum_item }; \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_def() {} \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_def_ov() {} \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_def_ov(int){} \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_def_ov(int*){} \n"); //$NON-NLS-1$
|
||||
writer.write( "int var_def; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
return importFile(fileName, contents );
|
||||
}
|
||||
|
||||
protected IFile createCDefs(String fileName) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write( "struct struct_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " int st_member; \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "union union_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " int un_member; \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$
|
||||
writer.write( "enum enum_def { \n"); //$NON-NLS-1$
|
||||
writer.write( " enum_item }; \n"); //$NON-NLS-1$
|
||||
writer.write( "int func_def() {} \n"); //$NON-NLS-1$
|
||||
writer.write( "int var_def; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
return importFile(fileName, contents );
|
||||
}
|
||||
|
||||
protected void assertRefactoringError(RefactoringStatus status, String msg) {
|
||||
RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.ERROR);
|
||||
assertNotNull("Expected refactoring error!", e); //$NON-NLS-1$
|
||||
assertEquals(msg, e.getMessage());
|
||||
}
|
||||
|
||||
protected void assertRefactoringWarning(RefactoringStatus status, String msg) {
|
||||
RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.WARNING);
|
||||
assertNotNull("Expected refactoring warning!", e); //$NON-NLS-1$
|
||||
assertEquals(msg, e.getMessage());
|
||||
}
|
||||
|
||||
protected void assertRefactoringOk(RefactoringStatus status) {
|
||||
assertTrue("Expected refactoring status ok: " + //$NON-NLS-1$
|
||||
status.getMessageMatchingSeverity(status.getSeverity()),
|
||||
status.getSeverity()==RefactoringStatus.OK);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,819 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
/**
|
||||
* @author markus.schorn@windriver.com
|
||||
*/
|
||||
public class RenameFunctionTests extends RenameTests {
|
||||
|
||||
public RenameFunctionTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
public static Test suite(){
|
||||
return suite(true);
|
||||
}
|
||||
public static Test suite( boolean cleanup ) {
|
||||
TestSuite suite = new TestSuite(RenameFunctionTests.class);
|
||||
|
||||
if (cleanup) {
|
||||
suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
public void testFunctionNameConflicts() throws Exception {
|
||||
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
|
||||
createCppDefs("cpp_def.hh"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s1(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s2(); \n"); //$NON-NLS-1$
|
||||
writer.write("void f(int par1){ \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w2; v2(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w3; v3(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
writer = new StringWriter();
|
||||
writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
|
||||
importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
|
||||
|
||||
|
||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||
int offset3= contents.indexOf("v3"); //$NON-NLS-1$
|
||||
|
||||
// conflicting renamings
|
||||
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w1 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: v1 \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par1 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w2 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par2 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w3 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par3 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
// renamings depending on scope
|
||||
status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: member \n" +
|
||||
"Conflicting element type: Field"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: method \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: static_member \n" +
|
||||
"Conflicting element type: Field"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: static_method \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
// lookup inside a static method also returns non-static members
|
||||
// we may want to have a check whether a binding is accessible or not.
|
||||
|
||||
// status= checkConditions(cpp, offset3, "member"); //$NON-NLS-1$
|
||||
// assertRefactoringOk(status);
|
||||
// status= checkConditions(cpp, offset3, "method"); //$NON-NLS-1$
|
||||
// assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: static_member \n" +
|
||||
"Conflicting element type: Field"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: static_method \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
|
||||
// renamings conflicting with global stuff.
|
||||
status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
// would be good to see an error here
|
||||
status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
// would be good to see an error here
|
||||
status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def_ov \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
|
||||
// renamings that are ok.
|
||||
status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: class_def \n" +
|
||||
"Conflicting element type: Constructor"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: class_def \n" +
|
||||
"Conflicting element type: Constructor"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: class_def \n" +
|
||||
"Conflicting element type: Constructor"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
// file static stuff
|
||||
status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: s2 \n" +
|
||||
"Conflicting element type: File static function"); //$NON-NLS-1$
|
||||
|
||||
status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringOk(status);
|
||||
}
|
||||
|
||||
public void testFunctionsPlainC() throws Exception {
|
||||
createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
|
||||
createCDefs("c_def.h"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
|
||||
writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
|
||||
writer.write("int func_proto(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s2(); \n"); //$NON-NLS-1$
|
||||
writer.write("void func_def(){ \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("func_proto"); //$NON-NLS-1$
|
||||
Change change= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
|
||||
assertTotalChanges(2, change);
|
||||
|
||||
offset1= contents.indexOf("func_def"); //$NON-NLS-1$
|
||||
change= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
|
||||
assertTotalChanges(2, change);
|
||||
}
|
||||
|
||||
|
||||
public void testFunctionNameConflictsPlainC() throws Exception {
|
||||
createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
|
||||
createCDefs("c_def.h"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
|
||||
writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s1(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s2(); \n"); //$NON-NLS-1$
|
||||
writer.write("void f(int par1){ \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
|
||||
|
||||
writer = new StringWriter();
|
||||
writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
|
||||
importFile( "other.c", writer.toString() ); //$NON-NLS-1$
|
||||
|
||||
|
||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||
|
||||
// conflicting renamings
|
||||
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w1 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: v1 \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par1 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
// renamings conflicting with global stuff.
|
||||
status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_proto \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: func_def \n" +
|
||||
"Conflicting element type: Global function"); //$NON-NLS-1$
|
||||
|
||||
// renamings that are ok.
|
||||
status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
// file static stuff
|
||||
status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: s2 \n" +
|
||||
"Conflicting element type: File static function"); //$NON-NLS-1$
|
||||
|
||||
status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringOk(status);
|
||||
}
|
||||
|
||||
public void testMethodNameConflicts1() throws Exception {
|
||||
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
|
||||
createCppDefs("cpp_def.hh"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("class Dummy { \n"); //$NON-NLS-1$
|
||||
writer.write(" int v1(); int v2(); \n"); //$NON-NLS-1$
|
||||
writer.write(" int member; \n"); //$NON-NLS-1$
|
||||
writer.write(" int method(int); \n"); //$NON-NLS-1$
|
||||
writer.write(" int method_samesig(); \n"); //$NON-NLS-1$
|
||||
writer.write(" static int static_method(int); \n"); //$NON-NLS-1$
|
||||
writer.write(" static int static_member; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("int Dummy::method(int par1) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
writer.write("static int Dummy::static_method(int par2) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w2; v2(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||
|
||||
// conflicting renamings
|
||||
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w1 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: v1 \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: v1 \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par1 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: w2 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: par2 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Shadowing \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
|
||||
|
||||
status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: member \n" +
|
||||
"Conflicting element type: Field"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
|
||||
assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Overloading \n" +
|
||||
"New element: method \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "method_samesig"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: method_samesig \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Redeclaration \n" +
|
||||
"New element: static_member \n" +
|
||||
"Conflicting element type: Field"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Overloading \n" +
|
||||
"New element: static_method \n" +
|
||||
"Conflicting element type: Method"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testMethodNameConflicts2() throws Exception {
|
||||
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
|
||||
createCppDefs("cpp_def.hh"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("class Dummy { \n"); //$NON-NLS-1$
|
||||
writer.write(" int v1(), v2(), v3(); \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("Dummy d; \n"); //$NON-NLS-1$
|
||||
writer.write("void f(int par1){ \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; d.v1(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w2; d.v2(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int w3; d.v3(); \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("v1"); //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("v2"); //$NON-NLS-1$
|
||||
int offset3= contents.indexOf("v3"); //$NON-NLS-1$
|
||||
|
||||
// conflicting renamings
|
||||
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
// renamings depending on scope
|
||||
status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
|
||||
status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
|
||||
assertRefactoringOk(status);
|
||||
}
|
||||
|
||||
public void testBug72605() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("class Foo { \n"); //$NON-NLS-1$
|
||||
writer.write(" void m1(int x=0); \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("void Foo::m1(int x) {} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset = contents.indexOf("m1") ; //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("m1", offset+1) ; //$NON-NLS-1$
|
||||
Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
|
||||
assertTotalChanges( 2, changes );
|
||||
changes = getRefactorChanges(cpp, offset2, "z"); //$NON-NLS-1$
|
||||
assertTotalChanges( 2, changes );
|
||||
}
|
||||
|
||||
public void testBug72732() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("class Foo { \n"); //$NON-NLS-1$
|
||||
writer.write(" virtual void mthd() = 0;\n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("class Moo: public Foo{ \n"); //$NON-NLS-1$
|
||||
writer.write(" void mthd() = 0; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
int offset = contents.indexOf("mthd") ; //$NON-NLS-1$
|
||||
offset= contents.indexOf("mthd", offset+1) ; //$NON-NLS-1$
|
||||
RefactoringStatus status= checkConditions(cpp, offset, "xxx"); //$NON-NLS-1$
|
||||
assertRefactoringWarning(status, "Renaming a virtual method. Consider renaming the base and derived class methods (if any)."); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,223 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
/**
|
||||
* @author markus.schorn@windriver.com
|
||||
*/
|
||||
public class RenameMacroTests extends RenameTests {
|
||||
|
||||
public RenameMacroTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
public static Test suite(){
|
||||
return suite(true);
|
||||
}
|
||||
public static Test suite( boolean cleanup ) {
|
||||
TestSuite suite = new TestSuite(RenameMacroTests.class);
|
||||
if (cleanup) {
|
||||
suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
public void testMacroRename() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#define HALLO x \n"); //$NON-NLS-1$
|
||||
writer.write("class v1 { \n"); //$NON-NLS-1$
|
||||
writer.write(" int HALLO; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("class HALLO { \n"); //$NON-NLS-1$
|
||||
writer.write(" int v; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("class v3 { \n"); //$NON-NLS-1$
|
||||
writer.write(" int v; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("class v4 { \n"); //$NON-NLS-1$
|
||||
writer.write(" int HALLO(); \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("int v4::HALLO(){} \n"); //$NON-NLS-1$
|
||||
writer.write("void f(int par1){ \n"); //$NON-NLS-1$
|
||||
writer.write(" { \n"); //$NON-NLS-1$
|
||||
writer.write(" int HALLO; v1::v++; \n"); //$NON-NLS-1$
|
||||
writer.write(" } \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("HALLO", offset1+1); //$NON-NLS-1$
|
||||
|
||||
Change ch= getRefactorChanges(cpp, offset1, "WELT"); //$NON-NLS-1$
|
||||
assertTotalChanges(6, ch);
|
||||
int off= offset1;
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
|
||||
ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$
|
||||
assertTotalChanges(6, ch);
|
||||
off= offset1;
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testMacroNameConflicts() throws Exception {
|
||||
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
|
||||
createCppDefs("cpp_def.hh"); //$NON-NLS-1$
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
|
||||
writer.write("#define MACRO 1 \n"); //$NON-NLS-1$
|
||||
writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s1(); \n"); //$NON-NLS-1$
|
||||
writer.write("static int s2(); \n"); //$NON-NLS-1$
|
||||
writer.write("void f(int par1){ \n"); //$NON-NLS-1$
|
||||
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
|
||||
writer.write("} \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
writer = new StringWriter();
|
||||
writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
|
||||
importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
|
||||
|
||||
|
||||
int offset1= contents.indexOf("MACRO"); //$NON-NLS-1$
|
||||
|
||||
// conflicting renamings
|
||||
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Name conflict \n" +
|
||||
"New element: w1 \n" +
|
||||
"Conflicting element type: Local variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, contents.indexOf("par1"), "MACRO"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
assertRefactoringError(status, "'MACRO' conflicts with the name of an existing macro!"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Name conflict \n" +
|
||||
"New element: par1 \n" +
|
||||
"Conflicting element type: Parameter"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Name conflict \n" +
|
||||
"New element: extern_var \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Name conflict \n" +
|
||||
"New element: var_def \n" +
|
||||
"Conflicting element type: Global variable"); //$NON-NLS-1$
|
||||
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
|
||||
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
|
||||
"Type of problem: Name conflict \n" +
|
||||
"New element: enum_item \n" +
|
||||
"Conflicting element type: Enumerator"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testClassMacroClash() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("class CC {int a;}; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
writer = new StringWriter();
|
||||
writer.write("#define CC mm \n"); //$NON-NLS-1$
|
||||
writer.write("int CC; \n"); //$NON-NLS-1$
|
||||
String contents2 = writer.toString();
|
||||
IFile cpp2= importFile("test2.cpp", contents2 ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("CC"); //$NON-NLS-1$
|
||||
Change ch= getRefactorChanges(cpp, offset1, "CCC"); //$NON-NLS-1$
|
||||
assertTotalChanges(1, ch);
|
||||
|
||||
int offset2= contents2.indexOf("CC"); //$NON-NLS-1$
|
||||
ch= getRefactorChanges(cpp2, offset2, "CCC"); //$NON-NLS-1$
|
||||
assertTotalChanges(2, ch);
|
||||
}
|
||||
|
||||
public void testIncludeGuard() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#ifndef _guard \n"); //$NON-NLS-1$
|
||||
writer.write("#define _guard \n"); //$NON-NLS-1$
|
||||
writer.write(" int HALLO \n"); //$NON-NLS-1$
|
||||
writer.write("#endif /* _guard */ \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("_guard"); //$NON-NLS-1$
|
||||
int offset2= contents.indexOf("_guard", offset1+1); //$NON-NLS-1$
|
||||
Change ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$
|
||||
assertTotalChanges(2, 0, 1, ch);
|
||||
int off= offset1;
|
||||
assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
|
||||
off= contents.indexOf("_guard", off+1); //$NON-NLS-1$
|
||||
assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testMacroParameters() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("int var; \n"); //$NON-NLS-1$
|
||||
writer.write("#define M1(var) var \n"); //$NON-NLS-1$
|
||||
writer.write("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$
|
||||
writer.write("#define M3 var \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("var"); //$NON-NLS-1$
|
||||
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
|
||||
assertTotalChanges(1, 1, 0, ch);
|
||||
}
|
||||
|
||||
public void testRenameMacroAsMacroArgument() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("#define M1(var) var \n"); //$NON-NLS-1$
|
||||
writer.write("#define M2 1 \n"); //$NON-NLS-1$
|
||||
writer.write("int b= M2; \n"); //$NON-NLS-1$
|
||||
writer.write("int a= M1(M2); \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("M2"); //$NON-NLS-1$
|
||||
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
|
||||
assertTotalChanges(countOccurrences(contents, "M2"), ch); //$NON-NLS-1$
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
/**
|
||||
* @author markus.schorn@windriver.com
|
||||
*/
|
||||
public class RenameTemplatesTests extends RenameTests {
|
||||
|
||||
public RenameTemplatesTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
public static Test suite(){
|
||||
return suite(true);
|
||||
}
|
||||
public static Test suite( boolean cleanup ) {
|
||||
TestSuite suite = new TestSuite(RenameTemplatesTests.class);
|
||||
if (cleanup) {
|
||||
suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
public void testClassTemplate() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("template <class Type> \n"); //$NON-NLS-1$
|
||||
writer.write("class Array { \n"); //$NON-NLS-1$
|
||||
writer.write("public: \n"); //$NON-NLS-1$
|
||||
writer.write(" Array(unsigned sz) {} \n"); //$NON-NLS-1$
|
||||
writer.write(" ~Array(){} \n"); //$NON-NLS-1$
|
||||
writer.write(" Type& operator[] (unsigned idx); \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
writer.write("template <class Type> \n"); //$NON-NLS-1$
|
||||
writer.write("inline Type& Array<Type>::operator[] (unsigned index) {\n"); //$NON-NLS-1$
|
||||
writer.write(" return 1; \n"); //$NON-NLS-1$
|
||||
writer.write("}; \n"); //$NON-NLS-1$
|
||||
String contents = writer.toString();
|
||||
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
|
||||
|
||||
int offset1= contents.indexOf("Array"); //$NON-NLS-1$
|
||||
|
||||
RefactoringStatus stat= checkConditions(cpp, offset1, "WELT"); //$NON-NLS-1$
|
||||
assertRefactoringOk(stat);
|
||||
|
||||
Change ch= getRefactorChanges(cpp, offset1, "WELT"); //$NON-NLS-1$
|
||||
assertTotalChanges(4, ch);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactoringArgument;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactory;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.rename.CRenameProcessor;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.rename.CRenameRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.rename.TextSearchWrapper;
|
||||
|
||||
/**
|
||||
* @author markus.schorn@windriver.com
|
||||
*/
|
||||
public class RenameTests extends RefactoringTests {
|
||||
|
||||
public RenameTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public RenameTests() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element The CElement to rename
|
||||
* @param newName The new name for the element
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Change getRefactorChanges(IFile file, int offset, String newName) throws Exception {
|
||||
CRenameRefactoring proc = createRefactoring(file, offset, newName);
|
||||
|
||||
RefactoringStatus rs = checkConditions(proc);
|
||||
if (!rs.hasError()) {
|
||||
Change change = proc.createChange( new NullProgressMonitor() );
|
||||
return change;
|
||||
}
|
||||
|
||||
fail ("Input check on "+ newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR) ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
//rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in
|
||||
//the UI for renaming a method to a constructor, the first message which is only
|
||||
//a warning is shown in the UI. If you click preview, then the error and the warning
|
||||
//is shown.
|
||||
return null;
|
||||
}
|
||||
|
||||
private CRenameRefactoring createRefactoring(IFile file, int offset, String newName) {
|
||||
CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
|
||||
CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
|
||||
proc.setReplacementText( newName );
|
||||
proc.setSelectedOptions(-1);
|
||||
proc.setScope(TextSearchWrapper.SCOPE_WORKSPACE);
|
||||
return new CRenameRefactoring(proc);
|
||||
}
|
||||
|
||||
public String[] getRefactorMessages(IFile file, int offset, String newName) throws Exception {
|
||||
String[] result;
|
||||
CRenameRefactoring proc = createRefactoring(file, offset, newName);
|
||||
RefactoringStatus rs = checkConditions(proc);
|
||||
if (!rs.hasWarning()){
|
||||
fail ("Input check on "+ newName + " passed. There should have been warnings or errors. ") ; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return null;
|
||||
}
|
||||
RefactoringStatusEntry[] rse = rs.getEntries();
|
||||
result = new String[rse.length];
|
||||
for (int i=0; i< rse.length; i++){
|
||||
RefactoringStatusEntry entry = rse[i];
|
||||
result[i]=entry.getMessage();
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public RefactoringStatus checkConditions(IFile file, int offset, String newName) throws Exception {
|
||||
CRenameRefactoring proc = createRefactoring(file, offset, newName);
|
||||
return checkConditions(proc);
|
||||
}
|
||||
|
||||
private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
|
||||
RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor() );
|
||||
if (!rs.hasError()){
|
||||
rs= proc.checkFinalConditions(new NullProgressMonitor());
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
public int getRefactorSeverity(IFile file, int offset, String newName) throws Exception {
|
||||
CRenameRefactoring proc = createRefactoring(file, offset, newName);
|
||||
RefactoringStatus rs = checkConditions(proc);
|
||||
|
||||
return (rs.getSeverity());
|
||||
}
|
||||
|
||||
protected int countOccurrences(String contents, String lookup) {
|
||||
int idx= contents.indexOf(lookup);
|
||||
int count= 0;
|
||||
while (idx >=0) {
|
||||
count++;
|
||||
idx= contents.indexOf(lookup, idx+lookup.length());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.runtime.*;
|
||||
import org.eclipse.ltk.core.refactoring.*;
|
||||
import org.eclipse.ltk.core.refactoring.participants.*;
|
||||
|
||||
public class TestRenameParticipant extends RenameParticipant {
|
||||
private static Object sElement= null;
|
||||
private static RenameArguments sArguments= null;
|
||||
private static int sConditionCheck= 0;
|
||||
private static int sCreateChange= 0;
|
||||
|
||||
public static int getConditionCheckCount() {
|
||||
return sConditionCheck;
|
||||
}
|
||||
|
||||
public static int getCreateChangeCount() {
|
||||
return sCreateChange;
|
||||
}
|
||||
|
||||
public static Object getElement() {
|
||||
return sElement;
|
||||
}
|
||||
|
||||
public static RenameArguments staticGetArguments() {
|
||||
return sArguments;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
sElement= null;
|
||||
sArguments= null;
|
||||
sConditionCheck= sCreateChange= 0;
|
||||
}
|
||||
|
||||
protected boolean initialize(Object element) {
|
||||
sElement= element;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "TestRenameParticipant"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
|
||||
sConditionCheck++;
|
||||
sArguments= getArguments();
|
||||
return new RefactoringStatus();
|
||||
}
|
||||
|
||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
sCreateChange++;
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class CorrectCaseTest extends TestCase {
|
||||
|
||||
public CorrectCaseTest(){
|
||||
super("Check Correct Identifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
IdentifierResult result;
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("A"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("Z"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("a"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("z"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_A"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_Z"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_a"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_z"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("__"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_0"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_9"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("Aaaa"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("Zaaa"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("aaaa"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("zaaa"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("_aaa"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class DigitFirstCaseTest extends TestCase {
|
||||
|
||||
public DigitFirstCaseTest() {
|
||||
super("Check Digit First Identifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
IdentifierResult result;
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("0"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("9"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("0a"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("99"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class EmptyCaseTest extends TestCase {
|
||||
|
||||
public EmptyCaseTest() {
|
||||
super("Check Empty Identifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
IdentifierResult result;
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName(""); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.EMPTY == result.getResult());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class IdentifierHelperTest extends TestSuite {
|
||||
|
||||
public IdentifierHelperTest() {
|
||||
super("Identifier Helper Test"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("Test for Identifier Helper"); //$NON-NLS-1$
|
||||
suite.addTest(new CorrectCaseTest());
|
||||
suite.addTest(new DigitFirstCaseTest());
|
||||
suite.addTest(new EmptyCaseTest());
|
||||
suite.addTest(new IllegalCharCaseTest());
|
||||
suite.addTest(new KeywordCaseTest());
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class IllegalCharCaseTest extends TestCase {
|
||||
|
||||
public IllegalCharCaseTest() {
|
||||
super("Check Illegal Character Identifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
IdentifierResult result;
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("a~"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("a%"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("a!"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("{}"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class KeywordCaseTest extends TestCase {
|
||||
|
||||
public KeywordCaseTest() {
|
||||
super("Check Keyword Identifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
IdentifierResult result;
|
||||
|
||||
result = IdentifierHelper.checkIdentifierName("using"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("bitand"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("for"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("const_cast"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("namespace"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("break"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("static_cast"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("false"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("volatile"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("template"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("else"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("dynamic_cast"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("static"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("or"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("not_eq"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("class"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("enum"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("typedef"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("restrict"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("and"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("reinterpret_cast"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("not"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("default"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("explicit"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("sizeof"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("auto"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("case"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("this"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("try"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("friend"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("asm"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("virtual"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("const"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("or_eq"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("catch"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("switch"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("goto"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("while"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("private"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("throw"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("protected"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("struct"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("if"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("extern"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("union"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("typeid"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("inline"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("compl"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("delete"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("do"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("xor"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("export"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("bitor"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("return"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("true"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("operator"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("register"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("new"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("and_eq"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("typename"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("continue"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("mutable"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("xor_eq"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
result = IdentifierHelper.checkIdentifierName("public"); //$NON-NLS-1$
|
||||
assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
||||
|
||||
/**
|
||||
* @author Mirko Stocker
|
||||
*
|
||||
*/
|
||||
public class TranslationUnitHelperTest extends RefactoringTest {
|
||||
|
||||
private int offset;
|
||||
|
||||
public TranslationUnitHelperTest(String name,Vector<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
IFile file = project.getFile(fileName);
|
||||
IASTTranslationUnit unit = TranslationUnitHelper.loadTranslationUnit(file);
|
||||
IASTNode firstNode = TranslationUnitHelper.getFirstNode(unit);
|
||||
assertEquals(offset, firstNode.getNodeLocations()[0].getNodeOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureRefactoring(Properties refactoringProperties) {
|
||||
String offsetKind = (System.getProperty("line.separator").equals("\n")) ? "offset_unix" : "offset_win"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
offset = new Integer(refactoringProperties.getProperty(offsetKind, "0")).intValue(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class UtilTestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("UtilTests"); //$NON-NLS-1$
|
||||
suite.addTest(IdentifierHelperTest.suite());
|
||||
suite.addTest(RefactoringTester.suite("TranslationUnitHelperTest", "resources/refactoring/TranslationunitHelper.rts")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,11 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.internal.ui.navigator,
|
||||
org.eclipse.cdt.internal.ui.preferences;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.preferences.formatter,
|
||||
org.eclipse.cdt.internal.ui.refactoring;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.dialogs,
|
||||
org.eclipse.cdt.internal.ui.refactoring.extractconstant;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.rename;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.refactoring.utils;x-friends:="org.eclipse.cdt.ui.tests",
|
||||
org.eclipse.cdt.internal.ui.search;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.search.actions;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text;x-internal:=true,
|
||||
|
@ -52,6 +57,8 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.ui.browser.typeinfo,
|
||||
org.eclipse.cdt.ui.dialogs,
|
||||
org.eclipse.cdt.ui.newui,
|
||||
org.eclipse.cdt.ui.refactoring,
|
||||
org.eclipse.cdt.ui.refactoring.actions,
|
||||
org.eclipse.cdt.ui.templateengine,
|
||||
org.eclipse.cdt.ui.templateengine.event,
|
||||
org.eclipse.cdt.ui.templateengine.pages,
|
||||
|
@ -61,8 +68,8 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.ui.text.c.hover,
|
||||
org.eclipse.cdt.ui.text.contentassist,
|
||||
org.eclipse.cdt.ui.text.doctools,
|
||||
org.eclipse.cdt.ui.text.doctools.generic,
|
||||
org.eclipse.cdt.ui.text.doctools.doxygen,
|
||||
org.eclipse.cdt.ui.text.doctools.generic,
|
||||
org.eclipse.cdt.ui.text.folding,
|
||||
org.eclipse.cdt.ui.wizards,
|
||||
org.eclipse.cdt.ui.wizards.conversion,
|
||||
|
@ -82,9 +89,10 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
|
|||
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
|
||||
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
|
||||
org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)",
|
||||
org.eclipse.cdt.refactoring;bundle-version="[5.0.0,6.0.0)",
|
||||
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)",
|
||||
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)"
|
||||
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
|
||||
org.eclipse.ltk.core.refactoring;bundle-version="3.4.0",
|
||||
org.eclipse.ltk.ui.refactoring;bundle-version="3.4.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Import-Package: com.ibm.icu.text
|
||||
|
|
|
@ -128,6 +128,24 @@ ActionDefinition.forwardMacroExpansion.description= Step forward in macro expans
|
|||
ActionDefinition.showMacroExplorer.name= Explore Macro Expansion
|
||||
ActionDefinition.showMacroExplorer.description= Opens a quick view for macro expansion exploration
|
||||
|
||||
category.refactoring.description= C/C++ Refactorings
|
||||
category.refactoring.name = Refactor - C++
|
||||
refactoringExtractConstant.label = Extract Constant...
|
||||
|
||||
|
||||
ActionDefinition.renameElement.name= Rename - Refactoring
|
||||
ActionDefinition.renameElement.description= Rename the selected element
|
||||
ActionDefinition.extractConstant.name= Extract Constant - Refactoring
|
||||
ActionDefinition.extractConstant.description= Extract a constant for the selected expression
|
||||
|
||||
# Action Set
|
||||
CodingActionSet.label= C/C++ Coding
|
||||
CodingActionSet.description= Action set containing coding related C/C++ actions
|
||||
|
||||
Refactoring.menu.label= Refac&tor
|
||||
Refactoring.renameAction.label=Re&name...
|
||||
Refactoring.extractConstant.label=Extr&act Constant...
|
||||
|
||||
CEditor.name=C/C++ Editor
|
||||
|
||||
CPluginPreferencePage.name=C/C++
|
||||
|
@ -198,7 +216,6 @@ CEditorPresentationActionSet.description=Actions to customize the C/C++ editor p
|
|||
|
||||
# Menus
|
||||
searchMenu.label= Se&arch
|
||||
refactoringMenu.label= Re&factor
|
||||
|
||||
# Open Element
|
||||
OpenTypeAction.label= Open &Element...
|
||||
|
|
|
@ -234,6 +234,7 @@
|
|||
<actionSet id="org.eclipse.cdt.ui.buildConfigActionSet"/>
|
||||
<actionSet id="org.eclipse.cdt.ui.NavigationActionSet"/>
|
||||
<actionSet id="org.eclipse.cdt.ui.OpenActionSet"/>
|
||||
<actionSet id="org.eclipse.cdt.ui.CodingActionSet"/>
|
||||
<actionSet id="org.eclipse.ui.edit.text.actionSet.presentation"/>
|
||||
|
||||
<showInPart id="org.eclipse.cdt.ui.includeBrowser"/>
|
||||
|
@ -1124,6 +1125,39 @@
|
|||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.actionSets">
|
||||
<actionSet
|
||||
label="%CodingActionSet.label"
|
||||
description="%CodingActionSet.description"
|
||||
visible="false"
|
||||
id="org.eclipse.cdt.ui.CodingActionSet">
|
||||
<menu
|
||||
label="%Refactoring.menu.label"
|
||||
path="edit"
|
||||
id="org.eclipse.jdt.ui.refactoring.menu">
|
||||
<separator name="reorgGroup"/>
|
||||
<separator name="codingGroup"/>
|
||||
<separator name="reorgGroup2"/>
|
||||
<separator name="typeGroup"/>
|
||||
<separator name="typeGroup2"/>
|
||||
<separator name="codingGroup2"/>
|
||||
<separator name="typeGroup3"/>
|
||||
</menu>
|
||||
<!-- reorg group -->
|
||||
<action
|
||||
definitionId="org.eclipse.cdt.ui.edit.text.rename.element"
|
||||
label="%Refactoring.renameAction.label"
|
||||
menubarPath="org.eclipse.jdt.ui.refactoring.menu/reorgGroup"
|
||||
id="org.eclipse.cdt.ui.actions.Rename"
|
||||
retarget="true">
|
||||
</action>
|
||||
<action
|
||||
definitionId="org.eclipse.cdt.ui.refactor.extract.constant"
|
||||
label="%Refactoring.extractConstant.label"
|
||||
menubarPath="org.eclipse.jdt.ui.refactoring.menu/codingGroup"
|
||||
id="org.eclipse.cdt.ui.actions.ExtractConstant"
|
||||
retarget="true">
|
||||
</action>
|
||||
</actionSet>
|
||||
<actionSet
|
||||
label="%CSearchActionSet.label"
|
||||
description="%CSearchActionSet.description"
|
||||
|
@ -1551,6 +1585,21 @@
|
|||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.open.quick.macro.explorer"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
sequence="M2+M3+R"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.rename.element"/>
|
||||
<key
|
||||
sequence="M2+M3+R"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
contextId="org.eclipse.cdt.ui.cViewScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.rename.element"/>
|
||||
<key
|
||||
sequence="M3+C"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.refactor.extract.constant"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
|
@ -1714,6 +1763,27 @@
|
|||
description="%ActionDefinition.showMacroExplorer.description"
|
||||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.open.quick.macro.explorer"/>
|
||||
<category
|
||||
name="%category.refactoring.name"
|
||||
description="%category.refactoring.description"
|
||||
id="org.eclipse.cdt.ui.category.refactoring"/>
|
||||
<command
|
||||
categoryId="org.eclipse.cdt.ui.category.refactoring"
|
||||
id="org.eclipse.cdt.ui.refactoring.command.ExtractConstant"
|
||||
name="%refactoringExtractConstant.label"/>
|
||||
<command
|
||||
name="%ActionDefinition.renameElement.name"
|
||||
description="%ActionDefinition.renameElement.description"
|
||||
categoryId="org.eclipse.cdt.ui.category.refactoring"
|
||||
id="org.eclipse.cdt.ui.edit.text.rename.element">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.extractConstant.name"
|
||||
description="%ActionDefinition.extractConstant.description"
|
||||
categoryId="org.eclipse.cdt.ui.category.refactoring"
|
||||
id="org.eclipse.cdt.ui.refactor.extract.constant">
|
||||
</command>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
id="pdomSearchPage"
|
||||
|
@ -1744,6 +1814,11 @@
|
|||
id="org.eclipse.search.SearchResultView">
|
||||
</part>
|
||||
</actionSetPartAssociation>
|
||||
<actionSetPartAssociation targetID="org.eclipse.cdt.ui.CodingActionSet">
|
||||
<part id="org.eclipse.cdt.ui.editor.CEditor"/>
|
||||
<part id="org.eclipse.cdt.ui.CView"/>
|
||||
</actionSetPartAssociation>
|
||||
|
||||
<actionSetPartAssociation
|
||||
targetID="org.eclipse.ui.edit.text.actionSet.annotationNavigation">
|
||||
<part
|
||||
|
@ -2566,6 +2641,23 @@
|
|||
singleline="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenSingleConfiguration">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ltk.ui.refactoring.changePreviewViewers">
|
||||
<changePreviewViewer
|
||||
class="org.eclipse.cdt.internal.ui.refactoring.dialogs.CreateFileChangePreview"
|
||||
id="org.eclipse.cdt.internal.ui.refactoring.createFileChangePreviewhangePreview">
|
||||
<enablement>
|
||||
<instanceof value="org.eclipse.cdt.internal.ui.refactoring.CreateFileChange"/>
|
||||
</enablement>
|
||||
</changePreviewViewer>
|
||||
<changePreviewViewer
|
||||
class="org.eclipse.cdt.internal.ui.refactoring.dialogs.CTextEditChangePreviewViewer"
|
||||
id="org.eclipse.cdt.internal.ui.refactoring.CTextChangePreviewhangePreview">
|
||||
<enablement>
|
||||
<instanceof value="org.eclipse.cdt.ui.refactoring.CTextFileChange"/>
|
||||
</enablement>
|
||||
</changePreviewViewer>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.decorators">
|
||||
<decorator
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
@ -27,13 +26,10 @@ public class CHMessages extends NLS {
|
|||
public static String CHViewPart_FilterVariables_label;
|
||||
public static String CHViewPart_FilterVariables_tooltip;
|
||||
public static String CHViewPart_FocusOn_label;
|
||||
public static String CHViewPart_HideMacros_label;
|
||||
public static String CHViewPart_HideMacros_tooltip;
|
||||
public static String CHViewPart_NextReference_label;
|
||||
public static String CHViewPart_NextReference_tooltip;
|
||||
public static String CHViewPart_Open_label;
|
||||
public static String CHViewPart_Open_tooltip;
|
||||
public static String CHViewPart_OpenReference_label;
|
||||
public static String CHViewPart_PreviousReference_label;
|
||||
public static String CHViewPart_PreviousReference_tooltip;
|
||||
public static String CHViewPart_Refresh_label;
|
||||
|
|
|
@ -17,8 +17,6 @@ CHViewPart_ShowReference_label=Show Reference
|
|||
CHViewPart_ShowReference_tooltip=Show Reference
|
||||
CHViewPart_FilterVariables_label=Filter Variables
|
||||
CHViewPart_FilterVariables_tooltip=Hide Variables, Constants and Enumerators
|
||||
CHViewPart_HideMacros_label=Hide Macros
|
||||
CHViewPart_HideMacros_tooltip=Hides Macros
|
||||
CHViewPart_ShowFiles_label=Show File Names
|
||||
CHViewPart_ShowFiles_tooltip=Show File Names
|
||||
CHViewPart_NextReference_label=Next Reference
|
||||
|
@ -35,7 +33,6 @@ CHViewPart_FocusOn_label=Focus On ''{0}''
|
|||
CHViewPart_Open_label=Open
|
||||
CHViewPart_Open_tooltip=Open
|
||||
CHLabelProvider_matches=matches
|
||||
CHViewPart_OpenReference_label=Open Reference
|
||||
CHHistoryDropDownAction_ClearHistory_label=Clear History
|
||||
CHHistoryListAction_HistoryDialog_title=Call Hierarchy History
|
||||
CHHistoryListAction_HistoryList_label=Select the input for the Call Hierarchy:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -64,9 +63,9 @@ import org.eclipse.cdt.core.model.IFunction;
|
|||
import org.eclipse.cdt.core.model.IMethod;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.util.CElementBaseLabels;
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
|
@ -97,7 +96,7 @@ public class CHViewPart extends ViewPart {
|
|||
private CHNode fNavigationNode;
|
||||
private int fNavigationDetail;
|
||||
|
||||
private ArrayList fHistoryEntries= new ArrayList(MAX_HISTORY_SIZE);
|
||||
private ArrayList<ICElement> fHistoryEntries= new ArrayList<ICElement>(MAX_HISTORY_SIZE);
|
||||
|
||||
// widgets
|
||||
private PageBook fPagebook;
|
||||
|
@ -136,7 +135,8 @@ public class CHViewPart extends ViewPart {
|
|||
private IContextActivation fContextActivation;
|
||||
|
||||
|
||||
public void setFocus() {
|
||||
@Override
|
||||
public void setFocus() {
|
||||
fPagebook.setFocus();
|
||||
}
|
||||
|
||||
|
@ -192,6 +192,7 @@ public class CHViewPart extends ViewPart {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
fPagebook = new PageBook(parent, SWT.NULL);
|
||||
fPagebook.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
@ -214,6 +215,7 @@ public class CHViewPart extends ViewPart {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (fContextActivation != null) {
|
||||
IContextService ctxService = (IContextService)getSite().getService(IContextService.class);
|
||||
|
@ -267,13 +269,15 @@ public class CHViewPart extends ViewPart {
|
|||
updateSorter();
|
||||
}
|
||||
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
@Override
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
fMemento= memento;
|
||||
super.init(site, memento);
|
||||
}
|
||||
|
||||
|
||||
public void saveState(IMemento memento) {
|
||||
@Override
|
||||
public void saveState(IMemento memento) {
|
||||
if (fWorkingSetFilterUI != null) {
|
||||
fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
|
||||
}
|
||||
|
@ -341,17 +345,20 @@ public class CHViewPart extends ViewPart {
|
|||
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||
|
||||
fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
||||
protected void onWorkingSetChange() {
|
||||
@Override
|
||||
protected void onWorkingSetChange() {
|
||||
updateWorkingSetFilter(this);
|
||||
}
|
||||
protected void onWorkingSetNameChange() {
|
||||
@Override
|
||||
protected void onWorkingSetNameChange() {
|
||||
updateDescription();
|
||||
}
|
||||
};
|
||||
|
||||
fReferencedByAction=
|
||||
new Action(CHMessages.CHViewPart_ShowCallers_label, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetShowReferencedBy(true);
|
||||
}
|
||||
|
@ -362,7 +369,8 @@ public class CHViewPart extends ViewPart {
|
|||
|
||||
fMakesReferenceToAction=
|
||||
new Action(CHMessages.CHViewPart_ShowCallees_label, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetShowReferencedBy(false);
|
||||
}
|
||||
|
@ -372,7 +380,8 @@ public class CHViewPart extends ViewPart {
|
|||
CPluginImages.setImageDescriptors(fMakesReferenceToAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_RELATES_TO);
|
||||
|
||||
fVariableFilter= new ViewerFilter() {
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (element instanceof CHNode) {
|
||||
CHNode node= (CHNode) element;
|
||||
return !node.isVariableOrEnumerator();
|
||||
|
@ -381,7 +390,8 @@ public class CHViewPart extends ViewPart {
|
|||
}
|
||||
};
|
||||
fFilterVariablesAction= new Action(CHMessages.CHViewPart_FilterVariables_label, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
fTreeViewer.addFilter(fVariableFilter);
|
||||
}
|
||||
|
@ -392,38 +402,18 @@ public class CHViewPart extends ViewPart {
|
|||
};
|
||||
fFilterVariablesAction.setToolTipText(CHMessages.CHViewPart_FilterVariables_tooltip);
|
||||
CPluginImages.setImageDescriptors(fFilterVariablesAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_FIELDS);
|
||||
|
||||
// fMacroFilter= new ViewerFilter() {
|
||||
// public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
// if (element instanceof CHNode) {
|
||||
// CHNode node= (CHNode) element;
|
||||
// return !node.isMacro();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// };
|
||||
// fFilterMacrosAction= new Action(CHMessages.CHViewPart_HideMacros_label, IAction.AS_CHECK_BOX) {
|
||||
// public void run() {
|
||||
// if (isChecked()) {
|
||||
// fTreeViewer.addFilter(fMacroFilter);
|
||||
// }
|
||||
// else {
|
||||
// fTreeViewer.removeFilter(fMacroFilter);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// fFilterMacrosAction.setToolTipText(CHMessages.CHViewPart_HideMacros_tooltip);
|
||||
// CPluginImages.setImageDescriptors(fFilterMacrosAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_MACROS);
|
||||
|
||||
fSorterAlphaNumeric= new ViewerComparator();
|
||||
fSorterReferencePosition= new ViewerComparator() {
|
||||
public int category(Object element) {
|
||||
@Override
|
||||
public int category(Object element) {
|
||||
if (element instanceof CHNode) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
@Override
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
if (!(e1 instanceof CHNode)) {
|
||||
if (!(e2 instanceof CHNode)) {
|
||||
return 0;
|
||||
|
@ -442,26 +432,30 @@ public class CHViewPart extends ViewPart {
|
|||
};
|
||||
|
||||
fShowReference= new Action(CHMessages.CHViewPart_ShowReference_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onShowSelectedReference(fTreeViewer.getSelection());
|
||||
}
|
||||
};
|
||||
fShowReference.setToolTipText(CHMessages.CHViewPart_ShowReference_tooltip);
|
||||
fOpenElement= new Action(CHMessages.CHViewPart_Open_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onOpenElement(fTreeViewer.getSelection());
|
||||
}
|
||||
};
|
||||
fOpenElement.setToolTipText(CHMessages.CHViewPart_Open_tooltip);
|
||||
|
||||
fShowFilesInLabelsAction= new Action(CHMessages.CHViewPart_ShowFiles_label, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onShowFilesInLabels(isChecked());
|
||||
}
|
||||
};
|
||||
fShowFilesInLabelsAction.setToolTipText(CHMessages.CHViewPart_ShowFiles_tooltip);
|
||||
fNextAction = new Action(CHMessages.CHViewPart_NextReference_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNextOrPrevious(true);
|
||||
}
|
||||
};
|
||||
|
@ -469,7 +463,8 @@ public class CHViewPart extends ViewPart {
|
|||
CPluginImages.setImageDescriptors(fNextAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_NEXT);
|
||||
|
||||
fPreviousAction = new Action(CHMessages.CHViewPart_PreviousReference_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNextOrPrevious(false);
|
||||
}
|
||||
};
|
||||
|
@ -477,7 +472,8 @@ public class CHViewPart extends ViewPart {
|
|||
CPluginImages.setImageDescriptors(fPreviousAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_PREV);
|
||||
|
||||
fRefreshAction = new Action(CHMessages.CHViewPart_Refresh_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onRefresh();
|
||||
}
|
||||
};
|
||||
|
@ -705,6 +701,7 @@ public class CHViewPart extends ViewPart {
|
|||
String label= Messages.format(CHMessages.CHViewPart_FocusOn_label,
|
||||
CElementLabels.getTextLabel(element, CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES));
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, new Action(label) {
|
||||
@Override
|
||||
public void run() {
|
||||
setInput(element);
|
||||
}
|
||||
|
@ -784,7 +781,7 @@ public class CHViewPart extends ViewPart {
|
|||
}
|
||||
|
||||
public ICElement[] getHistoryEntries() {
|
||||
return (ICElement[]) fHistoryEntries.toArray(new ICElement[fHistoryEntries.size()]);
|
||||
return fHistoryEntries.toArray(new ICElement[fHistoryEntries.size()]);
|
||||
}
|
||||
|
||||
public void setHistoryEntries(ICElement[] remaining) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -39,9 +39,9 @@ import org.eclipse.ui.ide.IDEActionFactory;
|
|||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||
|
@ -91,6 +91,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
/**
|
||||
* Handles key events in viewer.
|
||||
*/
|
||||
@Override
|
||||
public void handleKeyPressed(KeyEvent event) {
|
||||
refactorGroup.handleKeyPressed(event);
|
||||
openFileGroup.handleKeyPressed(event);
|
||||
|
@ -102,6 +103,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
/**
|
||||
* Handles key events in viewer.
|
||||
*/
|
||||
@Override
|
||||
public void handleKeyReleased(KeyEvent event) {
|
||||
refactorGroup.handleKeyReleased(event);
|
||||
openFileGroup.handleKeyReleased(event);
|
||||
|
@ -110,6 +112,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
buildGroup.handleKeyReleased(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void makeActions() {
|
||||
final Viewer viewer = getCView().getViewer();
|
||||
IShellProvider shellProvider = getCView().getViewSite();
|
||||
|
@ -147,8 +150,8 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
workingSetGroup.setWorkingSet(getCView().getWorkingSet());
|
||||
fCustomFiltersActionGroup= new CustomFiltersActionGroup(getCView(), getCView().getViewer());
|
||||
|
||||
addBookmarkAction = new AddBookmarkAction(shell);
|
||||
addTaskAction = new AddTaskAction(shell);
|
||||
addBookmarkAction = new AddBookmarkAction(shellProvider, true);
|
||||
addTaskAction = new AddTaskAction(shellProvider);
|
||||
|
||||
// Importing/exporting.
|
||||
importAction = new ImportResourcesAction(getCView().getSite().getWorkbenchWindow());
|
||||
|
@ -170,6 +173,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
* Called when the context menu is about to open. Override to add your own
|
||||
* context dependent menu contributions.
|
||||
*/
|
||||
@Override
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
IStructuredSelection celements = (IStructuredSelection) getCView().getViewer().getSelection();
|
||||
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(celements);
|
||||
|
@ -233,6 +237,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
* Extends the superclass implementation to set the context in the
|
||||
* subgroups.
|
||||
*/
|
||||
@Override
|
||||
public void setContext(ActionContext context) {
|
||||
super.setContext(context);
|
||||
gotoGroup.setContext(context);
|
||||
|
@ -276,6 +281,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDefaultAction(IStructuredSelection selection) {
|
||||
openFileGroup.runDefaultAction(selection);
|
||||
openProjectGroup.runDefaultAction(selection);
|
||||
|
@ -291,6 +297,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
* if the selection in the viewer hasn't. E.g. A project was opened or
|
||||
* closed.
|
||||
*/
|
||||
@Override
|
||||
public void updateActionBars() {
|
||||
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
|
||||
|
||||
|
@ -311,6 +318,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
crefactoringActionGroup.updateActionBars();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
|
||||
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), addTaskAction);
|
||||
|
@ -339,11 +347,13 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
|
||||
//---- Persistent state -----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void restoreFilterAndSorterState(IMemento memento) {
|
||||
//fWorkingSetFilterActionGroup.restoreState(memento);
|
||||
fCustomFiltersActionGroup.restoreState(memento);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFilterAndSorterState(IMemento memento) {
|
||||
//fWorkingSetFilterActionGroup.saveState(memento);
|
||||
fCustomFiltersActionGroup.saveState(memento);
|
||||
|
@ -353,6 +363,7 @@ public class MainActionGroup extends CViewActionGroup {
|
|||
return fCustomFiltersActionGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
importAction.dispose();
|
||||
exportAction.dispose();
|
||||
|
|
|
@ -138,7 +138,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
public IncludeGroupingAction(AbstractCModelOutlinePage outlinePage) {
|
||||
super(ActionMessages.getString("IncludesGroupingAction.label")); //$NON-NLS-1$
|
||||
setDescription(ActionMessages.getString("IncludesGroupingAction.description")); //$NON-NLS-1$
|
||||
setToolTipText(ActionMessages.getString("IncludeGroupingAction.tooltip")); //$NON-NLS-1$
|
||||
setToolTipText(ActionMessages.getString("IncludesGroupingAction.tooltip")); //$NON-NLS-1$
|
||||
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_GROUP_INCLUDE);
|
||||
|
||||
boolean enabled= isIncludesGroupingEnabled();
|
||||
|
@ -149,6 +149,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
/**
|
||||
* Runs the action.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, isChecked());
|
||||
}
|
||||
|
@ -177,6 +178,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
/**
|
||||
* Runs the action.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
boolean checked = isChecked();
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_LINK_TO_EDITOR, checked);
|
||||
|
@ -301,6 +303,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
return fTreeViewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
fTreeViewer = createTreeViewer(parent);
|
||||
initDragAndDrop();
|
||||
|
@ -344,6 +347,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
PlatformUI.getWorkbench().getHelpSystem().setHelp(control, ICHelpContextIds.COUTLINE_VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (fTreeViewer != null) {
|
||||
fTreeViewer.removeSelectionChangedListener(this);
|
||||
|
@ -498,6 +502,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Control getControl() {
|
||||
if (fTreeViewer == null)
|
||||
return null;
|
||||
|
@ -531,6 +536,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
/**
|
||||
* Sets focus to a part in the page.
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
fTreeViewer.getControl().setFocus();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -15,10 +15,10 @@ package org.eclipse.cdt.internal.ui.editor;
|
|||
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||
|
||||
|
@ -40,24 +40,29 @@ public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
|||
return (CEditor)fEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectionSearchGroup createSearchActionGroup() {
|
||||
return new SelectionSearchGroup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OpenViewActionGroup createOpenViewActionGroup() {
|
||||
OpenViewActionGroup ovag= new OpenViewActionGroup(this);
|
||||
ovag.setEnableIncludeBrowser(true);
|
||||
return ovag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionGroup createRefactoringActionGroup() {
|
||||
return new CRefactoringActionGroup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionGroup createCustomFiltersActionGroup() {
|
||||
return new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionGroup createMemberFilterActionGroup() {
|
||||
return new MemberFilterActionGroup(getTreeViewer(), "COutlineViewer"); //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -172,12 +172,12 @@ import org.eclipse.cdt.core.model.ISourceRange;
|
|||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.actions.GenerateActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
||||
|
||||
|
|
|
@ -80,13 +80,6 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
*/
|
||||
public static final String OPEN_DECL= "org.eclipse.cdt.ui.edit.opendecl"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the open definition action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.opendef"</code>).
|
||||
* @deprecated see bug 167162
|
||||
*/
|
||||
public static final String OPEN_DEF= "org.eclipse.cdt.ui.edit.opendef"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the show in C/C++ Projects View action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.opencview"</code>).
|
||||
|
@ -98,7 +91,13 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
* (value <code>"org.eclipse.cdt.ui.edit.text.rename.element"</code>).
|
||||
*/
|
||||
public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> extract constant action
|
||||
* (value <code>"org.eclipse.cdt.ui.refactor.extract.constant"</code>).
|
||||
*/
|
||||
public static final String EXTRACT_CONSTANT= "org.eclipse.cdt.ui.refactor.extract.constant"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> undo action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.undo.action"</code>).
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.includebrowser;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
@ -35,7 +34,6 @@ public class IBMessages extends NLS {
|
|||
public static String IBViewPart_jobCheckInput;
|
||||
public static String IBViewPart_nextMatch_label;
|
||||
public static String IBViewPart_nextMatch_tooltip;
|
||||
public static String IBViewPart_OpenWithMenu_label;
|
||||
public static String IBViewPart_previousMatch_label;
|
||||
public static String IBViewPart_previousMatch_tooltip;
|
||||
public static String IBViewPart_refresh_label;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2006, 2007 Wind River Systems, Inc and others.
|
||||
# Copyright (c) 2006, 2008 Wind River Systems, Inc and others.
|
||||
# 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
|
||||
#
|
||||
# Contributors:
|
||||
# Markus Schorn - Initial API and implementation
|
||||
# Markus Schorn - Initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
IBViewPart_instructionMessage=To display an include hierarchy, drop a c/c++-file onto this view.
|
||||
|
@ -23,7 +23,6 @@ IBViewPart_IncludedByContentDescription=Files including ''{0}'' - in {1}
|
|||
IBViewPart_IncludesToContentDescription=Files included by ''{0}'' - in {1}
|
||||
IBViewPart_hideInactive_tooltip=Hide Includes from Inactive Code
|
||||
IBViewPart_previousMatch_tooltip=Show Previous Include
|
||||
IBViewPart_OpenWithMenu_label=Open With
|
||||
IBViewPart_hideInactive_label=Hide Inactive Includes
|
||||
IBViewPart_hideSystem_tooltip=Hide System Includes
|
||||
IBViewPart_ShowInMenu_label=Show In
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
|
@ -9,7 +9,6 @@
|
|||
* Markus Schorn - initial API and implementation
|
||||
* Ed Swartz (Nokia)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.includebrowser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -113,7 +112,7 @@ public class IBViewPart extends ViewPart
|
|||
private IMemento fMemento;
|
||||
private boolean fShowsMessage;
|
||||
private IBNode fLastNavigationNode;
|
||||
private ArrayList fHistoryEntries= new ArrayList(MAX_HISTORY_SIZE);
|
||||
private ArrayList<ITranslationUnit> fHistoryEntries= new ArrayList<ITranslationUnit>(MAX_HISTORY_SIZE);
|
||||
|
||||
// widgets
|
||||
private PageBook fPagebook;
|
||||
|
@ -147,7 +146,8 @@ public class IBViewPart extends ViewPart
|
|||
private IBSetInputJob fSetInputJob;
|
||||
|
||||
|
||||
public void setFocus() {
|
||||
@Override
|
||||
public void setFocus() {
|
||||
fPagebook.setFocus();
|
||||
}
|
||||
|
||||
|
@ -206,6 +206,7 @@ public class IBViewPart extends ViewPart
|
|||
updateDescription();
|
||||
final Display display= Display.getCurrent();
|
||||
Job job= new Job(IBMessages.IBViewPart_jobCheckInput) {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(input.getCProject());
|
||||
|
@ -246,6 +247,7 @@ public class IBViewPart extends ViewPart
|
|||
fRefreshAction.setEnabled(!fShowsMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
fSetInputJob= new IBSetInputJob(this, Display.getCurrent());
|
||||
|
||||
|
@ -271,6 +273,7 @@ public class IBViewPart extends ViewPart
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (fContextActivation != null) {
|
||||
IContextService ctxService = (IContextService)getSite().getService(IContextService.class);
|
||||
|
@ -329,13 +332,15 @@ public class IBViewPart extends ViewPart
|
|||
}
|
||||
|
||||
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
@Override
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
fMemento= memento;
|
||||
super.init(site, memento);
|
||||
}
|
||||
|
||||
|
||||
public void saveState(IMemento memento) {
|
||||
@Override
|
||||
public void saveState(IMemento memento) {
|
||||
if (fWorkingSetFilter != null) {
|
||||
fWorkingSetFilter.getUI().saveState(memento, KEY_WORKING_SET_FILTER);
|
||||
}
|
||||
|
@ -410,17 +415,20 @@ public class IBViewPart extends ViewPart
|
|||
|
||||
private void createActions() {
|
||||
fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
||||
protected void onWorkingSetChange() {
|
||||
@Override
|
||||
protected void onWorkingSetChange() {
|
||||
updateWorkingSetFilter(this);
|
||||
}
|
||||
protected void onWorkingSetNameChange() {
|
||||
@Override
|
||||
protected void onWorkingSetNameChange() {
|
||||
updateDescription();
|
||||
}
|
||||
};
|
||||
|
||||
fIncludedByAction=
|
||||
new Action(IBMessages.IBViewPart_showIncludedBy_label, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetDirection(true);
|
||||
}
|
||||
|
@ -431,7 +439,8 @@ public class IBViewPart extends ViewPart
|
|||
|
||||
fIncludesToAction=
|
||||
new Action(IBMessages.IBViewPart_showIncludesTo_label, IAction.AS_RADIO_BUTTON) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
onSetDirection(false);
|
||||
}
|
||||
|
@ -441,7 +450,8 @@ public class IBViewPart extends ViewPart
|
|||
CPluginImages.setImageDescriptors(fIncludesToAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_RELATES_TO);
|
||||
|
||||
fInactiveFilter= new ViewerFilter() {
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (element instanceof IBNode) {
|
||||
IBNode node= (IBNode) element;
|
||||
return node.isActiveCode();
|
||||
|
@ -450,7 +460,8 @@ public class IBViewPart extends ViewPart
|
|||
}
|
||||
};
|
||||
fFilterInactiveAction= new Action(IBMessages.IBViewPart_hideInactive_label, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
fTreeViewer.addFilter(fInactiveFilter);
|
||||
}
|
||||
|
@ -463,7 +474,8 @@ public class IBViewPart extends ViewPart
|
|||
CPluginImages.setImageDescriptors(fFilterInactiveAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_INACTIVE);
|
||||
|
||||
fSystemFilter= new ViewerFilter() {
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (element instanceof IBNode) {
|
||||
IBNode node= (IBNode) element;
|
||||
return !node.isSystemInclude();
|
||||
|
@ -472,7 +484,8 @@ public class IBViewPart extends ViewPart
|
|||
}
|
||||
};
|
||||
fFilterSystemAction= new Action(IBMessages.IBViewPart_hideSystem_label, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isChecked()) {
|
||||
fTreeViewer.addFilter(fSystemFilter);
|
||||
}
|
||||
|
@ -486,13 +499,15 @@ public class IBViewPart extends ViewPart
|
|||
|
||||
fSorterAlphaNumeric= new ViewerComparator();
|
||||
fSorterReferencePosition= new ViewerComparator() {
|
||||
public int category(Object element) {
|
||||
@Override
|
||||
public int category(Object element) {
|
||||
if (element instanceof IBNode) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
@Override
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
if (!(e1 instanceof IBNode)) {
|
||||
if (!(e2 instanceof IBNode)) {
|
||||
return 0;
|
||||
|
@ -509,13 +524,15 @@ public class IBViewPart extends ViewPart
|
|||
};
|
||||
|
||||
fShowFolderInLabelsAction= new Action(IBMessages.IBViewPart_showFolders_label, IAction.AS_CHECK_BOX) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onShowFolderInLabels(isChecked());
|
||||
}
|
||||
};
|
||||
fShowFolderInLabelsAction.setToolTipText(IBMessages.IBViewPart_showFolders_tooltip);
|
||||
fNextAction = new Action(IBMessages.IBViewPart_nextMatch_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNextOrPrevious(true);
|
||||
}
|
||||
};
|
||||
|
@ -523,7 +540,8 @@ public class IBViewPart extends ViewPart
|
|||
CPluginImages.setImageDescriptors(fNextAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_NEXT);
|
||||
|
||||
fPreviousAction = new Action(IBMessages.IBViewPart_previousMatch_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onNextOrPrevious(false);
|
||||
}
|
||||
};
|
||||
|
@ -531,7 +549,8 @@ public class IBViewPart extends ViewPart
|
|||
CPluginImages.setImageDescriptors(fPreviousAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_PREV);
|
||||
|
||||
fRefreshAction = new Action(IBMessages.IBViewPart_refresh_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onRefresh();
|
||||
}
|
||||
};
|
||||
|
@ -694,7 +713,8 @@ public class IBViewPart extends ViewPart
|
|||
// open include
|
||||
if (node.getParent() != null && node.getDirectiveFile() != null) {
|
||||
m.add(new Action(IBMessages.IBViewPart_showInclude_label) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
onShowInclude(selection);
|
||||
}
|
||||
});
|
||||
|
@ -707,15 +727,6 @@ public class IBViewPart extends ViewPart
|
|||
ofa.selectionChanged(selection);
|
||||
m.add(ofa);
|
||||
|
||||
// open with
|
||||
// keep the menu shorter, no open with support
|
||||
// final IResource r= tu.getResource();
|
||||
// if (r != null) {
|
||||
// IMenuManager submenu= new MenuManager(IBMessages.IBViewPart_OpenWithMenu_label);
|
||||
// submenu.add(new OpenWithMenu(page, r));
|
||||
// m.add(submenu);
|
||||
// }
|
||||
|
||||
// show in
|
||||
IMenuManager submenu= new MenuManager(IBMessages.IBViewPart_ShowInMenu_label);
|
||||
submenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getSite().getWorkbenchWindow()));
|
||||
|
@ -723,7 +734,8 @@ public class IBViewPart extends ViewPart
|
|||
if (node.getParent() != null) {
|
||||
m.add(new Separator());
|
||||
m.add(new Action(Messages.format(IBMessages.IBViewPart_FocusOn_label, tu.getPath().lastSegment())) {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
setInput(tu);
|
||||
}
|
||||
});
|
||||
|
@ -804,7 +816,7 @@ public class IBViewPart extends ViewPart
|
|||
}
|
||||
|
||||
public ITranslationUnit[] getHistoryEntries() {
|
||||
return (ITranslationUnit[]) fHistoryEntries.toArray(new ITranslationUnit[fHistoryEntries.size()]);
|
||||
return fHistoryEntries.toArray(new ITranslationUnit[fHistoryEntries.size()]);
|
||||
}
|
||||
|
||||
public void setHistoryEntries(ITranslationUnit[] remaining) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2006, 2008 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -23,7 +23,7 @@ import org.eclipse.ui.navigator.ICommonActionExtensionSite;
|
|||
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
|
||||
import org.eclipse.ui.operations.UndoRedoActionGroup;
|
||||
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||
|
||||
|
@ -41,6 +41,7 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
|||
/*
|
||||
* @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
|
||||
*/
|
||||
@Override
|
||||
public void init(ICommonActionExtensionSite actionSite) {
|
||||
site = actionSite;
|
||||
resourceRefactorGroup= new CNavigatorRefactorActionGroup(site.getViewSite().getShell(), (Tree)site.getStructuredViewer().getControl());
|
||||
|
@ -55,12 +56,14 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
undoRedoGroup.dispose();
|
||||
resourceRefactorGroup.dispose();
|
||||
cElementRefactorGroup.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
undoRedoGroup.fillActionBars(actionBars);
|
||||
resourceRefactorGroup.fillActionBars(actionBars);
|
||||
|
@ -68,18 +71,21 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
|||
cElementRefactorGroup.fillActionBars(actionBars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
undoRedoGroup.fillContextMenu(menu);
|
||||
resourceRefactorGroup.fillContextMenu(menu);
|
||||
cElementRefactorGroup.fillContextMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContext(ActionContext context) {
|
||||
undoRedoGroup.setContext(context);
|
||||
resourceRefactorGroup.setContext(convertToResources(context));
|
||||
cElementRefactorGroup.setContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateActionBars() {
|
||||
undoRedoGroup.updateActionBars();
|
||||
resourceRefactorGroup.updateActionBars();
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
public class AddDeclarationNodeToClassChange {
|
||||
|
||||
private final ICPPASTCompositeTypeSpecifier nodeClass;
|
||||
private final VisibilityEnum visibility;
|
||||
private final IASTNode fieldNodes;
|
||||
private final ModificationCollector collector;
|
||||
|
||||
public static void createChange(ICPPASTCompositeTypeSpecifier nodeClass, VisibilityEnum visibility, IASTNode fieldNodes, boolean isField, ModificationCollector collector) {
|
||||
new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField);
|
||||
}
|
||||
|
||||
private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, VisibilityEnum visibility, IASTNode fieldNodes, ModificationCollector collector, boolean isField) {
|
||||
this.nodeClass = nodeClass;
|
||||
this.visibility = visibility;
|
||||
this.fieldNodes = fieldNodes;
|
||||
this.collector = collector;
|
||||
createRewrites(isField);
|
||||
}
|
||||
|
||||
private void createRewrites(boolean isField) {
|
||||
int lastFunctionDeclaration = -1;
|
||||
int lastFieldDeclaration = -1;
|
||||
IASTDeclaration[] members = nodeClass.getMembers();
|
||||
|
||||
// XXX Don't we have to differentiate between the default visibility in a class and a struct?
|
||||
VisibilityEnum currentVisibility = VisibilityEnum.v_private;
|
||||
|
||||
// Find the insert location by iterating over the elements of the class
|
||||
// and remembering the last element with the matching visibility
|
||||
for(int i = 0; i < members.length; i++) {
|
||||
IASTDeclaration declaration = members[i];
|
||||
|
||||
if(declaration instanceof ICPPASTVisiblityLabel){
|
||||
currentVisibility = VisibilityEnum.from((ICPPASTVisiblityLabel) declaration);
|
||||
}
|
||||
|
||||
if (declaration instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration;
|
||||
IASTDeclarator[] declarators = simple.getDeclarators();
|
||||
if(declarators.length > 0 && declarators[0] != null && declarators[0] instanceof IASTFunctionDeclarator){
|
||||
if(currentVisibility.equals(visibility)){
|
||||
lastFunctionDeclaration = i;
|
||||
}
|
||||
|
||||
} else if (declarators.length > 0 && declarators[0] != null){
|
||||
if(currentVisibility.equals(visibility)){
|
||||
lastFieldDeclaration = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IASTDeclaration nextFunctionDeclaration = null;
|
||||
if (lastFunctionDeclaration < members.length-1 && lastFunctionDeclaration >= 0)
|
||||
nextFunctionDeclaration = members[lastFunctionDeclaration+1];
|
||||
|
||||
IASTDeclaration nextFieldDeclaration = null;
|
||||
if (lastFieldDeclaration < members.length-1 && lastFieldDeclaration >= 0)
|
||||
nextFieldDeclaration = members[lastFieldDeclaration +1];
|
||||
|
||||
createInsert(isField, nextFunctionDeclaration, nextFieldDeclaration, currentVisibility);
|
||||
}
|
||||
|
||||
private void createInsert(boolean isField, IASTDeclaration nextFunctionDeclaration, IASTDeclaration nextFieldDeclaration, VisibilityEnum currentVisibility) {
|
||||
if(isField) {
|
||||
if(nextFieldDeclaration != null) {
|
||||
insertBefore(nextFieldDeclaration);
|
||||
} else if(nextFunctionDeclaration != null){
|
||||
insertBefore(nextFunctionDeclaration);
|
||||
} else {
|
||||
insertAtTheEnd(currentVisibility);
|
||||
}
|
||||
} else {
|
||||
if(nextFunctionDeclaration != null){
|
||||
insertBefore(nextFunctionDeclaration);
|
||||
} else if(nextFieldDeclaration != null) {
|
||||
insertBefore(nextFieldDeclaration);
|
||||
} else {
|
||||
insertAtTheEnd(currentVisibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void insertBefore(IASTNode nearestNode) {
|
||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(nearestNode.getTranslationUnit());
|
||||
rewrite.insertBefore(nearestNode.getParent(), nearestNode, fieldNodes, createEditDescription());
|
||||
}
|
||||
|
||||
private void insertAtTheEnd(VisibilityEnum currentVisibility) {
|
||||
|
||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(nodeClass.getTranslationUnit());
|
||||
|
||||
if(! currentVisibility.equals(visibility)) {
|
||||
ICPPASTVisiblityLabel label = new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility());
|
||||
rewrite.insertBefore(nodeClass, null, label, createEditDescription());
|
||||
}
|
||||
|
||||
rewrite.insertBefore(nodeClass, null, fieldNodes, createEditDescription());
|
||||
}
|
||||
|
||||
private TextEditGroup createEditDescription() {
|
||||
return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration, nodeClass.getName()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,425 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.EclipseObjects;
|
||||
|
||||
public abstract class CRefactoring extends Refactoring {
|
||||
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||
|
||||
protected String name = Messages.HSRRefactoring_name;
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected RefactoringStatus initStatus;
|
||||
protected IASTTranslationUnit unit;
|
||||
private IIndex fIndex;
|
||||
public static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
|
||||
public CRefactoring(IFile file, ISelection selection, boolean runHeadless) {
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
this.initStatus=new RefactoringStatus();
|
||||
|
||||
if(!runHeadless) {
|
||||
IWorkbenchPage activePage = EclipseObjects.getActivePage();
|
||||
|
||||
if(!activePage.saveAllEditors(true)){
|
||||
initStatus.addError("EDITOR_NOT_SAVE"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if(selection == null){
|
||||
initStatus.addError(Messages.HSRRefactoring_SelectionNotValid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CRefactoring(IFile file, ISelection selection) {
|
||||
this(file, selection, false);
|
||||
}
|
||||
|
||||
private class ProblemFinder extends ASTVisitor{
|
||||
|
||||
private boolean problemFound = false;
|
||||
private final RefactoringStatus status;
|
||||
|
||||
public ProblemFinder(RefactoringStatus status){
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
{
|
||||
shouldVisitProblems = true;
|
||||
shouldVisitDeclarations = true;
|
||||
shouldVisitExpressions = true;
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitTypeIds = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTProblem problem) {
|
||||
addWarningToState();
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
if (declaration instanceof IASTProblemDeclaration) {
|
||||
addWarningToState();
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof IASTProblemExpression) {
|
||||
addWarningToState();
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
if (statement instanceof IASTProblemStatement) {
|
||||
addWarningToState();
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTTypeId typeId) {
|
||||
if (typeId instanceof IASTProblemTypeId) {
|
||||
addWarningToState();
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public boolean hasProblem() {
|
||||
return problemFound;
|
||||
}
|
||||
|
||||
private void addWarningToState() {
|
||||
if(!problemFound){
|
||||
status.addWarning(Messages.HSRRefactoring_CompileErrorInTU);
|
||||
problemFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AmbiguityFinder extends ASTVisitor{
|
||||
|
||||
private boolean ambiguityFound = false;
|
||||
|
||||
{
|
||||
shouldVisitDeclarations = true;
|
||||
shouldVisitExpressions = true;
|
||||
shouldVisitStatements= true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
if (declaration instanceof IASTAmbiguousDeclaration || declaration instanceof IASTDeclarationAmbiguity) {
|
||||
ambiguityFound = true;
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof IASTAmbiguousExpression) {
|
||||
ambiguityFound = true;
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
if (statement instanceof IASTAmbiguousStatement) {
|
||||
ambiguityFound = true;
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public boolean ambiguityFound() {
|
||||
return ambiguityFound;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
|
||||
throws CoreException, OperationCanceledException {
|
||||
RefactoringStatus status = new RefactoringStatus();
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
||||
throws CoreException, OperationCanceledException {
|
||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||
sm.subTask(Messages.HSRRefactoring_PM_LoadTU);
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) {
|
||||
return initStatus;
|
||||
}
|
||||
if(!loadTranslationUnit(initStatus, sm.newChild(8))){
|
||||
initStatus.addError(Messages.HSRRefactoring_CantLoadTU);
|
||||
}
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) {
|
||||
return initStatus;
|
||||
}
|
||||
sm.subTask(Messages.HSRRefactoring_PM_CheckTU);
|
||||
translationUnitHasProblem();
|
||||
if(translationUnitIsAmbiguous()) {
|
||||
initStatus.addError(Messages.HSRRefactoring_Ambiguity);
|
||||
}
|
||||
sm.worked(2);
|
||||
sm.subTask(Messages.HSRRefactoring_PM_InitRef);
|
||||
sm.done();
|
||||
return initStatus;
|
||||
}
|
||||
|
||||
protected boolean isProgressMonitorCanceld(IProgressMonitor sm,
|
||||
RefactoringStatus initStatus2) {
|
||||
if(sm.isCanceled()) {
|
||||
initStatus2.addFatalError(Messages.HSRRefactoring_CanceledByUser);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
ModificationCollector collector = new ModificationCollector();
|
||||
collectModifications(pm, collector);
|
||||
return collector.createFinalChange();
|
||||
}
|
||||
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||
throws CoreException, OperationCanceledException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected boolean loadTranslationUnit(RefactoringStatus status, IProgressMonitor mon) {
|
||||
SubMonitor subMonitor = SubMonitor.convert(mon, 10);
|
||||
if (file != null) {
|
||||
try {
|
||||
subMonitor.subTask(Messages.HSRRefactoring_PM_ParseTU);
|
||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin
|
||||
.getDefault().getCoreModel().create(file);
|
||||
unit = tu.getAST(fIndex, AST_STYLE);
|
||||
subMonitor.worked(2);
|
||||
if(isProgressMonitorCanceld(subMonitor, initStatus)) {
|
||||
return true;
|
||||
}
|
||||
subMonitor.subTask(Messages.HSRRefactoring_PM_MergeComments);
|
||||
|
||||
subMonitor.worked(8);
|
||||
} catch (CoreException e) {
|
||||
status.addFatalError(e.getMessage());
|
||||
subMonitor.done();
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
status.addFatalError(Messages.NO_FILE);
|
||||
subMonitor.done();
|
||||
return false;
|
||||
}
|
||||
subMonitor.done();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class ExpressionPosition {
|
||||
public int start;
|
||||
public int end;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Position ranges from %d to %d and has a length of %d", Integer.valueOf(start), //$NON-NLS-1$
|
||||
Integer.valueOf(end), Integer.valueOf(end - start));
|
||||
}
|
||||
}
|
||||
|
||||
protected static ExpressionPosition createExpressionPosition(IASTNode expression) {
|
||||
ExpressionPosition selection = new ExpressionPosition();
|
||||
|
||||
int nodeLength = 0;
|
||||
IASTNodeLocation[] nodeLocations = expression.getNodeLocations();
|
||||
if (nodeLocations.length != 1) {
|
||||
for (IASTNodeLocation location : nodeLocations) {
|
||||
if (location instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||
selection.start = macroLoc.asFileLocation().getNodeOffset();
|
||||
nodeLength = macroLoc.asFileLocation().getNodeLength();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nodeLocations[0] instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) nodeLocations[0];
|
||||
selection.start = macroLoc.asFileLocation().getNodeOffset();
|
||||
nodeLength = macroLoc.asFileLocation().getNodeLength();
|
||||
} else {
|
||||
IASTFileLocation loc = expression.getFileLocation();
|
||||
selection.start = loc.getNodeOffset();
|
||||
nodeLength = loc.getNodeLength();
|
||||
}
|
||||
}
|
||||
selection.end = selection.start + nodeLength;
|
||||
return selection;
|
||||
}
|
||||
|
||||
protected boolean isExpressionWhollyInSelection(ITextSelection textSelection, IASTNode expression) {
|
||||
ExpressionPosition exprPos = createExpressionPosition(expression);
|
||||
|
||||
int selStart = textSelection.getOffset();
|
||||
int selEnd = textSelection.getLength() + selStart;
|
||||
|
||||
return exprPos.start >= selStart && exprPos.end <= selEnd;
|
||||
}
|
||||
|
||||
public static boolean isSelectionOnExpression(ITextSelection textSelection, IASTNode expression) {
|
||||
ExpressionPosition exprPos = createExpressionPosition(expression);
|
||||
int selStart = textSelection.getOffset();
|
||||
int selEnd = textSelection.getLength() + selStart;
|
||||
return exprPos.end > selStart && exprPos.start < selEnd;
|
||||
}
|
||||
|
||||
protected boolean isInSameFile(IASTNode node) {
|
||||
IPath path = new Path(node.getContainingFilename());
|
||||
IFile locFile = ResourcesPlugin.getWorkspace().getRoot().getFile(file.getLocation());
|
||||
IFile tmpFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
return locFile.equals(tmpFile);
|
||||
}
|
||||
|
||||
protected boolean isInSameFileSelection(ITextSelection textSelection, IASTNode node) {
|
||||
if( isInSameFile(node) ) {
|
||||
return isSelectionOnExpression(textSelection, node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected MethodContext findContext(IASTNode node) {
|
||||
boolean found = false;
|
||||
MethodContext context = new MethodContext();
|
||||
context.setType(MethodContext.ContextType.NONE);
|
||||
IASTName name = null;
|
||||
while(node != null && !found){
|
||||
node = node.getParent();
|
||||
if(node instanceof IASTFunctionDeclarator){
|
||||
name=((IASTFunctionDeclarator)node).getName();
|
||||
found = true;
|
||||
context.setType(MethodContext.ContextType.FUNCTION);
|
||||
} else if (node instanceof IASTFunctionDefinition){
|
||||
name=((IASTFunctionDefinition)node).getDeclarator().getName();
|
||||
found = true;
|
||||
context.setType(MethodContext.ContextType.FUNCTION);
|
||||
}
|
||||
}
|
||||
if(name instanceof ICPPASTQualifiedName){
|
||||
ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name;
|
||||
context.setMethodQName(qname);
|
||||
IBinding bind = qname.resolveBinding();
|
||||
IASTName[] decl = unit.getDeclarationsInAST(bind);//TODO HSR funktioniert nur fuer namen aus der aktuellen Translationunit
|
||||
for (IASTName tmpname : decl) {
|
||||
IASTNode methoddefinition = tmpname.getParent().getParent();
|
||||
if (methoddefinition instanceof IASTSimpleDeclaration) {
|
||||
context.setMethodDeclarationName(tmpname);
|
||||
context.setType(MethodContext.ContextType.METHOD);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
protected boolean translationUnitHasProblem() {
|
||||
ProblemFinder pf = new ProblemFinder(initStatus);
|
||||
unit.accept(pf);
|
||||
return pf.hasProblem();
|
||||
}
|
||||
|
||||
protected boolean translationUnitIsAmbiguous() {
|
||||
AmbiguityFinder af = new AmbiguityFinder();
|
||||
unit.accept(af);
|
||||
return af.ambiguityFound();
|
||||
}
|
||||
|
||||
public void lockIndex() throws CoreException, InterruptedException {
|
||||
if (fIndex == null) {
|
||||
ICProject[] projects= CoreModel.getDefault().getCModel().getCProjects();
|
||||
fIndex= CCorePlugin.getIndexManager().getIndex(projects);
|
||||
}
|
||||
fIndex.acquireReadLock();
|
||||
}
|
||||
|
||||
public void unlockIndex() {
|
||||
if (fIndex != null) {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
fIndex= null;
|
||||
}
|
||||
|
||||
public IIndex getIndex() {
|
||||
return fIndex;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
|
||||
import org.eclipse.cdt.ui.refactoring.CTextFileChange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ICTextFileChangeFactory;
|
||||
|
||||
/**
|
||||
* Factory provided to the core plugin to create appropriate text file changes.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class CTextFileChangeFactory implements ICTextFileChangeFactory {
|
||||
|
||||
public TextFileChange createCTextFileChange(IFile file) {
|
||||
return new CTextFileChange(file.getName(), file);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
public class Container<T>{
|
||||
private T object;
|
||||
|
||||
public Container(T object) {
|
||||
super();
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public Container() {
|
||||
super();
|
||||
this.object = null;
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(T object) {
|
||||
this.object = object;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class CreateFileChange extends Change {
|
||||
|
||||
private String name;
|
||||
private final IPath path;
|
||||
private final String source;
|
||||
private final String encoding;
|
||||
|
||||
|
||||
|
||||
public CreateFileChange(String name, IPath path, String source, String encoding) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
this.source = source;
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public CreateFileChange(IPath path, String source, String encoding) {
|
||||
this(null, path, source, encoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModifiedElement() {
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if(name == null) {
|
||||
return NLS.bind(Messages.CreateFileChange_CreateFile, path.toOSString());
|
||||
}else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeValidationData(IProgressMonitor pm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
|
||||
OperationCanceledException {
|
||||
RefactoringStatus result= new RefactoringStatus();
|
||||
IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
|
||||
URI location= file.getLocationURI();
|
||||
if (location == null) {
|
||||
result.addFatalError(NLS.bind(Messages.CreateFileChange_UnknownLoc, file.getFullPath().toString()));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
result.addFatalError( NLS.bind(Messages.CreateFileChange_FileExists,
|
||||
file.getFullPath().toString()));
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change perform(IProgressMonitor pm) throws CoreException {
|
||||
IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
InputStream is = new ByteArrayInputStream(source.getBytes());
|
||||
file.create(is, false, new SubProgressMonitor(pm, 1));
|
||||
if(encoding != null) {
|
||||
file.setCharset(encoding, new SubProgressMonitor(pm,1));
|
||||
}
|
||||
return new DeleteFileChange(file.getFullPath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class DeleteFileChange extends Change {
|
||||
|
||||
private IPath path;
|
||||
private String source;
|
||||
|
||||
public DeleteFileChange(IPath path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModifiedElement() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Messages.DeleteFileChange_0 + path.toOSString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initializeValidationData(IProgressMonitor pm) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
|
||||
OperationCanceledException {
|
||||
RefactoringStatus status = new RefactoringStatus();
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
if(!file.exists()) {
|
||||
status.addFatalError(Messages.DeleteFileChange_1 + path.toString());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private String getSource(IFile file) throws CoreException {
|
||||
String encoding= null;
|
||||
try {
|
||||
encoding= file.getCharset();
|
||||
} catch (CoreException ex) {
|
||||
// fall through. Take default encoding.
|
||||
}
|
||||
StringBuffer sb= new StringBuffer();
|
||||
BufferedReader br= null;
|
||||
InputStream in= null;
|
||||
try {
|
||||
in= file.getContents();
|
||||
if (encoding != null)
|
||||
br= new BufferedReader(new InputStreamReader(in, encoding));
|
||||
else
|
||||
br= new BufferedReader(new InputStreamReader(in));
|
||||
int read= 0;
|
||||
while ((read= br.read()) != -1) {
|
||||
sb.append((char) read);
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e){
|
||||
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change perform(IProgressMonitor pm) throws CoreException {
|
||||
IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
source = getSource(file);
|
||||
Change undo = new CreateFileChange(file.getFullPath(), source, file.getCharset());
|
||||
file.delete(true,true, pm);
|
||||
return undo;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,493 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.filebuffers.FileBuffers;
|
||||
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
||||
import org.eclipse.core.filebuffers.ITextFileBufferManager;
|
||||
import org.eclipse.core.filebuffers.LocationKind;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourceAttributes;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DefaultLineTracker;
|
||||
import org.eclipse.jface.text.DocumentEvent;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentListener;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.BufferChangedEvent;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IBufferChangedListener;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Adapts <code>IDocument</code> to <code>IBuffer</code>. Uses the
|
||||
* same algorithm as the text widget to determine the buffer's line delimiter.
|
||||
* All text inserted into the buffer is converted to this line delimiter.
|
||||
* This class is <code>public</code> for test purposes only.
|
||||
*
|
||||
* This class is similar to the JDT DocumentAdapter class.
|
||||
*/
|
||||
public class DocumentAdapter implements IBuffer, IAdaptable, IDocumentListener {
|
||||
|
||||
/**
|
||||
* Executes a document set content call in the ui thread.
|
||||
*/
|
||||
protected class DocumentSetCommand implements Runnable {
|
||||
|
||||
private String fContents;
|
||||
|
||||
public void run() {
|
||||
fDocument.set(fContents);
|
||||
}
|
||||
|
||||
public void set(String contents) {
|
||||
fContents= contents;
|
||||
Display.getDefault().syncExec(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a document replace call in the ui thread.
|
||||
*/
|
||||
protected class DocumentReplaceCommand implements Runnable {
|
||||
|
||||
private int fOffset;
|
||||
private int fLength;
|
||||
private String fText;
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
fDocument.replace(fOffset, fLength, fText);
|
||||
} catch (BadLocationException x) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public void replace(int offset, int length, String text) {
|
||||
fOffset= offset;
|
||||
fLength= length;
|
||||
fText= text;
|
||||
Display.getDefault().syncExec(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static final boolean DEBUG_LINE_DELIMITERS= true;
|
||||
public static final IBuffer NULL_BUFFER = new IBuffer(){
|
||||
public void addBufferChangedListener(IBufferChangedListener listener) {}
|
||||
public void append(char[] text) {}
|
||||
public void append(String text) {}
|
||||
public void close() {}
|
||||
public char getChar(int position) {return 0;}
|
||||
public char[] getCharacters() {return new char[0];}
|
||||
public String getContents() {return "";} //$NON-NLS-1$
|
||||
public int getLength() {return 0;}
|
||||
public IOpenable getOwner() {return null;}
|
||||
public String getText(int offset, int length) {return "";} //$NON-NLS-1$
|
||||
public IResource getUnderlyingResource() {return null;}
|
||||
public boolean hasUnsavedChanges() {return false;}
|
||||
public boolean isClosed() {return false;}
|
||||
public boolean isReadOnly() {return true;}
|
||||
public void removeBufferChangedListener(IBufferChangedListener listener) {}
|
||||
public void replace(int position, int length, char[] text) {}
|
||||
public void replace(int position, int length, String text) {}
|
||||
public void save(IProgressMonitor progress, boolean force) throws CModelException {}
|
||||
public void setContents(char[] contents) {}
|
||||
public void setContents(String contents) {}
|
||||
};
|
||||
|
||||
public static IBufferFactory FACTORY= new IBufferFactory() {
|
||||
public IBuffer createBuffer(IOpenable owner) {
|
||||
if (owner instanceof IWorkingCopy) {
|
||||
IWorkingCopy wc= (IWorkingCopy) owner;
|
||||
ITranslationUnit tu= wc.getOriginalElement();
|
||||
if (tu != null) {
|
||||
IResource r= tu.getResource();
|
||||
if (r instanceof IFile) {
|
||||
return new DocumentAdapter(wc, (IFile) r);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert false;
|
||||
return DocumentAdapter.NULL_BUFFER;
|
||||
}
|
||||
};
|
||||
|
||||
private ITranslationUnit fTranslationUnit;
|
||||
private IWorkingCopy fOwner;
|
||||
private IFile fFile;
|
||||
private ITextFileBuffer fTextFileBuffer;
|
||||
IDocument fDocument;
|
||||
|
||||
private DocumentSetCommand fSetCmd= new DocumentSetCommand();
|
||||
private DocumentReplaceCommand fReplaceCmd= new DocumentReplaceCommand();
|
||||
|
||||
private Set<String> fLegalLineDelimiters;
|
||||
|
||||
private List<IBufferChangedListener> fBufferListeners= new ArrayList<IBufferChangedListener>(3);
|
||||
private IStatus fStatus;
|
||||
|
||||
|
||||
public DocumentAdapter(IWorkingCopy owner, IFile file) {
|
||||
fOwner= owner;
|
||||
fFile= file;
|
||||
fTranslationUnit= owner.getOriginalElement();
|
||||
if (fTranslationUnit != null) {
|
||||
addBufferChangedListener(fTranslationUnit);
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
IPath location= fFile.getFullPath();
|
||||
try {
|
||||
manager.connect(location, LocationKind.IFILE, new NullProgressMonitor());
|
||||
fTextFileBuffer= manager.getTextFileBuffer(location, LocationKind.IFILE);
|
||||
fDocument= fTextFileBuffer.getDocument();
|
||||
} catch (CoreException x) {
|
||||
fStatus= x.getStatus();
|
||||
fDocument= manager.createEmptyDocument(location, LocationKind.IFILE);
|
||||
}
|
||||
fDocument.addPrenotifiedDocumentListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of this document adapter.
|
||||
*/
|
||||
public IStatus getStatus() {
|
||||
if (fStatus != null)
|
||||
return fStatus;
|
||||
if (fTextFileBuffer != null)
|
||||
return fTextFileBuffer.getStatus();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapted document.
|
||||
*
|
||||
* @return the adapted document
|
||||
*/
|
||||
public IDocument getDocument() {
|
||||
return fDocument;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBuffer#addBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
public void addBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
if (!fBufferListeners.contains(listener))
|
||||
fBufferListeners.add(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBuffer#removeBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
public void removeBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
fBufferListeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#append(char[])
|
||||
*/
|
||||
public void append(char[] text) {
|
||||
append(new String(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#append(java.lang.String)
|
||||
*/
|
||||
public void append(String text) {
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(text);
|
||||
}
|
||||
fReplaceCmd.replace(fDocument.getLength(), 0, text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#close()
|
||||
*/
|
||||
public void close() {
|
||||
|
||||
if (isClosed())
|
||||
return;
|
||||
|
||||
IDocument d= fDocument;
|
||||
fDocument= null;
|
||||
d.removePrenotifiedDocumentListener(this);
|
||||
|
||||
if (fTextFileBuffer != null) {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
manager.disconnect(fTextFileBuffer.getLocation(), LocationKind.IFILE, new NullProgressMonitor());
|
||||
} catch (CoreException x) {
|
||||
// ignore
|
||||
}
|
||||
fTextFileBuffer= null;
|
||||
}
|
||||
|
||||
fireBufferChanged(new BufferChangedEvent(this, 0, 0, null));
|
||||
fBufferListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getChar(int)
|
||||
*/
|
||||
public char getChar(int position) {
|
||||
try {
|
||||
return fDocument.getChar(position);
|
||||
} catch (BadLocationException x) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getCharacters()
|
||||
*/
|
||||
public char[] getCharacters() {
|
||||
String content= getContents();
|
||||
return content == null ? null : content.toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getContents()
|
||||
*/
|
||||
public String getContents() {
|
||||
return fDocument.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getLength()
|
||||
*/
|
||||
public int getLength() {
|
||||
return fDocument.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getOwner()
|
||||
*/
|
||||
public IOpenable getOwner() {
|
||||
return fOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getText(int, int)
|
||||
*/
|
||||
public String getText(int offset, int length) {
|
||||
try {
|
||||
return fDocument.get(offset, length);
|
||||
} catch (BadLocationException x) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getUnderlyingResource()
|
||||
*/
|
||||
public IResource getUnderlyingResource() {
|
||||
return fFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#hasUnsavedChanges()
|
||||
*/
|
||||
public boolean hasUnsavedChanges() {
|
||||
return fTextFileBuffer != null ? fTextFileBuffer.isDirty() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#isClosed()
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return fDocument == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#isReadOnly()
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
IResource resource= getUnderlyingResource();
|
||||
if (resource != null) {
|
||||
ResourceAttributes attributes = resource.getResourceAttributes();
|
||||
if (attributes != null) {
|
||||
return attributes.isReadOnly();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, char[])
|
||||
*/
|
||||
public void replace(int position, int length, char[] text) {
|
||||
replace(position, length, new String(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, java.lang.String)
|
||||
*/
|
||||
public void replace(int position, int length, String text) {
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(text);
|
||||
}
|
||||
fReplaceCmd.replace(position, length, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
|
||||
*/
|
||||
public void save(IProgressMonitor progress, boolean force) throws CModelException {
|
||||
try {
|
||||
if (fTextFileBuffer != null)
|
||||
fTextFileBuffer.commit(progress, force);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#setContents(char[])
|
||||
*/
|
||||
public void setContents(char[] contents) {
|
||||
setContents(new String(contents));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#setContents(java.lang.String)
|
||||
*/
|
||||
public void setContents(String contents) {
|
||||
int oldLength= fDocument.getLength();
|
||||
|
||||
if (contents == null) {
|
||||
|
||||
if (oldLength != 0)
|
||||
fSetCmd.set(""); //$NON-NLS-1$
|
||||
|
||||
} else {
|
||||
// set only if different
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(contents);
|
||||
}
|
||||
|
||||
int newLength= contents.length();
|
||||
if (oldLength != newLength || !contents.equals(fDocument.get()))
|
||||
fSetCmd.set(contents);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void validateLineDelimiters(String contents) {
|
||||
|
||||
if (fLegalLineDelimiters == null) {
|
||||
// collect all line delimiters in the document
|
||||
HashSet<String> existingDelimiters= new HashSet<String>();
|
||||
|
||||
for (int i= fDocument.getNumberOfLines() - 1; i >= 0; i-- ) {
|
||||
try {
|
||||
String curr= fDocument.getLineDelimiter(i);
|
||||
if (curr != null) {
|
||||
existingDelimiters.add(curr);
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
if (existingDelimiters.isEmpty()) {
|
||||
return; // first insertion of a line delimiter: no test
|
||||
}
|
||||
fLegalLineDelimiters= existingDelimiters;
|
||||
|
||||
}
|
||||
|
||||
DefaultLineTracker tracker= new DefaultLineTracker();
|
||||
tracker.set(contents);
|
||||
|
||||
int lines= tracker.getNumberOfLines();
|
||||
if (lines <= 1)
|
||||
return;
|
||||
|
||||
for (int i= 0; i < lines; i++) {
|
||||
try {
|
||||
String curr= tracker.getLineDelimiter(i);
|
||||
if (curr != null && !fLegalLineDelimiters.contains(curr)) {
|
||||
StringBuffer buf= new StringBuffer("New line delimiter added to new code: "); //$NON-NLS-1$
|
||||
for (int k= 0; k < curr.length(); k++) {
|
||||
buf.append(String.valueOf((int) curr.charAt(k)));
|
||||
}
|
||||
CCorePlugin.log(new Exception(buf.toString()));
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
|
||||
*/
|
||||
public void documentAboutToBeChanged(DocumentEvent event) {
|
||||
// there is nothing to do here
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentListener#documentChanged(DocumentEvent)
|
||||
*/
|
||||
public void documentChanged(DocumentEvent event) {
|
||||
fireBufferChanged(new BufferChangedEvent(this, event.getOffset(), event.getLength(), event.getText()));
|
||||
}
|
||||
|
||||
private void fireBufferChanged(BufferChangedEvent event) {
|
||||
if (fBufferListeners != null && fBufferListeners.size() > 0) {
|
||||
Iterator<IBufferChangedListener> e= new ArrayList<IBufferChangedListener>(fBufferListeners).iterator();
|
||||
while (e.hasNext())
|
||||
e.next().bufferChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
public ITextFileBuffer getTextFileBuffer() {
|
||||
return fTextFileBuffer;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class adapter) {
|
||||
if (adapter.isAssignableFrom(ITextFileBuffer.class)) {
|
||||
return fTextFileBuffer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public final class Messages extends NLS {
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.refactoring.messages";//$NON-NLS-1$
|
||||
|
||||
private Messages() {
|
||||
// Do not instantiate
|
||||
}
|
||||
|
||||
public static String DeleteFileChange_0;
|
||||
public static String DeleteFileChange_1;
|
||||
public static String HSRRefactoring_name;
|
||||
public static String HSRRefactoring_PM_LoadTU;
|
||||
public static String HSRRefactoring_PM_CheckTU;
|
||||
public static String HSRRefactoring_PM_InitRef;
|
||||
public static String HSRRefactoring_PM_ParseTU;
|
||||
public static String HSRRefactoring_PM_MergeComments;
|
||||
public static String HSRRefactoring_CanceledByUser;
|
||||
public static String HSRRefactoring_CompileErrorInTU;
|
||||
public static String AddDeclarationNodeToClassChange_AddDeclaration;
|
||||
public static String CreateFileChange_CreateFile;
|
||||
public static String CreateFileChange_UnknownLoc;
|
||||
public static String CreateFileChange_FileExists;
|
||||
public static String HSRRefactoring_SelectionNotValid;
|
||||
public static String HSRRefactoring_CantLoadTU;
|
||||
public static String HSRRefactoring_Ambiguity;
|
||||
public static String NO_FILE;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
|
||||
public class MethodContext {
|
||||
public enum ContextType{ NONE, FUNCTION, METHOD }
|
||||
|
||||
private ContextType type;
|
||||
private IASTName declarationName;
|
||||
private ICPPASTQualifiedName qname;
|
||||
|
||||
public ContextType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ContextType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setMethodDeclarationName(IASTName tmpname) {
|
||||
this.declarationName=tmpname;
|
||||
}
|
||||
|
||||
public IASTName getMethodDeclarationName(){
|
||||
return declarationName;
|
||||
}
|
||||
|
||||
public IASTSimpleDeclaration getMethodDeclaration(){
|
||||
IASTNode parent = declarationName.getParent().getParent();
|
||||
if (parent instanceof IASTSimpleDeclaration) {
|
||||
return (IASTSimpleDeclaration) parent;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ICPPASTVisiblityLabel getMethodDeclarationASTVisibility(){
|
||||
ICPPASTVisiblityLabel label = new CPPASTVisibilityLabel();
|
||||
ICPPMember member = ((ICPPMember)qname.resolveBinding());
|
||||
|
||||
try {
|
||||
label.setVisibility(member.getVisibility());
|
||||
} catch (DOMException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public Visibility getMethodDeclarationVisibility(){
|
||||
return Visibility.getVisibility(declarationName);
|
||||
}
|
||||
|
||||
public void setMethodQName(ICPPASTQualifiedName qname) {
|
||||
this.qname = qname;
|
||||
}
|
||||
|
||||
public ICPPASTQualifiedName getMethodQName() {
|
||||
return qname;
|
||||
}
|
||||
|
||||
public static boolean isSameClass(ICPPASTQualifiedName qname1, ICPPASTQualifiedName qname2) {
|
||||
ICPPInternalBinding bind1 = getClassBinding(qname1);
|
||||
ICPPInternalBinding bind2 = getClassBinding(qname2);
|
||||
return isSameClass(bind1,bind2);
|
||||
}
|
||||
|
||||
public static boolean isSameOrSubClass(MethodContext context1, MethodContext contextOfSameOrSubclass) {
|
||||
ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
|
||||
ICPPInternalBinding subclassBind = getICPPInternalBinding(contextOfSameOrSubclass);
|
||||
if(isSameClass(bind1,subclassBind)){
|
||||
return true;
|
||||
} else {
|
||||
return isSubclass(bind1,subclassBind);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSubclass(ICPPInternalBinding bind1, ICPPInternalBinding subclassBind) {
|
||||
if (subclassBind instanceof ICPPClassType) {
|
||||
ICPPClassType classType = (ICPPClassType) subclassBind;
|
||||
ICPPBase[] bases;
|
||||
try {
|
||||
bases = classType.getBases();
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
for (ICPPBase base : bases) {
|
||||
if(isSameClass(base,bind1)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSameClass(MethodContext context1, MethodContext context2) {
|
||||
ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
|
||||
ICPPInternalBinding bind2 = getICPPInternalBinding(context2);
|
||||
|
||||
return isSameClass(bind1,bind2);
|
||||
}
|
||||
|
||||
private static boolean isSameClass(ICPPBase base, ICPPInternalBinding bind2) {
|
||||
try {
|
||||
IBinding bind1 = base.getBaseClass();
|
||||
IScope scope1 = bind1.getScope();
|
||||
if(scope1 == null)
|
||||
return false;
|
||||
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
||||
|
||||
IScope scope2 = bind2.getScope();
|
||||
if(scope2 == null)
|
||||
return false;
|
||||
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
||||
|
||||
if( node1.equals(node2) ){
|
||||
if (bind1 instanceof ICPPInternalBinding) {
|
||||
ICPPInternalBinding bind1int = (ICPPInternalBinding) bind1;
|
||||
return bind1int.getDefinition().equals(bind2.getDefinition());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSameClass(ICPPInternalBinding bind1, ICPPInternalBinding bind2) {
|
||||
try {
|
||||
IScope scope1 = bind1.getScope();
|
||||
if(scope1 == null)
|
||||
return false;
|
||||
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
||||
|
||||
IScope scope2 = bind2.getScope();
|
||||
if(scope2 == null)
|
||||
return false;
|
||||
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
||||
|
||||
if( node1.equals(node2) ){
|
||||
return bind1.getDefinition().equals(bind2.getDefinition());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ICPPInternalBinding getICPPInternalBinding(MethodContext context) {
|
||||
IASTName decl = context.getMethodDeclarationName();
|
||||
IASTNode node = decl;
|
||||
while(node != null){
|
||||
if (node instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier type = (ICPPASTCompositeTypeSpecifier) node;
|
||||
IASTName classname = type.getName();
|
||||
ICPPInternalBinding bind = (ICPPInternalBinding)classname.resolveBinding();
|
||||
|
||||
return bind;
|
||||
}
|
||||
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ICPPInternalBinding getClassBinding(ICPPASTQualifiedName qname){
|
||||
IASTName classname = qname.getNames()[qname.getNames().length - 2];
|
||||
ICPPInternalBinding bind = (ICPPInternalBinding)classname.resolveBinding();
|
||||
return bind;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
|
||||
/**
|
||||
* @author Mirko Stocker
|
||||
*
|
||||
* A ModificationCollector can be passed through a refactoring and manages the rewriters
|
||||
* and additional changes a refactoring can create.
|
||||
*/
|
||||
public class ModificationCollector {
|
||||
|
||||
// Each Translationunit can have only one ASTRewrite
|
||||
private final Map<IASTTranslationUnit, ASTRewrite> rewriters = new HashMap<IASTTranslationUnit, ASTRewrite>();
|
||||
|
||||
private Collection<CreateFileChange> changes;
|
||||
|
||||
public ASTRewrite rewriterForTranslationUnit(IASTTranslationUnit unit) {
|
||||
if(! rewriters.containsKey(unit)) {
|
||||
rewriters.put(unit, ASTRewrite.create(unit));
|
||||
}
|
||||
|
||||
return rewriters.get(unit);
|
||||
}
|
||||
|
||||
// Creating new files doesn't concern the rewriter, the refactorings can add them here as needed.
|
||||
public void addFileChange(CreateFileChange change) {
|
||||
if(changes == null) {
|
||||
changes = new ArrayList<CreateFileChange>();
|
||||
}
|
||||
changes.add(change);
|
||||
}
|
||||
|
||||
public CompositeChange createFinalChange() {
|
||||
// Synthetic changes aren't displayed and therefore don't need a name
|
||||
CompositeChange result = new CompositeChange(""); //$NON-NLS-1$
|
||||
result.markAsSynthetic();
|
||||
|
||||
if(changes != null)
|
||||
result.addAll(changes.toArray(new Change[changes.size()]));
|
||||
|
||||
for (ASTRewrite each : rewriters.values()) {
|
||||
result.add(each.rewriteAST());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
public class NameNVisibilityInformation {
|
||||
|
||||
private String name = ""; //$NON-NLS-1$
|
||||
private VisibilityEnum visibility = VisibilityEnum.v_public;
|
||||
private final Vector<String> usedNames = new Vector<String>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public VisibilityEnum getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public void setVisibility(VisibilityEnum visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public Vector<String> getUsedNames(){
|
||||
return usedNames;
|
||||
}
|
||||
|
||||
public void addNameToUsedNames(String name) {
|
||||
usedNames.add(name);
|
||||
}
|
||||
|
||||
public void addNamesToUsedNames(Vector<String> names) {
|
||||
usedNames.addAll(names);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public abstract class RefactoringRunner {
|
||||
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected IWorkbenchWindow window;
|
||||
|
||||
public RefactoringRunner(IFile file, ISelection selection, IWorkbenchWindow window) {
|
||||
super();
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
if(window != null) {
|
||||
this.window = window;
|
||||
}else {
|
||||
this.window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 IBM Corporation and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.ContentStamp;
|
||||
import org.eclipse.ltk.core.refactoring.UndoTextFileChange;
|
||||
import org.eclipse.text.edits.MalformedTreeException;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.text.edits.UndoEdit;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
|
||||
/**
|
||||
* UndoCTextFileChange that uses a working copy in order to generate CModel events.
|
||||
* @author janees
|
||||
*/
|
||||
public class UndoCTextFileChange
|
||||
extends UndoTextFileChange {
|
||||
|
||||
UndoEdit mUndoEdit = null;
|
||||
|
||||
public UndoCTextFileChange(String name, IFile file, UndoEdit undo, ContentStamp stamp, int saveMode) {
|
||||
super(name, file, undo, stamp, saveMode);
|
||||
mUndoEdit = undo;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ltk.core.refactoring.UndoTextFileChange#perform(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
@Override
|
||||
public Change perform(IProgressMonitor pm)
|
||||
throws CoreException {
|
||||
if (pm == null){
|
||||
pm= new NullProgressMonitor();
|
||||
}
|
||||
Object obj = getModifiedElement();
|
||||
if(!(obj instanceof IFile)){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
final IFile file = (IFile) obj;
|
||||
ICElement element = CoreModel.getDefault().create(file);
|
||||
if (!(element instanceof ITranslationUnit)) {
|
||||
return super.perform(pm);
|
||||
}
|
||||
|
||||
final ITranslationUnit tu = (ITranslationUnit) element;
|
||||
IWorkingCopy wc= tu.getWorkingCopy(pm, DocumentAdapter.FACTORY);
|
||||
final IBuffer buffer= wc.getBuffer();
|
||||
assert buffer instanceof DocumentAdapter;
|
||||
if (buffer instanceof DocumentAdapter) {
|
||||
IDocument document= ((DocumentAdapter) buffer).getDocument();
|
||||
try {
|
||||
UndoEdit redo= mUndoEdit.apply(document, TextEdit.CREATE_UNDO);
|
||||
wc.commit(false, pm);
|
||||
return new UndoCTextFileChange(getName(), file, redo, null, getSaveMode());
|
||||
} catch (MalformedTreeException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (BadLocationException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
finally {
|
||||
wc.destroy();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
|
||||
public class Visibility {
|
||||
|
||||
/**
|
||||
* The visibility public.
|
||||
*/
|
||||
public static final Visibility PUBLIC = new Visibility(){
|
||||
@Override
|
||||
public String stringValue(){
|
||||
return "public"; //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The visibility protected.
|
||||
*/
|
||||
public static final Visibility PROTECTED = new Visibility(){
|
||||
@Override
|
||||
public String stringValue(){
|
||||
return "protected"; //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The visibility private.
|
||||
*/
|
||||
public static final Visibility PRIVATE = new Visibility(){
|
||||
@Override
|
||||
public String stringValue(){
|
||||
return "private"; //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The visibility unknown, cause of parsing error.
|
||||
*/
|
||||
public static final Visibility UNKNOWN = new Visibility(){ };
|
||||
|
||||
|
||||
|
||||
private Visibility(){ }
|
||||
|
||||
public static Visibility getVisibility(IASTName name){
|
||||
try {
|
||||
ICPPMember member = ((ICPPMember)name.resolveBinding());
|
||||
|
||||
switch (member.getVisibility()){
|
||||
case ICPPASTVisiblityLabel.v_public:
|
||||
return PUBLIC;
|
||||
case ICPPASTVisiblityLabel.v_protected:
|
||||
return PROTECTED;
|
||||
case ICPPASTVisiblityLabel.v_private:
|
||||
return PRIVATE;
|
||||
default:
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
} catch (DOMException e) {
|
||||
return UNKNOWN;
|
||||
} catch (RuntimeException e){
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public String stringValue(){
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringValue();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.eclipse.compare.CompareConfiguration;
|
||||
import org.eclipse.compare.CompareViewerPane;
|
||||
import org.eclipse.compare.IEncodedStreamContentAccessor;
|
||||
import org.eclipse.compare.IResourceProvider;
|
||||
import org.eclipse.compare.ITypedElement;
|
||||
import org.eclipse.compare.contentmergeviewer.IMergeViewerContentProvider;
|
||||
import org.eclipse.compare.structuremergeviewer.DiffNode;
|
||||
import org.eclipse.compare.structuremergeviewer.ICompareInput;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.TextViewer;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
|
||||
import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.refactoring.CTextFileChange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.compare.CMergeViewer;
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class CTextEditChangePreviewViewer implements IChangePreviewViewer {
|
||||
|
||||
private CPPMergeViewer viewer;
|
||||
private CTextEditChangePane viewerPane;
|
||||
private CTextEditChangePreviewViewerContentProvider textEditChangeContentProvider;
|
||||
|
||||
private static class CTextEditChangePane extends CompareViewerPane{
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param style
|
||||
*/
|
||||
public CTextEditChangePane(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class CPPMergeViewer extends CMergeViewer{
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param styles
|
||||
* @param mp
|
||||
*/
|
||||
public CPPMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
|
||||
super(parent, styles, mp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CSourceViewerConfiguration getSourceViewerConfiguration() {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||
return new CSourceViewerConfiguration(tools.getColorManager(), store, null, tools.getDocumentPartitioning());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureTextViewer(TextViewer textViewer) {
|
||||
if (textViewer instanceof SourceViewer) {
|
||||
((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class CTextEditChangePreviewViewerContentProvider implements IMergeViewerContentProvider{
|
||||
|
||||
public Object getAncestorContent(Object input) {
|
||||
if (input instanceof ICompareInput)
|
||||
return ((ICompareInput) input).getAncestor();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Image getAncestorImage(Object input) {
|
||||
if (input instanceof ICompareInput) {
|
||||
ITypedElement ancestor = ((ICompareInput) input).getAncestor();
|
||||
if(ancestor != null) {
|
||||
return ancestor.getImage();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAncestorLabel(Object input) {
|
||||
if (input instanceof ICompareInput) {
|
||||
ITypedElement ancestor = ((ICompareInput) input).getAncestor();
|
||||
if(ancestor != null) {
|
||||
return ancestor.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getLeftContent(Object input) {
|
||||
if (input instanceof ICompareInput)
|
||||
return ((ICompareInput) input).getLeft();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Image getLeftImage(Object input) {
|
||||
if (input instanceof ICompareInput)
|
||||
return ((ICompareInput) input).getLeft().getImage();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLeftLabel(Object input) {
|
||||
return Messages.CTextEditChangePreviewViewer_OrgSource;
|
||||
}
|
||||
|
||||
public Object getRightContent(Object input) {
|
||||
if (input instanceof ICompareInput)
|
||||
return ((ICompareInput) input).getRight();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Image getRightImage(Object input) {
|
||||
if (input instanceof ICompareInput)
|
||||
return ((ICompareInput) input).getRight().getImage();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getRightLabel(Object input) {
|
||||
return Messages.CTextEditChangePreviewViewer_RefactoredSource;
|
||||
}
|
||||
|
||||
public boolean isLeftEditable(Object input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRightEditable(Object input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void saveLeftContent(Object input, byte[] bytes) {
|
||||
//No Edits
|
||||
}
|
||||
|
||||
public void saveRightContent(Object input, byte[] bytes) {
|
||||
//No Edits
|
||||
}
|
||||
|
||||
public boolean showAncestor(Object input) {
|
||||
//no Ancestor
|
||||
return false;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
//
|
||||
}
|
||||
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class CompareElement implements ITypedElement, IEncodedStreamContentAccessor, IResourceProvider {
|
||||
private static final String ENCODING= "UTF-8"; //$NON-NLS-1$
|
||||
private final String fContent;
|
||||
private final String fType;
|
||||
private final IResource fResource;
|
||||
public CompareElement(String content, String type, IResource resource) {
|
||||
fContent= content;
|
||||
fType= type;
|
||||
fResource= resource;
|
||||
}
|
||||
public String getName() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
public Image getImage() {
|
||||
return null;
|
||||
}
|
||||
public String getType() {
|
||||
return fType;
|
||||
}
|
||||
public InputStream getContents() throws CoreException {
|
||||
try {
|
||||
return new ByteArrayInputStream(fContent.getBytes(ENCODING));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return new ByteArrayInputStream(fContent.getBytes());
|
||||
}
|
||||
}
|
||||
public String getCharset() {
|
||||
return ENCODING;
|
||||
}
|
||||
public IResource getResource() {
|
||||
return fResource;
|
||||
}
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
CompareConfiguration compConfig = new CompareConfiguration();
|
||||
compConfig.setLeftEditable(false);
|
||||
compConfig.setRightEditable(false);
|
||||
viewerPane = new CTextEditChangePane(parent, SWT.BORDER | SWT.FLAT);
|
||||
viewer = new CPPMergeViewer(viewerPane,SWT.MULTI | SWT.FULL_SELECTION, compConfig);
|
||||
textEditChangeContentProvider = new CTextEditChangePreviewViewerContentProvider();
|
||||
viewer.setContentProvider(textEditChangeContentProvider);
|
||||
viewerPane.setContent(viewer.getControl());
|
||||
}
|
||||
|
||||
public Control getControl() {
|
||||
return viewerPane;
|
||||
}
|
||||
|
||||
public void setInput(ChangePreviewViewerInput input) {
|
||||
try {
|
||||
Change change= input.getChange();
|
||||
if (change instanceof CTextFileChange) {
|
||||
CTextFileChange editChange= (CTextFileChange)change;
|
||||
setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()), editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
|
||||
return;
|
||||
} else {
|
||||
viewer.setInput(null);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
viewer.setInput(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setInput(CTextFileChange change, String left, String right, String type) {
|
||||
IFile resource = change.getFile();
|
||||
viewerPane.setText(resource.getName());
|
||||
viewerPane.setImage(new CElementLabelProvider().getImage(resource));
|
||||
viewer.setInput(new DiffNode(
|
||||
new CompareElement(left, type, resource),
|
||||
new CompareElement(right, type, resource)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
|
||||
import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CreateFileChange;
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.internal.ui.util.ViewerPane;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class CreateFileChangePreview implements IChangePreviewViewer {
|
||||
|
||||
private static class CreateFileChangePane extends ViewerPane{
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param style
|
||||
*/
|
||||
public CreateFileChangePane(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private CreateFileChangePane control;
|
||||
private SourceViewer srcViewer;
|
||||
private CTextTools textTools;
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
control = new CreateFileChangePane(parent, SWT.BORDER | SWT.FLAT);
|
||||
Dialog.applyDialogFont(control);
|
||||
srcViewer= new CSourceViewer(control, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, CUIPlugin.getDefault().getPreferenceStore());
|
||||
textTools = CUIPlugin.getDefault().getTextTools();
|
||||
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||
CSourceViewerConfiguration sourceViewerConfiguration = new CSourceViewerConfiguration(textTools.getColorManager(), store, null, textTools.getDocumentPartitioning());
|
||||
srcViewer.configure(sourceViewerConfiguration);
|
||||
srcViewer.setEditable(false);
|
||||
control.setContent(srcViewer.getControl());
|
||||
}
|
||||
|
||||
public Control getControl() {
|
||||
return control;
|
||||
}
|
||||
|
||||
public void setInput(ChangePreviewViewerInput input) {
|
||||
Assert.isNotNull(input);
|
||||
if(control != null) {
|
||||
Change change = input.getChange();
|
||||
if (change instanceof CreateFileChange) {
|
||||
CreateFileChange createFileChange = (CreateFileChange) change;
|
||||
control.setText(createFileChange.getName());
|
||||
Document document = new Document(createFileChange.getSource());
|
||||
textTools.setupCDocument(document);
|
||||
srcViewer.setDocument(document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
|
||||
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.swt.events.KeyAdapter;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public abstract class ExtractInputPage extends UserInputWizardPage {
|
||||
|
||||
protected NameAndVisibilityComposite control;
|
||||
protected NameNVisibilityInformation info;
|
||||
protected String label = Messages.ExtractInputPage_ReplaceInSubclass;
|
||||
protected String errorLabel = Messages.ExtractInputPage_EnterName;
|
||||
|
||||
public ExtractInputPage(String name, NameNVisibilityInformation info) {
|
||||
super(name);
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
control = new NameAndVisibilityComposite(parent, label);
|
||||
setTitle(getName());
|
||||
setPageComplete(false);
|
||||
control.getConstantNameText().addKeyListener(new KeyAdapter(){
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
info.setName(control.getConstantNameText().getText());
|
||||
checkName();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
for (Control buttons : control.getVisibiltyGroup().getChildren()) {
|
||||
buttons.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e) {
|
||||
String text = ((Button)e.getSource()).getText();
|
||||
visibilityChange(text);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
checkName();
|
||||
setControl(control);
|
||||
}
|
||||
|
||||
protected void checkName() {
|
||||
String methodName = control.getConstantNameText().getText();
|
||||
IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName);
|
||||
if(result.isCorrect()){
|
||||
setErrorMessage(null);
|
||||
setPageComplete(true);
|
||||
}
|
||||
else{
|
||||
setErrorMessage(NLS.bind(Messages.ExtractInputPage_CheckName, result.getMessage()));
|
||||
setPageComplete(false);
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected void verifyName(String name);
|
||||
|
||||
protected void visibilityChange(String visibilityText) {
|
||||
info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(visibilityText));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* @author Mirko Stocker
|
||||
*
|
||||
*/
|
||||
public class LabeledTextField extends Composite {
|
||||
|
||||
private final Text textField;
|
||||
|
||||
public LabeledTextField(Composite parent, String labelName, String textContent) {
|
||||
super(parent, SWT.NONE);
|
||||
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
layout.marginWidth = 0;
|
||||
setLayout(layout);
|
||||
|
||||
Label label = new Label(this, SWT.NONE);
|
||||
label.setText(labelName);
|
||||
label.setLayoutData(new GridData());
|
||||
|
||||
textField = new Text(this, SWT.BORDER |SWT.SINGLE);
|
||||
textField.setText(textContent);
|
||||
textField.selectAll();
|
||||
GridData textData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
textData.grabExcessHorizontalSpace = true;
|
||||
textField.setLayoutData(textData);
|
||||
}
|
||||
|
||||
public LabeledTextField(Composite parent, String labelName) {
|
||||
this(parent, labelName, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public Text getText() {
|
||||
return textField;
|
||||
}
|
||||
|
||||
public String getFieldContent(){
|
||||
return textField.getText();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public final class Messages extends NLS {
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.refactoring.dialogs.messages";//$NON-NLS-1$
|
||||
|
||||
private Messages() {
|
||||
// Do not instantiate
|
||||
}
|
||||
|
||||
public static String CTextEditChangePreviewViewer_OrgSource;
|
||||
public static String CTextEditChangePreviewViewer_RefactoredSource;
|
||||
public static String ExtractInputPage_ReplaceInSubclass;
|
||||
public static String ExtractInputPage_EnterName;
|
||||
public static String ExtractInputPage_CheckName;
|
||||
public static String VisibilitySelectionPanel_AccessModifier;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
public class NameAndVisibilityComposite extends Composite {
|
||||
|
||||
private LabeledTextField constantName;
|
||||
private final String labelName;
|
||||
private final VisibilitySelectionPanel visibilityPanel;
|
||||
|
||||
public NameAndVisibilityComposite(Composite parent, String labelName) {
|
||||
this(parent, labelName, VisibilityEnum.v_public);
|
||||
}
|
||||
|
||||
public NameAndVisibilityComposite(Composite parent, String labelName, VisibilityEnum defaultVisibility){
|
||||
|
||||
super(parent, SWT.NONE);
|
||||
|
||||
this.labelName = labelName;
|
||||
|
||||
setLayout(new GridLayout());
|
||||
|
||||
createNewMethodNameComposite(this);
|
||||
visibilityPanel = new VisibilitySelectionPanel(this, defaultVisibility,SWT.NONE);
|
||||
}
|
||||
|
||||
|
||||
public Text getConstantNameText() {
|
||||
return constantName.getText();
|
||||
}
|
||||
|
||||
public Group getVisibiltyGroup() {
|
||||
return visibilityPanel.getGroup();
|
||||
}
|
||||
|
||||
public void visibilityPanelsetVisible(boolean visible) {
|
||||
visibilityPanel.setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
private void createNewMethodNameComposite(Composite control) {
|
||||
Composite methodNameComposite = new Composite(control, SWT.NONE);
|
||||
FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL);
|
||||
GridData gridData = new GridData(SWT.FILL,SWT.BEGINNING, true, false);
|
||||
gridData.horizontalAlignment = GridData.FILL;
|
||||
methodNameComposite.setLayoutData(gridData);
|
||||
methodNameComposite.setLayout(compositeLayout);
|
||||
constantName = new LabeledTextField(methodNameComposite, labelName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.dialogs;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.RowLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class VisibilitySelectionPanel extends Composite {
|
||||
|
||||
|
||||
private Button publicAccessRadioButton;
|
||||
private Button protectedAccessRadioButton;
|
||||
private Button privateAccessRadioButton;
|
||||
private Group accessModifierGroup;
|
||||
|
||||
public VisibilitySelectionPanel(Composite parent, VisibilityEnum defaultVisibility, int style) {
|
||||
super(parent, style);
|
||||
|
||||
FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL);
|
||||
setLayout(compositeLayout);
|
||||
GridData gridData = new GridData(SWT.FILL,SWT.BEGINNING, true, false);
|
||||
gridData.horizontalAlignment = GridData.FILL;
|
||||
setLayoutData(gridData);
|
||||
|
||||
createAccessModifierComposite(this);
|
||||
setSelected(defaultVisibility);
|
||||
|
||||
}
|
||||
|
||||
private void createAccessModifierComposite(Composite control) {
|
||||
|
||||
accessModifierGroup = new Group(this, SWT.SHADOW_NONE );
|
||||
RowLayout groupLayout = new RowLayout(SWT.HORIZONTAL);
|
||||
groupLayout.fill = true;
|
||||
accessModifierGroup.setLayout(groupLayout);
|
||||
accessModifierGroup.setText(Messages.VisibilitySelectionPanel_AccessModifier);
|
||||
|
||||
publicAccessRadioButton = new Button(accessModifierGroup, SWT.RADIO | SWT.LEFT);
|
||||
publicAccessRadioButton.setText(VisibilityEnum.v_public.toString());
|
||||
|
||||
protectedAccessRadioButton = new Button(accessModifierGroup, SWT.RADIO | SWT.LEFT);
|
||||
protectedAccessRadioButton.setText(VisibilityEnum.v_protected.toString());
|
||||
|
||||
privateAccessRadioButton = new Button(accessModifierGroup, SWT.RADIO | SWT.LEFT);
|
||||
privateAccessRadioButton.setText(VisibilityEnum.v_private.toString());
|
||||
|
||||
}
|
||||
|
||||
private void setSelected(VisibilityEnum defaultVisibility) {
|
||||
switch (defaultVisibility){
|
||||
case v_public:
|
||||
publicAccessRadioButton.setSelection(true);
|
||||
break;
|
||||
case v_protected:
|
||||
protectedAccessRadioButton.setSelection(true);
|
||||
break;
|
||||
case v_private:
|
||||
privateAccessRadioButton.setSelection(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return accessModifierGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
accessModifierGroup.setEnabled(enabled);
|
||||
publicAccessRadioButton.setEnabled(enabled);
|
||||
protectedAccessRadioButton.setEnabled(enabled);
|
||||
privateAccessRadioButton.setEnabled(enabled);
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
# Rapperswil, University of applied sciences and others
|
||||
# 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
|
||||
#
|
||||
# Contributors:
|
||||
# Institute for Software - initial API and implementation
|
||||
###############################################################################
|
||||
CTextEditChangePreviewViewer_OrgSource=Original Source
|
||||
CTextEditChangePreviewViewer_RefactoredSource=Refactored Source
|
||||
ExtractInputPage_ReplaceInSubclass=Replace in subclass:
|
||||
ExtractInputPage_EnterName=Enter a name
|
||||
ExtractInputPage_CheckName=Check Name: {0}
|
||||
VisibilitySelectionPanel_AccessModifier=&Access modifier:
|
|
@ -0,0 +1,365 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
||||
|
||||
public class ExtractConstantRefactoring extends CRefactoring {
|
||||
|
||||
private IASTLiteralExpression target = null;
|
||||
private final Vector<IASTExpression> literalsToReplace = new Vector<IASTExpression>();
|
||||
private final NameNVisibilityInformation info;
|
||||
|
||||
public ExtractConstantRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info){
|
||||
this(file, selection, info, false);
|
||||
}
|
||||
|
||||
public ExtractConstantRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info, boolean runHeadless){
|
||||
super(file,selection, runHeadless);
|
||||
this.info = info;
|
||||
name = Messages.ExtractConstantRefactoring_ExtractConst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||
super.checkInitialConditions(sm.newChild(6));
|
||||
|
||||
Collection<IASTLiteralExpression> literalExpressionVector = findAllLiterals();
|
||||
if(literalExpressionVector.isEmpty()){
|
||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
||||
return initStatus;
|
||||
}
|
||||
sm.worked(1);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
ITextSelection textSelection = null;
|
||||
if (selection instanceof ITextSelection) {
|
||||
textSelection = (ITextSelection) selection;
|
||||
} else {
|
||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
||||
return initStatus;
|
||||
}
|
||||
sm.worked(1);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
//Feststellen das nur einer Markiert ist.
|
||||
boolean oneMarked = isOneMarked(literalExpressionVector, textSelection);
|
||||
if(!oneMarked){
|
||||
//No or more than one marked
|
||||
if(target == null){
|
||||
//No Selection found;
|
||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_NoLiteralSelected);
|
||||
} else {
|
||||
//To many selection found
|
||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_TooManyLiteralSelected);
|
||||
}
|
||||
return initStatus;
|
||||
}
|
||||
sm.worked(1);
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
// Alle Knoten zum ersetzen finden
|
||||
findAllNodesForReplacement(literalExpressionVector);
|
||||
|
||||
info.addNamesToUsedNames(findAllDeclaredNames());
|
||||
sm.done();
|
||||
return initStatus;
|
||||
}
|
||||
|
||||
private Vector<String> findAllDeclaredNames() {
|
||||
Vector<String>names = new Vector<String>();
|
||||
IASTFunctionDefinition funcDef = getFunctionDefinition();
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
|
||||
if(comTypeSpec != null) {
|
||||
for(IASTDeclaration dec : comTypeSpec.getMembers()) {
|
||||
if (dec instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration simpDec = (IASTSimpleDeclaration) dec;
|
||||
for(IASTDeclarator decor : simpDec.getDeclarators()) {
|
||||
names.add(decor.getName().getRawSignature());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) {
|
||||
if(funcDef != null) {
|
||||
IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
|
||||
if (binding instanceof CPPMethod) {
|
||||
|
||||
CPPMethod methode = (CPPMethod) binding;
|
||||
IASTNode decl = methode.getDeclarations()[0];
|
||||
|
||||
IASTNode spec = decl.getParent().getParent();
|
||||
if (spec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) spec;
|
||||
return compTypeSpec;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IASTFunctionDefinition getFunctionDefinition() {
|
||||
IASTNode node = target;
|
||||
while((node = node.getParent()) != null){
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition funcDef = (IASTFunctionDefinition) node;
|
||||
return funcDef;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void findAllNodesForReplacement(Collection<IASTLiteralExpression> literalExpressionVector) {
|
||||
|
||||
|
||||
if (target.getParent() instanceof IASTUnaryExpression) {
|
||||
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
if( target.getKind() == expression.getKind()
|
||||
&& target.toString().equals( expression.toString() )
|
||||
&& expression.getParent() instanceof IASTUnaryExpression
|
||||
&& unary.getOperator() == ((IASTUnaryExpression)expression.getParent()).getOperator()) {
|
||||
literalsToReplace.add( ((IASTUnaryExpression)expression.getParent()) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
if( target.getKind() == expression.getKind()
|
||||
&& target.toString().equals( expression.toString() ) ) {
|
||||
literalsToReplace.add( expression );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOneMarked(Collection<IASTLiteralExpression> literalExpressionVector, ITextSelection textSelection) {
|
||||
boolean oneMarked = false;
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
boolean isInSameFileSelection = isInSameFileSelection(textSelection, expression);
|
||||
if(isInSameFileSelection){
|
||||
if(target == null) {
|
||||
target = expression;
|
||||
oneMarked = true;
|
||||
} else {
|
||||
oneMarked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return oneMarked;
|
||||
}
|
||||
|
||||
private Collection<IASTLiteralExpression> findAllLiterals() {
|
||||
final Collection<IASTLiteralExpression> result = new ArrayList<IASTLiteralExpression>();
|
||||
|
||||
unit.accept(new CPPASTVisitor(){
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof IASTLiteralExpression) {
|
||||
if(!(expression.getNodeLocations().length == 1
|
||||
&& expression.getNodeLocations()[0] instanceof IASTMacroExpansionLocation)){
|
||||
IASTLiteralExpression literal = (IASTLiteralExpression) expression;
|
||||
result.add(literal);
|
||||
}
|
||||
}
|
||||
return super.visit(expression);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||
throws CoreException, OperationCanceledException {
|
||||
|
||||
MethodContext context = findContext(target);
|
||||
Collection<IASTExpression> locLiteralsToReplace = new ArrayList<IASTExpression>();
|
||||
|
||||
if(context.getType() == MethodContext.ContextType.METHOD){
|
||||
|
||||
for (IASTExpression expression : literalsToReplace) {
|
||||
MethodContext exprContext = findContext(expression);
|
||||
if(exprContext.getType() == MethodContext.ContextType.METHOD){
|
||||
if( MethodContext.isSameClass(exprContext.getMethodQName(), context.getMethodQName())){
|
||||
locLiteralsToReplace.add(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (IASTExpression expression : literalsToReplace) {
|
||||
IPath path = new Path(expression.getContainingFilename());
|
||||
IFile expressionFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||
//expressionFile may be null if the file is NOT in the workspace
|
||||
if( expressionFile != null && expressionFile.equals(file) ){
|
||||
locLiteralsToReplace.add(expression);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Create all Changes for literals
|
||||
String constName = info.getName();
|
||||
createLiteralToConstantChanges(constName, locLiteralsToReplace, collector);
|
||||
|
||||
if(context.getType() == MethodContext.ContextType.METHOD) {
|
||||
ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) context.getMethodDeclaration().getParent();
|
||||
AddDeclarationNodeToClassChange.createChange(classDefinition, info.getVisibility(), getConstNodesClass(constName), true, collector);
|
||||
} else {
|
||||
IASTDeclaration nodes = getConstNodesGlobal(constName);
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||
rewriter.insertBefore(unit, TranslationUnitHelper.getFirstNode(unit), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant));
|
||||
}
|
||||
}
|
||||
|
||||
private void createLiteralToConstantChanges(String constName, Iterable<? extends IASTExpression> literals, ModificationCollector collector) {
|
||||
|
||||
for (IASTExpression each : literals) {
|
||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(each.getTranslationUnit());
|
||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName(constName.toCharArray()));
|
||||
rewrite.replace(each, idExpression, new TextEditGroup(Messages.ExtractConstantRefactoring_ReplaceLiteral));
|
||||
}
|
||||
}
|
||||
|
||||
private IASTSimpleDeclaration getConstNodes(String newName){
|
||||
|
||||
ICPPASTSimpleDeclSpecifier declSpec = new CPPASTSimpleDeclSpecifier();
|
||||
declSpec.setConst(true);
|
||||
|
||||
switch(target.getKind()){
|
||||
case IASTLiteralExpression.lk_char_constant:
|
||||
declSpec.setType(IASTSimpleDeclSpecifier.t_char);
|
||||
break;
|
||||
case IASTLiteralExpression.lk_float_constant:
|
||||
declSpec.setType(IASTSimpleDeclSpecifier.t_float);
|
||||
break;
|
||||
case IASTLiteralExpression.lk_integer_constant:
|
||||
declSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
break;
|
||||
case IASTLiteralExpression.lk_string_literal:
|
||||
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t);
|
||||
break;
|
||||
case ICPPASTLiteralExpression.lk_false:
|
||||
//Like lk_true a boolean type
|
||||
case ICPPASTLiteralExpression.lk_true:
|
||||
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_bool);
|
||||
break;
|
||||
case ICPPASTLiteralExpression.lk_this:
|
||||
break;
|
||||
}
|
||||
|
||||
IASTSimpleDeclaration simple = new CPPASTSimpleDeclaration();
|
||||
simple.setDeclSpecifier(declSpec);
|
||||
|
||||
IASTDeclarator decl = new CPPASTDeclarator();
|
||||
IASTName name = new CPPASTName(newName.toCharArray());
|
||||
decl.setName(name);
|
||||
IASTInitializerExpression init = new CPPASTInitializerExpression();
|
||||
if (target.getParent() instanceof IASTUnaryExpression) {
|
||||
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
|
||||
init.setExpression(unary);
|
||||
} else {
|
||||
CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.toString());
|
||||
init.setExpression(expression);
|
||||
}
|
||||
decl.setInitializer(init);
|
||||
simple.addDeclarator(decl);
|
||||
|
||||
return simple;
|
||||
}
|
||||
|
||||
private IASTDeclaration getConstNodesGlobal(String newName){
|
||||
IASTSimpleDeclaration simple = getConstNodes(newName);
|
||||
|
||||
if(unit.getParserLanguage().isCPP()){
|
||||
ICPPASTNamespaceDefinition namespace = new CPPASTNamespaceDefinition();
|
||||
namespace.setName(new CPPASTName());
|
||||
namespace.addDeclaration(simple);
|
||||
return namespace;
|
||||
}
|
||||
|
||||
simple.getDeclSpecifier().setStorageClass(IASTDeclSpecifier.sc_static);
|
||||
return simple;
|
||||
}
|
||||
|
||||
private IASTDeclaration getConstNodesClass(String newName){
|
||||
IASTSimpleDeclaration simple = getConstNodes(newName);
|
||||
simple.getDeclSpecifier().setStorageClass(IASTDeclSpecifier.sc_static);
|
||||
return simple;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class ExtractConstantRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public ExtractConstantRefactoringRunner(IFile file, ISelection selection, IWorkbenchWindow window) {
|
||||
super(file, selection, window);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
CRefactoring refactoring = new ExtractConstantRefactoring(file,selection,info);
|
||||
ExtractConstantRefactoringWizard wizard = new ExtractConstantRefactoringWizard(refactoring, info);
|
||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||
|
||||
try {
|
||||
refactoring.lockIndex();
|
||||
try {
|
||||
operator.run(window.getShell(), refactoring.getName());
|
||||
}
|
||||
finally {
|
||||
refactoring.unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage;
|
||||
|
||||
public class ExtractConstantRefactoringWizard extends RefactoringWizard {
|
||||
|
||||
private ExtractInputPage page;
|
||||
private final NameNVisibilityInformation info;
|
||||
|
||||
public ExtractConstantRefactoringWizard(Refactoring refactoring, NameNVisibilityInformation info) {
|
||||
super(refactoring, WIZARD_BASED_USER_INTERFACE);
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addUserInputPages() {
|
||||
page = new InputPage(Messages.ExtractConstantRefactoring_ExtractConst, info);
|
||||
addPage(page);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage;
|
||||
|
||||
public class InputPage extends ExtractInputPage {
|
||||
|
||||
private final Vector<String> usedNames;
|
||||
|
||||
public InputPage(String name, NameNVisibilityInformation info) {
|
||||
super(name, info);
|
||||
label = Messages.InputPage_ConstName;
|
||||
errorLabel = Messages.InputPage_EnterContName;
|
||||
usedNames = info.getUsedNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void verifyName(String name) {
|
||||
if(usedNames.contains(name)) {
|
||||
setErrorMessage(NLS.bind(Messages.InputPage_NameAlreadyDefined, name));
|
||||
setPageComplete(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public final class Messages extends NLS {
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.refactoring.extractconstant.messages";//$NON-NLS-1$
|
||||
|
||||
private Messages() {
|
||||
// Do not instantiate
|
||||
}
|
||||
|
||||
public static String InputPage_ConstName;
|
||||
public static String InputPage_EnterContName;
|
||||
public static String InputPage_NameAlreadyDefined;
|
||||
public static String ExtractConstantRefactoring_ExtractConst;
|
||||
public static String ExtractConstantRefactoring_LiteralMustBeSelected;
|
||||
public static String ExtractConstantRefactoring_NoLiteralSelected;
|
||||
public static String ExtractConstantRefactoring_TooManyLiteralSelected;
|
||||
public static String ExtractConstantRefactoring_CreateConstant;
|
||||
public static String ExtractConstantRefactoring_ReplaceLiteral;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
# Rapperswil, University of applied sciences and others
|
||||
# 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
|
||||
#
|
||||
# Contributors:
|
||||
# Institute for Software - initial API and implementation
|
||||
###############################################################################
|
||||
InputPage_ConstName=Constant &name:
|
||||
InputPage_EnterContName=Enter a name for the new constant
|
||||
InputPage_NameAlreadyDefined=An element named '{0}' is already defined in this scope.
|
||||
ExtractConstantRefactoring_ExtractConst=Extract Constant
|
||||
ExtractConstantRefactoring_LiteralMustBeSelected=An literal expression must be selected to activate this refactoring.
|
||||
ExtractConstantRefactoring_NoLiteralSelected=No selected literal.
|
||||
ExtractConstantRefactoring_TooManyLiteralSelected=Too many literals selected.
|
||||
ExtractConstantRefactoring_CreateConstant=Create constant
|
||||
ExtractConstantRefactoring_ReplaceLiteral=Replace a literal
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
# Rapperswil, University of applied sciences and others
|
||||
# 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
|
||||
#
|
||||
# Contributors:
|
||||
# Institute for Software - initial API and implementation
|
||||
###############################################################################
|
||||
DeleteFileChange_0=Delete File
|
||||
DeleteFileChange_1=File doesn't exist.
|
||||
HSRRefactoring_name=HSR Refactoring
|
||||
HSRRefactoring_PM_LoadTU=Load Translation Unit
|
||||
HSRRefactoring_PM_CheckTU=Check Translation Unit
|
||||
HSRRefactoring_PM_InitRef=Initialize Refactoring
|
||||
HSRRefactoring_PM_ParseTU=Parse Translation Unit
|
||||
HSRRefactoring_PM_MergeComments=Merge Comments
|
||||
HSRRefactoring_CanceledByUser=Refactoring canceled by user.
|
||||
HSRRefactoring_CompileErrorInTU=The Translation Unit contains one or several problems. This can be caused by a syntax error in the code or a parser flaw. The refactoring will possibly fail.
|
||||
AddDeclarationNodeToClassChange_AddDeclaration=Add Declaration to Class {0}.
|
||||
CreateFileChange_CreateFile=Create file: {0}
|
||||
CreateFileChange_UnknownLoc=Unknown Location: {0}
|
||||
CreateFileChange_FileExists=File already exists: {0}
|
||||
HSRRefactoring_SelectionNotValid=Selection is not valid.
|
||||
HSRRefactoring_CantLoadTU=Can not load translation unit.
|
||||
HSRRefactoring_Ambiguity=Translation unit is ambiguous.
|
||||
NO_FILE=File not found.
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,95 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
||||
/**
|
||||
* Visitor to prefer simple ASTNames over the qualified ones. This is different
|
||||
* to the strategy used within the dom-package.
|
||||
*/
|
||||
abstract public class ASTNameVisitor extends ASTVisitor {
|
||||
private int fOffset= -1;
|
||||
private String fFileName;
|
||||
|
||||
public ASTNameVisitor(String fileName) {
|
||||
this(fileName, -1);
|
||||
}
|
||||
|
||||
public ASTNameVisitor(String fileName, int offset) {
|
||||
fFileName= fileName;
|
||||
fOffset= offset;
|
||||
shouldVisitNames=true;
|
||||
}
|
||||
|
||||
abstract protected int visitName(IASTName name);
|
||||
|
||||
@Override
|
||||
final public int visit(IASTName name) {
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name;
|
||||
IASTName[] names= qn.getNames();
|
||||
boolean visited= false;
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (checkLocation(names[i])) {
|
||||
if (visitName(names[i]) == PROCESS_ABORT) {
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
visited= true;
|
||||
}
|
||||
}
|
||||
if (!visited && names.length>0) {
|
||||
if (checkLocation(name)) {
|
||||
return visitName(names[names.length-1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (checkLocation(name)) {
|
||||
return visitName(name);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
private boolean checkLocation(IASTNode node) {
|
||||
if (fFileName==null) {
|
||||
return true;
|
||||
}
|
||||
if (!fFileName.equals(node.getContainingFilename())) {
|
||||
return false;
|
||||
}
|
||||
IASTFileLocation loc= null;
|
||||
if (node instanceof IASTName) {
|
||||
loc= ASTManager.getImageFileLocation((IASTName) node);
|
||||
}
|
||||
else {
|
||||
IASTNodeLocation[] locs= node.getNodeLocations();
|
||||
if (locs!=null && locs.length==1) {
|
||||
if (locs[0] instanceof IASTFileLocation) {
|
||||
loc= (IASTFileLocation) locs[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loc==null) {
|
||||
return false;
|
||||
}
|
||||
if (fOffset==-1) {
|
||||
return true;
|
||||
}
|
||||
int off= loc.getNodeOffset();
|
||||
int len = loc.getNodeLength();
|
||||
return off <= fOffset && fOffset < off+len;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004-2005 Wind River Systems, Inc.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
public abstract class ASTSpecificNameVisitor extends ASTNameVisitor {
|
||||
private String fSearchForName;
|
||||
|
||||
public ASTSpecificNameVisitor(String name) {
|
||||
super(null);
|
||||
fSearchForName= name;
|
||||
}
|
||||
|
||||
final public int visitName(IASTName name) {
|
||||
String nameStr= name.toString();
|
||||
if (nameStr != null) {
|
||||
final int len= nameStr.length();
|
||||
final int searchForLen= fSearchForName.length();
|
||||
if (len == searchForLen) {
|
||||
if (nameStr.equals(fSearchForName)) {
|
||||
return visitName(name, false);
|
||||
}
|
||||
}
|
||||
else if (len == searchForLen+1) {
|
||||
if (nameStr.charAt(0) == '~' && nameStr.endsWith(fSearchForName)) {
|
||||
return visitName(name, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
protected abstract int visitName(IASTName name, boolean isDestructor);
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
|
||||
|
||||
/**
|
||||
* Represents the input to a refactoring. Important is file and offset the rest
|
||||
* can be calculated from the AST.
|
||||
*/
|
||||
public class CRefactoringArgument {
|
||||
private int fOffset=0;
|
||||
private int fLength= 0;
|
||||
private String fText= ""; //$NON-NLS-1$
|
||||
private int fKind= CRefactory.ARGUMENT_UNKNOWN;
|
||||
private IFile fFile;
|
||||
|
||||
private IBinding fBinding;
|
||||
private IScope fScope;
|
||||
private IASTTranslationUnit fTranslationUnit;
|
||||
|
||||
public CRefactoringArgument(IFile file, int offset, int length) {
|
||||
fKind= CRefactory.ARGUMENT_UNKNOWN;
|
||||
fFile= file;
|
||||
fOffset= offset;
|
||||
fLength= length;
|
||||
}
|
||||
|
||||
public CRefactoringArgument(ICElement elem) {
|
||||
fKind= CRefactory.ARGUMENT_UNKNOWN;
|
||||
if (elem instanceof ISourceReference) {
|
||||
ISourceReference sref= (ISourceReference) elem;
|
||||
ISourceRange sr;
|
||||
try {
|
||||
sr = sref.getSourceRange();
|
||||
fFile= (IFile) sref.getTranslationUnit().getResource();
|
||||
fOffset= sr.getIdStartPos();
|
||||
fLength= sr.getIdLength();
|
||||
} catch (CModelException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrider
|
||||
public String getName() {
|
||||
return fText;
|
||||
}
|
||||
|
||||
// overrider
|
||||
public IFile getSourceFile() {
|
||||
return fFile;
|
||||
}
|
||||
|
||||
// overrider
|
||||
public int getArgumentKind() {
|
||||
return fKind;
|
||||
}
|
||||
|
||||
// overrider
|
||||
public int getOffset() {
|
||||
return fOffset;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return fLength;
|
||||
}
|
||||
|
||||
public void setName(IASTName name) {
|
||||
fText= name.toString();
|
||||
}
|
||||
|
||||
public void setBinding(IASTTranslationUnit tu, IBinding binding, IScope scope) {
|
||||
fTranslationUnit= tu;
|
||||
fBinding= binding;
|
||||
fScope= scope;
|
||||
if (binding instanceof IVariable) {
|
||||
IVariable var= (IVariable) binding;
|
||||
if (binding instanceof IField) {
|
||||
fKind= CRefactory.ARGUMENT_FIELD;
|
||||
}
|
||||
else if (binding instanceof IParameter) {
|
||||
fKind= CRefactory.ARGUMENT_PARAMETER;
|
||||
}
|
||||
else {
|
||||
if (ASTManager.isLocalVariable(var, scope)) {
|
||||
fKind= CRefactory.ARGUMENT_LOCAL_VAR;
|
||||
}
|
||||
else {
|
||||
boolean isStatic= false;
|
||||
try {
|
||||
isStatic= var.isStatic();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
if (isStatic) {
|
||||
fKind= CRefactory.ARGUMENT_FILE_LOCAL_VAR;
|
||||
}
|
||||
else {
|
||||
fKind= CRefactory.ARGUMENT_GLOBAL_VAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (binding instanceof IEnumerator) {
|
||||
fKind= CRefactory.ARGUMENT_ENUMERATOR;
|
||||
}
|
||||
else if (binding instanceof IFunction) {
|
||||
fKind= CRefactory.ARGUMENT_NON_VIRTUAL_METHOD;
|
||||
IFunction func= (IFunction) binding;
|
||||
if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod method= (ICPPMethod) binding;
|
||||
int isVirtual= ASTManager.UNKNOWN;
|
||||
try {
|
||||
isVirtual = ASTManager.isVirtualMethod(method);
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
if (isVirtual == ASTManager.TRUE) {
|
||||
fKind= CRefactory.ARGUMENT_VIRTUAL_METHOD;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isStatic= false;
|
||||
try {
|
||||
isStatic= func.isStatic();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
if (isStatic) {
|
||||
fKind= CRefactory.ARGUMENT_FILE_LOCAL_FUNCTION;
|
||||
}
|
||||
else {
|
||||
fKind= CRefactory.ARGUMENT_GLOBAL_FUNCTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (binding instanceof ICompositeType) {
|
||||
fKind= CRefactory.ARGUMENT_CLASS_TYPE;
|
||||
}
|
||||
else if (binding instanceof IEnumeration || binding instanceof ITypedef) {
|
||||
fKind= CRefactory.ARGUMENT_TYPE;
|
||||
}
|
||||
else if (binding instanceof ICPPNamespace) {
|
||||
fKind= CRefactory.ARGUMENT_NAMESPACE;
|
||||
}
|
||||
else if (binding instanceof IMacroBinding) {
|
||||
fKind= CRefactory.ARGUMENT_MACRO;
|
||||
}
|
||||
}
|
||||
|
||||
public IScope getScope() {
|
||||
return fScope;
|
||||
}
|
||||
|
||||
public IBinding getBinding() {
|
||||
return fBinding;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
return fTranslationUnit;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* A refactoring match initially is a plain text match. In the course of refactoring
|
||||
* it will be classified with a location (comment, code, ...) and with the information
|
||||
* whether it has been verified via AST or not.
|
||||
*/
|
||||
public class CRefactoringMatch {
|
||||
public static final int POTENTIAL= 0;
|
||||
public static final int AST_REFERENCE= 1;
|
||||
public static final int AST_REFERENCE_OTHER= 2;
|
||||
public static final int AST_REFEREENCE_CONFLICTING= 3;
|
||||
public static final int IN_COMMENT = 4;
|
||||
|
||||
private static String[] LABELS= {
|
||||
Messages.getString("CRefactoringMatch.label.potentialOccurrence"), //$NON-NLS-1$
|
||||
Messages.getString("CRefactoringMatch.label.occurrence"), //$NON-NLS-1$
|
||||
"", //$NON-NLS-1$
|
||||
Messages.getString("CRefactoringMatch.label.potentialOccurrence"), //$NON-NLS-1$
|
||||
Messages.getString("CRefactoringMatch.label.comment")}; //$NON-NLS-1$
|
||||
|
||||
private IFile fFile;
|
||||
private int fOffset;
|
||||
private int fLength;
|
||||
private int fLocation;
|
||||
private int fAstInformation= 0;
|
||||
|
||||
public int getAstInformation() {
|
||||
return fAstInformation;
|
||||
}
|
||||
|
||||
public CRefactoringMatch(IFile file, int offset, int length, int location) {
|
||||
fFile= file;
|
||||
fOffset= offset;
|
||||
fLength= length;
|
||||
fLocation= location;
|
||||
}
|
||||
public int getOffset() {
|
||||
return fOffset;
|
||||
}
|
||||
public void setLocation(int location) {
|
||||
fLocation= location;
|
||||
}
|
||||
public int getLocation() {
|
||||
return fLocation;
|
||||
}
|
||||
public int getLength() {
|
||||
return fLength;
|
||||
}
|
||||
public IFile getFile() {
|
||||
return fFile;
|
||||
}
|
||||
public void setASTInformation(int val) {
|
||||
switch(fAstInformation) {
|
||||
case AST_REFERENCE:
|
||||
case AST_REFERENCE_OTHER:
|
||||
case AST_REFEREENCE_CONFLICTING:
|
||||
if (val != fAstInformation) {
|
||||
fAstInformation= AST_REFEREENCE_CONFLICTING;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fAstInformation= val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public String getLabel() {
|
||||
if (fAstInformation == AST_REFERENCE) {
|
||||
return LABELS[AST_REFERENCE];
|
||||
}
|
||||
if (isInComment()) {
|
||||
return LABELS[IN_COMMENT];
|
||||
}
|
||||
return LABELS[POTENTIAL];
|
||||
}
|
||||
|
||||
public boolean isInComment() {
|
||||
return (fLocation & CRefactory.OPTION_IN_COMMENT) != 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
||||
public class CRefactoringMatchStore {
|
||||
private Map<IFile, IPath> fFileToPathMap= new HashMap<IFile, IPath>();
|
||||
private Map<IPath, SortedMap<CRefactoringMatch, CRefactoringMatch>> fPathToMatches= new HashMap<IPath, SortedMap<CRefactoringMatch, CRefactoringMatch>>();
|
||||
private Comparator<CRefactoringMatch> fOffsetComparator;
|
||||
|
||||
public CRefactoringMatchStore() {
|
||||
fOffsetComparator= new Comparator<CRefactoringMatch>() {
|
||||
public int compare(CRefactoringMatch o1, CRefactoringMatch o2) {
|
||||
return o1.getOffset() - o2.getOffset();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void addMatch(CRefactoringMatch match) {
|
||||
IPath path= resolvePath(match.getFile());
|
||||
if (path != null) {
|
||||
Map<CRefactoringMatch, CRefactoringMatch> matchesForPath= getMapForPath(path, true);
|
||||
matchesForPath.put(match, match);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<CRefactoringMatch, CRefactoringMatch> getMapForPath(IPath path, boolean create) {
|
||||
SortedMap<CRefactoringMatch, CRefactoringMatch> map= fPathToMatches.get(path);
|
||||
if (map == null && create) {
|
||||
map= new TreeMap<CRefactoringMatch, CRefactoringMatch>(fOffsetComparator);
|
||||
fPathToMatches.put(path, map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private IPath resolvePath(IFile file) {
|
||||
IPath path= fFileToPathMap.get(file);
|
||||
if (path == null) {
|
||||
path= file.getLocation();
|
||||
if (path == null) {
|
||||
path= file.getFullPath();
|
||||
}
|
||||
fFileToPathMap.put(file, path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public int getFileCount() {
|
||||
return fFileToPathMap.size();
|
||||
}
|
||||
|
||||
public List<IFile> getFileList() {
|
||||
return new ArrayList<IFile>(fFileToPathMap.keySet());
|
||||
}
|
||||
|
||||
public boolean contains(IResource file) {
|
||||
return fFileToPathMap.containsKey(file);
|
||||
}
|
||||
|
||||
public Collection<CRefactoringMatch> getMatchesForFile(IResource file) {
|
||||
return getMatchesForPath(fFileToPathMap.get(file));
|
||||
}
|
||||
|
||||
public Collection<CRefactoringMatch> getMatchesForPath(IPath path) {
|
||||
if (path != null) {
|
||||
Map<CRefactoringMatch, CRefactoringMatch> map= fPathToMatches.get(path);
|
||||
if (map != null) {
|
||||
return map.keySet();
|
||||
}
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public CRefactoringMatch findMatch(IPath path, int nodeOffset) {
|
||||
Map map= fPathToMatches.get(path);
|
||||
if (map != null) {
|
||||
return (CRefactoringMatch) map.get(new CRefactoringMatch(null, nodeOffset, 0, 0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removePath(IPath path) {
|
||||
Map map= fPathToMatches.remove(path);
|
||||
if (map != null && !map.isEmpty()) {
|
||||
IFile file= ((CRefactoringMatch) map.values().iterator().next()).getFile();
|
||||
fFileToPathMap.remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<CRefactoringMatch> findMatchesInRange(Path path, int offset, int end) {
|
||||
if (path != null) {
|
||||
SortedMap<CRefactoringMatch, CRefactoringMatch> map= fPathToMatches.get(path);
|
||||
if (map != null) {
|
||||
return map.subMap(new CRefactoringMatch(null, offset, 0, 0),
|
||||
new CRefactoringMatch(null, end, 0, 0)).keySet();
|
||||
}
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
/**
|
||||
* Collects some basic functionality.
|
||||
*/
|
||||
public class CRefactoringUtils {
|
||||
|
||||
public static boolean isIdentifierChar(char c) {
|
||||
return isLeadingIdentifierChar(c) || ('0'<=c && c<='9');
|
||||
}
|
||||
|
||||
public static boolean isLeadingIdentifierChar(char c) {
|
||||
return ('A'<=c && c<='Z') || ('a'<=c && c<='z') || c=='_';
|
||||
}
|
||||
|
||||
public static boolean checkIdentifier(String id) {
|
||||
if (id.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!isLeadingIdentifierChar(id.charAt(0))) {
|
||||
return false;
|
||||
}
|
||||
for (int i= 1; i < id.length(); i++) {
|
||||
if (!isIdentifierChar(id.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
|
||||
|
||||
/**
|
||||
* Serves to launch the various refactorings.
|
||||
*/
|
||||
public class CRefactory {
|
||||
public static final int OPTION_ASK_SCOPE = 0x01;
|
||||
public static final int OPTION_IN_COMMENT = 0x02;
|
||||
public static final int OPTION_IN_STRING_LITERAL = 0x04;
|
||||
public static final int OPTION_IN_INCLUDE_DIRECTIVE = 0x08;
|
||||
public static final int OPTION_IN_MACRO_DEFINITION = 0x10;
|
||||
public static final int OPTION_IN_PREPROCESSOR_DIRECTIVE = 0x20;
|
||||
public static final int OPTION_IN_INACTIVE_CODE = 0x40;
|
||||
public static final int OPTION_IN_CODE = 0x80;
|
||||
|
||||
public static final int ARGUMENT_UNKNOWN = 0;
|
||||
public static final int ARGUMENT_LOCAL_VAR = 1;
|
||||
public static final int ARGUMENT_PARAMETER = 2;
|
||||
public static final int ARGUMENT_FILE_LOCAL_VAR = 3;
|
||||
public static final int ARGUMENT_GLOBAL_VAR = 4;
|
||||
public static final int ARGUMENT_FIELD = 5;
|
||||
public static final int ARGUMENT_FILE_LOCAL_FUNCTION = 6;
|
||||
public static final int ARGUMENT_GLOBAL_FUNCTION = 7;
|
||||
public static final int ARGUMENT_VIRTUAL_METHOD = 8;
|
||||
public static final int ARGUMENT_NON_VIRTUAL_METHOD = 9;
|
||||
public static final int ARGUMENT_TYPE = 10;
|
||||
public static final int ARGUMENT_MACRO = 11;
|
||||
public static final int ARGUMENT_INCLUDE_DIRECTIVE = 12;
|
||||
public static final int ARGUMENT_ENUMERATOR = 13;
|
||||
public static final int ARGUMENT_CLASS_TYPE = 14;
|
||||
public static final int ARGUMENT_NAMESPACE = 15;
|
||||
|
||||
private static CRefactory sInstance= new CRefactory();
|
||||
private TextSearchWrapper fTextSearch;
|
||||
|
||||
public static CRefactory getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private CRefactory() {
|
||||
}
|
||||
|
||||
// runs the rename refactoring
|
||||
public void rename(Shell shell, ICElement arg) {
|
||||
if (!IDE.saveAllEditors(
|
||||
new IResource[] {ResourcesPlugin.getWorkspace().getRoot()},
|
||||
false)) {
|
||||
return;
|
||||
}
|
||||
CRefactoringArgument iarg= new CRefactoringArgument(arg);
|
||||
final CRenameProcessor processor = new CRenameProcessor(this, iarg);
|
||||
try {
|
||||
processor.lockIndex();
|
||||
try {
|
||||
CRenameRefactoring r= new CRenameRefactoring(processor);
|
||||
RefactoringWizardOpenOperation op=
|
||||
new RefactoringWizardOpenOperation(new CRenameRefactoringWizard(r));
|
||||
op.run(shell, Messages.getString("CRefactory.title.rename")); //$NON-NLS-1$
|
||||
}
|
||||
finally {
|
||||
processor.unlockIndex();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void rename(Shell shell, IWorkingCopy wc, ITextSelection s) {
|
||||
IResource res= wc.getResource();
|
||||
if (res instanceof IFile == false) {
|
||||
return;
|
||||
}
|
||||
if (!IDE.saveAllEditors(
|
||||
new IResource[] {ResourcesPlugin.getWorkspace().getRoot()},
|
||||
false)) {
|
||||
return;
|
||||
}
|
||||
CRefactoringArgument iarg= new CRefactoringArgument((IFile) res, s.getOffset(), s.getLength());
|
||||
CRenameRefactoring r= new CRenameRefactoring(new CRenameProcessor(this, iarg));
|
||||
RefactoringWizardOpenOperation op=
|
||||
new RefactoringWizardOpenOperation(new CRenameRefactoringWizard(r));
|
||||
try {
|
||||
op.run(shell, Messages.getString("CRefactory.title.rename")); //$NON-NLS-1$
|
||||
} catch (InterruptedException e) {
|
||||
// operation was canceled
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TextSearchWrapper getTextSearch() {
|
||||
if (fTextSearch == null) {
|
||||
return new TextSearchWrapper();
|
||||
}
|
||||
return fTextSearch;
|
||||
}
|
||||
|
||||
public String[] getCCppPatterns() {
|
||||
IContentType[] cts= Platform.getContentTypeManager().getAllContentTypes();
|
||||
HashSet<String> all= new HashSet<String>();
|
||||
for (int i= 0; i < cts.length; i++) {
|
||||
IContentType type= cts[i];
|
||||
boolean useit= false;
|
||||
while (!useit && type != null) {
|
||||
String id= type.getId();
|
||||
if (id.equals(CCorePlugin.CONTENT_TYPE_CHEADER) ||
|
||||
id.equals(CCorePlugin.CONTENT_TYPE_CSOURCE) ||
|
||||
id.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER) ||
|
||||
id.equals(CCorePlugin.CONTENT_TYPE_CXXSOURCE)) {
|
||||
useit= true;
|
||||
}
|
||||
else {
|
||||
type= type.getBaseType();
|
||||
}
|
||||
}
|
||||
if (useit) {
|
||||
String exts[] =
|
||||
type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
|
||||
all.addAll(Arrays.asList(exts));
|
||||
}
|
||||
}
|
||||
String[] result= new String[all.size()];
|
||||
Iterator it= all.iterator();
|
||||
for (int i= 0; i < result.length; i++) {
|
||||
result[i]= "*." + (String) it.next(); //$NON-NLS-1$
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* Processor adding constructor and destructor to the bindings to be renamed.
|
||||
*/
|
||||
public class CRenameClassProcessor extends CRenameTypeProcessor {
|
||||
|
||||
public CRenameClassProcessor(CRenameProcessor processor, String kind) {
|
||||
super(processor, kind);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
|
||||
CRefactoringArgument argument= getArgument();
|
||||
IBinding binding= argument.getBinding();
|
||||
ArrayList<IBinding> bindings= new ArrayList<IBinding>();
|
||||
if (binding != null) {
|
||||
bindings.add(binding);
|
||||
}
|
||||
if (binding instanceof ICPPClassType) {
|
||||
ICPPClassType ctype= (ICPPClassType) binding;
|
||||
try {
|
||||
ICPPConstructor[] ctors= ctype.getConstructors();
|
||||
if (ctors != null) {
|
||||
bindings.addAll(Arrays.asList(ctors));
|
||||
}
|
||||
|
||||
IScope scope= ctype.getCompositeScope();
|
||||
if (scope != null) {
|
||||
IBinding[] dtors= scope.find("~" + argument.getName()); //$NON-NLS-1$
|
||||
if (dtors != null) {
|
||||
bindings.addAll(Arrays.asList(dtors));
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
getAstManager().handleDOMException(argument.getTranslationUnit(), e, status);
|
||||
}
|
||||
}
|
||||
return bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
|
||||
/**
|
||||
* Rename processor that sets up the input page for renaming a global entity.
|
||||
*/
|
||||
public class CRenameGlobalProcessor extends CRenameProcessorDelegate {
|
||||
|
||||
public CRenameGlobalProcessor(CRenameProcessor processor, String name) {
|
||||
super(processor, name);
|
||||
setAvailableOptions(CRefactory.OPTION_ASK_SCOPE |
|
||||
CRefactory.OPTION_IN_CODE |
|
||||
CRefactory.OPTION_IN_COMMENT |
|
||||
CRefactory.OPTION_IN_MACRO_DEFINITION);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004,2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
/**
|
||||
* Rename processor setting up input page for renaming include directives.
|
||||
*/
|
||||
public class CRenameIncludeProcessor extends CRenameProcessorDelegate {
|
||||
|
||||
public CRenameIncludeProcessor(CRenameProcessor input, String kind) {
|
||||
super(input, kind);
|
||||
setAvailableOptions(CRefactory.OPTION_ASK_SCOPE |
|
||||
CRefactory.OPTION_IN_COMMENT |
|
||||
CRefactory.OPTION_IN_MACRO_DEFINITION);
|
||||
setOptionsForcingPreview(-1);
|
||||
setOptionsEnablingScope(-1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getAcceptedLocations(int selectedOptions) {
|
||||
return selectedOptions | CRefactory.OPTION_IN_INCLUDE_DIRECTIVE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
|
||||
|
||||
/**
|
||||
* Rename processor, setting up input page for a local rename.
|
||||
*/
|
||||
public class CRenameLocalProcessor extends CRenameProcessorDelegate {
|
||||
private IScope fScope;
|
||||
public CRenameLocalProcessor(CRenameProcessor input, String kind, IScope scope) {
|
||||
super(input, kind);
|
||||
fScope= scope;
|
||||
setAvailableOptions(0);
|
||||
setOptionsForcingPreview(0);
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
protected int getAcceptedLocations(int selectedOptions) {
|
||||
return CRefactory.OPTION_IN_CODE | CRefactory.OPTION_IN_MACRO_DEFINITION | selectedOptions;
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
protected int getSearchScope() {
|
||||
return TextSearchWrapper.SCOPE_FILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor,
|
||||
RefactoringStatus status) {
|
||||
if (fScope != null) {
|
||||
CRefactoringArgument argument = getArgument();
|
||||
ASTManager r = getAstManager();
|
||||
int[] result= new int[] {0, Integer.MAX_VALUE};
|
||||
IScope scope= argument.getScope();
|
||||
IASTNode node= null;
|
||||
try {
|
||||
node = ASTInternal.getPhysicalNodeOfScope(scope);
|
||||
if (argument.getBinding() instanceof IParameter) {
|
||||
node= node.getParent();
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
r.handleDOMException(argument.getTranslationUnit(), e, status);
|
||||
}
|
||||
if (node != null) {
|
||||
IASTFileLocation loc= ASTManager.getLocationInTranslationUnit(node);
|
||||
if (loc != null) {
|
||||
result[0]= loc.getNodeOffset();
|
||||
result[1]= result[0] + loc.getNodeLength();
|
||||
}
|
||||
}
|
||||
int[] range= result;
|
||||
for (Iterator iter = matches.iterator(); iter.hasNext();) {
|
||||
CRefactoringMatch m = (CRefactoringMatch) iter.next();
|
||||
int off= m.getOffset();
|
||||
if (off < range[0] || off > range[1]) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
super.analyzeTextMatches(matches, monitor, status);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
|
||||
/**
|
||||
* Rename processor that sets up the input page for renaming a global entity.
|
||||
*/
|
||||
public class CRenameMacroProcessor extends CRenameGlobalProcessor {
|
||||
|
||||
public CRenameMacroProcessor(CRenameProcessor processor, String name) {
|
||||
super(processor, name);
|
||||
setAvailableOptions(CRefactory.OPTION_ASK_SCOPE |
|
||||
CRefactory.OPTION_IN_CODE |
|
||||
CRefactory.OPTION_IN_COMMENT |
|
||||
CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getAcceptedLocations(int selectedOptions) {
|
||||
return selectedOptions | CRefactory.OPTION_IN_MACRO_DEFINITION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor,
|
||||
RefactoringStatus status) {
|
||||
for (Iterator iter = matches.iterator(); iter.hasNext();) {
|
||||
CRefactoringMatch m = (CRefactoringMatch) iter.next();
|
||||
if ((m.getLocation() & CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE) != 0) {
|
||||
m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
|
||||
}
|
||||
}
|
||||
super.analyzeTextMatches(matches, monitor, status);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
|
||||
|
||||
/**
|
||||
* Rename processor for methods.
|
||||
*/
|
||||
public class CRenameMethodProcessor extends CRenameGlobalProcessor {
|
||||
|
||||
public CRenameMethodProcessor(CRenameProcessor processor, String kind) {
|
||||
super(processor, kind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
||||
throws OperationCanceledException, CoreException {
|
||||
CRefactoringArgument argument= getArgument();
|
||||
IBinding binding= argument.getBinding();
|
||||
if (binding instanceof ICPPConstructor) {
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameMethodProcessor.fatalError.renameConstructor")); //$NON-NLS-1$
|
||||
}
|
||||
String identifier= argument.getName();
|
||||
if (identifier.startsWith("~")) { //$NON-NLS-1$
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameMethodProcessor.fatalError.renameDestructor")); //$NON-NLS-1$
|
||||
}
|
||||
if (identifier.startsWith("operator") && //$NON-NLS-1$
|
||||
identifier.length() > 8 &&
|
||||
!CRefactoringUtils.isIdentifierChar(identifier.charAt(8))) {
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameMethodProcessor.fatalError.renameOperator")); //$NON-NLS-1$
|
||||
}
|
||||
return super.checkInitialConditions(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor,
|
||||
CheckConditionsContext context) throws OperationCanceledException, CoreException {
|
||||
CRefactoringArgument argument= getArgument();
|
||||
RefactoringStatus result= new RefactoringStatus();
|
||||
IScope scope= argument.getScope();
|
||||
if (scope != null) {
|
||||
IASTNode node= null;
|
||||
try {
|
||||
node = ASTInternal.getPhysicalNodeOfScope(scope);
|
||||
} catch (DOMException e) {
|
||||
getAstManager().handleDOMException(argument.getTranslationUnit(), e, result);
|
||||
}
|
||||
if (node instanceof IASTCompositeTypeSpecifier) {
|
||||
IASTCompositeTypeSpecifier se= (IASTCompositeTypeSpecifier) node;
|
||||
IASTName name= ASTManager.getSimpleName(se.getName());
|
||||
if (getReplacementText().equals(name.toString())) {
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameMethodProcessor.fatalError.renameToConstructor")); //$NON-NLS-1$
|
||||
}
|
||||
if (getReplacementText().startsWith("~")) { //$NON-NLS-1$
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameMethodProcessor.fatalError.renameToDestructor")); //$NON-NLS-1$);
|
||||
}
|
||||
if (!CRefactoringUtils.checkIdentifier(getReplacementText())) {
|
||||
result.merge(RefactoringStatus.createErrorStatus(Messages.getString("CRenameMethodProcessor.warning.illegalCharacters"))); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argument.getArgumentKind() == CRefactory.ARGUMENT_VIRTUAL_METHOD) {
|
||||
result.merge(RefactoringStatus.createWarningStatus(Messages.getString("CRenameMethodProcessor.warning.renameVirtual"))); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
result.merge(super.checkFinalConditions(monitor, context));
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,290 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
|
||||
import org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
|
||||
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
|
||||
/**
|
||||
* This is the processor used for the rename. It decides which of the delegates to
|
||||
* use and forwards further calls to the delegate.
|
||||
*/
|
||||
public class CRenameProcessor extends RenameProcessor {
|
||||
public static final String IDENTIFIER= "org.eclips.cdt.refactoring.RenameProcessor"; //$NON-NLS-1$
|
||||
|
||||
private CRefactoringArgument fArgument;
|
||||
private CRenameProcessorDelegate fDelegate;
|
||||
private String fReplacementText;
|
||||
private String fWorkingSet;
|
||||
private int fScope;
|
||||
private int fSelectedOptions;
|
||||
private CRefactory fManager;
|
||||
private ASTManager fAstManager;
|
||||
private IIndex fIndex;
|
||||
|
||||
public CRenameProcessor(CRefactory refactoringManager, CRefactoringArgument arg) {
|
||||
fManager= refactoringManager;
|
||||
fArgument= arg;
|
||||
fAstManager= new ASTManager(arg);
|
||||
}
|
||||
|
||||
public CRefactoringArgument getArgument() {
|
||||
return fArgument;
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public Object[] getElements() {
|
||||
return new Object[] {fArgument.getBinding()};
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public String getProcessorName() {
|
||||
String result= null;
|
||||
if (fDelegate != null) {
|
||||
result= fDelegate.getProcessorName();
|
||||
}
|
||||
if (result == null) {
|
||||
String identifier= getArgument().getName();
|
||||
if (identifier != null && identifier.length() > 0) {
|
||||
result= MessageFormat.format(Messages.getString("CRenameTopProcessor.wizard.title"), //$NON-NLS-1$
|
||||
new Object[] {identifier});
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result= Messages.getString("CRenameTopProcessor.wizard.backup.title"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public boolean isApplicable() throws CoreException {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
||||
throws CoreException, OperationCanceledException {
|
||||
String identifier= null;
|
||||
RefactoringStatus status= new RefactoringStatus();
|
||||
if (fArgument != null) {
|
||||
fAstManager.analyzeArgument(fIndex, pm, status);
|
||||
identifier= fArgument.getName();
|
||||
}
|
||||
if (identifier == null || identifier.length() < 1) {
|
||||
status.addFatalError(Messages.getString("CRenameTopProcessor.error.invalidTextSelection")); //$NON-NLS-1$
|
||||
return status;
|
||||
}
|
||||
IFile file= fArgument.getSourceFile();
|
||||
IPath path= null;
|
||||
if (file != null) {
|
||||
path= file.getLocation();
|
||||
}
|
||||
if (path == null) {
|
||||
return RefactoringStatus.createFatalErrorStatus(Messages.getString("CRenameTopProcessor.error.renameWithoutSourceFile")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
fDelegate= createDelegate();
|
||||
if (fDelegate == null) {
|
||||
status.addFatalError(Messages.getString("CRenameTopProcessor.error.invalidName")); //$NON-NLS-1$
|
||||
return status;
|
||||
}
|
||||
RefactoringStatus s1= fDelegate.checkInitialConditions(new NullProgressMonitor());
|
||||
status.merge(s1);
|
||||
return status;
|
||||
}
|
||||
|
||||
private CRenameProcessorDelegate createDelegate() {
|
||||
switch (fArgument.getArgumentKind()) {
|
||||
case CRefactory.ARGUMENT_LOCAL_VAR:
|
||||
return new CRenameLocalProcessor(this,
|
||||
Messages.getString("CRenameTopProcessor.localVar"), //$NON-NLS-1$
|
||||
fArgument.getScope());
|
||||
case CRefactory.ARGUMENT_PARAMETER:
|
||||
return new CRenameLocalProcessor(this,
|
||||
Messages.getString("CRenameTopProcessor.parameter"), //$NON-NLS-1$
|
||||
fArgument.getScope());
|
||||
case CRefactory.ARGUMENT_FILE_LOCAL_VAR:
|
||||
return new CRenameLocalProcessor(this,
|
||||
Messages.getString("CRenameTopProcessor.filelocalVar"), //$NON-NLS-1$
|
||||
null);
|
||||
case CRefactory.ARGUMENT_GLOBAL_VAR:
|
||||
return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.globalVar")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_ENUMERATOR:
|
||||
return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.enumerator")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_FIELD:
|
||||
return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.field")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_FILE_LOCAL_FUNCTION:
|
||||
return new CRenameLocalProcessor(this,
|
||||
Messages.getString("CRenameTopProcessor.filelocalFunction"), //$NON-NLS-1$
|
||||
null);
|
||||
case CRefactory.ARGUMENT_GLOBAL_FUNCTION:
|
||||
return new CRenameGlobalProcessor(this, Messages.getString("CRenameTopProcessor.globalFunction")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_VIRTUAL_METHOD:
|
||||
return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.virtualMethod")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_NON_VIRTUAL_METHOD:
|
||||
return new CRenameMethodProcessor(this, Messages.getString("CRenameTopProcessor.method")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_CLASS_TYPE:
|
||||
return new CRenameClassProcessor(this, Messages.getString("CRenameTopProcessor.type")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_NAMESPACE:
|
||||
return new CRenameTypeProcessor(this, Messages.getString("CRenameTopProcessor.namespace")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_TYPE:
|
||||
return new CRenameTypeProcessor(this, Messages.getString("CRenameTopProcessor.type")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_MACRO:
|
||||
return new CRenameMacroProcessor(this, Messages.getString("CRenameTopProcessor.macro")); //$NON-NLS-1$
|
||||
case CRefactory.ARGUMENT_INCLUDE_DIRECTIVE:
|
||||
return new CRenameIncludeProcessor(this, Messages.getString("CRenameIncludeProcessor.includeDirective")); //$NON-NLS-1$
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
|
||||
CheckConditionsContext context) throws CoreException,
|
||||
OperationCanceledException {
|
||||
return fDelegate.checkFinalConditions(pm, context);
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public Change createChange(IProgressMonitor pm) throws CoreException,
|
||||
OperationCanceledException {
|
||||
return fDelegate.createChange(pm);
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
|
||||
SharableParticipants sharedParticipants) throws CoreException {
|
||||
RenameArguments arguments= new RenameArguments(getReplacementText(),
|
||||
true);
|
||||
final String[] natures= {CCProjectNature.CC_NATURE_ID, CCProjectNature.C_NATURE_ID};
|
||||
List<RenameParticipant> result= new ArrayList<RenameParticipant>();
|
||||
IBinding binding= getArgument().getBinding();
|
||||
if (binding != null) {
|
||||
result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status,
|
||||
this, binding, arguments, natures, sharedParticipants)));
|
||||
}
|
||||
return result.toArray(new RefactoringParticipant[result.size()]);
|
||||
}
|
||||
|
||||
// options for the input page in the refactoring wizard
|
||||
public int getAvailableOptions() {
|
||||
if (fDelegate == null) {
|
||||
return 0;
|
||||
}
|
||||
return fDelegate.getAvailableOptions();
|
||||
}
|
||||
|
||||
// options for the input page that trigger the preview
|
||||
public int getOptionsForcingPreview() {
|
||||
if (fDelegate == null) {
|
||||
return 0;
|
||||
}
|
||||
return fDelegate.getOptionsForcingPreview();
|
||||
}
|
||||
|
||||
// options for the input page that trigger the preview
|
||||
public int getOptionsEnablingScope() {
|
||||
if (fDelegate == null) {
|
||||
return 0;
|
||||
}
|
||||
return fDelegate.getOptionsEnablingScope();
|
||||
}
|
||||
|
||||
// overrider
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
public int getScope() {
|
||||
return fScope;
|
||||
}
|
||||
public void setScope(int scope) {
|
||||
fScope = scope;
|
||||
}
|
||||
public int getSelectedOptions() {
|
||||
return fSelectedOptions;
|
||||
}
|
||||
public void setSelectedOptions(int selectedOptions) {
|
||||
fSelectedOptions = selectedOptions;
|
||||
}
|
||||
public String getWorkingSet() {
|
||||
return fWorkingSet;
|
||||
}
|
||||
public void setWorkingSet(String workingSet) {
|
||||
fWorkingSet = workingSet;
|
||||
}
|
||||
public String getReplacementText() {
|
||||
return fReplacementText;
|
||||
}
|
||||
public void setReplacementText(String replacementText) {
|
||||
fReplacementText = replacementText;
|
||||
}
|
||||
public CRefactory getManager() {
|
||||
return fManager;
|
||||
}
|
||||
public ASTManager getAstManager() {
|
||||
return fAstManager;
|
||||
}
|
||||
|
||||
public void lockIndex() throws CoreException, InterruptedException {
|
||||
if (fIndex == null) {
|
||||
ICProject[] projects= CoreModel.getDefault().getCModel().getCProjects();
|
||||
fIndex= CCorePlugin.getIndexManager().getIndex(projects);
|
||||
}
|
||||
fIndex.acquireReadLock();
|
||||
}
|
||||
|
||||
public void unlockIndex() {
|
||||
if (fIndex != null) {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
fIndex= null;
|
||||
}
|
||||
|
||||
public IIndex getIndex() {
|
||||
return fIndex;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,316 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* IBM Corporation - Bug 112366
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
|
||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
|
||||
import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker;
|
||||
import org.eclipse.text.edits.MultiTextEdit;
|
||||
import org.eclipse.text.edits.ReplaceEdit;
|
||||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.ui.refactoring.CTextFileChange;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base for all different rename processors used by the top
|
||||
* processor.
|
||||
*/
|
||||
public abstract class CRenameProcessorDelegate {
|
||||
private CRenameProcessor fTopProcessor;
|
||||
private ArrayList<CRefactoringMatch> fMatches= null;
|
||||
protected String fProcessorBaseName;
|
||||
private int fAvailableOptions=
|
||||
CRefactory.OPTION_ASK_SCOPE |
|
||||
CRefactory.OPTION_IN_CODE |
|
||||
CRefactory.OPTION_IN_COMMENT |
|
||||
CRefactory.OPTION_IN_MACRO_DEFINITION |
|
||||
CRefactory.OPTION_IN_STRING_LITERAL;
|
||||
|
||||
private int fOptionsForcingPreview=
|
||||
CRefactory.OPTION_IN_CODE |
|
||||
CRefactory.OPTION_IN_COMMENT |
|
||||
CRefactory.OPTION_IN_MACRO_DEFINITION |
|
||||
CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE |
|
||||
CRefactory.OPTION_IN_STRING_LITERAL;
|
||||
|
||||
private int fOptionsEnablingScope= fOptionsForcingPreview;
|
||||
|
||||
|
||||
protected CRenameProcessorDelegate(CRenameProcessor topProcessor, String name) {
|
||||
fTopProcessor= topProcessor;
|
||||
fProcessorBaseName= name;
|
||||
}
|
||||
|
||||
final public CRefactoringArgument getArgument() {
|
||||
return fTopProcessor.getArgument();
|
||||
}
|
||||
final public String getReplacementText() {
|
||||
return fTopProcessor.getReplacementText();
|
||||
}
|
||||
final public int getSelectedScope() {
|
||||
return fTopProcessor.getScope();
|
||||
}
|
||||
final public int getSelectedOptions() {
|
||||
return fTopProcessor.getSelectedOptions();
|
||||
}
|
||||
final public String getSelectedWorkingSet() {
|
||||
return fTopProcessor.getWorkingSet();
|
||||
}
|
||||
final public CRefactory getManager() {
|
||||
return fTopProcessor.getManager();
|
||||
}
|
||||
final public ASTManager getAstManager() {
|
||||
return fTopProcessor.getAstManager();
|
||||
}
|
||||
final public String getProcessorName() {
|
||||
String identifier= getArgument().getName();
|
||||
if (identifier != null) {
|
||||
return MessageFormat.format(
|
||||
Messages.getString("CRenameProcessorDelegate.wizard.title"), //$NON-NLS-1$
|
||||
new Object[] {fProcessorBaseName, identifier});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options presented by the page in the refactoring wizard.
|
||||
*/
|
||||
public void setAvailableOptions(int options) {
|
||||
fAvailableOptions= options;
|
||||
}
|
||||
final int getAvailableOptions() {
|
||||
return fAvailableOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options each of which forces the preview, when selected.
|
||||
*/
|
||||
public void setOptionsForcingPreview(int options) {
|
||||
fOptionsForcingPreview= options;
|
||||
}
|
||||
|
||||
final int getOptionsForcingPreview() {
|
||||
return fOptionsForcingPreview;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options that need the scope definition. When one of them is
|
||||
* selected, the scope options are enabled.
|
||||
*/
|
||||
public void setOptionsEnablingScope(int options) {
|
||||
fOptionsEnablingScope= options;
|
||||
}
|
||||
|
||||
final int getOptionsEnablingScope() {
|
||||
return fOptionsEnablingScope;
|
||||
}
|
||||
|
||||
protected int getSearchScope() {
|
||||
return getSelectedScope();
|
||||
}
|
||||
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
return new RefactoringStatus();
|
||||
}
|
||||
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException {
|
||||
RefactoringStatus result= new RefactoringStatus();
|
||||
monitor.beginTask(Messages.getString("CRenameProcessorDelegate.task.checkFinalCondition"), 2); //$NON-NLS-1$
|
||||
IFile file= getArgument().getSourceFile();
|
||||
//assert file!=null;
|
||||
|
||||
// perform text-search
|
||||
fMatches= new ArrayList<CRefactoringMatch>();
|
||||
TextSearchWrapper txtSearch= getManager().getTextSearch();
|
||||
IStatus stat= txtSearch.searchWord(getSearchScope(), file, getSelectedWorkingSet(),
|
||||
getManager().getCCppPatterns(), getArgument().getName(),
|
||||
new SubProgressMonitor(monitor, 1), fMatches);
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
result.merge(RefactoringStatus.create(stat));
|
||||
if (result.hasFatalError()) {
|
||||
return result;
|
||||
}
|
||||
selectMatchesByLocation(fMatches);
|
||||
analyzeTextMatches(fMatches, new SubProgressMonitor(monitor, 1), result);
|
||||
if (result.hasFatalError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
HashSet<IFile> fileset= new HashSet<IFile>();
|
||||
int potentialMatchCount= 0;
|
||||
int commentCount=0;
|
||||
for (Iterator<CRefactoringMatch> iter = fMatches.iterator(); iter.hasNext();) {
|
||||
CRefactoringMatch tm = iter.next();
|
||||
if (tm.isInComment()) {
|
||||
commentCount++;
|
||||
fileset.add(tm.getFile());
|
||||
}
|
||||
else {
|
||||
switch(tm.getAstInformation()) {
|
||||
case CRefactoringMatch.AST_REFERENCE_OTHER:
|
||||
iter.remove();
|
||||
break;
|
||||
case CRefactoringMatch.POTENTIAL:
|
||||
potentialMatchCount++;
|
||||
fileset.add(tm.getFile());
|
||||
break;
|
||||
default:
|
||||
fileset.add(tm.getFile());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (potentialMatchCount != 0) {
|
||||
String msg= null;
|
||||
if (potentialMatchCount == 1) {
|
||||
msg= Messages.getString("CRenameProcessorDelegate.warning.potentialMatch.singular"); //$NON-NLS-1$
|
||||
}
|
||||
else {
|
||||
msg= MessageFormat.format(
|
||||
Messages.getString("CRenameProcessorDelegate.warning.potentialMatch.plural"), //$NON-NLS-1$
|
||||
new Object[]{new Integer(potentialMatchCount)});
|
||||
}
|
||||
result.addWarning(msg);
|
||||
}
|
||||
if (commentCount != 0) {
|
||||
String msg= null;
|
||||
if (commentCount == 1) {
|
||||
msg= Messages.getString("CRenameProcessorDelegate.warning.commentMatch.singular"); //$NON-NLS-1$
|
||||
}
|
||||
else {
|
||||
msg= MessageFormat.format(
|
||||
Messages.getString("CRenameProcessorDelegate.warning.commentMatch.plural"), //$NON-NLS-1$
|
||||
new Object[]{new Integer(commentCount)});
|
||||
}
|
||||
result.addWarning(msg);
|
||||
}
|
||||
IFile[] files= fileset.toArray(new IFile[fileset.size()]);
|
||||
if (context != null) {
|
||||
ValidateEditChecker editChecker=
|
||||
(ValidateEditChecker) context.getChecker(ValidateEditChecker.class);
|
||||
editChecker.addFiles(files);
|
||||
}
|
||||
monitor.done();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void analyzeTextMatches(ArrayList<CRefactoringMatch> matches, IProgressMonitor monitor, RefactoringStatus status) {
|
||||
CRefactoringArgument argument= getArgument();
|
||||
IBinding[] renameBindings= getBindingsToBeRenamed(status);
|
||||
if (renameBindings != null && renameBindings.length > 0 &&
|
||||
argument.getArgumentKind() != CRefactory.ARGUMENT_UNKNOWN) {
|
||||
ASTManager mngr= getAstManager();
|
||||
mngr.setValidBindings(renameBindings);
|
||||
mngr.setRenameTo(getReplacementText());
|
||||
mngr.analyzeTextMatches(fTopProcessor.getIndex(), matches, monitor, status);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectMatchesByLocation(ArrayList<CRefactoringMatch> matches) {
|
||||
int acceptTextLocation= getAcceptedLocations(getSelectedOptions());
|
||||
for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) {
|
||||
CRefactoringMatch match = iter.next();
|
||||
int location= match.getLocation();
|
||||
if (location != 0 && ((location & acceptTextLocation) == 0)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int getAcceptedLocations(int selectedOptions) {
|
||||
return selectedOptions;
|
||||
}
|
||||
|
||||
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
|
||||
if (fMatches.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
Collections.sort(fMatches, new Comparator<CRefactoringMatch>(){
|
||||
public int compare(CRefactoringMatch m1, CRefactoringMatch m2) {
|
||||
IFile f1= m1.getFile();
|
||||
IFile f2= m2.getFile();
|
||||
int cmp= f1.getName().compareTo(f2.getName());
|
||||
if (cmp != 0) return cmp;
|
||||
|
||||
cmp= f1.getFullPath().toString().compareTo(f2.getFullPath().toString());
|
||||
if (cmp != 0) return cmp;
|
||||
|
||||
return m1.getOffset() - m2.getOffset();
|
||||
}});
|
||||
pm.beginTask(Messages.getString("CRenameProcessorDelegate.task.createChange"), fMatches.size()); //$NON-NLS-1$
|
||||
final String identifier= getArgument().getName();
|
||||
final String replacement= getReplacementText();
|
||||
CompositeChange overallChange= new CompositeChange(getProcessorName());
|
||||
IFile file= null;
|
||||
TextFileChange fileChange= null;
|
||||
MultiTextEdit fileEdit= null;
|
||||
for (Iterator<CRefactoringMatch> iter = fMatches.iterator(); iter.hasNext();) {
|
||||
CRefactoringMatch match= iter.next();
|
||||
switch(match.getAstInformation()) {
|
||||
case CRefactoringMatch.AST_REFERENCE_OTHER:
|
||||
continue;
|
||||
case CRefactoringMatch.IN_COMMENT:
|
||||
case CRefactoringMatch.POTENTIAL:
|
||||
break;
|
||||
case CRefactoringMatch.AST_REFERENCE:
|
||||
break;
|
||||
}
|
||||
if (match.getAstInformation() != CRefactoringMatch.AST_REFERENCE_OTHER) {
|
||||
IFile mfile= match.getFile();
|
||||
if (file==null || !file.equals(mfile)) {
|
||||
file= mfile;
|
||||
fileEdit= new MultiTextEdit();
|
||||
fileChange = new CTextFileChange(file.getName(), file);
|
||||
fileChange.setEdit(fileEdit);
|
||||
overallChange.add(fileChange);
|
||||
}
|
||||
|
||||
ReplaceEdit replaceEdit= new ReplaceEdit(match.getOffset(),
|
||||
identifier.length(), replacement);
|
||||
fileEdit.addChild(replaceEdit);
|
||||
TextEditGroup editGroup= new TextEditGroup(match.getLabel(), replaceEdit);
|
||||
TextEditChangeGroup changeGroup= new TextEditChangeGroup(fileChange, editGroup);
|
||||
fileChange.addTextEditChangeGroup(changeGroup);
|
||||
}
|
||||
pm.worked(1);
|
||||
}
|
||||
return overallChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of bindings that must be renamed
|
||||
*/
|
||||
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
|
||||
return new IBinding[] {getArgument().getBinding()};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 Wind River Systems, Inc. and others.
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
|
||||
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
|
||||
|
||||
/**
|
||||
* Refactoring implementation using a refactoring processor.
|
||||
*/
|
||||
public class CRenameRefactoring extends ProcessorBasedRefactoring {
|
||||
|
||||
private CRenameProcessor fProcessor;
|
||||
|
||||
public CRenameRefactoring(CRenameProcessor processor) {
|
||||
super(processor);
|
||||
fProcessor= processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringProcessor getProcessor() {
|
||||
return fProcessor;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue