Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 200067
Collapse All | Expand All

(-)core extension/org/eclipse/jdt/internal/corext/template/java/JavaContext.java (-12 / +1 lines)
Lines 205-211 Link Here
205
			int start= getCompletionOffset();
205
			int start= getCompletionOffset();
206
			int end= getCompletionOffset() + getCompletionLength();
206
			int end= getCompletionOffset() + getCompletionLength();
207
			
207
			
208
			while (start != 0 && isTempalteNamePart(document.getChar(start - 1)))
208
			while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
209
				start--;
209
				start--;
210
			
210
			
211
			while (start != end && Character.isWhitespace(document.getChar(start)))
211
			while (start != end && Character.isWhitespace(document.getChar(start)))
Lines 221-237 Link Here
221
		}
221
		}
222
	}
222
	}
223
223
224
	/**
225
	 * Tells whether the given character can be part of a template name.
226
	 * 
227
	 * @param ch the character to test
228
	 * @return <code>true</code> if the given character can be part of a template name
229
	 * @since 3.3
230
	 */
231
	private boolean isTempalteNamePart(char ch) {
232
		return !Character.isWhitespace(ch) && ch != '(' && ch != ')' && ch != '{' && ch != '}' && ch != ';';
233
	}
234
235
	/*
224
	/*
236
	 * @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
225
	 * @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
237
	 */
226
	 */
(-)core extension/org/eclipse/jdt/internal/corext/template/java/JavaDocContext.java (-3 / +3 lines)
Lines 99-108 Link Here
99
				if ((start != 0) && (document.getChar(start - 1) == HTML_TAG_END))
99
				if ((start != 0) && (document.getChar(start - 1) == HTML_TAG_END))
100
					start--;
100
					start--;
101
		
101
		
102
				while ((start != 0) && !Character.isWhitespace(document.getChar(start - 1)))
102
				while ((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
103
					start--;
103
					start--;
104
				
104
				
105
				if ((start != 0) && !Character.isWhitespace(document.getChar(start - 1)))
105
				if ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1)))
106
					start--;
106
					start--;
107
		
107
		
108
				// include html and javadoc tags
108
				// include html and javadoc tags
Lines 120-126 Link Here
120
			int start= getCompletionOffset();
120
			int start= getCompletionOffset();
121
			int end= getCompletionOffset() + getCompletionLength();
121
			int end= getCompletionOffset() + getCompletionLength();
122
			
122
			
123
			while (start != 0 && !Character.isWhitespace(document.getChar(start - 1)))
123
			while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
124
				start--;
124
				start--;
125
			
125
			
126
			while (start != end && Character.isWhitespace(document.getChar(start)))
