1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46: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:
Alain Magloire 2005-02-26 03:12:35 +00:00
parent 67adb089c5
commit c9e12353d6
8 changed files with 117 additions and 110 deletions

View file

@ -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
Fix PR 69572: Key binding action for Matching Bracket ... Ctrl+Shift+P
* src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java

View file

@ -39,8 +39,7 @@ public class CContext extends TranslationUnitContext {
* @param unit the compilation unit (may be <code>null</code>).
*/
public CContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength,
ITranslationUnit translationUnit)
{
ITranslationUnit translationUnit) {
super(type, document, completionOffset, completionLength, translationUnit);
}

View file

@ -41,8 +41,6 @@ public class CContextType extends TranslationUnitContextType {
addResolver(new File());
addResolver(new ReturnType());
addResolver(new Method());
addResolver(new Type());
addResolver(new Package());
addResolver(new Project());
addResolver(new Arguments());

View file

@ -13,17 +13,17 @@ GlobalVariables.variable.description.user=User name
JavaDocContextType.variable.description.file=Filename of compilation unit
JavaContextType.variable.description.file=Filename of compilation unit
JavaContextType.variable.description.array=A proposal for an array
JavaContextType.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
JavaContextType.variable.description.index=A proposal for an index (int)
JavaContextType.variable.description.collector=A proposal for a collector (java.util.Collector)
JavaContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator)
JavaContextType.variable.description.arguments=Method arguments (evaluates to empty string)
JavaContextType.variable.description.enclosing.method=Enclosing method name
JavaContextType.variable.description.enclosing.type=Enclosing type name
JavaContextType.variable.description.enclosing.package=Enclosing package name
JavaContextType.variable.description.enclosing.project=Enclosing project name
JavaContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method
JavaContextType.variable.description.return.type=Enclosing method return type
CContextType.variable.description.file=Filename of compilation unit
CContextType.variable.description.array=A proposal for an array
CContextType.variable.description.array.type=A proposal for the element type of an array
CContextType.variable.description.array.element=A proposal for the element name of an array
CContextType.variable.description.index=A proposal for an index (int)
CContextType.variable.description.collector=A proposal for a collector (java.util.Collector)
CContextType.variable.description.iterator=A proposal for an iterator (java.util.Iterator)
CContextType.variable.description.arguments=Method arguments (evaluates to empty string)
CContextType.variable.description.enclosing.method=Enclosing method name
CContextType.variable.description.enclosing.type=Enclosing type name
CContextType.variable.description.enclosing.package=Enclosing package name
CContextType.variable.description.enclosing.project=Enclosing project name
CContextType.variable.description.enclosing.method.arguments=Argument names of enclosing method
CContextType.variable.description.return.type=Enclosing method return type

View file

@ -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;
/*

View file

@ -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;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.templates.TemplateContext;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.eclipse.jface.text.templates.TemplateVariableResolver;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
/**
* Compilation unit context type.
*/
@ -28,111 +36,106 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
protected static class ReturnType extends TemplateVariableResolver {
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) {
/* IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
if (element == null)
public String resolve(TemplateContext context) {
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD);
if (element == null) {
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION);
}
if (element == null) {
return null;
}
try {
return Signature.toString(((IMethod) element).getReturnType());
} catch (JavaModelException e) {
return null;
} */
if (element instanceof IFunctionDeclaration) {
return ((IFunctionDeclaration) element).getReturnType();
}
return null;
}
public boolean isResolved(TemplateContext context) {
return evaluate(context) != null;
}
}
protected static class File extends TemplateVariableResolver {
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) {
//ICompilationUnit unit= ((TranslationUnitContext) context).getCompilationUnit();
public String resolve(TemplateContext context) {
ITranslationUnit unit= ((TranslationUnitContext) context).getTranslationUnit();
//return (unit == null) ? null : unit.getElementName();
return null;
return (unit == null) ? null : unit.getElementName();
}
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;
public EnclosingJavaElement(String name, String description, int elementType) {
public EnclosingCElement(String name, String description, int elementType) {
super(name, description);
fElementType= elementType;
}
public String evaluate(TemplateContext context) {
/*IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(fElementType);
return (element == null) ? null : element.getElementName(); */
return null;
}
public boolean isResolved(TemplateContext context) {
return evaluate(context) != null;
public String resolve(TemplateContext context) {
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(fElementType);
return (element == null) ? null : element.getElementName();
}
}
protected static class Method extends EnclosingJavaElement {
protected static class Method extends EnclosingCElement {
public Method() {
//super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), IJavaElement.METHOD);
super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), 0); //$NON-NLS-1$ //$NON-NLS-2$
super("enclosing_method", TemplateMessages.getString("CContextType.variable.description.enclosing.method"), ICElement.C_METHOD); //$NON-NLS-1$ //$NON-NLS-2$
}
}
protected static class Type extends EnclosingJavaElement {
/*
protected static class Type extends EnclosingCElement {
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 EnclosingJavaElement {
protected static class SuperClass extends EnclosingCElement {
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() {
super("enclosing_package", TemplateMessages.getString("JavaContextType.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();
super("enclosing_package", TemplateMessages.getString("CContextType.variable.description.enclosing.package"), 0); //$NON-NLS-1$ //$NON-NLS-2$
}
}
*/
// 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 {
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) {
/*IJavaElement element= ((TranslationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
if (element == null)
return null;
IMethod method= (IMethod) element;
try {
String[] arguments= method.getParameterNames();
public String resolve(TemplateContext context) {
ICElement element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION);
if (element == null) {
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_FUNCTION_DECLARATION);
if (element == null) {
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD);
if (element == null) {
element= ((TranslationUnitContext) context).findEnclosingElement(ICElement.C_METHOD_DECLARATION);
}
}
}
if (element instanceof IFunctionDeclaration) {
String[] arguments= ((IFunctionDeclaration)element).getParameterTypes();
StringBuffer buffer= new StringBuffer();
for (int i= 0; i < arguments.length; i++) {
@ -142,25 +145,11 @@ public abstract class TranslationUnitContextType extends TemplateContextType {
}
return buffer.toString();
} catch (JavaModelException e) {
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)
*/

View file

@ -97,7 +97,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
}
protected IWorkingCopyManager fManager;
private CEditor fEditor;
private char[] fProposalAutoActivationSet;
private CCompletionProposalComparator fComparator;
@ -123,7 +123,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
public CCompletionProcessor(IEditorPart editor) {
fEditor = (CEditor) editor;
fManager= CUIPlugin.getDefault().getWorkingCopyManager();
// Needed for search
searchResultCollector = new BasicSearchResultCollector ();
resultCollector = new ResultCollector();
@ -257,7 +257,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset) {
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput());
IDocument document = viewer.getDocument();
@ -373,7 +372,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
if (fTemplateEngine != null) {
try {
fTemplateEngine.reset();
fTemplateEngine.complete(viewer, fCurrentOffset, null);
fTemplateEngine.complete(viewer, fCurrentOffset, fCurrentSourceUnit);
} catch (Exception x) {
CUIPlugin.getDefault().log(x);
}

View file

@ -26,7 +26,7 @@ All Rights Reserved.
<!ENTITY printtostderr "print to standard error">
<!ENTITY authorname "author name">
<!ENTITY commentText "To change this generated comment edit the template variable &quot;comment&quot;:
* Window&gt;Preferences&gt;C&gt;Templates.">
* Window&gt;Preferences&gt;C&gt;Editor&gt;Templates.">
]>