issue_id
int64
2.03k
426k
title
stringlengths
9
251
body
stringlengths
1
32.8k
status
stringclasses
6 values
after_fix_sha
stringlengths
7
7
project_name
stringclasses
6 values
repo_url
stringclasses
6 values
repo_name
stringclasses
6 values
language
stringclasses
1 value
issue_url
null
before_fix_sha
null
pull_url
null
commit_datetime
unknown
report_datetime
unknown
updated_file
stringlengths
2
187
file_content
stringlengths
0
368k
4,086
Bug 4086 Format problem in single element mode (1GKPJI8)
EG (27.09.2001 12:32:36) from WSAD newsgoup If you select Format (from the popup menu when you right click on .java file) while in "View selected element only" mode (ie - looking at only one method) the auot format adds a large amount of whitespace to the begining of each line. Repeated "Formats" just add more space. You then have to go to the "whole document" view and reformat the entire document to fix this (well, I guess I could manual remove the whitespace, but then what's the point of autoformat?). NOTES: EG (10.10.2001 22:38:03) pls investigate whether this is the formatting strategy or the Java editor
verified fixed
44b869a
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T11:58:37"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/codemanipulation/AddGetterSetterOperation.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.internal.ui.codemanipulation; import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.internal.ui.util.JavaModelUtil; /** * For given fields, method stubs for getters and setters are created. */ public class AddGetterSetterOperation implements IWorkspaceRunnable { private IField[] fFields; private List fCreatedAccessors; private IRequestQuery fSkipExistingQuery; private IRequestQuery fSkipFinalSettersQuery; private boolean fSkipAllFinalSetters; private boolean fSkipAllExisting; /** * Creates the operation. * @param fields The fields to create setter/getters for. * @param skipFinalSettersQuery Callback to ask if the setter can be skipped for a final field. * Argument of the query is the final field. * @param skipExistingQuery Callback to ask if setter / getters that already exist can be skipped. * Argument of the query is the existing method. */ public AddGetterSetterOperation(IField[] fields, IRequestQuery skipFinalSettersQuery, IRequestQuery skipExistingQuery) { super(); fFields= fields; fSkipExistingQuery= skipExistingQuery; fSkipFinalSettersQuery= skipFinalSettersQuery; fCreatedAccessors= new ArrayList(); } /** * The policy to evaluate the base name (no 'set'/'get' of the accessor. */ private String evalAccessorName(String fieldname) { if (fieldname.length() > 0) { char firstLetter= fieldname.charAt(0); if (!Character.isUpperCase(firstLetter)) { if (fieldname.length() > 1) { char secondLetter= fieldname.charAt(1); if (Character.isUpperCase(secondLetter)) { return fieldname.substring(1); } if (firstLetter == '_') { return String.valueOf(Character.toUpperCase(secondLetter)) + fieldname.substring(2); } } return String.valueOf(Character.toUpperCase(firstLetter)) + fieldname.substring(1); } } return fieldname; } /** * Creates the name of the parameter from an accessor name. */ private String getArgumentName(String accessorName) { if (accessorName.length() > 0) { char firstLetter= accessorName.charAt(0); if (!Character.isLowerCase(firstLetter)) { return "" + Character.toLowerCase(firstLetter) + accessorName.substring(1); //$NON-NLS-1$ } } return accessorName; } /** * Runs the operation. * @throws OperationCanceledException Runtime error thrown when operation is cancelled. */ public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor= new NullProgressMonitor(); } try { int nFields= fFields.length; monitor.beginTask(CodeManipulationMessages.getString("AddGetterSetterOperation.description"), nFields); //$NON-NLS-1$ for (int i= 0; i < nFields; i++) { generateStubs(fFields[i], new SubProgressMonitor(monitor, 1)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } } } finally { monitor.done(); } } private boolean querySkipFinalSetters(IField field) throws OperationCanceledException { if (!fSkipAllFinalSetters) { switch (fSkipFinalSettersQuery.doQuery(field)) { case IRequestQuery.CANCEL: throw new OperationCanceledException(); case IRequestQuery.NO: return false; case IRequestQuery.YES_ALL: fSkipAllFinalSetters= true; } } return true; } private boolean querySkipExistingMethods(IMethod method) throws OperationCanceledException { if (!fSkipAllExisting) { switch (fSkipExistingQuery.doQuery(method)) { case IRequestQuery.CANCEL: throw new OperationCanceledException(); case IRequestQuery.NO: return false; case IRequestQuery.YES_ALL: fSkipAllExisting= true; } } return true; } /** * Creates setter and getter for a given field. */ private void generateStubs(IField field, IProgressMonitor monitor) throws JavaModelException, OperationCanceledException { try { monitor.beginTask(CodeManipulationMessages.getFormattedString("AddGetterSetterOperation.processField", field.getElementName()), 2); //$NON-NLS-1$ fSkipAllFinalSetters= false; fSkipAllExisting= false; String fieldName= field.getElementName(); String accessorName= evalAccessorName(fieldName); String argname= getArgumentName(accessorName); boolean isStatic= Flags.isStatic(field.getFlags()); String typeName= Signature.toString(field.getTypeSignature()); IType parentType= field.getDeclaringType(); String lineDelim= StubUtility.getLineDelimiterUsed(parentType); int indent= StubUtility.getIndentUsed(parentType) + 1; // test if the getter already exists String getterName= "get" + accessorName; //$NON-NLS-1$ IMethod existing= JavaModelUtil.findMethod(getterName, new String[0], false, parentType); if (!(existing != null && querySkipExistingMethods(existing))) { // create the getter stub StringBuffer buf= new StringBuffer(); buf.append("/**\n"); //$NON-NLS-1$ buf.append(" * Gets the "); buf.append(argname); buf.append(".\n"); //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" * @return Returns a "); buf.append(typeName); buf.append('\n'); //$NON-NLS-1$ buf.append(" */\n"); //$NON-NLS-1$ buf.append("public "); //$NON-NLS-1$ if (isStatic) { buf.append("static "); //$NON-NLS-1$ } buf.append(typeName); buf.append(' '); buf.append(getterName); buf.append("() {\nreturn "); buf.append(fieldName); buf.append(";\n}\n"); //$NON-NLS-2$ //$NON-NLS-1$ IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findSibling(existing); existing.delete(false, null); } String formattedContent= StubUtility.codeFormat(buf.toString(), indent, lineDelim) + lineDelim; fCreatedAccessors.add(parentType.createMethod(formattedContent, sibling, true, null)); } monitor.worked(1); String setterName= "set" + accessorName; //$NON-NLS-1$ String[] args= new String[] { field.getTypeSignature() }; // test if the setter already exists or field is final boolean isFinal= Flags.isFinal(field.getFlags()); existing= JavaModelUtil.findMethod(setterName, args, false, parentType); if (!(isFinal && querySkipFinalSetters(field)) && !(existing != null && querySkipExistingMethods(existing))) { // create the setter stub StringBuffer buf= new StringBuffer(); buf.append("/**\n"); //$NON-NLS-1$ buf.append(" * Sets the "); buf.append(argname); buf.append(".\n"); //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" * @param "); buf.append(argname); buf.append(" The "); buf.append(argname); buf.append(" to set\n"); //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" */\n"); //$NON-NLS-1$ buf.append("public "); //$NON-NLS-1$ if (isStatic) { buf.append("static "); //$NON-NLS-1$ } buf.append("void "); buf.append(setterName); //$NON-NLS-1$ buf.append('('); buf.append(typeName); buf.append(' '); buf.append(argname); buf.append(") {\n"); //$NON-NLS-1$ if (argname.equals(fieldName)) { if (isStatic) { buf.append(parentType.getElementName()); buf.append('.'); } else { buf.append("this."); //$NON-NLS-1$ } } buf.append(fieldName); buf.append("= "); buf.append(argname); buf.append(";\n}\n"); //$NON-NLS-1$ //$NON-NLS-2$ IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findSibling(existing); existing.delete(false, null); } String formattedContent= StubUtility.codeFormat(buf.toString(), indent, lineDelim) + lineDelim; fCreatedAccessors.add(parentType.createMethod(formattedContent, sibling, true, null)); } } finally { monitor.done(); } } /** * Returns the created accessors. To be called after a sucessful run. */ public IMethod[] getCreatedAccessors() { return (IMethod[]) fCreatedAccessors.toArray(new IMethod[fCreatedAccessors.size()]); } }
4,086
Bug 4086 Format problem in single element mode (1GKPJI8)
EG (27.09.2001 12:32:36) from WSAD newsgoup If you select Format (from the popup menu when you right click on .java file) while in "View selected element only" mode (ie - looking at only one method) the auot format adds a large amount of whitespace to the begining of each line. Repeated "Formats" just add more space. You then have to go to the "whole document" view and reformat the entire document to fix this (well, I guess I could manual remove the whitespace, but then what's the point of autoformat?). NOTES: EG (10.10.2001 22:38:03) pls investigate whether this is the formatting strategy or the Java editor
verified fixed
44b869a
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T11:58:37"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/codemanipulation/StubUtility.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.internal.ui.codemanipulation; import java.util.ArrayList; import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IBuffer; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IParent; import org.eclipse.jdt.core.ISourceReference; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeHierarchy; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.ITypeNameRequestor; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.internal.formatter.CodeFormatter; import org.eclipse.jdt.internal.ui.preferences.CodeFormatterPreferencePage; import org.eclipse.jdt.internal.ui.util.JavaModelUtil; import org.eclipse.jdt.internal.ui.util.TypeInfo; import org.eclipse.jdt.internal.ui.util.TypeInfoRequestor; public class StubUtility { /** * Generates a stub. Given a template method, a stub with the same signature * will be constructed so it can be added to a type. * The method is asumed to be from a supertype, as a super call will be generated in * the method body. * @param parenttype The type to which the method will be added to * @param method A method template (method belongs to different type than the parent) * @param imports Imports required by the sub are added to the imports structure * @throws JavaModelException */ public static String genStub(IType parenttype, IMethod method, IImportsStructure imports) throws JavaModelException { boolean callSuper= !Flags.isAbstract(method.getFlags()) && !Flags.isStatic(method.getFlags()) && method.getDeclaringType().isClass(); return genStub(parenttype, method, callSuper, true, imports); } /** * Generates a stub. Given a template method, a stub with the same signature * will be constructed so it can be added to a type. * @param parenttype The type to which the method will be added to * @param method A method template (method belongs to different type than the parent) * @param callSuper If set a super call will be added to the method body * @param imports Imports required by the sub are added to the imports structure * @throws JavaModelException */ public static String genStub(IType parenttype, IMethod method, boolean callSuper, boolean addSeeTag, IImportsStructure imports) throws JavaModelException { IType declaringtype= method.getDeclaringType(); StringBuffer buf= new StringBuffer(); String[] paramTypes= method.getParameterTypes(); String[] paramNames= method.getParameterNames(); String[] excTypes= method.getExceptionTypes(); String retTypeSig= method.getReturnType(); int lastParam= paramTypes.length -1; if (!method.isConstructor()) { // java doc if (addSeeTag) { genJavaDocSeeTag(declaringtype.getElementName(), method.getElementName(), paramTypes, buf); } else { // generate a default java doc comment String desc= "Method " + method.getElementName(); //$NON-NLS-1$ genJavaDocStub(desc, paramNames, retTypeSig, excTypes, buf); } } else { String desc= "Constructor for " + parenttype.getElementName(); //$NON-NLS-1$ genJavaDocStub(desc, paramNames, Signature.SIG_VOID, excTypes, buf); } int flags= method.getFlags(); if (Flags.isPublic(flags) || (declaringtype.isInterface() && parenttype.isClass())) { buf.append("public "); //$NON-NLS-1$ } else if (Flags.isProtected(flags)) { buf.append("protected "); //$NON-NLS-1$ } else if (Flags.isPrivate(flags)) { buf.append("private "); //$NON-NLS-1$ } if (Flags.isSynchronized(flags)) { buf.append("synchronized "); //$NON-NLS-1$ } if (Flags.isVolatile(flags)) { buf.append("volatile "); //$NON-NLS-1$ } if (Flags.isStrictfp(flags)) { buf.append("strictfp "); //$NON-NLS-1$ } if (Flags.isStatic(flags)) { buf.append("static "); //$NON-NLS-1$ } if (!method.isConstructor()) { String retTypeFrm= Signature.toString(retTypeSig); if (!isBuiltInType(retTypeSig)) { resolveAndAdd(retTypeSig, declaringtype, imports); } buf.append(Signature.getSimpleName(retTypeFrm)); buf.append(' '); buf.append(method.getElementName()); } else { buf.append(parenttype.getElementName()); } buf.append('('); for (int i= 0; i <= lastParam; i++) { String paramTypeSig= paramTypes[i]; String paramTypeFrm= Signature.toString(paramTypeSig); if (!isBuiltInType(paramTypeSig)) { resolveAndAdd(paramTypeSig, declaringtype, imports); } buf.append(Signature.getSimpleName(paramTypeFrm)); buf.append(' '); buf.append(paramNames[i]); if (i < lastParam) { buf.append(", "); //$NON-NLS-1$ } } buf.append(')'); int lastExc= excTypes.length - 1; if (lastExc >= 0) { buf.append(" throws "); //$NON-NLS-1$ for (int i= 0; i <= lastExc; i++) { String excTypeSig= excTypes[i]; String excTypeFrm= Signature.toString(excTypeSig); resolveAndAdd(excTypeSig, declaringtype, imports); buf.append(Signature.getSimpleName(excTypeFrm)); if (i < lastExc) { buf.append(", "); //$NON-NLS-1$ } } } if (parenttype.isInterface()) { buf.append(";\n\n"); //$NON-NLS-1$ } else { buf.append(" {\n\t"); //$NON-NLS-1$ if (!callSuper) { if (retTypeSig != null && !retTypeSig.equals(Signature.SIG_VOID)) { buf.append('\t'); if (!isBuiltInType(retTypeSig) || Signature.getArrayCount(retTypeSig) > 0) { buf.append("return null;\n\t"); //$NON-NLS-1$ } else if (retTypeSig.equals(Signature.SIG_BOOLEAN)) { buf.append("return false;\n\t"); //$NON-NLS-1$ } else { buf.append("return 0;\n\t"); //$NON-NLS-1$ } } } else { buf.append('\t'); if (!method.isConstructor()) { if (!Signature.SIG_VOID.equals(retTypeSig)) { buf.append("return "); //$NON-NLS-1$ } buf.append("super."); //$NON-NLS-1$ buf.append(method.getElementName()); } else { buf.append("super"); //$NON-NLS-1$ } buf.append('('); for (int i= 0; i <= lastParam; i++) { buf.append(paramNames[i]); if (i < lastParam) { buf.append(", "); //$NON-NLS-1$ } } buf.append(");\n\t"); //$NON-NLS-1$ } buf.append("}\n\n"); //$NON-NLS-1$ } return buf.toString(); } private static boolean isBuiltInType(String typeName) { char first= Signature.getElementType(typeName).charAt(0); return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED); } private static void resolveAndAdd(String refTypeSig, IType declaringType, IImportsStructure imports) throws JavaModelException { String resolvedTypeName= JavaModelUtil.getResolvedTypeName(refTypeSig, declaringType); if (resolvedTypeName != null) { imports.addImport(resolvedTypeName); } } /** * Generates a default JavaDoc comment stub for a method. */ public static void genJavaDocStub(String descr, String[] paramNames, String retTypeSig, String[] excTypeSigs, StringBuffer buf) { buf.append("/**\n"); //$NON-NLS-1$ buf.append(" * "); buf.append(descr); buf.append(".\n"); //$NON-NLS-2$ //$NON-NLS-1$ for (int i= 0; i < paramNames.length; i++) { buf.append(" * @param "); buf.append(paramNames[i]); buf.append('\n'); //$NON-NLS-1$ } if (retTypeSig != null && !retTypeSig.equals(Signature.SIG_VOID)) { String simpleName= Signature.getSimpleName(Signature.toString(retTypeSig)); buf.append(" * @return "); buf.append(simpleName); buf.append('\n'); //$NON-NLS-1$ } for (int i= 0; i < excTypeSigs.length; i++) { String simpleName= Signature.getSimpleName(Signature.toString(excTypeSigs[i])); buf.append(" * @throws "); buf.append(simpleName); buf.append('\n'); //$NON-NLS-1$ } buf.append(" */\n"); //$NON-NLS-1$ } /** * Generates a '@see' tag to the defined method. */ public static void genJavaDocSeeTag(String declaringTypeName, String methodName, String[] paramTypes, StringBuffer buf) { // create a @see link buf.append("/*\n"); //$NON-NLS-1$ buf.append(" * @see "); //$NON-NLS-1$ buf.append(declaringTypeName); buf.append('#'); buf.append(methodName); buf.append('('); for (int i= 0; i < paramTypes.length; i++) { if (i > 0) { buf.append(", "); //$NON-NLS-1$ } buf.append(Signature.getSimpleName(Signature.toString(paramTypes[i]))); } buf.append(")\n"); //$NON-NLS-1$ buf.append(" */\n"); //$NON-NLS-1$ } /** * Finds a method in a list of methods. * @return The found method or null, if nothing found */ private static IMethod findMethod(IMethod method, List allMethods) throws JavaModelException { String name= method.getElementName(); String[] paramTypes= method.getParameterTypes(); boolean isConstructor= method.isConstructor(); for (int i= allMethods.size() - 1; i >= 0; i--) { IMethod curr= (IMethod) allMethods.get(i); if (JavaModelUtil.isSameMethodSignature(name, paramTypes, isConstructor, curr)) { return curr; } } return null; } /** * Creates needed constructors for a type. * @param type The type to create constructors for * @param supertype The type's super type * @param newMethods The resulting source for the created constructors (List of String) * @param imports Type names for input declarations required (for example 'java.util.Vector') */ public static void evalConstructors(IType type, IType supertype, List newMethods, IImportsStructure imports) throws JavaModelException { IMethod[] methods= supertype.getMethods(); for (int i= 0; i < methods.length; i++) { IMethod curr= methods[i]; if (curr.isConstructor() && JavaModelUtil.isVisible(curr, type.getPackageFragment())) { String newStub= genStub(type, methods[i], imports); newMethods.add(newStub); } } } /** * Searches for unimplemented methods of a type. * @param newMethods The source for the created methods (Vector of String) * @param imports Type names for input declarations required (for example 'java.util.Vector') */ public static void evalUnimplementedMethods(IType type, ITypeHierarchy hierarchy, List newMethods, IImportsStructure imports) throws JavaModelException { List allMethods= new ArrayList(); IMethod[] typeMethods= type.getMethods(); for (int i= 0; i < typeMethods.length; i++) { IMethod curr= typeMethods[i]; if (!curr.isConstructor() && !Flags.isStatic(curr.getFlags())) { allMethods.add(curr); } } IType[] superTypes= hierarchy.getAllSuperclasses(type); for (int i= 0; i < superTypes.length; i++) { IMethod[] methods= superTypes[i].getMethods(); for (int k= 0; k < methods.length; k++) { IMethod curr= methods[k]; if (!curr.isConstructor() && !Flags.isStatic(curr.getFlags())) { if (findMethod(curr, allMethods) == null) { allMethods.add(curr); } } } } for (int i= allMethods.size() - 1; i >= 0; i--) { IMethod curr= (IMethod) allMethods.get(i); if (Flags.isAbstract(curr.getFlags()) && !type.equals(curr.getDeclaringType())) { // implement all abstract methods String newStub= genStub(type, curr, false, true, imports); newMethods.add(newStub); } } IType[] superInterfaces= hierarchy.getAllSuperInterfaces(type); for (int i= 0; i < superInterfaces.length; i++) { IMethod[] methods= superInterfaces[i].getMethods(); for (int k= 0; k < methods.length; k++) { IMethod curr= methods[k]; // binary interfaces can contain static initializers (variable intializations) // 1G4CKUS if (!Flags.isStatic(curr.getFlags())) { IMethod impl= findMethod(curr, allMethods); if (impl == null || curr.getExceptionTypes().length < impl.getExceptionTypes().length) { // implement an interface method when it does not exist in the hierarchy // or when it throws less exceptions that the implemented String newStub= genStub(type, curr, false, true, imports); newMethods.add(newStub); allMethods.add(curr); } } } } } /** * Examines a string and returns the first line delimiter found. */ public static String getLineDelimiterUsed(IJavaElement elem) throws JavaModelException { ICompilationUnit cu= (ICompilationUnit) JavaModelUtil.findElementOfKind(elem, IJavaElement.COMPILATION_UNIT); if (cu != null && cu.exists()) { IBuffer buf= cu.getBuffer(); int length= buf.getLength(); for (int i= 0; i < length; i++) { char ch= buf.getChar(i); if (ch == SWT.CR) { if (i + 1 < length) { if (buf.getChar(i + 1) == SWT.LF) { return "\r\n"; //$NON-NLS-1$ } } return "\r"; //$NON-NLS-1$ } else if (ch == SWT.LF) { return "\n"; //$NON-NLS-1$ } } } return System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Embodies the policy which line delimiter to use when inserting into * a document. */ public static String getLineDelimiterFor(IDocument doc) { // new for: 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format String lineDelim= null; try { lineDelim= doc.getLineDelimiter(0); } catch (BadLocationException e) { } if (lineDelim == null) { String systemDelimiter= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ String[] lineDelims= doc.getLegalLineDelimiters(); for (int i= 0; i < lineDelims.length; i++) { if (lineDelims[i].equals(systemDelimiter)) { lineDelim= systemDelimiter; break; } } if (lineDelim == null) { lineDelim= lineDelims.length > 0 ? lineDelims[0] : systemDelimiter; } } return lineDelim; } /** * Evaluates the indention used by a Java element. (in tabulators) */ public static int getIndentUsed(IJavaElement elem) throws JavaModelException { if (elem instanceof ISourceReference) { int tabWidth= CodeFormatterPreferencePage.getTabSize(); ICompilationUnit cu= (ICompilationUnit)JavaModelUtil.findElementOfKind(elem, IJavaElement.COMPILATION_UNIT); if (cu != null) { IBuffer buf= cu.getBuffer(); int i= ((ISourceReference)elem).getSourceRange().getOffset(); int result= 0; int blanks= 0; while (i > 0) { i--; char ch= buf.getChar(i); switch (ch) { case '\t': result++; blanks= 0; break; case ' ': blanks++; if (blanks == tabWidth) { result++; blanks= 0; } break; default: return result; } } } } return 0; } public static String codeFormat(String sourceString, int initialIndentationLevel, String lineDelim) { // code formatter does not offer all options we need CodeFormatter formatter= new CodeFormatter(JavaCore.getOptions()); formatter.options.setLineSeparator(lineDelim); formatter.setInitialIndentationLevel(initialIndentationLevel); return formatter.formatSourceString(sourceString) + lineDelim; } /** * Returns the element after the give element. */ public static IJavaElement findSibling(IJavaElement member) throws JavaModelException { IJavaElement parent= member.getParent(); if (parent instanceof IParent) { IJavaElement[] elements= ((IParent)parent).getChildren(); for (int i= elements.length - 2; i >= 0 ; i--) { if (member.equals(elements[i])) { return elements[i+1]; } } } return null; } }
4,086
Bug 4086 Format problem in single element mode (1GKPJI8)
EG (27.09.2001 12:32:36) from WSAD newsgoup If you select Format (from the popup menu when you right click on .java file) while in "View selected element only" mode (ie - looking at only one method) the auot format adds a large amount of whitespace to the begining of each line. Repeated "Formats" just add more space. You then have to go to the "whole document" view and reformat the entire document to fix this (well, I guess I could manual remove the whitespace, but then what's the point of autoformat?). NOTES: EG (10.10.2001 22:38:03) pls investigate whether this is the formatting strategy or the Java editor
verified fixed
44b869a
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T11:58:37"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java
package org.eclipse.jdt.internal.ui.text.java; /* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.formatter.IFormattingStrategy; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.internal.formatter.CodeFormatter; import org.eclipse.jdt.internal.ui.codemanipulation.StubUtility; public class JavaFormattingStrategy implements IFormattingStrategy { private String fInitialIndentation; private ISourceViewer fViewer; public JavaFormattingStrategy(ISourceViewer viewer) { fViewer = viewer; } /** * @see IFormattingStrategy#formatterStarts(String) */ public void formatterStarts(String initialIndentation) { fInitialIndentation= initialIndentation; } /** * @see IFormattingStrategy#formatterStops() */ public void formatterStops() { } /** * @see IFormattingStrategy#format(String, boolean, String, int[]) */ public String format(String content, boolean isLineStart, String indentation, int[] positions) { CodeFormatter formatter= new CodeFormatter(JavaCore.getOptions()); IDocument doc= fViewer.getDocument(); String lineDelimiter= StubUtility.getLineDelimiterFor(doc); formatter.options.setLineSeparator(lineDelimiter); formatter.setPositionsToMap(positions); formatter.setInitialIndentationLevel(fInitialIndentation == null ? 0 : fInitialIndentation.length()); return formatter.formatSourceString(content); } }
4,283
Bug 4283 assertion failed on opening rename parameters (1GKYY5N)
ak (10/2/2001 2:27:26 PM) during file editing i selected 'Rename parameters..' from the global 'Refactor' menu 4 org.eclipse.ui 0 null argument; org.eclipse.jface.util.Assert$AssertionFailedException: null argument; at org.eclipse.jface.util.Assert.isNotNull(Assert.java:133) at org.eclipse.jface.util.Assert.isNotNull(Assert.java(Compiled Code)) at org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard.<init>(RefactoringWizard.java:47) at org.eclipse.jdt.internal.ui.refactoring.RenameParametersWizard.<init>(RenameParametersWizard.java:14) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringGroup$1.createWizard(RefactoringGroup.java:77) at org.eclipse.jdt.internal.ui.refactoring.actions.OpenRefactoringWizardAction.run(OpenRefactoringWizardAction.java:49) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringActionDelegate.run(RefactoringActionDelegate.java:47) at org.eclipse.ui.internal.PluginAction.run(PluginAction.java:125) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java(Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:658) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:820) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:285) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:433) at org.eclipse.core.launcher.Main.main(Main.java:306) NOTES:
resolved fixed
fb1f1e3
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T13:50:36"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui
4,283
Bug 4283 assertion failed on opening rename parameters (1GKYY5N)
ak (10/2/2001 2:27:26 PM) during file editing i selected 'Rename parameters..' from the global 'Refactor' menu 4 org.eclipse.ui 0 null argument; org.eclipse.jface.util.Assert$AssertionFailedException: null argument; at org.eclipse.jface.util.Assert.isNotNull(Assert.java:133) at org.eclipse.jface.util.Assert.isNotNull(Assert.java(Compiled Code)) at org.eclipse.jdt.internal.ui.refactoring.RefactoringWizard.<init>(RefactoringWizard.java:47) at org.eclipse.jdt.internal.ui.refactoring.RenameParametersWizard.<init>(RenameParametersWizard.java:14) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringGroup$1.createWizard(RefactoringGroup.java:77) at org.eclipse.jdt.internal.ui.refactoring.actions.OpenRefactoringWizardAction.run(OpenRefactoringWizardAction.java:49) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringActionDelegate.run(RefactoringActionDelegate.java:47) at org.eclipse.ui.internal.PluginAction.run(PluginAction.java:125) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java(Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java(Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:658) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:820) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:285) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:433) at org.eclipse.core.launcher.Main.main(Main.java:306) NOTES:
resolved fixed
fb1f1e3
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T13:50:36"
"2001-10-11T03:13:20"
refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/OpenRefactoringWizardAction.java
4,376
Bug 4376 refactoring CCE
1. create a non java project abc 2. create junit 3. rename Assert.java java.lang.reflect.InvocationTargetException: java.lang.ClassCastException: org.eclipse.jdt.internal.core.JavaProject at org.eclipse.jdt.internal.core.refactoring.Checks.excludeCompilationUnits (Checks.java:413) at org.eclipse.jdt.internal.core.refactoring.rename.RenameTypeRefactoring.analyzeAf fectedCompilationUnits(RenameTypeRefactoring.java:459) at org.eclipse.jdt.internal.core.refactoring.rename.RenameTypeRefactoring.checkInpu t(RenameTypeRefactoring.java:231) at org.eclipse.jdt.internal.core.refactoring.rename.RenameCompilationUnitRefactorin g.checkInput(RenameCompilationUnitRefactoring.java:177) at org.eclipse.jdt.internal.ui.refactoring.CheckConditionsOperation.run (CheckConditionsOperation.java:58) at org.eclipse.jdt.internal.ui.refactoring.CreateChangeOperation.run (CreateChangeOperation.java:93) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run (ModalContext.java:98)
resolved fixed
85dcbd0
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T14:33:26"
"2001-10-11T14:20:00"
org.eclipse.jdt.ui/core
4,376
Bug 4376 refactoring CCE
1. create a non java project abc 2. create junit 3. rename Assert.java java.lang.reflect.InvocationTargetException: java.lang.ClassCastException: org.eclipse.jdt.internal.core.JavaProject at org.eclipse.jdt.internal.core.refactoring.Checks.excludeCompilationUnits (Checks.java:413) at org.eclipse.jdt.internal.core.refactoring.rename.RenameTypeRefactoring.analyzeAf fectedCompilationUnits(RenameTypeRefactoring.java:459) at org.eclipse.jdt.internal.core.refactoring.rename.RenameTypeRefactoring.checkInpu t(RenameTypeRefactoring.java:231) at org.eclipse.jdt.internal.core.refactoring.rename.RenameCompilationUnitRefactorin g.checkInput(RenameCompilationUnitRefactoring.java:177) at org.eclipse.jdt.internal.ui.refactoring.CheckConditionsOperation.run (CheckConditionsOperation.java:58) at org.eclipse.jdt.internal.ui.refactoring.CreateChangeOperation.run (CreateChangeOperation.java:93) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run (ModalContext.java:98)
resolved fixed
85dcbd0
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T14:33:26"
"2001-10-11T14:20:00"
refactoring/org/eclipse/jdt/internal/core/refactoring/Checks.java
4,373
Bug 4373 Packages View - double clich doesn't expand two hiearchy levels
- enable: Show CU children in packages view - double click on CU observe: only one level gets expanded - now expand a node by clicking on the + observe: two levels get expanded
resolved fixed
d00ad36
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T14:57:29"
"2001-10-11T14:20:00"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerPart.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.internal.ui.packageview; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaModel; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.ISourceReference; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.actions.ContextMenuGroup; import org.eclipse.jdt.internal.ui.compare.JavaAddElementFromHistory; import org.eclipse.jdt.internal.ui.compare.JavaReplaceWithEditionAction; import org.eclipse.jdt.internal.ui.dnd.DelegatingDragAdapter; import org.eclipse.jdt.internal.ui.dnd.DelegatingDropAdapter; import org.eclipse.jdt.internal.ui.dnd.LocalSelectionTransfer; import org.eclipse.jdt.internal.ui.dnd.TransferDragSourceListener; import org.eclipse.jdt.internal.ui.dnd.TransferDropTargetListener; import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditorInput; import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; import org.eclipse.jdt.internal.ui.javaeditor.JarEntryEditorInput; import org.eclipse.jdt.internal.ui.preferences.JavaBasePreferencePage; import org.eclipse.jdt.internal.ui.IPreferencesConstants; import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringGroup; import org.eclipse.jdt.internal.ui.refactoring.actions.StructuredSelectionProvider; import org.eclipse.jdt.internal.ui.reorg.DeleteAction; import org.eclipse.jdt.internal.ui.reorg.ReorgGroup; import org.eclipse.jdt.internal.ui.search.JavaSearchGroup; import org.eclipse.jdt.internal.ui.util.JavaModelUtil; import org.eclipse.jdt.internal.ui.util.OpenTypeHierarchyUtil; import org.eclipse.jdt.internal.ui.viewsupport.MarkerErrorTickProvider; import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer; import org.eclipse.jdt.internal.ui.viewsupport.StatusBarUpdater; import org.eclipse.jdt.internal.ui.wizards.NewGroup; import org.eclipse.jdt.ui.IContextMenuConstants; import org.eclipse.jdt.ui.IPackagesViewPart; import org.eclipse.jdt.ui.JavaElementContentProvider; import org.eclipse.jdt.ui.JavaElementLabelProvider; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeViewerListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DragSource; import org.eclipse.swt.dnd.FileTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPartListener; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.OpenPerspectiveMenu; import org.eclipse.ui.actions.OpenWithMenu; import org.eclipse.ui.actions.RefreshAction; import org.eclipse.ui.dialogs.PropertyDialogAction; import org.eclipse.ui.help.ViewContextComputer; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.part.ISetSelectionTarget; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.views.internal.framelist.BackAction; import org.eclipse.ui.views.internal.framelist.ForwardAction; import org.eclipse.ui.views.internal.framelist.FrameList; import org.eclipse.ui.views.internal.framelist.GoIntoAction; import org.eclipse.ui.views.internal.framelist.UpAction; /** * The ViewPart for the ProjectExplorer. It listens to part activation events. * When selection linking with the editor is enabled the view selection tracks * the active editor page. Similarly when a resource is selected in the packages * view the corresponding editor is activated. */ public class PackageExplorerPart extends ViewPart implements ISetSelectionTarget, IMenuListener, IPackagesViewPart, IPropertyChangeListener { public final static String VIEW_ID= JavaUI.ID_PACKAGES; // Persistance tags. static final String TAG_SELECTION= "selection"; //$NON-NLS-1$ static final String TAG_EXPANDED= "expanded"; //$NON-NLS-1$ static final String TAG_ELEMENT= "element"; //$NON-NLS-1$ static final String TAG_PATH= "path"; //$NON-NLS-1$ static final String TAG_VERTICAL_POSITION= "verticalPosition"; //$NON-NLS-1$ static final String TAG_HORIZONTAL_POSITION= "horizontalPosition"; //$NON-NLS-1$ static final String TAG_FILTERS = "filters"; //$NON-NLS-1$ static final String TAG_FILTER = "filter"; //$NON-NLS-1$ static final String TAG_SHOWLIBRARIES = "showLibraries"; //$NON-NLS-1$ static final String TAG_SHOWBINARIES = "showBinaries"; //$NON-NLS-1$ private JavaElementPatternFilter fPatternFilter= new JavaElementPatternFilter(); private LibraryFilter fLibraryFilter= new LibraryFilter(); private BinaryProjectFilter fBinaryFilter= new BinaryProjectFilter(); private ProblemTreeViewer fViewer; private PackagesFrameSource fFrameSource; private FrameList fFrameList; private ContextMenuGroup[] fStandardGroups; private Menu fContextMenu; private OpenResourceAction fOpenCUAction; private Action fOpenToAction; private Action fShowTypeHierarchyAction; private Action fShowNavigatorAction; private Action fPropertyDialogAction; private Action fDeleteAction; private RefreshAction fRefreshAction; private BackAction fBackAction; private ForwardAction fForwardAction; private GoIntoAction fZoomInAction; private UpAction fUpAction; private GotoTypeAction fGotoTypeAction; private GotoPackageAction fGotoPackageAction; private AddBookmarkAction fAddBookmarkAction; private FilterSelectionAction fFilterAction; private ShowLibrariesAction fShowLibrariesAction; private ShowBinariesAction fShowBinariesAction; private IMemento fMemento; private IPartListener fPartListener= new IPartListener() { public void partActivated(IWorkbenchPart part) { if (part instanceof IEditorPart) editorActivated((IEditorPart) part); } public void partBroughtToTop(IWorkbenchPart part) { } public void partClosed(IWorkbenchPart part) { } public void partDeactivated(IWorkbenchPart part) { } public void partOpened(IWorkbenchPart part) { } }; private ITreeViewerListener fExpansionListener= new ITreeViewerListener() { public void treeCollapsed(TreeExpansionEvent event) { } public void treeExpanded(TreeExpansionEvent event) { Object element= event.getElement(); if (element instanceof ICompilationUnit || element instanceof IClassFile) expandMainType(element); } }; public PackageExplorerPart() { } /* (non-Javadoc) * Method declared on IViewPart. */ public void init(IViewSite site, IMemento memento) throws PartInitException { super.init(site, memento); fMemento= memento; } /** * Initializes the default preferences */ public static void initDefaults(IPreferenceStore store) { store.setDefault(TAG_SHOWLIBRARIES, true); store.setDefault(TAG_SHOWBINARIES, true); } /** * Returns the package explorer part of the active perspective. If * there isn't any package explorer part <code>null</code> is returned. */ public static PackageExplorerPart getFromActivePerspective() { IViewPart view= JavaPlugin.getActivePage().findView(VIEW_ID); if (view instanceof PackageExplorerPart) return (PackageExplorerPart)view; return null; } /** * Makes the package explorer part visible in the active perspective. If there * isn't a package explorer part registered <code>null</code> is returned. * Otherwise the opened view part is returned. */ public static PackageExplorerPart openInActivePerspective() { try { return (PackageExplorerPart)JavaPlugin.getActivePage().showView(VIEW_ID); } catch(PartInitException pe) { return null; } } public void dispose() { if (fViewer != null) JavaPlugin.getDefault().getProblemMarkerManager().removeListener(fViewer); if (fContextMenu != null && !fContextMenu.isDisposed()) fContextMenu.dispose(); getSite().getPage().removePartListener(fPartListener); JavaPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); if (fViewer != null) fViewer.removeTreeListener(fExpansionListener); super.dispose(); } /** * Implementation of IWorkbenchPart.createPartControl(Composite) */ public void createPartControl(Composite parent) { fViewer= new ProblemTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); boolean showCUChildren= JavaBasePreferencePage.showCompilationUnitChildren(); fViewer.setContentProvider(new JavaElementContentProvider(showCUChildren)); JavaPlugin.getDefault().getProblemMarkerManager().addListener(fViewer); JavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); int labelFlags= JavaElementLabelProvider.SHOW_BASICS | JavaElementLabelProvider.SHOW_OVERLAY_ICONS | JavaElementLabelProvider.SHOW_SMALL_ICONS | JavaElementLabelProvider.SHOW_VARIABLE | JavaElementLabelProvider.SHOW_PARAMETERS; JavaElementLabelProvider labelProvider = new JavaElementLabelProvider(labelFlags); labelProvider.setErrorTickManager(new MarkerErrorTickProvider()); fViewer.setLabelProvider(new DecoratingLabelProvider(labelProvider, null)); fViewer.setSorter(new PackageViewerSorter()); fViewer.addFilter(new EmptyInnerPackageFilter()); fViewer.setUseHashlookup(true); fViewer.addFilter(fPatternFilter); fViewer.addFilter(fLibraryFilter); fViewer.addFilter(fBinaryFilter); if(fMemento != null) restoreFilters(); else initFilterFromPreferences(); // Set input after filter and sorter has been set. This avoids resorting // and refiltering. fViewer.setInput(findInputElement()); initDragAndDrop(); initFrameList(); initRefreshKey(); updateTitle(); MenuManager menuMgr= new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(this); fContextMenu= menuMgr.createContextMenu(fViewer.getTree()); fViewer.getTree().setMenu(fContextMenu); getSite().registerContextMenu(menuMgr, fViewer); makeActions(); // call before registering for selection changes fViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { handleSelectionChanged(event); } }); fViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { handleDoubleClick(event); } }); fViewer.getControl().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { handleKeyPressed(e); } }); getSite().setSelectionProvider(fViewer); getSite().getPage().addPartListener(fPartListener); IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); fViewer.addSelectionChangedListener(new StatusBarUpdater(slManager)); fViewer.addTreeListener(fExpansionListener); if (fMemento != null) restoreState(fMemento); fMemento= null; // Set help for the view // fixed for 1GETAYN: ITPJUI:WIN - F1 help does nothing WorkbenchHelp.setHelp(fViewer.getControl(), new ViewContextComputer(this, IJavaHelpContextIds.PACKAGE_VIEW)); fillActionBars(); } private void fillActionBars() { IActionBars actionBars= getViewSite().getActionBars(); IToolBarManager toolBar= actionBars.getToolBarManager(); toolBar.add(fBackAction); toolBar.add(fForwardAction); toolBar.add(fUpAction); actionBars.updateActionBars(); IMenuManager menu = actionBars.getMenuManager(); menu.add(fFilterAction); menu.add(fShowLibrariesAction); menu.add(fShowBinariesAction); } private Object findInputElement() { Object input= getSite().getPage().getInput(); if (input instanceof IWorkspace) { return JavaCore.create(((IWorkspace)input).getRoot()); } else if (input instanceof IContainer) { return JavaCore.create((IContainer)input); } //1GERPRT: ITPJUI:ALL - Packages View is empty when shown in Type Hierarchy Perspective // we can't handle the input // fall back to show the workspace return JavaCore.create(JavaPlugin.getWorkspace().getRoot()); } /** * Answer the property defined by key. */ public Object getAdapter(Class key) { if (key.equals(ISelectionProvider.class)) return fViewer; return super.getAdapter(key); } /** * Returns the tool tip text for the given element. */ String getToolTipText(Object element) { if (!(element instanceof IResource)) return ((ILabelProvider) getViewer().getLabelProvider()).getText(element); IPath path= ((IResource) element).getFullPath(); if (path.isRoot()) { return PackagesMessages.getString("PackageExplorer.title"); //$NON-NLS-1$ } else { return path.makeRelative().toString(); } } /** * @see IWorkbenchPart#setFocus() */ public void setFocus() { fViewer.getTree().setFocus(); } /** * Returns the shell to use for opening dialogs. * Used in this class, and in the actions. */ private Shell getShell() { return fViewer.getTree().getShell(); } /** * Returns the selection provider. */ private ISelectionProvider getSelectionProvider() { return fViewer; } /** * Returns the current selection. */ private ISelection getSelection() { return fViewer.getSelection(); } //---- Action handling ---------------------------------------------------------- /** * Called when the context menu is about to open. * Override to add your own context dependent menu contributions. */ public void menuAboutToShow(IMenuManager menu) { JavaPlugin.createStandardGroups(menu); IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection(); boolean selectionHasElements= !selection.isEmpty(); Object element= selection.getFirstElement(); // updateActions(selection); if (selection.size() == 1 && fViewer.isExpandable(element)) menu.appendToGroup(IContextMenuConstants.GROUP_GOTO, fZoomInAction); addGotoMenu(menu); fOpenCUAction.update(); if (fOpenCUAction.isEnabled()) menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenCUAction); addOpenWithMenu(menu, selection); addOpenToMenu(menu, selection); addRefactoring(menu); if (selection.size() == 1) { menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new JavaReplaceWithEditionAction(fViewer)); menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new JavaAddElementFromHistory(null, fViewer)); } ContextMenuGroup.add(menu, fStandardGroups, fViewer); if (fAddBookmarkAction.canOperateOnSelection()) menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, fAddBookmarkAction); menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fRefreshAction); fRefreshAction.selectionChanged(selection); if (selectionHasElements) { // update the action to use the right selection since the refresh // action doesn't listen to selection changes. menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fPropertyDialogAction); } } void addGotoMenu(IMenuManager menu) { MenuManager gotoMenu= new MenuManager(PackagesMessages.getString("PackageExplorer.gotoTitle")); //$NON-NLS-1$ menu.appendToGroup(IContextMenuConstants.GROUP_GOTO, gotoMenu); gotoMenu.add(fBackAction); gotoMenu.add(fForwardAction); gotoMenu.add(fUpAction); gotoMenu.add(fGotoTypeAction); gotoMenu.add(fGotoPackageAction); } private void makeActions() { ISelectionProvider provider= getSelectionProvider(); fOpenCUAction= new OpenResourceAction(provider); fPropertyDialogAction= new PropertyDialogAction(getShell(), provider); // fShowTypeHierarchyAction= new ShowTypeHierarchyAction(provider); fShowNavigatorAction= new ShowInNavigatorAction(provider); fAddBookmarkAction= new AddBookmarkAction(provider); fStandardGroups= new ContextMenuGroup[] { new NewGroup(), new BuildGroup(), new ReorgGroup(), new JavaSearchGroup() }; fDeleteAction= new DeleteAction(StructuredSelectionProvider.createFrom(provider)); fRefreshAction= new RefreshAction(getShell()); fFilterAction = new FilterSelectionAction(getShell(), this, PackagesMessages.getString("PackageExplorer.filters")); //$NON-NLS-1$ fShowLibrariesAction = new ShowLibrariesAction(this, PackagesMessages.getString("PackageExplorer.referencedLibs")); //$NON-NLS-1$ fShowBinariesAction = new ShowBinariesAction(getShell(), this, PackagesMessages.getString("PackageExplorer.binaryProjects")); //$NON-NLS-1$ fBackAction= new BackAction(fFrameList); fForwardAction= new ForwardAction(fFrameList); fZoomInAction= new GoIntoAction(fFrameList); fUpAction= new UpAction(fFrameList); fGotoTypeAction= new GotoTypeAction(this); fGotoPackageAction= new GotoPackageAction(this); IActionBars actionService= getViewSite().getActionBars(); actionService.setGlobalActionHandler(IWorkbenchActionConstants.DELETE, fDeleteAction); } private void addRefactoring(IMenuManager menu){ MenuManager refactoring= new MenuManager(PackagesMessages.getString("PackageExplorer.refactoringTitle")); //$NON-NLS-1$ ContextMenuGroup.add(refactoring, new ContextMenuGroup[] { new RefactoringGroup() }, fViewer); if (!refactoring.isEmpty()) menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, refactoring); } private void addOpenToMenu(IMenuManager menu, IStructuredSelection selection) { if (selection.size() != 1) return; IAdaptable element= (IAdaptable) selection.getFirstElement(); IResource resource= (IResource)element.getAdapter(IResource.class); if ((resource instanceof IContainer)) { // Create a menu flyout. MenuManager submenu = new MenuManager(PackagesMessages.getString("PackageExplorer.openPerspective")); //$NON-NLS-1$ submenu.add(new OpenPerspectiveMenu(getSite().getWorkbenchWindow(), resource)); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); } OpenTypeHierarchyUtil.addToMenu(getSite().getWorkbenchWindow(), menu, element); } private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) { // If one file is selected get it. // Otherwise, do not show the "open with" menu. if (selection.size() != 1) return; IAdaptable element= (IAdaptable)selection.getFirstElement(); Object resource= element.getAdapter(IResource.class); if (!(resource instanceof IFile)) return; // Create a menu flyout. MenuManager submenu= new MenuManager(PackagesMessages.getString("PackageExplorer.openWith")); //$NON-NLS-1$ submenu.add(new OpenWithMenu(getSite().getPage(), (IFile) resource)); // Add the submenu. menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); } private boolean isSelectionOfType(ISelection s, Class clazz, boolean considerUnderlyingResource) { if (! (s instanceof IStructuredSelection) || s.isEmpty()) return false; IStructuredSelection selection= (IStructuredSelection)s; Iterator iter= selection.iterator(); while (iter.hasNext()) { Object o= iter.next(); if (clazz.isInstance(o)) return true; if (considerUnderlyingResource) { if (! (o instanceof IJavaElement)) return false; IJavaElement element= (IJavaElement)o; Object resource= element.getAdapter(IResource.class); if (! clazz.isInstance(resource)) return false; } } return true; } //---- Event handling ---------------------------------------------------------- private void initDragAndDrop() { int ops= DND.DROP_COPY | DND.DROP_MOVE; final LocalSelectionTransfer lt= LocalSelectionTransfer.getInstance(); Transfer[] transfers= new Transfer[] {lt, FileTransfer.getInstance()}; // Drop Adapter TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] { new SelectionTransferDropAdapter(fViewer), new FileTransferDropAdapter(fViewer) }; fViewer.addDropSupport(ops, transfers, new DelegatingDropAdapter(dropListeners)); // Drag Adapter Control control= fViewer.getControl(); TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] { new SelectionTransferDragAdapter(fViewer), new FileTransferDragAdapter(fViewer) }; DragSource source= new DragSource(control, ops); // Note, that the transfer agents are set by the delegating drag adapter itself. source.addDragListener(new DelegatingDragAdapter(dragListeners)); } /** * Handles key events in viewer. */ void handleKeyPressed(KeyEvent event) { if (event.character == SWT.DEL && event.stateMask == 0 && fDeleteAction.isEnabled()) fDeleteAction.run(); } /** * Handles double clicks in viewer. * Opens editor if file double-clicked. */ private void handleDoubleClick(DoubleClickEvent event) { IStructuredSelection s= (IStructuredSelection) event.getSelection(); Object element= s.getFirstElement(); // if the resource is already open then always open it if (EditorUtility.isOpenInEditor(element) == null) { if (fOpenCUAction.isEnabled()) { fOpenCUAction.run(); return; } } if (fViewer.isExpandable(element)) { if (JavaBasePreferencePage.doubleClockGoesInto()) fZoomInAction.run(); else fViewer.setExpandedState(element, !fViewer.getExpandedState(element)); } } /** * Handles selection changed in viewer. * Updates global actions. * Links to editor (if option enabled) */ private void handleSelectionChanged(SelectionChangedEvent event) { IStructuredSelection sel= (IStructuredSelection) event.getSelection(); //updateGlobalActions(sel); fZoomInAction.update(); linkToEditor(sel); } public void selectReveal(ISelection selection) { ISelection javaSelection= convertSelection(selection); fViewer.setSelection(javaSelection, true); } private ISelection convertSelection(ISelection s) { List converted= new ArrayList(); if (s instanceof StructuredSelection) { Object[] elements= ((StructuredSelection)s).toArray(); for (int i= 0; i < elements.length; i++) { Object e= elements[i]; if (e instanceof IJavaElement) converted.add(e); else if (e instanceof IResource) { IJavaElement element= JavaCore.create((IResource)e); if (element != null) converted.add(element); else converted.add(e); } } } return new StructuredSelection(converted.toArray()); } public void selectAndReveal(Object element) { selectReveal(new StructuredSelection(element)); } /** * Returns whether the preference to link selection to active editor is enabled. */ boolean isLinkingEnabled() { return JavaBasePreferencePage.linkPackageSelectionToEditor(); } /** * Links to editor (if option enabled) */ private void linkToEditor(IStructuredSelection selection) { //if (!isLinkingEnabled()) // return; Object obj= selection.getFirstElement(); Object element= null; if (selection.size() == 1) { if (obj instanceof IJavaElement) { IJavaElement cu= JavaModelUtil.findParentOfKind((IJavaElement)obj, IJavaElement.COMPILATION_UNIT); if (cu != null) element= getResourceFor(cu); if (element == null) element= JavaModelUtil.findParentOfKind((IJavaElement)obj, IJavaElement.CLASS_FILE); } else if (obj instanceof IFile) element= obj; if (element == null) return; IWorkbenchPage page= getSite().getPage(); IEditorPart editorArray[]= page.getEditors(); for (int i= 0; i < editorArray.length; ++i) { IEditorPart editor= editorArray[i]; Object input= getElementOfInput(editor.getEditorInput()); if (input != null && input.equals(element)) { page.bringToTop(editor); if (obj instanceof ISourceReference) EditorUtility.revealInEditor(editor, (ISourceReference)obj); return; } } } } private IResource getResourceFor(Object element) { if (element instanceof IJavaElement) { try { element= ((IJavaElement)element).getUnderlyingResource(); } catch (JavaModelException e) { return null; } } if (!(element instanceof IResource) || ((IResource)element).isPhantom()) { return null; } return (IResource)element; } public void saveState(IMemento memento) { if (fViewer == null) { // part has not been created if (fMemento != null) //Keep the old state; memento.putMemento(fMemento); return; } saveExpansionState(memento); saveSelectionState(memento); saveScrollState(memento, fViewer.getTree()); savePatternFilterState(memento); saveFilterState(memento); } protected void saveFilterState(IMemento memento) { boolean showLibraries= getLibraryFilter().getShowLibraries(); String show= "true"; //$NON-NLS-1$ if (!showLibraries) show= "false"; //$NON-NLS-1$ memento.putString(TAG_SHOWLIBRARIES, show); //save binary filter boolean showBinaries= getBinaryFilter().getShowBinaries(); String showBinString= "true"; //$NON-NLS-1$ if (!showBinaries) showBinString= "false"; //$NON-NLS-1$ memento.putString(TAG_SHOWBINARIES, showBinString); } protected void savePatternFilterState(IMemento memento) { String filters[] = getPatternFilter().getPatterns(); if(filters.length > 0) { IMemento filtersMem = memento.createChild(TAG_FILTERS); for (int i = 0; i < filters.length; i++){ IMemento child = filtersMem.createChild(TAG_FILTER); child.putString(TAG_ELEMENT,filters[i]); } } } protected void saveScrollState(IMemento memento, Tree tree) { ScrollBar bar= tree.getVerticalBar(); int position= bar != null ? bar.getSelection() : 0; memento.putString(TAG_VERTICAL_POSITION, String.valueOf(position)); //save horizontal position bar= tree.getHorizontalBar(); position= bar != null ? bar.getSelection() : 0; memento.putString(TAG_HORIZONTAL_POSITION, String.valueOf(position)); } protected void saveSelectionState(IMemento memento) { Object elements[]= ((IStructuredSelection) fViewer.getSelection()).toArray(); if (elements.length > 0) { IMemento selectionMem= memento.createChild(TAG_SELECTION); for (int i= 0; i < elements.length; i++) { IMemento elementMem= selectionMem.createChild(TAG_ELEMENT); // we can only persist JavaElements for now Object o= elements[i]; if (o instanceof IJavaElement) elementMem.putString(TAG_PATH, ((IJavaElement) elements[i]).getHandleIdentifier()); } } } protected void saveExpansionState(IMemento memento) { Object expandedElements[]= fViewer.getExpandedElements(); if (expandedElements.length > 0) { IMemento expandedMem= memento.createChild(TAG_EXPANDED); for (int i= 0; i < expandedElements.length; i++) { IMemento elementMem= expandedMem.createChild(TAG_ELEMENT); // we can only persist JavaElements for now Object o= expandedElements[i]; if (o instanceof IJavaElement) elementMem.putString(TAG_PATH, ((IJavaElement) expandedElements[i]).getHandleIdentifier()); } } } void restoreState(IMemento memento) { restoreExpansionState(memento); restoreSelectionState(memento); restoreScrollState(memento, fViewer.getTree()); } protected void restoreScrollState(IMemento memento, Tree tree) { ScrollBar bar= tree.getVerticalBar(); if (bar != null) { try { String posStr= memento.getString(TAG_VERTICAL_POSITION); int position; position= new Integer(posStr).intValue(); bar.setSelection(position); } catch (NumberFormatException e) { // ignore, don't set scrollposition } } bar= tree.getHorizontalBar(); if (bar != null) { try { String posStr= memento.getString(TAG_HORIZONTAL_POSITION); int position; position= new Integer(posStr).intValue(); bar.setSelection(position); } catch (NumberFormatException e) { // ignore don't set scroll position } } } protected void restoreSelectionState(IMemento memento) { IMemento childMem; childMem= memento.getChild(TAG_SELECTION); if (childMem != null) { ArrayList list= new ArrayList(); IMemento[] elementMem= childMem.getChildren(TAG_ELEMENT); for (int i= 0; i < elementMem.length; i++) { Object element= JavaCore.create(elementMem[i].getString(TAG_PATH)); list.add(element); } fViewer.setSelection(new StructuredSelection(list)); } } protected void restoreExpansionState(IMemento memento) { IMemento childMem= memento.getChild(TAG_EXPANDED); if (childMem != null) { ArrayList elements= new ArrayList(); IMemento[] elementMem= childMem.getChildren(TAG_ELEMENT); for (int i= 0; i < elementMem.length; i++) { Object element= JavaCore.create(elementMem[i].getString(TAG_PATH)); elements.add(element); } fViewer.setExpandedElements(elements.toArray()); } } /** * Create the KeyListener for doing the refresh on the viewer. */ private void initRefreshKey() { fViewer.getControl().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent event) { if (event.keyCode == SWT.F5) { fRefreshAction.selectionChanged( (IStructuredSelection) fViewer.getSelection()); if (fRefreshAction.isEnabled()) fRefreshAction.run(); } } }); } void initFrameList() { fFrameSource= new PackagesFrameSource(this); fFrameList= new FrameList(fFrameSource); fFrameSource.connectTo(fFrameList); } /** * An editor has been activated. Set the selection in this Packages Viewer * to be the editor's input, if linking is enabled. */ void editorActivated(IEditorPart editor) { if (!isLinkingEnabled()) return; Object input= getElementOfInput(editor.getEditorInput()); Object element= null; if (input instanceof IFile) element= JavaCore.create((IFile)input); if (element == null) // try a non Java resource element= input; if (element != null) { // if the current selection is a child of the new // selection then ignore it. IStructuredSelection oldSelection= (IStructuredSelection)getSelection(); if (oldSelection.size() == 1) { Object o= oldSelection.getFirstElement(); if (o instanceof IMember) { IMember m= (IMember)o; if (element.equals(m.getCompilationUnit())) return; if (element.equals(m.getClassFile())) return; } } ISelection newSelection= new StructuredSelection(element); if (!fViewer.getSelection().equals(newSelection)) { fViewer.setSelection(newSelection); } } } /** * A compilation unit or class was expanded, expand * the main type. */ void expandMainType(Object element) { try { IType type= null; if (element instanceof ICompilationUnit) { ICompilationUnit cu= (ICompilationUnit)element; IType[] types= cu.getTypes(); if (types.length > 0) type= types[0]; } else if (element instanceof IClassFile) { IClassFile cf= (IClassFile)element; type= cf.getType(); } if (type != null) { final IType type2= type; Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) { ctrl.getDisplay().asyncExec(new Runnable() { public void run() { Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) fViewer.expandToLevel(type2, 1); } }); } } } catch(JavaModelException e) { // no reveal } } /** * Returns the element contained in the EditorInput */ Object getElementOfInput(IEditorInput input) { if (input instanceof IFileEditorInput) return ((IFileEditorInput)input).getFile(); else if (input instanceof ClassFileEditorInput) return ((ClassFileEditorInput)input).getClassFile(); else if (input instanceof JarEntryEditorInput) return ((JarEntryEditorInput)input).getStorage(); return null; } /** * Returns the Viewer. */ TreeViewer getViewer() { return fViewer; } /** * Returns the pattern filter for this view. * @return the pattern filter */ JavaElementPatternFilter getPatternFilter() { return fPatternFilter; } /** * Returns the library filter for this view. * @return the library filter */ LibraryFilter getLibraryFilter() { return fLibraryFilter; } /** * Returns the Binary filter for this view. * @return the binary filter */ BinaryProjectFilter getBinaryFilter() { return fBinaryFilter; } void restoreFilters() { IMemento filtersMem= fMemento.getChild(TAG_FILTERS); if(filtersMem != null) { IMemento children[]= filtersMem.getChildren(TAG_FILTER); String filters[]= new String[children.length]; for (int i = 0; i < children.length; i++) { filters[i]= children[i].getString(TAG_ELEMENT); } getPatternFilter().setPatterns(filters); } else { getPatternFilter().setPatterns(new String[0]); } //restore library String show= fMemento.getString(TAG_SHOWLIBRARIES); if (show != null) getLibraryFilter().setShowLibraries(show.equals("true")); //$NON-NLS-1$ else initLibraryFilterFromPreferences(); //restore binary fileter String showbin= fMemento.getString(TAG_SHOWBINARIES); if (showbin != null) getBinaryFilter().setShowBinaries(show.equals("true")); //$NON-NLS-1$ else initBinaryFilterFromPreferences(); } void initFilterFromPreferences() { initBinaryFilterFromPreferences(); initLibraryFilterFromPreferences(); } void initLibraryFilterFromPreferences() { JavaPlugin plugin= JavaPlugin.getDefault(); boolean show= plugin.getPreferenceStore().getBoolean(TAG_SHOWLIBRARIES); getLibraryFilter().setShowLibraries(show); } void initBinaryFilterFromPreferences() { JavaPlugin plugin= JavaPlugin.getDefault(); boolean showbin= plugin.getPreferenceStore().getBoolean(TAG_SHOWBINARIES); getBinaryFilter().setShowBinaries(showbin); } /** * Updates the title text and title tool tip. * Called whenever the input of the viewer changes. */ void updateTitle() { Object input= getViewer().getInput(); String viewName= getConfigurationElement().getAttribute("name"); //$NON-NLS-1$ if (input == null || (input instanceof IJavaModel)) { setTitle(viewName); setTitleToolTip(""); //$NON-NLS-1$ } else { ILabelProvider labelProvider = (ILabelProvider) getViewer().getLabelProvider(); String inputText= labelProvider.getText(input); String title= PackagesMessages.getFormattedString("PackageExplorer.argTitle", new String[] { viewName, inputText }); //$NON-NLS-1$ setTitle(title); setTitleToolTip(getToolTipText(input)); } } /** * Sets the decorator for the package explorer. * * @param decorator a label decorator or <code>null</code> for no decorations. */ public void setLabelDecorator(ILabelDecorator decorator) { int labelFlags= JavaElementLabelProvider.SHOW_BASICS | JavaElementLabelProvider.SHOW_OVERLAY_ICONS | JavaElementLabelProvider.SHOW_SMALL_ICONS | JavaElementLabelProvider.SHOW_VARIABLE; JavaElementLabelProvider javaProvider= new JavaElementLabelProvider(labelFlags); javaProvider.setErrorTickManager(new MarkerErrorTickProvider()); if (decorator == null) { fViewer.setLabelProvider(javaProvider); } else { fViewer.setLabelProvider(new DecoratingLabelProvider(javaProvider, decorator)); } } /* * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { if (event.getProperty() != IPreferencesConstants.SHOW_CU_CHILDREN) return; if (fViewer != null) { IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); boolean b= store.getBoolean(IPreferencesConstants.SHOW_CU_CHILDREN); ((JavaElementContentProvider)fViewer.getContentProvider()).setProvideMembers(b); fViewer.refresh(); } } }
3,811
Bug 3811 Setter / Getter generates setter for final fields (1GEUMGT)
- private final String fName; - generate Setter and Getter - you get public void setName(String name) { fName= name; } which produces a compile error. NOTES: EG (6/5/2001 3:41:01 AM) not critical, can be documented. MA (02.08.2001 16:49:08) fixed in 200
verified fixed
2c52566
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T14:57:53"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/codemanipulation/AddGetterSetterOperation.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.internal.ui.codemanipulation; import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.internal.ui.util.JavaModelUtil; /** * For given fields, method stubs for getters and setters are created. */ public class AddGetterSetterOperation implements IWorkspaceRunnable { private IField[] fFields; private List fCreatedAccessors; private IRequestQuery fSkipExistingQuery; private IRequestQuery fSkipFinalSettersQuery; private boolean fSkipAllFinalSetters; private boolean fSkipAllExisting; /** * Creates the operation. * @param fields The fields to create setter/getters for. * @param skipFinalSettersQuery Callback to ask if the setter can be skipped for a final field. * Argument of the query is the final field. * @param skipExistingQuery Callback to ask if setter / getters that already exist can be skipped. * Argument of the query is the existing method. */ public AddGetterSetterOperation(IField[] fields, IRequestQuery skipFinalSettersQuery, IRequestQuery skipExistingQuery) { super(); fFields= fields; fSkipExistingQuery= skipExistingQuery; fSkipFinalSettersQuery= skipFinalSettersQuery; fCreatedAccessors= new ArrayList(); } /** * The policy to evaluate the base name (no 'set'/'get' of the accessor. */ private String evalAccessorName(String fieldname) { if (fieldname.length() > 0) { char firstLetter= fieldname.charAt(0); if (!Character.isUpperCase(firstLetter)) { if (fieldname.length() > 1) { char secondLetter= fieldname.charAt(1); if (Character.isUpperCase(secondLetter)) { return fieldname.substring(1); } if (firstLetter == '_') { return String.valueOf(Character.toUpperCase(secondLetter)) + fieldname.substring(2); } } return String.valueOf(Character.toUpperCase(firstLetter)) + fieldname.substring(1); } } return fieldname; } /** * Creates the name of the parameter from an accessor name. */ private String getArgumentName(String accessorName) { if (accessorName.length() > 0) { char firstLetter= accessorName.charAt(0); if (!Character.isLowerCase(firstLetter)) { return "" + Character.toLowerCase(firstLetter) + accessorName.substring(1); //$NON-NLS-1$ } } return accessorName; } /** * Runs the operation. * @throws OperationCanceledException Runtime error thrown when operation is cancelled. */ public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor= new NullProgressMonitor(); } try { int nFields= fFields.length; monitor.beginTask(CodeManipulationMessages.getString("AddGetterSetterOperation.description"), nFields); //$NON-NLS-1$ for (int i= 0; i < nFields; i++) { generateStubs(fFields[i], new SubProgressMonitor(monitor, 1)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } } } finally { monitor.done(); } } private boolean querySkipFinalSetters(IField field) throws OperationCanceledException { if (!fSkipAllFinalSetters) { switch (fSkipFinalSettersQuery.doQuery(field)) { case IRequestQuery.CANCEL: throw new OperationCanceledException(); case IRequestQuery.NO: return false; case IRequestQuery.YES_ALL: fSkipAllFinalSetters= true; } } return true; } private boolean querySkipExistingMethods(IMethod method) throws OperationCanceledException { if (!fSkipAllExisting) { switch (fSkipExistingQuery.doQuery(method)) { case IRequestQuery.CANCEL: throw new OperationCanceledException(); case IRequestQuery.NO: return false; case IRequestQuery.YES_ALL: fSkipAllExisting= true; } } return true; } /** * Creates setter and getter for a given field. */ private void generateStubs(IField field, IProgressMonitor monitor) throws JavaModelException, OperationCanceledException { try { monitor.beginTask(CodeManipulationMessages.getFormattedString("AddGetterSetterOperation.processField", field.getElementName()), 2); //$NON-NLS-1$ fSkipAllFinalSetters= false; fSkipAllExisting= false; String fieldName= field.getElementName(); String accessorName= evalAccessorName(fieldName); String argname= getArgumentName(accessorName); boolean isStatic= Flags.isStatic(field.getFlags()); String typeName= Signature.toString(field.getTypeSignature()); IType parentType= field.getDeclaringType(); String lineDelim= StubUtility.getLineDelimiterUsed(parentType); int indent= StubUtility.getIndentUsed(field); // test if the getter already exists String getterName= "get" + accessorName; //$NON-NLS-1$ IMethod existing= JavaModelUtil.findMethod(getterName, new String[0], false, parentType); if (!(existing != null && querySkipExistingMethods(existing))) { // create the getter stub StringBuffer buf= new StringBuffer(); buf.append("/**\n"); //$NON-NLS-1$ buf.append(" * Gets the "); buf.append(argname); buf.append(".\n"); //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" * @return Returns a "); buf.append(typeName); buf.append('\n'); //$NON-NLS-1$ buf.append(" */\n"); //$NON-NLS-1$ buf.append("public "); //$NON-NLS-1$ if (isStatic) { buf.append("static "); //$NON-NLS-1$ } buf.append(typeName); buf.append(' '); buf.append(getterName); buf.append("() {\nreturn "); buf.append(fieldName); buf.append(";\n}\n"); //$NON-NLS-2$ //$NON-NLS-1$ IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findSibling(existing); existing.delete(false, null); } String formattedContent= StubUtility.codeFormat(buf.toString(), indent, lineDelim) + lineDelim; fCreatedAccessors.add(parentType.createMethod(formattedContent, sibling, true, null)); } monitor.worked(1); String setterName= "set" + accessorName; //$NON-NLS-1$ String[] args= new String[] { field.getTypeSignature() }; // test if the setter already exists or field is final boolean isFinal= Flags.isFinal(field.getFlags()); existing= JavaModelUtil.findMethod(setterName, args, false, parentType); if (!(isFinal && querySkipFinalSetters(field)) && !(existing != null && querySkipExistingMethods(existing))) { // create the setter stub StringBuffer buf= new StringBuffer(); buf.append("/**\n"); //$NON-NLS-1$ buf.append(" * Sets the "); buf.append(argname); buf.append(".\n"); //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" * @param "); buf.append(argname); buf.append(" The "); buf.append(argname); buf.append(" to set\n"); //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ buf.append(" */\n"); //$NON-NLS-1$ buf.append("public "); //$NON-NLS-1$ if (isStatic) { buf.append("static "); //$NON-NLS-1$ } buf.append("void "); buf.append(setterName); //$NON-NLS-1$ buf.append('('); buf.append(typeName); buf.append(' '); buf.append(argname); buf.append(") {\n"); //$NON-NLS-1$ if (argname.equals(fieldName)) { if (isStatic) { buf.append(parentType.getElementName()); buf.append('.'); } else { buf.append("this."); //$NON-NLS-1$ } } buf.append(fieldName); buf.append("= "); buf.append(argname); buf.append(";\n}\n"); //$NON-NLS-1$ //$NON-NLS-2$ IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findSibling(existing); existing.delete(false, null); } String formattedContent= StubUtility.codeFormat(buf.toString(), indent, lineDelim) + lineDelim; fCreatedAccessors.add(parentType.createMethod(formattedContent, sibling, true, null)); } } finally { monitor.done(); } } /** * Returns the created accessors. To be called after a sucessful run. */ public IMethod[] getCreatedAccessors() { return (IMethod[]) fCreatedAccessors.toArray(new IMethod[fCreatedAccessors.size()]); } }
3,811
Bug 3811 Setter / Getter generates setter for final fields (1GEUMGT)
- private final String fName; - generate Setter and Getter - you get public void setName(String name) { fName= name; } which produces a compile error. NOTES: EG (6/5/2001 3:41:01 AM) not critical, can be documented. MA (02.08.2001 16:49:08) fixed in 200
verified fixed
2c52566
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T14:57:53"
"2001-10-11T03:13:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/codemanipulation/ImportsStructure.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.internal.ui.codemanipulation; import java.util.ArrayList; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IImportContainer; import org.eclipse.jdt.core.IImportDeclaration; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.ISourceRange; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.util.DocumentManager; import org.eclipse.jdt.internal.ui.util.JavaModelUtil; public class ImportsStructure implements IImportsStructure { private ICompilationUnit fCompilationUnit; private ArrayList fPackageEntries; private int fImportOnDemandThreshold; private boolean fReplaceExistingImports; /** * Creates an ImportsStructure for a compilation unit with existing * imports. New imports are added next to the existing import that * has the best match. */ public ImportsStructure(ICompilationUnit cu) throws JavaModelException { fCompilationUnit= cu; IImportDeclaration[] decls= cu.getImports(); fPackageEntries= new ArrayList(decls.length + 5); PackageEntry curr= null; for (int i= 0; i < decls.length; i++) { String packName= Signature.getQualifier(decls[i].getElementName()); if (curr == null || !packName.equals(curr.getName())) { curr= new PackageEntry(packName, -1); fPackageEntries.add(curr); } curr.add(decls[i]); } fImportOnDemandThreshold= Integer.MAX_VALUE; fReplaceExistingImports= false; } /** * Creates an ImportsStructure for a compilation unit where exiting imports should be * completly ignored. Create will replace all existing imports * @param preferenceOrder Defines the prefered order of imports. * @param importThreshold Defines the number of imports in a package needed to introduce a * import on demand instead (e.g. java.util.*) */ public ImportsStructure(ICompilationUnit cu, String[] preferenceOrder, int importThreshold) { fCompilationUnit= cu; int nEntries= preferenceOrder.length; fPackageEntries= new ArrayList(20 + nEntries); for (int i= 0; i < nEntries; i++) { PackageEntry entry= new PackageEntry(preferenceOrder[i], i); fPackageEntries.add(entry); } fImportOnDemandThreshold= importThreshold; fReplaceExistingImports= true; } public ICompilationUnit getCompilationUnit() { return fCompilationUnit; } private static boolean sameMatchLenTest(String newName, String bestName, String currName, int matchLen) { // known: bestName and currName differ from newName at position 'matchLen' // currName and bestName dont have to differ at position 'matchLen' // determine the order and return true if currName is closer to newName char newChar= getCharAt(newName, matchLen); char currChar= getCharAt(currName, matchLen); char bestChar= getCharAt(bestName, matchLen); if (newChar < currChar) { if (bestChar < newChar) { // b < n < c return (currChar - newChar) < (newChar - bestChar); // -> (c - n) < (n - b) } else { // n < b && n < c return currName.compareTo(bestName) < 0; // -> (c < b) } } else { if (bestChar > newChar) { // c < n < b return (newChar - currChar) < (bestChar - newChar); // -> (n - c) < (b - n) } else { // n > b && n > c return bestName.compareTo(currName) < 0; // -> (c > b) } } } private PackageEntry findBestMatch(String newName) { int bestMatchLen= -1; PackageEntry bestMatch= null; String bestName= ""; //$NON-NLS-1$ for (int i= 0; i < fPackageEntries.size(); i++) { boolean isBetterMatch; PackageEntry curr= (PackageEntry) fPackageEntries.get(i); String currName= curr.getName(); int currMatchLen= getMatchLen(currName, newName); if (currMatchLen > bestMatchLen) { isBetterMatch= true; } else if (currMatchLen == bestMatchLen) { if (currMatchLen == newName.length() && currMatchLen == currName.length() && currMatchLen == bestName.length()) { // dulicate entry and complete match isBetterMatch= curr.getNumberOfImports() > bestMatch.getNumberOfImports(); } else { isBetterMatch= sameMatchLenTest(newName, bestName, currName, currMatchLen); } } else { isBetterMatch= false; } if (isBetterMatch) { bestMatchLen= currMatchLen; bestMatch= curr; bestName= currName; } } return bestMatch; } /** * Adds a new import declaration that is sorted in the structure using * the best match algorithm. If an import already exists, the import is * not added. * @param qualifiedTypeName The fully qualified name of the type to import */ public void addImport(String qualifiedTypeName) { String packName= Signature.getQualifier(qualifiedTypeName); String typeName= Signature.getSimpleName(qualifiedTypeName); addImport(packName, typeName); } /** * Adds a new import declaration that is sorted in the structure using * the best match algorithm. If an import already exists, the import is * not added. * @param packageName The package name of the type to import * @param typeName The type name of the type to import (can be '*' for imports-on-demand) */ public void addImport(String packageName, String typeName) { String fullTypeName= JavaModelUtil.concatenateName(packageName, typeName); IImportDeclaration decl= fCompilationUnit.getImport(fullTypeName); PackageEntry bestMatch= findBestMatch(packageName); if (bestMatch == null) { PackageEntry packEntry= new PackageEntry(packageName, -1); packEntry.add(decl); fPackageEntries.add(packEntry); } else { int cmp= packageName.compareTo(bestMatch.getName()); if (cmp == 0) { bestMatch.sortIn(decl); } else { // create a new packageentry PackageEntry packEntry= new PackageEntry(packageName, bestMatch.getCategory()); packEntry.add(decl); int index= fPackageEntries.indexOf(bestMatch); if (cmp < 0) { // sort in ahead of best match fPackageEntries.add(index, packEntry); } else { // sort in after best match fPackageEntries.add(index + 1, packEntry); } } } } /** * Adds a new import declaration that is sorted in the structure using * the best match algorithm. If an import already exists, the import is * not added. * @param packageName The package name of the type to import * @param enclosingTypeName Name of the enclosing type (dor-separated) * @param typeName The type name of the type to import (can be '*' for imports-on-demand) */ public void addImport(String packageName, String enclosingTypeName, String typeName) { addImport(JavaModelUtil.concatenateName(packageName, enclosingTypeName), typeName); } private static int getMatchLen(String s, String t) { int len= Math.min(s.length(), t.length()); for (int i= 0; i < len; i++) { if (s.charAt(i) != t.charAt(i)) { return i; } } return len; } private static char getCharAt(String str, int index) { if (str.length() > index) { return str.charAt(index); } return 0; } /** * Creates all new elements in the import structure. * Returns all created IImportDeclaration. Does not return null */ public IImportDeclaration[] create(boolean save, IProgressMonitor monitor) throws CoreException { DocumentManager docManager= new DocumentManager(fCompilationUnit); docManager.connect(); try { IImportDeclaration[] res= create(docManager.getDocument(), monitor); if (save) { docManager.save(null); } return res; } finally { docManager.disconnect(); } } /** * Creates all new elements in the import structure. * Returns all created IImportDeclaration. Does not return null */ public IImportDeclaration[] create(IDocument doc, IProgressMonitor monitor) throws CoreException { ArrayList created= new ArrayList(); try { performCreate(created, doc); } finally { if (monitor != null) { monitor.done(); } } return (IImportDeclaration[]) created.toArray(new IImportDeclaration[created.size()]); } private int getPackageStatementEndPos() throws JavaModelException { IPackageDeclaration[] packDecls= fCompilationUnit.getPackageDeclarations(); if (packDecls != null && packDecls.length > 0) { ISourceRange range= packDecls[0].getSourceRange(); return range.getOffset() + range.getLength(); // semicolon is included } return 0; } private void performCreate(ArrayList created, IDocument doc) throws JavaModelException { int importsStart, importsLen; // 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format String lineDelim= StubUtility.getLineDelimiterFor(doc); int lastPos; StringBuffer buf= new StringBuffer(); IImportContainer container= fCompilationUnit.getImportContainer(); if (container.exists()) { ISourceRange importSourceRange= container.getSourceRange(); importsStart= importSourceRange.getOffset(); importsLen= importSourceRange.getLength(); if (!fReplaceExistingImports) { buf.append(container.getSource()); } lastPos= buf.length(); } else { importsStart= getPackageStatementEndPos(); importsLen= 0; lastPos= 0; } // all (top level) types in this cu IType[] topLevelTypes= fCompilationUnit.getTypes(); int lastCategory= -1; // create from last to first to not invalidate positions for (int i= fPackageEntries.size() -1; i >= 0; i--) { PackageEntry pack= (PackageEntry) fPackageEntries.get(i); int nImports= pack.getNumberOfImports(); if (nImports > 0) { String packName= pack.getName(); if (isImportNeeded(packName, topLevelTypes)) { // add empty line if (pack.getCategory() != lastCategory) { if (lastCategory != -1) { buf.insert(lastPos, lineDelim); } lastCategory= pack.getCategory(); } if (nImports >= fImportOnDemandThreshold) { // assume no existing imports String starimport= packName + ".*"; //$NON-NLS-1$ lastPos= insertImport(buf, lastPos, starimport, lineDelim); created.add(fCompilationUnit.getImport(starimport)); } else { for (int j= nImports - 1; j >= 0; j--) { IImportDeclaration currDecl= pack.getImportAt(j); if (fReplaceExistingImports || !currDecl.exists()) { lastPos= insertImport(buf, lastPos, currDecl.getElementName(), lineDelim); created.add(currDecl); } else { lastPos= currDecl.getSourceRange().getOffset() - importsStart; } } } } } } try { if (!container.exists() && created.size() > 0) { buf.append(lineDelim); // nl after import (<nl+>) if (importsStart > 0) { // package statement buf.insert(0, lineDelim); buf.insert(0, lineDelim); //<pack><nl*><nl*><import><nl+><nl-pack><cl> } else { buf.append(lineDelim); } } String newContent= buf.toString(); if (hasChanged(doc, importsStart, importsLen, newContent)) { doc.replace(importsStart, importsLen, newContent); } } catch (BadLocationException e) { // can not happen JavaPlugin.log(e); } } private boolean hasChanged(IDocument doc, int offset, int length, String content) throws BadLocationException { if (content.length() != length) { return true; } for (int i= 0; i < length; i++) { if (content.charAt(i) != doc.getChar(offset + i)) { return true; } } return false; } private boolean isImportNeeded(String packName, IType[] cuTypes) { if (packName.length() == 0 || "java.lang".equals(packName)) { //$NON-NLS-1$ return false; } if (cuTypes.length > 0) { if (packName.equals(cuTypes[0].getPackageFragment().getElementName())) { return false; } for (int i= 0; i < cuTypes.length; i++) { if (packName.equals(JavaModelUtil.getFullyQualifiedName(cuTypes[i]))) { return false; } } } return true; } private int insertImport(StringBuffer buf, int pos, String importName, String lineDelim) { StringBuffer name= new StringBuffer(); if (pos > 0 && pos == buf.length()) { buf.append(lineDelim); pos= buf.length(); } name.append("import "); //$NON-NLS-1$ name.append(importName); name.append(';'); if (pos < buf.length()) { name.append(lineDelim); } buf.insert(pos, name.toString()); return pos; } /* * Internal element for the import structure: A container for imports * of all types from the same package */ private static class PackageEntry { private String fName; private ArrayList fImportEntries; private int fCategory; public PackageEntry(String name, int category) { fName= name; fImportEntries= new ArrayList(5); fCategory= category; } public int findInsertPosition(String fullImportName) { int nInports= fImportEntries.size(); for (int i= 0; i < nInports; i++) { IImportDeclaration curr= getImportAt(i); if (fullImportName.compareTo(curr.getElementName()) <= 0) { return i; } } return nInports; } public void sortIn(IImportDeclaration imp) { String fullImportName= imp.getElementName(); int insertPosition= -1; int nInports= fImportEntries.size(); for (int i= 0; i < nInports; i++) { int cmp= fullImportName.compareTo(getImportAt(i).getElementName()); if (cmp == 0) { return; // exists already } else if (cmp < 0 && insertPosition == -1) { insertPosition= i; } } if (insertPosition == -1) { fImportEntries.add(imp); } else { fImportEntries.add(insertPosition, imp); } } public void add(IImportDeclaration imp) { fImportEntries.add(imp); } /*public IImportDeclaration findTypeName(String typeName) { int nInports= fImportEntries.size(); if (nInports > 0) { String fullName= StubUtility.getFullTypeName(fName, typeName); for (int i= 0; i < nInports; i++) { IImportDeclaration curr= getImportAt(i); if (!curr.isOnDemand()) { if (fullName.equals(curr.getElementName())) { return curr; } } } } return null; }*/ public final IImportDeclaration getImportAt(int index) { return (IImportDeclaration)fImportEntries.get(index); } public int getNumberOfImports() { return fImportEntries.size(); } public String getName() { return fName; } public int getCategory() { return fCategory; } } }
4,365
Bug 4365 Deadlock on save
D:\devel\sdk203>.\jre\bin\java -verify -cp startup.jar org.eclipse.core.launcher .UIMain -application org.eclipse.ui.workbench -ws win32 -platform d:\workspaces\ eclipse-sh1\plugins Full thread dump Classic VM (J2RE 1.3.0 IBM build cn130-20010502, native threads ): "org.eclipse.jface.text.reconciler.MonoReconciler" (TID:0x2c8bee8, sys_threa d_t:0x13d10ab0, state:CW, native ID:0x424) prio=1 at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:421) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:138) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:1 8) at org.eclipse.swt.widgets.Display.syncExec(Display.java:1572) at org.eclipse.jdt.ui.JavaElementContentProvider.postRunnable(JavaElemen tContentProvider.java:277) at org.eclipse.jdt.ui.JavaElementContentProvider.postRefresh(JavaElement ContentProvider.java:242) at org.eclipse.jdt.ui.JavaElementContentProvider.processDelta(JavaElemen tContentProvider.java:143) at org.eclipse.jdt.ui.JavaElementContentProvider.elementChanged(JavaElem entContentProvider.java:82) at org.eclipse.jdt.internal.core.JavaModelManager.fire(JavaModelManager. java:255) at org.eclipse.jdt.internal.core.WorkingCopy.reconcile(WorkingCopy.java: 250) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconci le(JavaReconcilingStrategy.java:39) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconci le(JavaReconcilingStrategy.java:51) at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconcil er.java:66) at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread .run(AbstractReconciler.java:153) "HelpServer" (TID:0x1fb7320, sys_thread_t:0x13b5c698, state:R, native ID:0x6 74) prio=5 at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:430) at java.net.ServerSocket.implAccept(ServerSocket.java:255) at java.net.ServerSocket.accept(ServerSocket.java:234) at org.eclipse.help.internal.server.HelpServer.run(HelpServer.java:127) "Java indexing: org.eclipse.jdt.internal.core.search.indexing.IndexManager" (TID:0x8e6ad0, sys_thread_t:0x123ca2a0, state:CW, native ID:0x6c8) prio=5 at java.lang.Thread.sleep(Native Method) at org.eclipse.jdt.internal.core.search.processing.JobManager.run(JobMan ager.java(Compiled Code)) at java.lang.Thread.run(Thread.java:498) "Finalizer" (TID:0x8e8708, sys_thread_t:0x86b710, state:CW, native ID:0x4c0) prio=8 at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java(Compiled Code )) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java(Compiled Code )) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java(Compiled C ode)) "Reference Handler" (TID:0x8e8750, sys_thread_t:0x839cc0, state:CW, native I D:0x668) prio=10 at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:421) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java(Compiled Code)) "Signal dispatcher" (TID:0x8e8798, sys_thread_t:0x835310, state:R, native ID :0x5dc) prio=5 "main" (TID:0x8e87e0, sys_thread_t:0x2355d8, state:CW, native ID:0x58c) prio =5 at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSave(C ompilationUnitEditor.java:252) at org.eclipse.ui.internal.EditorManager$9.run(EditorManager.java:776) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalCont ext.java:296) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:249) at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDi alog.java:335) at org.eclipse.ui.internal.EditorManager.runProgressMonitorOperation(Edi torManager.java:634) at org.eclipse.ui.internal.EditorManager.saveEditor(EditorManager.java:7 81) at org.eclipse.ui.internal.WorkbenchPage.saveEditor(WorkbenchPage.java:1 173) at org.eclipse.ui.internal.SaveAction.run(SaveAction.java:31) at org.eclipse.jface.action.Action.runWithEvent(Action.java:451) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(Act ionContributionItem.java:361) at org.eclipse.jface.action.ActionContributionItem.access$0(ActionContri butionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handle Event(ActionContributionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:645) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1359) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1160) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:675) at org.eclipse.ui.internal.Workbench.run(Workbench.java:658) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoa der.java:820) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:285) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:502) at org.eclipse.core.launcher.UIMain.main(UIMain.java:52) Monitor pool info: Initial monitor count: 32 Minimum number of free monitors before expansion: 5 Pool will next be expanded by: 16 Current total number of monitors: 32 Current number of free monitors: 9 Monitor Pool Dump (inflated object-monitors): sys_mon_t:0x00234ec0 infl_mon_t: 0x00234ab0: java.lang.ref.Reference$Lock@8F1738/8F1740: <unowned> Waiting to be notified: "Reference Handler" (0x839cc0) sys_mon_t:0x00234f10 infl_mon_t: 0x00234af0: java.lang.ref.ReferenceQueue$Lock@8F4350/8F4358: <unowned> Waiting to be notified: "Finalizer" (0x86b710) sys_mon_t:0x002351e8 infl_mon_t: 0x00000000: org.eclipse.jdt.internal.core.WorkingCopy@2DAF488/2DAF490: <unowned> Waiting to be notified: "main" (0x2355d8) sys_mon_t:0x00235210 infl_mon_t: 0x00234d50: org.eclipse.swt.widgets.RunnableLock@43C6310/43C6318: <unowned> Waiting to be notified: "org.eclipse.jface.text.reconciler.MonoReconciler" (0x13d10ab0) JVM System Monitor Dump (registered monitors): ACS Heap lock: <unowned> System Heap lock: <unowned> Sleep lock: <unowned> Waiting to be notified: "Java indexing: org.eclipse.jdt.internal.core.search.indexing.IndexM anager" (0x123ca2a0) Method trace lock: <unowned> UTF8 Cache lock: <unowned> Heap lock: <unowned> Rewrite Code lock: <unowned> Monitor Cache lock: owner "Signal dispatcher" (0x835310) 1 entry JNI Pinning lock: <unowned> JNI Global Reference lock: <unowned> Classloader lock: <unowned> Linking class lock: <unowned> Binclass lock: <unowned> Monitor Registry lock: owner "Signal dispatcher" (0x835310) 1 entry Thread queue lock: owner "Signal dispatcher" (0x835310) 1 entry Thread identifiers (as used in flat monitors): ident 13 "org.eclipse.jface.text.reconciler.MonoReconciler" (0x13d10ab0) ee 0x13d108e0 ident 7 "HelpServer" (0x13b5c698) ee 0x13b5c4c8 ident 6 "Java indexing: org.eclipse.jdt.internal.core.search.indexing.IndexM anager" (0x123ca2a0) ee 0x123ca0d0 ident 5 "Finalizer" (0x86b710) ee 0x0086b540 ident 4 "Reference Handler" (0x839cc0) ee 0x00839af0 ident 3 "Signal dispatcher" (0x835310) ee 0x00835140 ident 2 "main" (0x2355d8) ee 0x00235408 Java Object Monitor Dump (flat & inflated object-monitors): java.lang.ref.Reference$Lock@8F1738/8F1740 locknflags 80000200 Monitor inflated infl_mon 0x00234ab0 java.lang.ref.ReferenceQueue$Lock@8F4350/8F4358 locknflags 80000400 Monitor inflated infl_mon 0x00234af0 java.net.PlainSocketImpl@1142FB8/1142FC0 locknflags 00070000 Flat locked by threadIdent 7. Entrycount 1 org.eclipse.jdt.internal.core.WorkingCopy@2DAF488/2DAF490 locknflags 00130000 Flat locked by threadIdent 13. Entrycount 1 Writing java dump to D:\devel\sdk203/javacore764.1002803130.txt... OK
resolved fixed
07b70de
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T15:26:49"
"2001-10-11T11:33:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/JavaElementContentProvider.java
/* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ package org.eclipse.jdt.ui; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.jdt.internal.ui.*; import org.eclipse.jdt.internal.ui.viewsupport.*; import org.eclipse.jface.viewers.*; import org.eclipse.swt.widgets.*; /** * Standard tree content provider for Java elements. * Use this class when you want to present the Java elements in a viewer. * <p> * The following Java element hierarchy is surfaced by this content provider: * <p> * <pre> Java model (<code>IJavaModel</code>) Java project (<code>IJavaProject</code>) package fragment root (<code>IPackageFragmentRoot</code>) package fragment (<code>IPackageFragment</code>) compilation unit (<code>ICompilationUnit</code>) binary class file (<code>IClassFile</code>) * </pre> * </p> * <p> * Note that when the entire Java project is declared to be package fragment root, * the corresponding package fragment root element that normally appears between the * Java project and the package fragments is automatically filtered out. * </p> * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> */ public class JavaElementContentProvider extends BaseJavaElementContentProvider implements ITreeContentProvider, IElementChangedListener { protected TreeViewer fViewer; protected Object fInput; /* (non-Javadoc) * Method declared on IContentProvider. */ public void dispose() { super.dispose(); JavaCore.removeElementChangedListener(this); } /* (non-Javadoc) * Method declared on IContentProvider. */ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { super.inputChanged(viewer, oldInput, newInput); fViewer= (TreeViewer)viewer; if (oldInput == null && newInput != null) { JavaCore.addElementChangedListener(this); } else if (oldInput != null && newInput == null) { JavaCore.removeElementChangedListener(this); } fInput= newInput; } /** * Creates a new content provider for Java elements. */ public JavaElementContentProvider() { } /** * Creates a new content provider for Java elements. */ public JavaElementContentProvider(boolean provideMembers) { super(provideMembers); } /* (non-Javadoc) * Method declared on IElementChangedListener. */ public void elementChanged(final ElementChangedEvent event) { try { processDelta(event.getDelta()); } catch(JavaModelException e) { JavaPlugin.getDefault().logErrorStatus(JavaUIMessages.getString("JavaElementContentProvider.errorMessage"), e.getStatus()); //$NON-NLS-1$ } } /** * Processes a delta recursively. When more than two children are affected the * tree is fully refreshed starting at this node. The delta is processed in the * current thread but the viewer updates are posted to the UI thread. */ protected void processDelta(IJavaElementDelta delta) throws JavaModelException { int kind= delta.getKind(); int flags= delta.getFlags(); IJavaElement element= delta.getElement(); // handle open and closing of a solution or project if (((flags & IJavaElementDelta.F_CLOSED) != 0) || ((flags & IJavaElementDelta.F_OPENED) != 0)) { postRefresh(element); return; } if (kind == IJavaElementDelta.REMOVED) { Object parent= internalGetParent(element); postRemove(element); if (parent instanceof IPackageFragment) updatePackageIcon((IPackageFragment)parent); // we are filtering out empty subpackages, so we // a package becomes empty we remove it from the viewer. if (isPackageFragmentEmpty(element.getParent())) { if (fViewer.testFindItem(parent) != null) postRefresh(internalGetParent(parent)); } return; } if (kind == IJavaElementDelta.ADDED) { Object parent= internalGetParent(element); // we are filtering out empty subpackages, so we // have to handle additions to them specially. if (parent instanceof IPackageFragment) { Object grandparent= internalGetParent(parent); // 1GE8SI6: ITPJUI:WIN98 - Rename is not shown in Packages View // avoid posting a refresh to an unvisible parent if (parent.equals(fInput)) { postRefresh(parent); } else { // refresh from grandparent if parent isn't visible yet if (fViewer.testFindItem(parent) == null) postRefresh(grandparent); else { postRefresh(parent); } } } else { postAdd(parent, element); } } if (element instanceof ICompilationUnit) { if (kind == IJavaElementDelta.CHANGED) { postRefresh(element); } } // we don't show the contents of a compilation or IClassFile, so don't go any deeper if ((element instanceof ICompilationUnit) || (element instanceof IClassFile)) return; if (isClassPathChange(delta)) { // throw the towel and do a full refresh of the affected java project. postRefresh(element.getJavaProject()); } if (delta.getResourceDeltas() != null) { IResourceDelta[] rd= delta.getResourceDeltas(); IJavaProject project= element.getJavaProject(); for (int i= 0; i < rd.length; i++) { processResourceDelta(rd[i], element); } } IJavaElementDelta[] affectedChildren= delta.getAffectedChildren(); if (affectedChildren.length > 1) { // a package fragment might become non empty refresh from the parent if (element instanceof IPackageFragment) { IJavaElement parent= (IJavaElement)internalGetParent(element); // 1GE8SI6: ITPJUI:WIN98 - Rename is not shown in Packages View // avoid posting a refresh to an unvisible parent if (element.equals(fInput)) { postRefresh(element); } else { postRefresh(parent); } return; } // more than one child changed, refresh from here downwards if (element instanceof IPackageFragmentRoot) postRefresh(skipProjectPackageFragmentRoot((IPackageFragmentRoot)element)); else postRefresh(element); return; } for (int i= 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i]); } } /** * Updates the package icon */ private void updatePackageIcon(final IJavaElement element) { postRunnable(new Runnable() { public void run() { // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) fViewer.update(element, new String[]{IBasicPropertyConstants.P_IMAGE}); } }); } /** * Process resource deltas */ private void processResourceDelta(IResourceDelta delta, Object parent) { int status= delta.getKind(); IResource resource= delta.getResource(); // filter out changes affecting the output folder if (resource == null) return; // this could be optimized by handling all the added children in the parent if ((status & IResourceDelta.REMOVED) != 0) { if (parent instanceof IPackageFragment) // refresh one level above to deal with empty package filtering properly postRefresh(internalGetParent(parent)); else postRemove(resource); } if ((status & IResourceDelta.ADDED) != 0) { if (parent instanceof IPackageFragment) // refresh one level above to deal with empty package filtering properly postRefresh(internalGetParent(parent)); else postAdd(parent, resource); } int changeFlags= delta.getFlags(); IResourceDelta[] affectedChildren= delta.getAffectedChildren(); if (affectedChildren.length > 1) { // more than one child changed, refresh from here downwards postRefresh(resource); return; } for (int i= 0; i < affectedChildren.length; i++) processResourceDelta(affectedChildren[i], resource); } private void postRefresh(final Object root) { postRunnable(new Runnable() { public void run() { // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) fViewer.refresh(root); } }); } private void postAdd(final Object parent, final Object element) { postRunnable(new Runnable() { public void run() { // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) fViewer.add(parent, element); } }); } private void postRemove(final Object element) { postRunnable(new Runnable() { public void run() { // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) fViewer.remove(element); } }); } private void postRunnable(final Runnable r) { Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) { ctrl.getDisplay().syncExec(r); } } }
4,385
Bug 4385 QualifiedAllocationExpression.sourceEnd incorrect if type is an AnonymousLocalTypeDeclaration
Consider the following source: Protectable p= new Protectable() { public void protect() throws Exception { setUp(); basicRun(result); tearDown(); } }; SourceEnd of the QualifiedAllocationExpression new Protectable is the e of Protectable and not the closing } of the type declaration
resolved fixed
5f2190e
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T16:25:05"
"2001-10-11T14:20:00"
org.eclipse.jdt.ui/core
4,385
Bug 4385 QualifiedAllocationExpression.sourceEnd incorrect if type is an AnonymousLocalTypeDeclaration
Consider the following source: Protectable p= new Protectable() { public void protect() throws Exception { setUp(); basicRun(result); tearDown(); } }; SourceEnd of the QualifiedAllocationExpression new Protectable is the e of Protectable and not the closing } of the type declaration
resolved fixed
5f2190e
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-11T16:25:05"
"2001-10-11T14:20:00"
refactoring/org/eclipse/jdt/internal/core/refactoring/code/StatementAnalyzer.java
4,916
Bug 4916 Potential IDE freeze on Template Preference Page
Comments from Adam Kiezun: SEVERE: 1. go to template pref page. 2. select the first one 3. edit the name - empty the field and then put a single space whole IDE freezes (infinite loop?)
resolved fixed
d8ca187
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-12T12:11:08"
"2001-10-12T12:33:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/TemplatePreferencePage.java
package org.eclipse.jdt.internal.ui.preferences; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; import org.eclipse.jdt.internal.ui.text.template.Template; import org.eclipse.jdt.internal.ui.text.template.TemplateContentProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateLabelProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateMessages; import org.eclipse.jdt.internal.ui.text.template.TemplateSet; import org.eclipse.jdt.internal.ui.util.SWTUtil; import org.eclipse.jdt.internal.ui.util.TabFolderLayout; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; import org.eclipse.jdt.ui.text.JavaTextTools; import org.eclipse.jface.dialogs.ControlEnableState; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.help.DialogPageContextComputer; import org.eclipse.ui.help.WorkbenchHelp; public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { // preference store keys private static final String PREF_FORMAT_TEMPLATES= JavaUI.ID_PLUGIN + ".template.format"; //$NON-NLS-1$ private CheckboxTableViewer fTableViewer; private Button fAddButton; private Button fRemoveButton; private Button fEnableAllButton; private Button fDisableAllButton; private Group fEditor; private Text fNameText; private Text fDescriptionText; private Combo fContextCombo; private SourceViewer fPatternEditor; private Button fFormatButton; private ControlEnableState fEditorEnabler; private List fEditorComponents; private Template fCurrent; public TemplatePreferencePage() { super(); setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$ } /** * @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite ancestor) { Composite parent= new Composite(ancestor, SWT.NULL); GridLayout layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; parent.setLayout(layout); TabFolder folder= new TabFolder(parent, SWT.NONE); folder.setLayout(new TabFolderLayout()); folder.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite firstPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 2; firstPage.setLayout(layout); TabItem item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.edit")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(firstPage); fTableViewer= new CheckboxTableViewer(firstPage, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); Table table= fTableViewer.getTable(); GridData data= new GridData(GridData.FILL_BOTH); data.widthHint= convertWidthInCharsToPixels(80); data.heightHint= convertHeightInCharsToPixels(10); fTableViewer.getTable().setLayoutData(data); table.setHeaderVisible(true); table.setLinesVisible(true); TableLayout tableLayout= new TableLayout(); table.setLayout(tableLayout); // TableColumn column1= new TableColumn(table, SWT.NULL); TableColumn column1= table.getColumn(0); column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$ TableColumn column2= new TableColumn(table, SWT.NULL); column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$ tableLayout.addColumnData(new ColumnWeightData(30)); tableLayout.addColumnData(new ColumnWeightData(70)); fTableViewer.setLabelProvider(new TemplateLabelProvider()); fTableViewer.setContentProvider(new TemplateContentProvider(fTableViewer, TemplateSet.getInstance())); fTableViewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object object1, Object object2) { if ((object1 instanceof Template) && (object2 instanceof Template)) { Template left= (Template) object1; Template right= (Template) object2; int result= left.getName().compareToIgnoreCase(right.getName()); if (result != 0) return result; return left.getDescription().compareToIgnoreCase(right.getDescription()); } return super.compare(viewer, object1, object2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { selectionChanged1(); } }); fTableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { Template template= (Template) event.getElement(); template.setEnabled(event.getChecked()); } }); Composite buttons= new Composite(firstPage, SWT.NULL); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; buttons.setLayout(layout); fAddButton= new Button(buttons, SWT.PUSH); fAddButton.setLayoutData(getButtonGridData(fAddButton)); fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$ fAddButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { add(); } }); fRemoveButton= new Button(buttons, SWT.PUSH); fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton)); fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$ fRemoveButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { remove(); } }); fEnableAllButton= new Button(buttons, SWT.PUSH); fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton)); fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$ fEnableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(true); } }); fDisableAllButton= new Button(buttons, SWT.PUSH); fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton)); fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$ fDisableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(false); } }); fEditor= new Group(firstPage, SWT.NULL); fEditor.setText(TemplateMessages.getString("TemplatePreferencePage.editor")); //$NON-NLS-1$ fEditor.setLayoutData(new GridData(GridData.FILL_BOTH)); layout= new GridLayout(); layout.numColumns= 2; fEditor.setLayout(layout); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.name")); //$NON-NLS-1$ Composite composite= new Composite(fEditor, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout= new GridLayout(); layout.numColumns= 3; layout.marginWidth= 0; layout.marginHeight= 0; composite.setLayout(layout); fNameText= createText(composite); fNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setName(fNameText.getText()); fTableViewer.refresh(fCurrent); updateButtons(); } }); createLabel(composite, TemplateMessages.getString("TemplatePreferencePage.context")); //$NON-NLS-1$ fContextCombo= new Combo(composite, SWT.READ_ONLY); fContextCombo.setItems(new String[] {"java", "javadoc"}); //$NON-NLS-1$ //$NON-NLS-2$ fContextCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setContext(fContextCombo.getText()); fTableViewer.refresh(fCurrent); } }); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.description")); //$NON-NLS-1$ fDescriptionText= createText(fEditor); fDescriptionText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setDescription(fDescriptionText.getText()); fTableViewer.refresh(fCurrent); } }); Label patternLabel= createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.pattern")); //$NON-NLS-1$ patternLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); fPatternEditor= createEditor(fEditor); StyledText text= fPatternEditor.getTextWidget(); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setPattern(fPatternEditor.getTextWidget().getText()); } }); Composite secondPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 1; secondPage.setLayout(layout); item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.options")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(secondPage); fFormatButton= new Button(secondPage, SWT.CHECK); fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$ IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES)); fTableViewer.setInput(TemplateSet.getInstance()); fTableViewer.setAllChecked(false); fTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); WorkbenchHelp.setHelp(parent, new DialogPageContextComputer(this, IJavaHelpContextIds.JRE_PREFERENCE_PAGE)); leaveEditor(); return parent; } private Template[] getEnabledTemplates() { Template[] templates= TemplateSet.getInstance().getTemplates(); List list= new ArrayList(templates.length); for (int i= 0; i != templates.length; i++) if (templates[i].isEnabled()) list.add(templates[i]); return (Template[]) list.toArray(new Template[list.size()]); } private static Label createLabel(Composite parent, String name) { Label label= new Label(parent, SWT.NULL); label.setText(name); label.setLayoutData(new GridData()); return label; } private static Text createText(Composite parent) { Text text= new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } private SourceViewer createEditor(Composite parent) { SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); viewer.configure(new JavaSourceViewerConfiguration(tools, null)); viewer.setEditable(true); viewer.setDocument(new Document()); Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT); viewer.getTextWidget().setFont(font); Control control= viewer.getControl(); GridData data= new GridData(GridData.FILL_BOTH); data.heightHint= convertHeightInCharsToPixels(5); control.setLayoutData(data); return viewer; } private static GridData getButtonGridData(Button button) { GridData data= new GridData(GridData.FILL_HORIZONTAL); data.widthHint= SWTUtil.getButtonWidthHint(button); data.heightHint= SWTUtil.getButtonHeigthHint(button); return data; } private void selectionChanged1() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { Template template= (Template) selection.getFirstElement(); enterEditor(template); } else { leaveEditor(); } updateButtons(); } private void updateButtons() { int selectionCount= ((IStructuredSelection) fTableViewer.getSelection()).size(); int itemCount= fTableViewer.getTable().getItemCount(); boolean error= (fCurrent != null) && (fCurrent.getName().length() == 0); fAddButton.setEnabled(!error); fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount); fEnableAllButton.setEnabled(itemCount > 0); fDisableAllButton.setEnabled(itemCount > 0); StatusInfo status= new StatusInfo(); if (error) status.setError(TemplateMessages.getString("TemplatePreferencePage.error.noname")); //$NON-NLS-1$ setValid(!status.matches(IStatus.ERROR)); StatusUtil.applyToStatusLine(this, status); } private static int getIndex(String context) { if (context.equals("java")) //$NON-NLS-1$ return 0; else if (context.equals("javadoc")) //$NON-NLS-1$ return 1; else return -1; } private void enterEditor(Template template) { fCurrent= template; fNameText.setText(template.getName()); fDescriptionText.setText(template.getDescription()); fContextCombo.select(getIndex(template.getContext())); fPatternEditor.getDocument().set(template.getPattern()); if (fEditorEnabler != null) { fEditorEnabler.restore(); fEditorEnabler= null; } } private void leaveEditor() { fCurrent= null; fNameText.setText(""); //$NON-NLS-1$ fDescriptionText.setText(""); //$NON-NLS-1$ fContextCombo.select(getIndex("")); //$NON-NLS-1$ fPatternEditor.getDocument().set(""); //$NON-NLS-1$ if (fEditorEnabler == null) fEditorEnabler= ControlEnableState.disable(fEditor); } private void add() { Template template= new Template(); template.setContext("java"); //$NON-NLS-1$ TemplateSet.getInstance().add(template); fTableViewer.refresh(); fTableViewer.setChecked(template, template.isEnabled()); enterEditor(template); fNameText.setFocus(); } private void remove() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); Iterator elements= selection.iterator(); while (elements.hasNext()) { Template template= (Template) elements.next(); TemplateSet.getInstance().remove(template); } leaveEditor(); fTableViewer.refresh(); } private void enableAll(boolean enable) { Template[] templates= TemplateSet.getInstance().getTemplates(); for (int i= 0; i != templates.length; i++) templates[i].setEnabled(enable); fTableViewer.setAllChecked(enable); } /* * @see IWorkbenchPreferencePage#init(IWorkbench) */ public void init(IWorkbench workbench) {} /* * @see Control#setVisible(boolean) */ public void setVisible(boolean visible) { super.setVisible(visible); if (visible) setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$ } /* * @see PreferencePage#performDefaults() */ protected void performDefaults() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES)); TemplateSet.getInstance().restoreDefaults(); fTableViewer.refresh(); } /* * @see PreferencePage#performOk() */ public boolean performOk() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection()); TemplateSet.getInstance().save(); return super.performOk(); } /* * @see PreferencePage#performCancel() */ public boolean performCancel() { TemplateSet.getInstance().reset(); return super.performCancel(); } /** * Initializes the default values of this page in the preference bundle. * Will be called on startup of the JavaPlugin */ public static void initDefaults(IPreferenceStore prefs) { prefs.setDefault(PREF_FORMAT_TEMPLATES, true); } public static boolean useCodeFormatter() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); return prefs.getBoolean(PREF_FORMAT_TEMPLATES); } }
4,358
Bug 4358 Template - steals closing bracket
Steps to reproduce - press new - enter name for - enter description for(collection, type, var) - iterate over collection - enter pattern for (Iterator iter= ${0}.iterator; iter.hasNext(); ) { ${1} ${2}= (${1})iter.next(); ${cursor} - press return several times - position cursor after ${cursor} - press enter - press } - press OK - reopen dialog ==> observe: closing bracket } is missing.
resolved fixed
4b44b25
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-12T13:33:04"
"2001-10-11T11:33:20"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/TemplatePreferencePage.java
package org.eclipse.jdt.internal.ui.preferences; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; import org.eclipse.jdt.internal.ui.text.template.Template; import org.eclipse.jdt.internal.ui.text.template.TemplateContentProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateLabelProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateMessages; import org.eclipse.jdt.internal.ui.text.template.TemplateSet; import org.eclipse.jdt.internal.ui.util.SWTUtil; import org.eclipse.jdt.internal.ui.util.TabFolderLayout; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; import org.eclipse.jdt.ui.text.JavaTextTools; import org.eclipse.jface.dialogs.ControlEnableState; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.help.DialogPageContextComputer; import org.eclipse.ui.help.WorkbenchHelp; public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { // preference store keys private static final String PREF_FORMAT_TEMPLATES= JavaUI.ID_PLUGIN + ".template.format"; //$NON-NLS-1$ private CheckboxTableViewer fTableViewer; private Button fAddButton; private Button fRemoveButton; private Button fEnableAllButton; private Button fDisableAllButton; private Group fEditor; private Text fNameText; private Text fDescriptionText; private Combo fContextCombo; private SourceViewer fPatternEditor; private Button fFormatButton; private ControlEnableState fEditorEnabler; private List fEditorComponents; private Template fCurrent; public TemplatePreferencePage() { super(); setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$ } /** * @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite ancestor) { Composite parent= new Composite(ancestor, SWT.NULL); GridLayout layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; parent.setLayout(layout); TabFolder folder= new TabFolder(parent, SWT.NONE); folder.setLayout(new TabFolderLayout()); folder.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite firstPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 2; firstPage.setLayout(layout); TabItem item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.edit")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(firstPage); fTableViewer= new CheckboxTableViewer(firstPage, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); Table table= fTableViewer.getTable(); GridData data= new GridData(GridData.FILL_BOTH); data.widthHint= convertWidthInCharsToPixels(80); data.heightHint= convertHeightInCharsToPixels(10); fTableViewer.getTable().setLayoutData(data); table.setHeaderVisible(true); table.setLinesVisible(true); TableLayout tableLayout= new TableLayout(); table.setLayout(tableLayout); // TableColumn column1= new TableColumn(table, SWT.NULL); TableColumn column1= table.getColumn(0); column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$ TableColumn column2= new TableColumn(table, SWT.NULL); column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$ tableLayout.addColumnData(new ColumnWeightData(30)); tableLayout.addColumnData(new ColumnWeightData(70)); fTableViewer.setLabelProvider(new TemplateLabelProvider()); fTableViewer.setContentProvider(new TemplateContentProvider(fTableViewer, TemplateSet.getInstance())); fTableViewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object object1, Object object2) { if ((object1 instanceof Template) && (object2 instanceof Template)) { Template left= (Template) object1; Template right= (Template) object2; int result= left.getName().compareToIgnoreCase(right.getName()); if (result != 0) return result; return left.getDescription().compareToIgnoreCase(right.getDescription()); } return super.compare(viewer, object1, object2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { selectionChanged1(); } }); fTableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { Template template= (Template) event.getElement(); template.setEnabled(event.getChecked()); } }); Composite buttons= new Composite(firstPage, SWT.NULL); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; buttons.setLayout(layout); fAddButton= new Button(buttons, SWT.PUSH); fAddButton.setLayoutData(getButtonGridData(fAddButton)); fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$ fAddButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { add(); } }); fRemoveButton= new Button(buttons, SWT.PUSH); fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton)); fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$ fRemoveButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { remove(); } }); fEnableAllButton= new Button(buttons, SWT.PUSH); fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton)); fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$ fEnableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(true); } }); fDisableAllButton= new Button(buttons, SWT.PUSH); fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton)); fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$ fDisableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(false); } }); fEditor= new Group(firstPage, SWT.NULL); fEditor.setText(TemplateMessages.getString("TemplatePreferencePage.editor")); //$NON-NLS-1$ fEditor.setLayoutData(new GridData(GridData.FILL_BOTH)); layout= new GridLayout(); layout.numColumns= 2; fEditor.setLayout(layout); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.name")); //$NON-NLS-1$ Composite composite= new Composite(fEditor, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout= new GridLayout(); layout.numColumns= 3; layout.marginWidth= 0; layout.marginHeight= 0; composite.setLayout(layout); fNameText= createText(composite); fNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setName(fNameText.getText()); fTableViewer.refresh(fCurrent); updateButtons(); } }); createLabel(composite, TemplateMessages.getString("TemplatePreferencePage.context")); //$NON-NLS-1$ fContextCombo= new Combo(composite, SWT.READ_ONLY); fContextCombo.setItems(new String[] {"java", "javadoc"}); //$NON-NLS-1$ //$NON-NLS-2$ fContextCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setContext(fContextCombo.getText()); fTableViewer.refresh(fCurrent); } }); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.description")); //$NON-NLS-1$ fDescriptionText= createText(fEditor); fDescriptionText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setDescription(fDescriptionText.getText()); fTableViewer.refresh(fCurrent); } }); Label patternLabel= createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.pattern")); //$NON-NLS-1$ patternLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); fPatternEditor= createEditor(fEditor); StyledText text= fPatternEditor.getTextWidget(); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setPattern(fPatternEditor.getTextWidget().getText()); } }); Composite secondPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 1; secondPage.setLayout(layout); item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.options")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(secondPage); fFormatButton= new Button(secondPage, SWT.CHECK); fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$ IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES)); fTableViewer.setInput(TemplateSet.getInstance()); fTableViewer.setAllChecked(false); fTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); WorkbenchHelp.setHelp(parent, new DialogPageContextComputer(this, IJavaHelpContextIds.JRE_PREFERENCE_PAGE)); leaveEditor(); return parent; } private Template[] getEnabledTemplates() { Template[] templates= TemplateSet.getInstance().getTemplates(); List list= new ArrayList(templates.length); for (int i= 0; i != templates.length; i++) if (templates[i].isEnabled()) list.add(templates[i]); return (Template[]) list.toArray(new Template[list.size()]); } private static Label createLabel(Composite parent, String name) { Label label= new Label(parent, SWT.NULL); label.setText(name); label.setLayoutData(new GridData()); return label; } private static Text createText(Composite parent) { Text text= new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } private SourceViewer createEditor(Composite parent) { SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); viewer.configure(new JavaSourceViewerConfiguration(tools, null)); viewer.setEditable(true); viewer.setDocument(new Document()); Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT); viewer.getTextWidget().setFont(font); Control control= viewer.getControl(); GridData data= new GridData(GridData.FILL_BOTH); data.heightHint= convertHeightInCharsToPixels(5); control.setLayoutData(data); return viewer; } private static GridData getButtonGridData(Button button) { GridData data= new GridData(GridData.FILL_HORIZONTAL); data.widthHint= SWTUtil.getButtonWidthHint(button); data.heightHint= SWTUtil.getButtonHeigthHint(button); return data; } private void selectionChanged1() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { Template template= (Template) selection.getFirstElement(); enterEditor(template); } else { leaveEditor(); } updateButtons(); } private void updateButtons() { int selectionCount= ((IStructuredSelection) fTableViewer.getSelection()).size(); int itemCount= fTableViewer.getTable().getItemCount(); boolean error= (fCurrent != null) && (fCurrent.getName().length() == 0); fAddButton.setEnabled(!error); fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount); fEnableAllButton.setEnabled(itemCount > 0); fDisableAllButton.setEnabled(itemCount > 0); StatusInfo status= new StatusInfo(); if (error) status.setError(TemplateMessages.getString("TemplatePreferencePage.error.noname")); //$NON-NLS-1$ setValid(!status.matches(IStatus.ERROR)); StatusUtil.applyToStatusLine(this, status); } private static int getIndex(String context) { if (context.equals("java")) //$NON-NLS-1$ return 0; else if (context.equals("javadoc")) //$NON-NLS-1$ return 1; else return -1; } private void enterEditor(Template template) { if (template == fCurrent) // #4916 return; fCurrent= template; fNameText.setText(template.getName()); fDescriptionText.setText(template.getDescription()); fContextCombo.select(getIndex(template.getContext())); fPatternEditor.getDocument().set(template.getPattern()); if (fEditorEnabler != null) { fEditorEnabler.restore(); fEditorEnabler= null; } } private void leaveEditor() { fCurrent= null; fNameText.setText(""); //$NON-NLS-1$ fDescriptionText.setText(""); //$NON-NLS-1$ fContextCombo.select(getIndex("")); //$NON-NLS-1$ fPatternEditor.getDocument().set(""); //$NON-NLS-1$ if (fEditorEnabler == null) fEditorEnabler= ControlEnableState.disable(fEditor); } private void add() { Template template= new Template(); template.setContext("java"); //$NON-NLS-1$ TemplateSet.getInstance().add(template); fTableViewer.refresh(); fTableViewer.setChecked(template, template.isEnabled()); enterEditor(template); fNameText.setFocus(); } private void remove() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); Iterator elements= selection.iterator(); while (elements.hasNext()) { Template template= (Template) elements.next(); TemplateSet.getInstance().remove(template); } leaveEditor(); fTableViewer.refresh(); } private void enableAll(boolean enable) { Template[] templates= TemplateSet.getInstance().getTemplates(); for (int i= 0; i != templates.length; i++) templates[i].setEnabled(enable); fTableViewer.setAllChecked(enable); } /* * @see IWorkbenchPreferencePage#init(IWorkbench) */ public void init(IWorkbench workbench) {} /* * @see Control#setVisible(boolean) */ public void setVisible(boolean visible) { super.setVisible(visible); if (visible) setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$ } /* * @see PreferencePage#performDefaults() */ protected void performDefaults() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES)); TemplateSet.getInstance().restoreDefaults(); fTableViewer.refresh(); } /* * @see PreferencePage#performOk() */ public boolean performOk() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection()); TemplateSet.getInstance().save(); return super.performOk(); } /* * @see PreferencePage#performCancel() */ public boolean performCancel() { TemplateSet.getInstance().reset(); return super.performCancel(); } /** * Initializes the default values of this page in the preference bundle. * Will be called on startup of the JavaPlugin */ public static void initDefaults(IPreferenceStore prefs) { prefs.setDefault(PREF_FORMAT_TEMPLATES, true); } public static boolean useCodeFormatter() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); return prefs.getBoolean(PREF_FORMAT_TEMPLATES); } }
4,354
Bug 4354 Template - pressing new presents an error
- go to Preferences->Java->Templates - press the new button - you get an error saying that the template name must not be null. This is annoying since I didn't have the change to specify one.
resolved fixed
2a1a288
JDT
https://github.com/eclipse-jdt/eclipse.jdt.ui
eclipse-jdt/eclipse.jdt.ui
java
null
null
null
"2001-10-12T15:09:58"
"2001-10-11T08:46:40"
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/TemplatePreferencePage.java
package org.eclipse.jdt.internal.ui.preferences; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; import org.eclipse.jdt.internal.ui.text.template.Template; import org.eclipse.jdt.internal.ui.text.template.TemplateContentProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateLabelProvider; import org.eclipse.jdt.internal.ui.text.template.TemplateMessages; import org.eclipse.jdt.internal.ui.text.template.TemplateSet; import org.eclipse.jdt.internal.ui.util.SWTUtil; import org.eclipse.jdt.internal.ui.util.TabFolderLayout; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; import org.eclipse.jdt.ui.text.JavaTextTools; import org.eclipse.jface.dialogs.ControlEnableState; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.help.DialogPageContextComputer; import org.eclipse.ui.help.WorkbenchHelp; public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { // preference store keys private static final String PREF_FORMAT_TEMPLATES= JavaUI.ID_PLUGIN + ".template.format"; //$NON-NLS-1$ private CheckboxTableViewer fTableViewer; private Button fAddButton; private Button fRemoveButton; private Button fEnableAllButton; private Button fDisableAllButton; private Group fEditor; private Text fNameText; private Text fDescriptionText; private Combo fContextCombo; private SourceViewer fPatternEditor; private Button fFormatButton; private ControlEnableState fEditorEnabler; private List fEditorComponents; private Template fCurrent; public TemplatePreferencePage() { super(); setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$ } /** * @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite ancestor) { Composite parent= new Composite(ancestor, SWT.NULL); GridLayout layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; parent.setLayout(layout); TabFolder folder= new TabFolder(parent, SWT.NONE); folder.setLayout(new TabFolderLayout()); folder.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite firstPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 2; firstPage.setLayout(layout); TabItem item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.edit")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(firstPage); fTableViewer= new CheckboxTableViewer(firstPage, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); Table table= fTableViewer.getTable(); GridData data= new GridData(GridData.FILL_BOTH); data.widthHint= convertWidthInCharsToPixels(80); data.heightHint= convertHeightInCharsToPixels(10); fTableViewer.getTable().setLayoutData(data); table.setHeaderVisible(true); table.setLinesVisible(true); TableLayout tableLayout= new TableLayout(); table.setLayout(tableLayout); // TableColumn column1= new TableColumn(table, SWT.NULL); TableColumn column1= table.getColumn(0); column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$ TableColumn column2= new TableColumn(table, SWT.NULL); column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$ tableLayout.addColumnData(new ColumnWeightData(30)); tableLayout.addColumnData(new ColumnWeightData(70)); fTableViewer.setLabelProvider(new TemplateLabelProvider()); fTableViewer.setContentProvider(new TemplateContentProvider(fTableViewer, TemplateSet.getInstance())); fTableViewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object object1, Object object2) { if ((object1 instanceof Template) && (object2 instanceof Template)) { Template left= (Template) object1; Template right= (Template) object2; int result= left.getName().compareToIgnoreCase(right.getName()); if (result != 0) return result; return left.getDescription().compareToIgnoreCase(right.getDescription()); } return super.compare(viewer, object1, object2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent e) { selectionChanged1(); } }); fTableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { Template template= (Template) event.getElement(); template.setEnabled(event.getChecked()); } }); Composite buttons= new Composite(firstPage, SWT.NULL); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; buttons.setLayout(layout); fAddButton= new Button(buttons, SWT.PUSH); fAddButton.setLayoutData(getButtonGridData(fAddButton)); fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$ fAddButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { add(); } }); fRemoveButton= new Button(buttons, SWT.PUSH); fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton)); fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$ fRemoveButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { remove(); } }); fEnableAllButton= new Button(buttons, SWT.PUSH); fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton)); fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$ fEnableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(true); } }); fDisableAllButton= new Button(buttons, SWT.PUSH); fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton)); fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$ fDisableAllButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { enableAll(false); } }); fEditor= new Group(firstPage, SWT.NULL); fEditor.setText(TemplateMessages.getString("TemplatePreferencePage.editor")); //$NON-NLS-1$ fEditor.setLayoutData(new GridData(GridData.FILL_BOTH)); layout= new GridLayout(); layout.numColumns= 2; fEditor.setLayout(layout); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.name")); //$NON-NLS-1$ Composite composite= new Composite(fEditor, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout= new GridLayout(); layout.numColumns= 3; layout.marginWidth= 0; layout.marginHeight= 0; composite.setLayout(layout); fNameText= createText(composite); fNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setName(fNameText.getText()); fTableViewer.refresh(fCurrent); updateButtons(); } }); createLabel(composite, TemplateMessages.getString("TemplatePreferencePage.context")); //$NON-NLS-1$ fContextCombo= new Combo(composite, SWT.READ_ONLY); fContextCombo.setItems(new String[] {"java", "javadoc"}); //$NON-NLS-1$ //$NON-NLS-2$ fContextCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setContext(fContextCombo.getText()); fTableViewer.refresh(fCurrent); } }); createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.description")); //$NON-NLS-1$ fDescriptionText= createText(fEditor); fDescriptionText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (fCurrent == null) return; fCurrent.setDescription(fDescriptionText.getText()); fTableViewer.refresh(fCurrent); } }); Label patternLabel= createLabel(fEditor, TemplateMessages.getString("TemplatePreferencePage.pattern")); //$NON-NLS-1$ patternLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); fPatternEditor= createEditor(fEditor); Composite secondPage= new Composite(folder, SWT.NONE); layout= new GridLayout(); layout.numColumns= 1; secondPage.setLayout(layout); item= new TabItem(folder, SWT.NONE); item.setText(TemplateMessages.getString("TemplatePreferencePage.tab.options")); //$NON-NLS-1$ item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)); item.setControl(secondPage); fFormatButton= new Button(secondPage, SWT.CHECK); fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$ IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES)); fTableViewer.setInput(TemplateSet.getInstance()); fTableViewer.setAllChecked(false); fTableViewer.setCheckedElements(getEnabledTemplates()); updateButtons(); WorkbenchHelp.setHelp(parent, new DialogPageContextComputer(this, IJavaHelpContextIds.JRE_PREFERENCE_PAGE)); leaveEditor(); return parent; } private Template[] getEnabledTemplates() { Template[] templates= TemplateSet.getInstance().getTemplates(); List list= new ArrayList(templates.length); for (int i= 0; i != templates.length; i++) if (templates[i].isEnabled()) list.add(templates[i]); return (Template[]) list.toArray(new Template[list.size()]); } private static Label createLabel(Composite parent, String name) { Label label= new Label(parent, SWT.NULL); label.setText(name); label.setLayoutData(new GridData()); return label; } private static Text createText(Composite parent) { Text text= new Text(parent, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return text; } private SourceViewer createEditor(Composite parent) { SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); viewer.configure(new JavaSourceViewerConfiguration(tools, null)); viewer.setEditable(true); viewer.setDocument(new Document()); Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT); viewer.getTextWidget().setFont(font); Control control= viewer.getControl(); GridData data= new GridData(GridData.FILL_BOTH); data.heightHint= convertHeightInCharsToPixels(5); control.setLayoutData(data); return viewer; } private static GridData getButtonGridData(Button button) { GridData data= new GridData(GridData.FILL_HORIZONTAL); data.widthHint= SWTUtil.getButtonWidthHint(button); data.heightHint= SWTUtil.getButtonHeigthHint(button); return data; } private void selectionChanged1() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { Template template= (Template) selection.getFirstElement(); enterEditor(template); } else { leaveEditor(); } updateButtons(); } private void updateButtons() { int selectionCount= ((IStructuredSelection) fTableViewer.getSelection()).size(); int itemCount= fTableViewer.getTable().getItemCount(); boolean error= (fCurrent != null) && (fCurrent.getName().length() == 0); fAddButton.setEnabled(!error); fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount); fEnableAllButton.setEnabled(itemCount > 0); fDisableAllButton.setEnabled(itemCount > 0); StatusInfo status= new StatusInfo(); if (error) status.setError(TemplateMessages.getString("TemplatePreferencePage.error.noname")); //$NON-NLS-1$ setValid(!status.matches(IStatus.ERROR)); StatusUtil.applyToStatusLine(this, status); } private static int getIndex(String context) { if (context.equals("java")) //$NON-NLS-1$ return 0; else if (context.equals("javadoc")) //$NON-NLS-1$ return 1; else return -1; } private void enterEditor(Template template) { if (template == fCurrent) // #4916 return; if (fCurrent != null) // #4358 leaveEditor(); fCurrent= template; fNameText.setText(template.getName()); fDescriptionText.setText(template.getDescription()); fContextCombo.select(getIndex(template.getContext())); fPatternEditor.getDocument().set(template.getPattern()); if (fEditorEnabler != null) { fEditorEnabler.restore(); fEditorEnabler= null; } } private void leaveEditor() { if (fCurrent == null) return; // #4358 fCurrent.setPattern(fPatternEditor.getTextWidget().getText()); fCurrent= null; fNameText.setText(""); //$NON-NLS-1$ fDescriptionText.setText(""); //$NON-NLS-1$ fContextCombo.select(getIndex("")); //$NON-NLS-1$ fPatternEditor.getDocument().set(""); //$NON-NLS-1$ if (fEditorEnabler == null) fEditorEnabler= ControlEnableState.disable(fEditor); } private void add() { Template template= new Template(); template.setContext("java"); //$NON-NLS-1$ TemplateSet.getInstance().add(template); fTableViewer.refresh(); fTableViewer.setChecked(template, template.isEnabled()); enterEditor(template); fNameText.setFocus(); } private void remove() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); Iterator elements= selection.iterator(); while (elements.hasNext()) { Template template= (Template) elements.next(); TemplateSet.getInstance().remove(template); } leaveEditor(); fTableViewer.refresh(); } private void enableAll(boolean enable) { Template[] templates= TemplateSet.getInstance().getTemplates(); for (int i= 0; i != templates.length; i++) templates[i].setEnabled(enable); fTableViewer.setAllChecked(enable); } /* * @see IWorkbenchPreferencePage#init(IWorkbench) */ public void init(IWorkbench workbench) {} /* * @see Control#setVisible(boolean) */ public void setVisible(boolean visible) { super.setVisible(visible); if (visible) setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$ } /* * @see PreferencePage#performDefaults() */ protected void performDefaults() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES)); TemplateSet.getInstance().restoreDefaults(); fTableViewer.refresh(); } /* * @see PreferencePage#performOk() */ public boolean performOk() { leaveEditor(); // #4358 IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection()); TemplateSet.getInstance().save(); return super.performOk(); } /* * @see PreferencePage#performCancel() */ public boolean performCancel() { TemplateSet.getInstance().reset(); return super.performCancel(); } /** * Initializes the default values of this page in the preference bundle. * Will be called on startup of the JavaPlugin */ public static void initDefaults(IPreferenceStore prefs) { prefs.setDefault(PREF_FORMAT_TEMPLATES, true); } public static boolean useCodeFormatter() { IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore(); return prefs.getBoolean(PREF_FORMAT_TEMPLATES); } }
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
34
Edit dataset card