126
			while (start != end && Character.isWhitespace(document.getChar(start)))
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties (-1 / +1 lines)
Lines 800-806 Link Here
800
800
801
# edit template dialog
801
# edit template dialog
802
EditTemplateDialog_error_noname=Template name cannot be empty.
802
EditTemplateDialog_error_noname=Template name cannot be empty.
803
EditTemplateDialog_error_spaces=Template name cannot contain spaces.
803
EditTemplateDialog_error_spaces=Template name contains invalid characters.
804
EditTemplateDialog_title_new=New Template
804
EditTemplateDialog_title_new=New Template
805
EditTemplateDialog_title_edit=Edit Template
805
EditTemplateDialog_title_edit=Edit Template
806
806
(-)ui/org/eclipse/jdt/internal/ui/preferences/EditTemplateDialog.java (-6 / +38 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 73-78 Link Here
73
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
73
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
74
import org.eclipse.ui.texteditor.IUpdate;
74
import org.eclipse.ui.texteditor.IUpdate;
75
75
76
import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType;
77
76
import org.eclipse.jdt.ui.IContextMenuConstants;
78
import org.eclipse.jdt.ui.IContextMenuConstants;
77
import org.eclipse.jdt.ui.PreferenceConstants;
79
import org.eclipse.jdt.ui.PreferenceConstants;
78
import org.eclipse.jdt.ui.text.IJavaPartitions;
80
import org.eclipse.jdt.ui.text.IJavaPartitions;
Lines 201-208 Link Here
201
	public void create() {
203
	public void create() {
202
		super.create();
204
		super.create();
203
		updateStatusAndButtons();
205
		updateStatusAndButtons();
204
		boolean isEmpty= fNameText != null && fNameText.getText().length() == 0;
206
		getButton(IDialogConstants.OK_ID).setEnabled(getStatus().isOK());
205
		getButton(IDialogConstants.OK_ID).setEnabled(!isEmpty);
206
	}
207
	}
207
	
208
	
208
	/*
209
	/*
Lines 310-316 Link Here
310
	protected void doTextWidgetChanged(Widget w) {
311
	protected void doTextWidgetChanged(Widget w) {
311
		if (w == fNameText) {
312
		if (w == fNameText) {
312
			fSuppressError= false;
313
			fSuppressError= false;
313
			updateStatusAndButtons();			
314
			updateStatusAndButtons();
314
		} else if (w == fContextCombo) {
315
		} else if (w == fContextCombo) {
315
			String contextId= getContextId();
316
			String contextId= getContextId();
316
			fTemplateProcessor.setContextType(fContextTypeRegistry.getContextType(contextId));
317
			fTemplateProcessor.setContextType(fContextTypeRegistry.getContextType(contextId));
Lines 318-323 Link Here
318
			String prefix= getPrefix();
319
			String prefix= getPrefix();
319
			document.set(prefix + getPattern());
320
			document.set(prefix + getPattern());
320
			fPatternEditor.setVisibleRegion(prefix.length(), document.getLength() - prefix.length());
321
			fPatternEditor.setVisibleRegion(prefix.length(), document.getLength() - prefix.length());
322
			updateStatusAndButtons();
321
		} else if (w == fDescriptionText) {
323
		} else if (w == fDescriptionText) {
322
			// nothing
324
			// nothing
323
		}	
325
		}	
Lines 562-574 Link Here
562
		if (!fSuppressError && isEmpty) {
564
		if (!fSuppressError && isEmpty) {
563
			status= new StatusInfo();
565
			status= new StatusInfo();
564
			status.setError(PreferencesMessages.EditTemplateDialog_error_noname); 
566
			status.setError(PreferencesMessages.EditTemplateDialog_error_noname); 
565
		} else if (fNameText != null && fNameText.getText().indexOf(' ') > -1) {
567
		} else if (fNameText != null && !isValidTemplateName(fNameText.getText())) {
566
			status= new StatusInfo();
568
			status= new StatusInfo();
567
			status.setError(PreferencesMessages.EditTemplateDialog_error_spaces); 
569
			status.setError(PreferencesMessages.EditTemplateDialog_error_spaces); 
568
		}
570
		}
569
		updateStatus(status);
571
		updateStatus(status);
570
	}
572
	}
571
	
573
574
	/**
575
	 * Checks whether the given string is a valid
576
	 * template name.
577
	 *  
578
	 * @param name the string to test
579
	 * @return <code>true</code> if the name is valid
580
	 * @since 3.3.1
581
	 */
582
	private boolean isValidTemplateName(String name) {
583
		int nameLength= name.length();
584
		if (nameLength == 0)
585
			return true;
586
587
		char firstChar= name.charAt(0);
588
		boolean isJavadocTemplate= JavaDocContextType.NAME.equals(getContextId());
589
		if (!Character.isUnicodeIdentifierStart(firstChar) && !(isJavadocTemplate && (firstChar == '<' || firstChar == '@')))
590
			return false;
591
592
		if (nameLength == 1)
593
			return true;
594
		
595
		for (int i= 1; i < nameLength - 1; i++) {
596
			if (!Character.isUnicodeIdentifierPart(name.charAt(i)))
597
				return false;
598
		}
599
600
		char lastChar= name.charAt(nameLength - 1);
601
		return Character.isUnicodeIdentifierPart(lastChar) || isJavadocTemplate && lastChar == '>';
602
	}
603
572
	/*
604
	/*
573
	 * @see org.eclipse.jface.window.Window#configureShell(Shell)
605
	 * @see org.eclipse.jface.window.Window#configureShell(Shell)
574
	 */
606
	 */

Return to bug 200067