X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;ds=sidebyside;f=case-study%2Fjdt-before%2Fcore%20extension%2Forg%2Feclipse%2Fjdt%2Finternal%2Fcorext%2Ftemplate%2Fjava%2FJavaDocContextType.java;fp=case-study%2Fjdt-before%2Fcore%20extension%2Forg%2Feclipse%2Fjdt%2Finternal%2Fcorext%2Ftemplate%2Fjava%2FJavaDocContextType.java;h=b7cf5fcce6e1e02134c944497beff62afa4315b7;hb=1b2798f607d741df30e5197f427381cbff326adc;hp=0000000000000000000000000000000000000000;hpb=246231e4bd9b24345490f369747c0549ca308c4d;p=ifi-stolz-refaktor.git diff --git a/case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/JavaDocContextType.java b/case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/JavaDocContextType.java new file mode 100644 index 00000000..b7cf5fcc --- /dev/null +++ b/case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/JavaDocContextType.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.internal.corext.template.java; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.templates.GlobalTemplateVariables; +import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; +import org.eclipse.jface.text.templates.TemplateContext; + +import org.eclipse.jdt.core.ICompilationUnit; + + +/** + * The context type for templates inside Javadoc. + */ +public class JavaDocContextType extends CompilationUnitContextType { + + /** + * The word selection variable determines templates that work on a full + * lines selection. + *

+ * This class contains additional description that tells about the + * 'Source > Surround With > ...' menu.

+ * + * @since 3.7 + * @see org.eclipse.jface.text.templates.GlobalTemplateVariables.WordSelection + */ + protected static class SurroundWithWordSelection extends SimpleTemplateVariableResolver { + + /** + * Creates a new word selection variable + */ + public SurroundWithWordSelection() { + super(org.eclipse.jface.text.templates.GlobalTemplateVariables.WordSelection.NAME, JavaTemplateMessages.JavaDocContextType_variable_description_word_selection); + } + @Override + protected String resolve(TemplateContext context) { + String selection= context.getVariable(org.eclipse.jface.text.templates.GlobalTemplateVariables.SELECTION); + if (selection == null) + return ""; //$NON-NLS-1$ + return selection; + } + } + + /** + * The id under which this context type is registered + */ + public static final String ID= "javadoc"; //$NON-NLS-1$ + + /** + * Creates a java context type. + */ + public JavaDocContextType() { + + // global + addResolver(new GlobalTemplateVariables.Cursor()); + addResolver(new SurroundWithLineSelection()); + addResolver(new SurroundWithWordSelection()); + addResolver(new GlobalTemplateVariables.Dollar()); + addResolver(new GlobalTemplateVariables.Date()); + addResolver(new GlobalTemplateVariables.Year()); + addResolver(new GlobalTemplateVariables.Time()); + addResolver(new GlobalTemplateVariables.User()); + + // compilation unit + addResolver(new File()); + addResolver(new PrimaryTypeName()); + addResolver(new Method()); + addResolver(new ReturnType()); + addResolver(new Arguments()); + addResolver(new Type()); + addResolver(new Package()); + addResolver(new Project()); + } + + /* + * @see org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, int, int, org.eclipse.jdt.core.ICompilationUnit) + */ + @Override + public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) { + return new JavaDocContext(this, document, offset, length, compilationUnit); + } + + /* + * @see org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position, org.eclipse.jdt.core.ICompilationUnit) + */ + @Override + public CompilationUnitContext createContext(IDocument document, Position completionPosition, ICompilationUnit compilationUnit) { + return new JavaDocContext(this, document, completionPosition, compilationUnit); + } +}