mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
2005-02-25 Alain Magloire
Fix PR 82292: Code template variable not working. * src/org/eclipse/cdt/internal/corext/template/c/CContext.java * src/org/eclipse/cdt/internal/corext/template/c/CContextType.java * src/org/eclipse/cdt/internal/corext/template/c/TemplateMessage.properties * src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContext.java * src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java * src/org/eclipse/cdt/internal/ui/text/contentassit/CCompletionProcessor.java * templates/default-templates.xml
This commit is contained in:
parent
67adb089c5
commit
c9e12353d6
8 changed files with 117 additions and 110 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2005-02-25 Alain Magloire
|
||||||
|
Fix PR 82292: Code template variable not working.
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/c/CContext.java
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/c/CContextType.java
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/c/TemplateMessage.properties
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContext.java
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/c/TranslationUnitContextType.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/contentassit/CCompletionProcessor.java
|
||||||
|
* templates/default-templates.xml
|
||||||
|
|
||||||
2005-02-25 Alain Magloire
|
2005-02-25 Alain Magloire
|
||||||
Fix PR 69572: Key binding action for Matching Bracket ... Ctrl+Shift+P
|
Fix PR 69572: Key binding action for Matching Bracket ... Ctrl+Shift+P
|
||||||
* src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
|
* src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class CContext extends TranslationUnitContext {
|
||||||
* @param unit the compilation unit (may be <code>null</code>).
|
* @param unit the compilation unit (may be <code>null</code>).
|
||||||
*/
|
*/
|
||||||
public CContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength,
|
public CContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength,
|
||||||
ITranslationUnit translationUnit)
|
ITranslationUnit translationUnit) {
|
||||||
{
|
|
||||||
super(type, document, completionOffset, completionLength, translationUnit);
|
super(type, document, completionOffset, completionLength, translationUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,6 @@ public class CContextType extends TranslationUnitContextType {
|
||||||
addResolver(new File());
|
addResolver(new File());
|
||||||
addResolver(new ReturnType());
|
addResolver(new ReturnType());
|
||||||
addResolver(new Method());
|
addResolver(new Method());
|
||||||
addResolver(new Type());
|
|
||||||
addResolver(new Package());
|
|
||||||
addResolver(new Project());
|
addResolver(new Project());
|
||||||
addResolver(new Arguments());
|
addResolver(new Arguments());
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,17 @@ GlobalVariables.variable.description.user=User name
|
||||||
|
|
||||||
JavaDocContextType.variable.description.file=Filename of compilation unit
|
JavaDocContextType.variable.description.file=Filename of compilation unit
|
||||||
|
|
||||||
JavaContextType.variable.description.file=Filename of compilation unit
|
CContextType.variable.description.file=Filename of compilation unit
|
||||||
JavaContextType.variable.description.array=A proposal for an array
|
CContextType.variable.description.array=A proposal for an array
|
||||||
JavaContextType.variable.description.array.type=A proposal for the element type of an array
|
CContextType.variable.description.array.type=A proposal for the element type of an array
|
||||||
JavaContextType.variable.description.array.element=A proposal for the element name of an array
|
CContextType.variable.description.array.element=A proposal for the element name of an array
|
||||||
JavaContextType.variable.description.index=A proposal for an index (int)
|
CContextType.variable.description.index=A proposal for an index (int)
|
||||||
JavaContextType.variable.description.collector=A proposal for a collector (java.util.Collector)
|
CContextType.variable.description.collector=A proposal for a collector (java.util.Collector)
|
||||||
JavaContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator)
|
CContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator)
|
||||||
JavaContextType.variable.description.arguments=Method arguments (evaluates to empty string)
|
CContextType.variable.description.arguments=Method arguments (evaluates to empty string)
|
||||||
JavaContextType.variable.description.enclosing.method=Enclosing method name
|
CContextType.variable.description.enclosing.method=Enclosing method name
|
||||||
JavaContextType.variable.description.enclosing.type=Enclosing type name
|
CContextType.variable.description.enclosing.type=Enclosing type name
|
||||||
JavaContextType.variable.description.enclosing.package=Enclosing package name
|
CContextType.variable.description.enclosing.package=Enclosing package name
|
||||||
JavaContextType.variable.description.enclosing.project=Enclosing project name
|
CContextType.variable.description.enclosing.project=Enclosing project name
|
||||||
JavaContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method
|
CContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method
|
||||||
JavaContextType.variable.description.return.type=Enclosing method return type
|
CContextType.variable.description.return.type=Enclosing method return type
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2004, 2005 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
* QNX Software System
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.corext.template.c;
|
package org.eclipse.cdt.internal.corext.template.c;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000, 2004, 2005 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
* QNX Software System
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.corext.template.c;
|
package org.eclipse.cdt.internal.corext.template.c;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.templates.TemplateContext;
|
import org.eclipse.jface.text.templates.TemplateContext;
|
||||||
import org.eclipse.jface.text.templates.TemplateContextType;
|
import org.eclipse.jface.text.templates.TemplateContextType;
|
||||||
import org.eclipse.jface.text.templates.TemplateVariableResolver;
|
import org.eclipse.jface.text.templates.TemplateVariableResolver;
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) Copyright IBM Corp. 2000, 2001.
|
|
||||||
* All Rights Reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compilation unit context type.
|
* Compilation unit context type.
|
||||||
*/
|
*/
|
||||||
|
@ -28,111 +36,106 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
|
||||||
|
|
||||||
protected static class ReturnType extends TemplateVariableResolver {
|
protected static class ReturnType extends TemplateVariableResolver {
|
||||||
public ReturnType() {
|
public ReturnType() {
|
||||||
super("return_type", TemplateMessages.getString("JavaContextType.variable.description.return.type")); //$NON-NLS-1$ //$NON-NLS-2$
|
super("return_type", TemplateMessages.getString("CContextType.variable.description.return.type")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
public String evaluate(TemplateContext context) {
|
public String resolve(TemplateContext context) {
|
||||||
/* IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
|
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD);
|
||||||
if (element == null)
|
if (element == null) {
|
||||||
|
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION);
|
||||||
|
}
|
||||||
|
if (element == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
if (element instanceof IFunctionDeclaration) {
|
||||||
return Signature.toString(((IMethod) element).getReturnType());
|
return ((IFunctionDeclaration) element).getReturnType();
|
||||||
} catch (JavaModelException e) {
|
}
|
||||||
return null;
|
|
||||||
} */
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public boolean isResolved(TemplateContext context) {
|
|
||||||
return evaluate(context) != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class File extends TemplateVariableResolver {
|
protected static class File extends TemplateVariableResolver {
|
||||||
public File() {
|
public File() {
|
||||||
super("file", TemplateMessages.getString("JavaContextType.variable.description.file")); //$NON-NLS-1$ //$NON-NLS-2$
|
super("file", TemplateMessages.getString("CContextType.variable.description.file")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
public String evaluate(TemplateContext context) {
|
public String resolve(TemplateContext context) {
|
||||||
//ICompilationUnit unit= ((TranslationUnitContext) context).getCompilationUnit();
|
ITranslationUnit unit= ((TranslationUnitContext) context).getTranslationUnit();
|
||||||
|
|
||||||
//return (unit == null) ? null : unit.getElementName();
|
return (unit == null) ? null : unit.getElementName();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public boolean isResolved(TemplateContext context) {
|
|
||||||
return evaluate(context) != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class EnclosingJavaElement extends TemplateVariableResolver {
|
protected static class EnclosingCElement extends TemplateVariableResolver {
|
||||||
protected final int fElementType;
|
protected final int fElementType;
|
||||||
|
|
||||||
public EnclosingJavaElement(String name, String description, int elementType) {
|
public EnclosingCElement(String name, String description, int elementType) {
|
||||||
super(name, description);
|
super(name, description);
|
||||||
fElementType= elementType;
|
fElementType= elementType;
|
||||||
}
|
}
|
||||||
public String evaluate(TemplateContext context) {
|
public String resolve(TemplateContext context) {
|
||||||
/*IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(fElementType);
|
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(fElementType);
|
||||||
return (element == null) ? null : element.getElementName(); */
|
return (element == null) ? null : element.getElementName();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public boolean isResolved(TemplateContext context) {
|
|
||||||
return evaluate(context) != null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class Method extends EnclosingJavaElement {
|
protected static class Method extends EnclosingCElement {
|
||||||
public Method() {
|
public Method() {
|
||||||
//super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), IJavaElement.METHOD);
|
super("enclosing_method", TemplateMessages.getString("CContextType.variable.description.enclosing.method"), ICElement.C_METHOD); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class Type extends EnclosingJavaElement {
|
/*
|
||||||
|
protected static class Type extends EnclosingCElement {
|
||||||
public Type() {
|
public Type() {
|
||||||
super("enclosing_type", TemplateMessages.getString("JavaContextType.variable.description.enclosing.type"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
super("enclosing_type", TemplateMessages.getString("CContextType.variable.description.enclosing.type"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
protected static class SuperClass extends EnclosingCElement {
|
||||||
protected static class SuperClass extends EnclosingJavaElement {
|
|
||||||
public Type() {
|
public Type() {
|
||||||
super("super_class", TemplateMessages.getString("JavaContextType.variable.description.type"), IJavaElement.TYPE);
|
super("super_class", TemplateMessages.getString("CContextType.variable.description.type"), IJavaElement.TYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
protected static class Package extends EnclosingJavaElement {
|
protected static class Package extends EnclosingCElement {
|
||||||
public Package() {
|
public Package() {
|
||||||
super("enclosing_package", TemplateMessages.getString("JavaContextType.variable.description.enclosing.package"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
super("enclosing_package", TemplateMessages.getString("CContextType.variable.description.enclosing.package"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class Project extends EnclosingJavaElement {
|
|
||||||
public Project() {
|
|
||||||
super("enclosing_project", TemplateMessages.getString("JavaContextType.variable.description.enclosing.project"), 0); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
protected static class Project2 extends TemplateVariable {
|
|
||||||
public Project2() {
|
|
||||||
super("project", TemplateMessages.getString("JavaContextType.variable.description.project"));
|
|
||||||
}
|
|
||||||
public String evaluate(TemplateContext context) {
|
|
||||||
ICompilationUnit unit= ((JavaContext) context).getUnit();
|
|
||||||
return (unit == null) ? null : unit.getJavaProject().getElementName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// protected static class Project extends EnclosingCElement {
|
||||||
|
// public Project() {
|
||||||
|
// super("enclosing_project", TemplateMessages.getString("CContextType.variable.description.enclosing.project"), ICElement.C_PROJECT); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
protected static class Project extends TemplateVariableResolver {
|
||||||
|
public Project() {
|
||||||
|
super("enclosing_project", TemplateMessages.getString("CContextType.variable.description.project"));
|
||||||
|
}
|
||||||
|
public String resolve(TemplateContext context) {
|
||||||
|
ITranslationUnit unit= ((CContext) context).getTranslationUnit();
|
||||||
|
return (unit == null) ? null : unit.getCProject().getElementName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static class Arguments extends TemplateVariableResolver {
|
protected static class Arguments extends TemplateVariableResolver {
|
||||||
public Arguments() {
|
public Arguments() {
|
||||||
super("enclosing_method_arguments", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method.arguments")); //$NON-NLS-1$ //$NON-NLS-2$
|
super("enclosing_method_arguments", TemplateMessages.getString("CContextType.variable.description.enclosing.method.arguments")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
public String evaluate(TemplateContext context) {
|
public String resolve(TemplateContext context) {
|
||||||
/*IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
|
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION);
|
||||||
if (element == null)
|
if (element == null) {
|
||||||
return null;
|
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION_DECLARATION);
|
||||||
|
if (element == null) {
|
||||||
IMethod method= (IMethod) element;
|
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD);
|
||||||
|
if (element == null) {
|
||||||
try {
|
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD_DECLARATION);
|
||||||
String[] arguments= method.getParameterNames();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element instanceof IFunctionDeclaration) {
|
||||||
|
String[] arguments= ((IFunctionDeclaration)element).getParameterTypes();
|
||||||
StringBuffer buffer= new StringBuffer();
|
StringBuffer buffer= new StringBuffer();
|
||||||
|
|
||||||
for (int i= 0; i < arguments.length; i++) {
|
for (int i= 0; i < arguments.length; i++) {
|
||||||
|
@ -142,25 +145,11 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
}
|
||||||
} catch (JavaModelException e) {
|
|
||||||
return null;
|
|
||||||
} */
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
protected static class Line extends TemplateVariable {
|
|
||||||
public Line() {
|
|
||||||
super("line", TemplateMessages.getString("TranslationUnitContextType.variable.description.line"));
|
|
||||||
}
|
|
||||||
public String evaluate(TemplateContext context) {
|
|
||||||
return ((JavaTemplateContext) context).guessLineNumber();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see ContextType#ContextType(String)
|
* @see ContextType#ContextType(String)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IWorkingCopyManager fManager;
|
||||||
private CEditor fEditor;
|
private CEditor fEditor;
|
||||||
private char[] fProposalAutoActivationSet;
|
private char[] fProposalAutoActivationSet;
|
||||||
private CCompletionProposalComparator fComparator;
|
private CCompletionProposalComparator fComparator;
|
||||||
|
@ -123,7 +123,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
|
|
||||||
public CCompletionProcessor(IEditorPart editor) {
|
public CCompletionProcessor(IEditorPart editor) {
|
||||||
fEditor = (CEditor) editor;
|
fEditor = (CEditor) editor;
|
||||||
|
fManager= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||||
// Needed for search
|
// Needed for search
|
||||||
searchResultCollector = new BasicSearchResultCollector ();
|
searchResultCollector = new BasicSearchResultCollector ();
|
||||||
resultCollector = new ResultCollector();
|
resultCollector = new ResultCollector();
|
||||||
|
@ -257,7 +257,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset) {
|
private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset) {
|
||||||
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
|
|
||||||
IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput());
|
IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
|
|
||||||
IDocument document = viewer.getDocument();
|
IDocument document = viewer.getDocument();
|
||||||
|
@ -373,7 +372,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
if (fTemplateEngine != null) {
|
if (fTemplateEngine != null) {
|
||||||
try {
|
try {
|
||||||
fTemplateEngine.reset();
|
fTemplateEngine.reset();
|
||||||
fTemplateEngine.complete(viewer, fCurrentOffset, null);
|
fTemplateEngine.complete(viewer, fCurrentOffset, fCurrentSourceUnit);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
CUIPlugin.getDefault().log(x);
|
CUIPlugin.getDefault().log(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ All Rights Reserved.
|
||||||
<!ENTITY printtostderr "print to standard error">
|
<!ENTITY printtostderr "print to standard error">
|
||||||
<!ENTITY authorname "author name">
|
<!ENTITY authorname "author name">
|
||||||
<!ENTITY commentText "To change this generated comment edit the template variable "comment":
|
<!ENTITY commentText "To change this generated comment edit the template variable "comment":
|
||||||
* Window>Preferences>C>Templates.">
|
* Window>Preferences>C>Editor>Templates.">
|
||||||
|
|
||||||
]>
|
]>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue