import net.sourceforge.phpdt.internal.core.util.Util;
import net.sourceforge.phpdt.internal.corext.Assert;
-
/**
* Handle for a source type. Info object is a SourceTypeElementInfo.
- *
+ *
* Note: Parent is either an IClassFile, an ICompilationUnit or an IType.
- *
+ *
* @see IType
*/
public class SourceType extends Member implements IType {
- /**
- * An empty list of Strings
- */
- protected static final String[] fgEmptyList= new String[] {};
- protected SourceType(JavaElement parent, String name) {
- super(parent, name);
- Assert.isTrue(name.indexOf('.') == -1, Util.bind("sourcetype.invalidName", name)); //$NON-NLS-1$
- }
-/**
- * @see IType
- */
-//public void codeComplete(char[] snippet,int insertion,int position,char[][] localVariableTypeNames,char[][] localVariableNames,int[] localVariableModifiers,boolean isStatic,ICompletionRequestor requestor) throws JavaModelException {
-// if (requestor == null) {
-// throw new IllegalArgumentException(Util.bind("codeAssist.nullRequestor")); //$NON-NLS-1$
-// }
-//
-// JavaProject project = (JavaProject) getJavaProject();
-// SearchableEnvironment environment = (SearchableEnvironment) project.getSearchableNameEnvironment();
-// NameLookup nameLookup = project.getNameLookup();
-// CompletionEngine engine = new CompletionEngine(environment, new CompletionRequestorWrapper(requestor,nameLookup), project.getOptions(true), project);
-//
-// String source = getCompilationUnit().getSource();
-// if (source != null && insertion > -1 && insertion < source.length()) {
-// String encoding = project.getOption(JavaCore.CORE_ENCODING, true);
-//
-// char[] prefix = CharOperation.concat(source.substring(0, insertion).toCharArray(), new char[]{'{'});
-// char[] suffix = CharOperation.concat(new char[]{'}'}, source.substring(insertion).toCharArray());
-// char[] fakeSource = CharOperation.concat(prefix, snippet, suffix);
-//
-// BasicCompilationUnit cu =
-// new BasicCompilationUnit(
-// fakeSource,
-// null,
-// getElementName(),
-// encoding);
-//
-// engine.complete(cu, prefix.length + position, prefix.length);
-// } else {
-// engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
-// }
-//}
-/**
- * @see IType
- */
-//public IField createField(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// CreateFieldOperation op = new CreateFieldOperation(this, contents, force);
-// if (sibling != null) {
-// op.createBefore(sibling);
-// }
-// runOperation(op, monitor);
-// return (IField) op.getResultElements()[0];
-//}
-/**
- * @see IType
- */
-//public IInitializer createInitializer(String contents, IJavaElement sibling, IProgressMonitor monitor) throws JavaModelException {
-// CreateInitializerOperation op = new CreateInitializerOperation(this, contents);
-// if (sibling != null) {
-// op.createBefore(sibling);
-// }
-// runOperation(op, monitor);
-// return (IInitializer) op.getResultElements()[0];
-//}
-/**
- * @see IType
- */
-//public IMethod createMethod(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// CreateMethodOperation op = new CreateMethodOperation(this, contents, force);
-// if (sibling != null) {
-// op.createBefore(sibling);
-// }
-// runOperation(op, monitor);
-// return (IMethod) op.getResultElements()[0];
-//}
-/**
- * @see IType
- */
-//public IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException {
-// CreateTypeOperation op = new CreateTypeOperation(this, contents, force);
-// if (sibling != null) {
-// op.createBefore(sibling);
-// }
-// runOperation(op, monitor);
-// return (IType) op.getResultElements()[0];
-//}
-/**
- * @see JavaElement#equalsDOMNode
- */
-protected boolean equalsDOMNode(IDOMNode node) throws JavaModelException {
- return (node.getNodeType() == IDOMNode.TYPE) && super.equalsDOMNode(node);
-}
-/*
- * @see IType
- */
-public IMethod[] findMethods(IMethod method) {
- try {
- return this.findMethods(method, this.getMethods());
- } catch (JavaModelException e) {
- // if type doesn't exist, no matching method can exist
- return null;
- }
-}
-/**
- * @see IMember
- */
-public IType getDeclaringType() {
- IJavaElement parent = getParent();
- while (parent != null) {
- if (parent.getElementType() == IJavaElement.TYPE) {
- return (IType) parent;
- } else
- if (parent instanceof IMember) {
- parent = parent.getParent();
- } else {
- return null;
- }
- }
- return null;
-}
-/**
- * @see IJavaElement
- */
-public int getElementType() {
- return TYPE;
-}
-/**
- * @see IType#getField
- */
-public IField getField(String name) {
- return new SourceField(this, name);
-}
-/**
- * @see IType
- */
-public IField[] getFields() throws JavaModelException {
- ArrayList list = getChildrenOfType(FIELD);
- IField[] array= new IField[list.size()];
- list.toArray(array);
- return array;
-}
-/**
- * @see IType#getFullyQualifiedName
- */
-public String getFullyQualifiedName() {
- return this.getFullyQualifiedName('$');
-}
-/**
- * @see IType#getFullyQualifiedName(char)
- */
-public String getFullyQualifiedName(char enclosingTypeSeparator) {
- String packageName = getPackageFragment().getElementName();
- if (packageName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
- return getTypeQualifiedName(enclosingTypeSeparator);
- }
- return packageName + '.' + getTypeQualifiedName(enclosingTypeSeparator);
-}
+ /**
+ * An empty list of Strings
+ */
+ protected static final String[] fgEmptyList = new String[] {};
-/**
- * @see IType
- */
-//public IInitializer getInitializer(int occurrenceCount) {
-// return new Initializer(this, occurrenceCount);
-//}
-/**
- * @see IType
- */
-//public IInitializer[] getInitializers() throws JavaModelException {
-// ArrayList list = getChildrenOfType(INITIALIZER);
-// IInitializer[] array= new IInitializer[list.size()];
-// list.toArray(array);
-// return array;
-//}
-/**
- * @see IType#getMethod
- */
-public IMethod getMethod(String name, String[] parameterTypeSignatures) {
- return new SourceMethod(this, name, parameterTypeSignatures);
-}
-/**
- * @see IType
- */
-public IMethod[] getMethods() throws JavaModelException {
- ArrayList list = getChildrenOfType(METHOD);
- IMethod[] array= new IMethod[list.size()];
- list.toArray(array);
- return array;
-}
-/**
- * @see IType
- */
-public IPackageFragment getPackageFragment() {
- IJavaElement parentElement = this.parent;
- while (parentElement != null) {
- if (parentElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
- return (IPackageFragment)parentElement;
- }
- else {
- parentElement = parentElement.getParent();
- }
- }
- Assert.isTrue(false); // should not happen
- return null;
-}
+ protected SourceType(JavaElement parent, String name) {
+ super(parent, name);
+ Assert.isTrue(name.indexOf('.') == -1, Util.bind("sourcetype.invalidName", name)); //$NON-NLS-1$
+ }
-/**
- * @see IType
- */
-public String getSuperclassName() throws JavaModelException {
- SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
- char[] superclassName= info.getSuperclassName();
- if (superclassName == null) {
- return null;
- }
- return new String(superclassName);
-}
-/**
- * @see IType
- */
-public String[] getSuperInterfaceNames() throws JavaModelException {
- SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
- char[][] names= info.getInterfaceNames();
- if (names == null) {
- return fgEmptyList;
- }
- String[] strings= new String[names.length];
- for (int i= 0; i < names.length; i++) {
- strings[i]= new String(names[i]);
- }
- return strings;
-}
+ /**
+ * @see IType
+ */
+ //public void codeComplete(char[] snippet,int insertion,int position,char[][] localVariableTypeNames,char[][]
+ // localVariableNames,int[] localVariableModifiers,boolean isStatic,ICompletionRequestor requestor) throws JavaModelException {
+ // if (requestor == null) {
+ // throw new IllegalArgumentException(Util.bind("codeAssist.nullRequestor")); //$NON-NLS-1$
+ // }
+ //
+ // JavaProject project = (JavaProject) getJavaProject();
+ // SearchableEnvironment environment = (SearchableEnvironment) project.getSearchableNameEnvironment();
+ // NameLookup nameLookup = project.getNameLookup();
+ // CompletionEngine engine = new CompletionEngine(environment, new CompletionRequestorWrapper(requestor,nameLookup),
+ // project.getOptions(true), project);
+ //
+ // String source = getCompilationUnit().getSource();
+ // if (source != null && insertion > -1 && insertion < source.length()) {
+ // String encoding = project.getOption(JavaCore.CORE_ENCODING, true);
+ //
+ // char[] prefix = CharOperation.concat(source.substring(0, insertion).toCharArray(), new char[]{'{'});
+ // char[] suffix = CharOperation.concat(new char[]{'}'}, source.substring(insertion).toCharArray());
+ // char[] fakeSource = CharOperation.concat(prefix, snippet, suffix);
+ //
+ // BasicCompilationUnit cu =
+ // new BasicCompilationUnit(
+ // fakeSource,
+ // null,
+ // getElementName(),
+ // encoding);
+ //
+ // engine.complete(cu, prefix.length + position, prefix.length);
+ // } else {
+ // engine.complete(this, snippet, position, localVariableTypeNames, localVariableNames, localVariableModifiers, isStatic);
+ // }
+ //}
+ /**
+ * @see IType
+ */
+ //public IField createField(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws
+ // JavaModelException {
+ // CreateFieldOperation op = new CreateFieldOperation(this, contents, force);
+ // if (sibling != null) {
+ // op.createBefore(sibling);
+ // }
+ // runOperation(op, monitor);
+ // return (IField) op.getResultElements()[0];
+ //}
+ /**
+ * @see IType
+ */
+ //public IInitializer createInitializer(String contents, IJavaElement sibling, IProgressMonitor monitor) throws
+ // JavaModelException {
+ // CreateInitializerOperation op = new CreateInitializerOperation(this, contents);
+ // if (sibling != null) {
+ // op.createBefore(sibling);
+ // }
+ // runOperation(op, monitor);
+ // return (IInitializer) op.getResultElements()[0];
+ //}
+ /**
+ * @see IType
+ */
+ //public IMethod createMethod(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws
+ // JavaModelException {
+ // CreateMethodOperation op = new CreateMethodOperation(this, contents, force);
+ // if (sibling != null) {
+ // op.createBefore(sibling);
+ // }
+ // runOperation(op, monitor);
+ // return (IMethod) op.getResultElements()[0];
+ //}
+ /**
+ * @see IType
+ */
+ //public IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws
+ // JavaModelException {
+ // CreateTypeOperation op = new CreateTypeOperation(this, contents, force);
+ // if (sibling != null) {
+ // op.createBefore(sibling);
+ // }
+ // runOperation(op, monitor);
+ // return (IType) op.getResultElements()[0];
+ //}
+ /**
+ * @see JavaElement#equalsDOMNode
+ */
+ protected boolean equalsDOMNode(IDOMNode node) throws JavaModelException {
+ return (node.getNodeType() == IDOMNode.TYPE) && super.equalsDOMNode(node);
+ }
-/**
- * @see IType
- */
-public IType getType(String name) {
- return new SourceType(this, name);
-}
-/**
- * @see IType#getTypeQualifiedName
- */
-public String getTypeQualifiedName() {
- return this.getTypeQualifiedName('$');
-}
-/**
- * @see IType#getTypeQualifiedName(char)
- */
-public String getTypeQualifiedName(char enclosingTypeSeparator) {
- if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
- return name;
- } else {
- return ((IType) parent).getTypeQualifiedName(enclosingTypeSeparator) + enclosingTypeSeparator + name;
- }
-}
+ /*
+ * @see IType
+ */
+ public IMethod[] findMethods(IMethod method) {
+ try {
+ return this.findMethods(method, this.getMethods());
+ } catch (JavaModelException e) {
+ // if type doesn't exist, no matching method can exist
+ return null;
+ }
+ }
-/**
- * @see IType
- */
-public IType[] getTypes() throws JavaModelException {
- ArrayList list= getChildrenOfType(TYPE);
- IType[] array= new IType[list.size()];
- list.toArray(array);
- return array;
-}
-/**
- * @see IParent
- */
-public boolean hasChildren() throws JavaModelException {
- return getChildren().length > 0;
-}
-/**
- * @see IType#isAnonymous()
- */
-public boolean isAnonymous() throws JavaModelException {
- return false; // cannot create source handle onto anonymous types
-}
-/**
- * @see IType
- */
-public boolean isClass() throws JavaModelException {
- return !isInterface();
-}
-/**
- * @see IType
- */
-public boolean isInterface() throws JavaModelException {
- SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
- return info.isInterface();
-}
-/**
- * @see IType#isLocal()
- */
-public boolean isLocal() throws JavaModelException {
- return false; // cannot create source handle onto local types
-}
-/**
- * @see IType#isMember()
- */
-public boolean isMember() throws JavaModelException {
- return getDeclaringType() != null;
-}
-/**
- * @see IType
- */
-//public ITypeHierarchy loadTypeHierachy(InputStream input, IProgressMonitor monitor) throws JavaModelException {
-// return TypeHierarchy.load(this, input);
-//}
-/**
- * @see IType
- */
-//public ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException {
-// return this.newSupertypeHierarchy(null, monitor);
-//}
-/**
- * @see IType#newSupertypeHierarchy(IWorkingCopy[], IProgressMonitor)
- */
-//public ITypeHierarchy newSupertypeHierarchy(
-// IWorkingCopy[] workingCopies,
-// IProgressMonitor monitor)
-// throws JavaModelException {
-//
-// CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), false);
-// runOperation(op, monitor);
-// return op.getResult();
-//}
+ /**
+ * @see IMember
+ */
+ public IType getDeclaringType() {
+ IJavaElement parent = getParent();
+ while (parent != null) {
+ if (parent.getElementType() == IJavaElement.TYPE) {
+ return (IType) parent;
+ } else if (parent instanceof IMember) {
+ parent = parent.getParent();
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
-/**
- * @see IType
- */
-//public ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException {
-// return this.newTypeHierarchy((IWorkingCopy[])null, monitor);
-//}
-/**
- * @see IType#newTypeHierarchy(IWorkingCopy[], IProgressMonitor)
- */
-//public ITypeHierarchy newTypeHierarchy(
-// IWorkingCopy[] workingCopies,
-// IProgressMonitor monitor)
-// throws JavaModelException {
-//
-// CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(), true);
-// runOperation(op, monitor);
-// return op.getResult();
-//}
+ /**
+ * @see IJavaElement
+ */
+ public int getElementType() {
+ return TYPE;
+ }
-/**
- * @see IType
- */
-//public ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException {
-// if (project == null) {
-// throw new IllegalArgumentException(Util.bind("hierarchy.nullProject")); //$NON-NLS-1$
-// }
-//
-// CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(
-// this,
-// (IWorkingCopy[])null, // no working copies
-// project,
-// true);
-// runOperation(op, monitor);
-// return op.getResult();
-//}
-/**
- * See ISourceType.resolveType(...)
- */
+ /**
+ * @see IType#getField
+ */
+ public IField getField(String name) {
+ return new SourceField(this, name);
+ }
-// public String[][] resolveType(String typeName) throws JavaModelException {
-// ISourceType info = (ISourceType) this.getElementInfo();
-// ISearchableNameEnvironment environment = ((JavaProject)getJavaProject()).getSearchableNameEnvironment();
-//
-// class TypeResolveRequestor implements ISelectionRequestor {
-// String[][] answers = null;
-// void acceptType(String[] answer){
-// if (answers == null) {
-// answers = new String[][]{ answer };
-// } else {
-// // grow
-// int length = answers.length;
-// System.arraycopy(answers, 0, answers = new String[length+1][], 0, length);
-// answers[length] = answer;
-// }
-// }
-// public void acceptClass(char[] packageName, char[] className, boolean needQualification) {
-// acceptType(new String[] { new String(packageName), new String(className) });
-// }
-//
-// public void acceptInterface(char[] packageName, char[] interfaceName, boolean needQualification) {
-// acceptType(new String[] { new String(packageName), new String(interfaceName) });
-// }
-//
-// public void acceptError(IProblem error) {}
-// public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name) {}
-// public void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, char[][] parameterPackageNames, char[][] parameterTypeNames, boolean isConstructor) {}
-// public void acceptPackage(char[] packageName){}
-//
-// }
-// TypeResolveRequestor requestor = new TypeResolveRequestor();
-// SelectionEngine engine =
-// new SelectionEngine(environment, requestor, this.getJavaProject().getOptions(true));
-//
-// IType[] topLevelTypes = this.getCompilationUnit().getTypes();
-// int length = topLevelTypes.length;
-// ISourceType[] topLevelInfos = new ISourceType[length];
-// for (int i = 0; i < length; i++) {
-// topLevelInfos[i] = (ISourceType)((SourceType)topLevelTypes[i]).getElementInfo();
-// }
-//
-// engine.selectType(info, typeName.toCharArray(), topLevelInfos, false);
-// return requestor.answers;
-//}
-/**
- * @private Debugging purposes
- */
-protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
- buffer.append(this.tabString(tab));
- if (info == null) {
- buffer.append(this.getElementName());
- buffer.append(" (not open)"); //$NON-NLS-1$
- } else if (info == NO_INFO) {
- buffer.append(getElementName());
- } else {
- try {
- if (this.isInterface()) {
- buffer.append("interface "); //$NON-NLS-1$
- } else {
- buffer.append("class "); //$NON-NLS-1$
- }
- buffer.append(this.getElementName());
- } catch (JavaModelException e) {
- buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
- }
- }
-}
-}
+ /**
+ * @see IType
+ */
+ public IField[] getFields() throws JavaModelException {
+ ArrayList list = getChildrenOfType(FIELD);
+ IField[] array = new IField[list.size()];
+ list.toArray(array);
+ return array;
+ }
+
+ /**
+ * @see IType#getFullyQualifiedName
+ */
+ public String getFullyQualifiedName() {
+ return this.getFullyQualifiedName('$');
+ }
+
+ /**
+ * @see IType#getFullyQualifiedName(char)
+ */
+ public String getFullyQualifiedName(char enclosingTypeSeparator) {
+ String packageName = getPackageFragment().getElementName();
+ if (packageName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
+ return getTypeQualifiedName(enclosingTypeSeparator);
+ }
+ return packageName + '.' + getTypeQualifiedName(enclosingTypeSeparator);
+ }
+
+ /**
+ * @see IType
+ */
+ //public IInitializer getInitializer(int occurrenceCount) {
+ // return new Initializer(this, occurrenceCount);
+ //}
+ /**
+ * @see IType
+ */
+ //public IInitializer[] getInitializers() throws JavaModelException {
+ // ArrayList list = getChildrenOfType(INITIALIZER);
+ // IInitializer[] array= new IInitializer[list.size()];
+ // list.toArray(array);
+ // return array;
+ //}
+ /**
+ * @see IType#getMethod
+ */
+ public IMethod getMethod(String name, String[] parameterTypeSignatures) {
+ return new SourceMethod(this, name, parameterTypeSignatures);
+ }
+
+ /**
+ * @see IType
+ */
+ public IMethod[] getMethods() throws JavaModelException {
+ ArrayList list = getChildrenOfType(METHOD);
+ IMethod[] array = new IMethod[list.size()];
+ list.toArray(array);
+ return array;
+ }
+
+ /**
+ * @see IType
+ */
+ public IPackageFragment getPackageFragment() {
+ IJavaElement parentElement = this.parent;
+ while (parentElement != null) {
+ if (parentElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
+ return (IPackageFragment) parentElement;
+ } else {
+ parentElement = parentElement.getParent();
+ }
+ }
+ Assert.isTrue(false); // should not happen
+ return null;
+ }
+
+ /**
+ * @see IType
+ */
+ public String getSuperclassName() throws JavaModelException {
+ SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
+ char[] superclassName = info.getSuperclassName();
+ if (superclassName == null) {
+ return null;
+ }
+ return new String(superclassName);
+ }
+
+ /**
+ * @see IType
+ */
+ public String[] getSuperInterfaceNames() throws JavaModelException {
+ SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
+ char[][] names = info.getInterfaceNames();
+ if (names == null) {
+ return fgEmptyList;
+ }
+ String[] strings = new String[names.length];
+ for (int i = 0; i < names.length; i++) {
+ strings[i] = new String(names[i]);
+ }
+ return strings;
+ }
+
+ /**
+ * @see IType
+ */
+ public IType getType(String name) {
+ return new SourceType(this, name);
+ }
+
+ /**
+ * @see IType#getTypeQualifiedName
+ */
+ public String getTypeQualifiedName() {
+ return this.getTypeQualifiedName('$');
+ }
+
+ /**
+ * @see IType#getTypeQualifiedName(char)
+ */
+ public String getTypeQualifiedName(char enclosingTypeSeparator) {
+ if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
+ return name;
+ } else {
+ return ((IType) parent).getTypeQualifiedName(enclosingTypeSeparator) + enclosingTypeSeparator + name;
+ }
+ }
+
+ /**
+ * @see IType
+ */
+ public IType[] getTypes() throws JavaModelException {
+ ArrayList list = getChildrenOfType(TYPE);
+ IType[] array = new IType[list.size()];
+ list.toArray(array);
+ return array;
+ }
+
+ /**
+ * @see IParent
+ */
+ public boolean hasChildren() throws JavaModelException {
+ return getChildren().length > 0;
+ }
+
+ /**
+ * @see IType#isAnonymous()
+ */
+ public boolean isAnonymous() throws JavaModelException {
+ return false; // cannot create source handle onto anonymous types
+ }
+
+ /**
+ * @see IType
+ */
+ public boolean isClass() throws JavaModelException {
+ return !isInterface();
+ }
+
+ /**
+ * @see IType
+ */
+ public boolean isInterface() throws JavaModelException {
+ Object obj = getElementInfo();
+ if (obj instanceof SourceTypeElementInfo) {
+ SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
+ return info.isInterface();
+ }
+ return false;
+ }
+
+ /**
+ * @see IType#isLocal()
+ */
+ public boolean isLocal() throws JavaModelException {
+ return false; // cannot create source handle onto local types
+ }
+
+ /**
+ * @see IType#isMember()
+ */
+ public boolean isMember() throws JavaModelException {
+ return getDeclaringType() != null;
+ }
+
+ /**
+ * @see IType
+ */
+ //public ITypeHierarchy loadTypeHierachy(InputStream input, IProgressMonitor monitor) throws JavaModelException {
+ // return TypeHierarchy.load(this, input);
+ //}
+ /**
+ * @see IType
+ */
+ //public ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException {
+ // return this.newSupertypeHierarchy(null, monitor);
+ //}
+ /**
+ * @see IType#newSupertypeHierarchy(IWorkingCopy[], IProgressMonitor)
+ */
+ //public ITypeHierarchy newSupertypeHierarchy(
+ // IWorkingCopy[] workingCopies,
+ // IProgressMonitor monitor)
+ // throws JavaModelException {
+ //
+ // CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(),
+ // false);
+ // runOperation(op, monitor);
+ // return op.getResult();
+ //}
+ /**
+ * @see IType
+ */
+ //public ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException {
+ // return this.newTypeHierarchy((IWorkingCopy[])null, monitor);
+ //}
+ /**
+ * @see IType#newTypeHierarchy(IWorkingCopy[], IProgressMonitor)
+ */
+ //public ITypeHierarchy newTypeHierarchy(
+ // IWorkingCopy[] workingCopies,
+ // IProgressMonitor monitor)
+ // throws JavaModelException {
+ //
+ // CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, workingCopies, SearchEngine.createWorkspaceScope(),
+ // true);
+ // runOperation(op, monitor);
+ // return op.getResult();
+ //}
+ /**
+ * @see IType
+ */
+ //public ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException {
+ // if (project == null) {
+ // throw new IllegalArgumentException(Util.bind("hierarchy.nullProject")); //$NON-NLS-1$
+ // }
+ //
+ // CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(
+ // this,
+ // (IWorkingCopy[])null, // no working copies
+ // project,
+ // true);
+ // runOperation(op, monitor);
+ // return op.getResult();
+ //}
+ /**
+ * See ISourceType.resolveType(...)
+ */
+
+ // public String[][] resolveType(String typeName) throws JavaModelException {
+ // ISourceType info = (ISourceType) this.getElementInfo();
+ // ISearchableNameEnvironment environment = ((JavaProject)getJavaProject()).getSearchableNameEnvironment();
+ //
+ // class TypeResolveRequestor implements ISelectionRequestor {
+ // String[][] answers = null;
+ // void acceptType(String[] answer){
+ // if (answers == null) {
+ // answers = new String[][]{ answer };
+ // } else {
+ // // grow
+ // int length = answers.length;
+ // System.arraycopy(answers, 0, answers = new String[length+1][], 0, length);
+ // answers[length] = answer;
+ // }
+ // }
+ // public void acceptClass(char[] packageName, char[] className, boolean needQualification) {
+ // acceptType(new String[] { new String(packageName), new String(className) });
+ // }
+ //
+ // public void acceptInterface(char[] packageName, char[] interfaceName, boolean needQualification) {
+ // acceptType(new String[] { new String(packageName), new String(interfaceName) });
+ // }
+ //
+ // public void acceptError(IProblem error) {}
+ // public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name) {}
+ // public void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, char[][]
+ // parameterPackageNames, char[][] parameterTypeNames, boolean isConstructor) {}
+ // public void acceptPackage(char[] packageName){}
+ //
+ // }
+ // TypeResolveRequestor requestor = new TypeResolveRequestor();
+ // SelectionEngine engine =
+ // new SelectionEngine(environment, requestor, this.getJavaProject().getOptions(true));
+ //
+ // IType[] topLevelTypes = this.getCompilationUnit().getTypes();
+ // int length = topLevelTypes.length;
+ // ISourceType[] topLevelInfos = new ISourceType[length];
+ // for (int i = 0; i < length; i++) {
+ // topLevelInfos[i] = (ISourceType)((SourceType)topLevelTypes[i]).getElementInfo();
+ // }
+ //
+ // engine.selectType(info, typeName.toCharArray(), topLevelInfos, false);
+ // return requestor.answers;
+ //}
+ /**
+ * @private Debugging purposes
+ */
+ protected void toStringInfo(int tab, StringBuffer buffer, Object info) {
+ buffer.append(this.tabString(tab));
+ if (info == null) {
+ buffer.append(this.getElementName());
+ buffer.append(" (not open)"); //$NON-NLS-1$
+ } else if (info == NO_INFO) {
+ buffer.append(getElementName());
+ } else {
+ try {
+ if (this.isInterface()) {
+ buffer.append("interface "); //$NON-NLS-1$
+ } else {
+ buffer.append("class "); //$NON-NLS-1$
+ }
+ buffer.append(this.getElementName());
+ } catch (JavaModelException e) {
+ buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
+ }
+ }
+ }
+}
\ No newline at end of file
IBM Corporation - Initial implementation
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ISynchronizable;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextInputListener;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.ui.editors.text.IEncodingSupport;
import org.eclipse.ui.part.IShowInTargetList;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
+import org.eclipse.ui.texteditor.AnnotationPreference;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
-import org.eclipse.ui.texteditor.DefaultRangeIndicator;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
protected String fOutlinerContextMenuId;
/**
- * The editor selection changed listener.
- *
- * @since 3.0
- */
- // private EditorSelectionChangedListener fEditorSelectionChangedListener;
- /**
* Indicates whether this editor should react on outline page selection changes
*/
private int fIgnoreOutlinePageSelection;
/** The mouse listener */
private MouseClickListener fMouseListener;
+ /**
+ * Indicates whether this editor is about to update any annotation views.
+ *
+ * @since 3.0
+ */
+ private boolean fIsUpdatingAnnotationViews = false;
+
+ /**
+ * The marker that served as last target for a goto marker request.
+ *
+ * @since 3.0
+ */
+ private IMarker fLastMarkerTarget = null;
+
protected CompositeActionGroup fActionGroups;
protected CompositeActionGroup fContextMenuGroup;
* @since 3.0
*/
private IJavaFoldingStructureProvider fProjectionModelUpdater;
+
/**
- * The override and implements indicator manager for this editor.
- * @since 3.0
- */
-// protected OverrideIndicatorManager fOverrideIndicatorManager;
+ * The override and implements indicator manager for this editor.
+ *
+ * @since 3.0
+ */
+ // protected OverrideIndicatorManager fOverrideIndicatorManager;
/**
* The action group for folding.
*
*/
protected void initializeEditor() {
//jsurfer old code
-// JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
-// setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //, IJavaPartitions.JAVA_PARTITIONING));
- IPreferenceStore store= createCombinedPreferenceStore(null);
- setPreferenceStore(store);
- JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
- setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this, IPHPPartitions.PHP_PARTITIONING));
+ // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+ // setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //,
+ // IJavaPartitions.JAVA_PARTITIONING));
+ IPreferenceStore store = createCombinedPreferenceStore(null);
+ setPreferenceStore(store);
+ JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+ setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
+ IPHPPartitions.PHP_PARTITIONING));
// TODO changed in 3.x ?
-// setRangeIndicator(new DefaultRangeIndicator());
-// if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
-// fUpdater = new OutlinePageSelectionUpdater();
+ // setRangeIndicator(new DefaultRangeIndicator());
+ // if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
+ // fUpdater = new OutlinePageSelectionUpdater();
// jsurfer end
// IPreferenceStore store= createCombinedPreferenceStore(null);
}
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
-
- support.setCharacterPairMatcher(fBracketMatcher);
- support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
-
- super.configureSourceViewerDecorationSupport(support);
+
+ support.setCharacterPairMatcher(fBracketMatcher);
+ support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
+
+ super.configureSourceViewerDecorationSupport(support);
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
+ */
+ public void gotoMarker(IMarker marker) {
+ fLastMarkerTarget = marker;
+ if (!fIsUpdatingAnnotationViews) {
+ super.gotoMarker(marker);
+ }
+ }
+
+ /**
+ * Jumps to the next enabled annotation according to the given direction. An annotation type is enabled if it is configured to be
+ * in the Next/Previous tool bar drop down menu and if it is checked.
+ *
+ * @param forward
+ * <code>true</code> if search direction is forward, <code>false</code> if backward
+ */
+ public void gotoAnnotation(boolean forward) {
+ ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
+ Position position = new Position(0, 0);
+ if (false /* delayed - see bug 18316 */) {
+ getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
+ selectAndReveal(position.getOffset(), position.getLength());
+ } else /* no delay - see bug 18316 */{
+ Annotation annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
+ setStatusLineErrorMessage(null);
+ setStatusLineMessage(null);
+ if (annotation != null) {
+ updateAnnotationViews(annotation);
+ selectAndReveal(position.getOffset(), position.getLength());
+ setStatusLineMessage(annotation.getText());
+ }
+ }
+ }
+
+ /**
+ * Returns the lock object for the given annotation model.
+ *
+ * @param annotationModel
+ * the annotation model
+ * @return the annotation model's lock object
+ * @since 3.0
+ */
+ private Object getLockObject(IAnnotationModel annotationModel) {
+ if (annotationModel instanceof ISynchronizable)
+ return ((ISynchronizable) annotationModel).getLockObject();
+ else
+ return annotationModel;
+ }
+
+ /**
+ * Updates the annotation views that show the given annotation.
+ *
+ * @param annotation
+ * the annotation
+ */
+ private void updateAnnotationViews(Annotation annotation) {
+ IMarker marker = null;
+ if (annotation instanceof MarkerAnnotation)
+ marker = ((MarkerAnnotation) annotation).getMarker();
+ else if (annotation instanceof IJavaAnnotation) {
+ Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
+ if (e != null) {
+ while (e.hasNext()) {
+ Object o = e.next();
+ if (o instanceof MarkerAnnotation) {
+ marker = ((MarkerAnnotation) o).getMarker();
+ break;
+ }
+ }
+ }
+ }
+
+ if (marker != null && !marker.equals(fLastMarkerTarget)) {
+ try {
+ boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
+ IWorkbenchPage page = getSite().getPage();
+ IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$ //$NON-NLS-2$
+ if (view != null) {
+ Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
+ method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE });
+ }
+ } catch (CoreException x) {
+ } catch (NoSuchMethodException x) {
+ } catch (IllegalAccessException x) {
+ } catch (InvocationTargetException x) {
+ }
+ // ignore exceptions, don't update any of the lists, just set status line
+ }
}
-
+
/**
* Returns this document's complete text.
*
super.doSetInput(input);
if (getSourceViewer() instanceof JavaSourceViewer) {
- JavaSourceViewer viewer= (JavaSourceViewer)getSourceViewer();
- if (viewer.getReconciler() == null) {
- IReconciler reconciler= getSourceViewerConfiguration().getReconciler(viewer);
- if (reconciler != null) {
- reconciler.install(viewer);
- viewer.setReconciler(reconciler);
- }
- }
- }
-
+ JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
+ if (viewer.getReconciler() == null) {
+ IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer);
+ if (reconciler != null) {
+ reconciler.install(viewer);
+ viewer.setReconciler(reconciler);
+ }
+ }
+ }
+
if (fEncodingSupport != null)
fEncodingSupport.reset();
if (fProjectionModelUpdater != null)
fProjectionModelUpdater.initialize();
-// if (isShowingOverrideIndicators())
-// installOverrideIndicator(false);
+// if (isShowingOverrideIndicators())
+// installOverrideIndicator(false);
}
/*
}
if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
- if ((event.getNewValue() instanceof Boolean) && ((Boolean)event.getNewValue()).booleanValue())
- selectionChanged();
- return;
- }
+ if ((event.getNewValue() instanceof Boolean) && ((Boolean) event.getNewValue()).booleanValue())
+ selectionChanged();
+ return;
+ }
if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
if (event.getNewValue() instanceof Boolean) {
// }
// }
// }
-
- ((PHPSourceViewerConfiguration)getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
-
-// if (affectsOverrideIndicatorAnnotations(event)) {
-// if (isShowingOverrideIndicators()) {
-// if (fOverrideIndicatorManager == null)
-// installOverrideIndicator(true);
-// } else {
-// if (fOverrideIndicatorManager != null)
-// uninstallOverrideIndicator();
-// }
-// return;
-// }
-
+
+ ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
+
+ // if (affectsOverrideIndicatorAnnotations(event)) {
+ // if (isShowingOverrideIndicators()) {
+ // if (fOverrideIndicatorManager == null)
+ // installOverrideIndicator(true);
+ // } else {
+ // if (fOverrideIndicatorManager != null)
+ // uninstallOverrideIndicator();
+ // }
+ // return;
+ // }
+
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
if (sourceViewer instanceof ProjectionViewer) {
ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
// ruler.addDecorator(1, createLineNumberRulerColumn());
// return ruler;
// }
-// private static IRegion getSignedSelection(ITextViewer viewer) {
-//
-// StyledText text = viewer.getTextWidget();
-// int caretOffset = text.getCaretOffset();
-// Point selection = text.getSelection();
-//
-// // caret left
-// int offset, length;
-// if (caretOffset == selection.x) {
-// offset = selection.y;
-// length = selection.x - selection.y;
-//
-// // caret right
-// } else {
-// offset = selection.x;
-// length = selection.y - selection.x;
-// }
-//
-// return new Region(offset, length);
-// }
- protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
- StyledText text= sourceViewer.getTextWidget();
- Point selection= text.getSelectionRange();
-
- if (text.getCaretOffset() == selection.x) {
- selection.x= selection.x + selection.y;
- selection.y= -selection.y;
- }
-
- selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x);
-
- return new Region(selection.x, selection.y);
- }
+ // private static IRegion getSignedSelection(ITextViewer viewer) {
+ //
+ // StyledText text = viewer.getTextWidget();
+ // int caretOffset = text.getCaretOffset();
+ // Point selection = text.getSelection();
+ //
+ // // caret left
+ // int offset, length;
+ // if (caretOffset == selection.x) {
+ // offset = selection.y;
+ // length = selection.x - selection.y;
+ //
+ // // caret right
+ // } else {
+ // offset = selection.x;
+ // length = selection.y - selection.x;
+ // }
+ //
+ // return new Region(offset, length);
+ // }
+ protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
+ StyledText text = sourceViewer.getTextWidget();
+ Point selection = text.getSelectionRange();
+
+ if (text.getCaretOffset() == selection.x) {
+ selection.x = selection.x + selection.y;
+ selection.y = -selection.y;
+ }
+
+ selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
+
+ return new Region(selection.x, selection.y);
+ }
+
/** Preference key for matching brackets */
protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
/** Preference key for highlighting current line */
-// protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
-
+ // protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
/** Preference key for highlight color of current line */
-// protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
-
+ // protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
/** Preference key for showing print marging ruler */
-// protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
-
+ // protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
/** Preference key for print margin ruler color */
-// protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
-
+ // protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
/** Preference key for print margin ruler column */
-// protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
-
+ // protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
/** Preference key for error indication */
// protected final static String ERROR_INDICATION =
// PreferenceConstants.EDITOR_PROBLEM_INDICATION;
*/
abstract protected IJavaElement getInputJavaElement();
+ protected void updateStatusLine() {
+ ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
+ Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
+ setStatusLineErrorMessage(null);
+ setStatusLineMessage(null);
+ if (annotation != null) {
+ try {
+ fIsUpdatingAnnotationViews = true;
+ updateAnnotationViews(annotation);
+ } finally {
+ fIsUpdatingAnnotationViews = false;
+ }
+ if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem())
+ setStatusLineMessage(annotation.getText());
+ }
+ }
+
/**
* Jumps to the matching bracket.
*/
}
/**
+ * Sets the given message as message to this editor's status line.
+ *
+ * @param msg
+ * message to be set
+ * @since 3.0
+ */
+ protected void setStatusLineMessage(String msg) {
+ IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
+ if (statusLine != null)
+ statusLine.setMessage(false, msg, null);
+ }
+
+ /**
+ * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the annotations
+ * current position is copied into the provided annotation position.
+ *
+ * @param offset
+ * the region offset
+ * @param length
+ * the region length
+ * @param forward
+ * <code>true</code> for forwards, <code>false</code> for backward
+ * @param annotationPosition
+ * the position of the found annotation
+ * @return the found annotation
+ */
+ private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
+
+ Annotation nextAnnotation = null;
+ Position nextAnnotationPosition = null;
+ Annotation containingAnnotation = null;
+ Position containingAnnotationPosition = null;
+ boolean currentAnnotation = false;
+
+ IDocument document = getDocumentProvider().getDocument(getEditorInput());
+ int endOfDocument = document.getLength();
+ int distance = Integer.MAX_VALUE;
+
+ IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
+ Iterator e = new JavaAnnotationIterator(model, true, true);
+ while (e.hasNext()) {
+ Annotation a = (Annotation) e.next();
+ if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a))
+ continue;
+
+ Position p = model.getPosition(a);
+ if (p == null)
+ continue;
+
+ if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) {
+ if (containingAnnotation == null
+ || (forward && p.length >= containingAnnotationPosition.length || !forward
+ && p.length >= containingAnnotationPosition.length)) {
+ containingAnnotation = a;
+ containingAnnotationPosition = p;
+ currentAnnotation = p.length == length;
+ }
+ } else {
+ int currentDistance = 0;
+
+ if (forward) {
+ currentDistance = p.getOffset() - offset;
+ if (currentDistance < 0)
+ currentDistance = endOfDocument + currentDistance;
+
+ if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
+ distance = currentDistance;
+ nextAnnotation = a;
+ nextAnnotationPosition = p;
+ }
+ } else {
+ currentDistance = offset + length - (p.getOffset() + p.length);
+ if (currentDistance < 0)
+ currentDistance = endOfDocument + currentDistance;
+
+ if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
+ distance = currentDistance;
+ nextAnnotation = a;
+ nextAnnotationPosition = p;
+ }
+ }
+ }
+ }
+ if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
+ annotationPosition.setOffset(containingAnnotationPosition.getOffset());
+ annotationPosition.setLength(containingAnnotationPosition.getLength());
+ return containingAnnotation;
+ }
+ if (nextAnnotationPosition != null) {
+ annotationPosition.setOffset(nextAnnotationPosition.getOffset());
+ annotationPosition.setLength(nextAnnotationPosition.getLength());
+ }
+
+ return nextAnnotation;
+ }
+
+ /**
+ * Returns the annotation overlapping with the given range or <code>null</code>.
+ *
+ * @param offset
+ * the region offset
+ * @param length
+ * the region length
+ * @return the found annotation or <code>null</code>
+ * @since 3.0
+ */
+ private Annotation getAnnotation(int offset, int length) {
+ IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
+ Iterator e = new JavaAnnotationIterator(model, true, true);
+ while (e.hasNext()) {
+ Annotation a = (Annotation) e.next();
+ if (!isNavigationTarget(a))
+ continue;
+
+ Position p = model.getPosition(a);
+ if (p != null && p.overlapsWith(offset, length))
+ return a;
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns whether the given annotation is configured as a target for the "Go to Next/Previous Annotation" actions
+ *
+ * @param annotation
+ * the annotation
+ * @return <code>true</code> if this is a target, <code>false</code> otherwise
+ * @since 3.0
+ */
+ private boolean isNavigationTarget(Annotation annotation) {
+ Preferences preferences = EditorsUI.getPluginPreferences();
+ AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
+ // See bug 41689
+ // String key= forward ? preference.getIsGoToNextNavigationTargetKey() : preference.getIsGoToPreviousNavigationTargetKey();
+ String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey();
+ return (key != null && preferences.getBoolean(key));
+ }
+
+ /**
* Returns a segmentation of the line of the given document appropriate for bidi rendering. The default implementation returns
* only the string literals of a php code line as segments.
*
return viewer;
}
+
/*
- * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
- */
- protected boolean affectsTextPresentation(PropertyChangeEvent event) {
- return ((PHPSourceViewerConfiguration)getSourceViewerConfiguration()).affectsTextPresentation(event) || super.affectsTextPresentation(event);
- }
-//
-// protected boolean affectsTextPresentation(PropertyChangeEvent event) {
-// JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
-// return textTools.affectsBehavior(event);
-// }
+ * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
+ */
+ protected boolean affectsTextPresentation(PropertyChangeEvent event) {
+ return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)
+ || super.affectsTextPresentation(event);
+ }
+
+ //
+ // protected boolean affectsTextPresentation(PropertyChangeEvent event) {
+ // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+ // return textTools.affectsBehavior(event);
+ // }
/**
* Creates and returns the preference store for this Java editor with the given input.
*
}
}
- // protected void uninstallOverrideIndicator() {
- // if (fOverrideIndicatorManager != null) {
- // fOverrideIndicatorManager.removeAnnotations();
- // fOverrideIndicatorManager= null;
- // }
- //}
+ protected void uninstallOverrideIndicator() {
+// if (fOverrideIndicatorManager != null) {
+// fOverrideIndicatorManager.removeAnnotations();
+// fOverrideIndicatorManager= null;
+// }
+ }
protected void installOverrideIndicator(boolean waitForReconcilation) {
- // uninstallOverrideIndicator();
- IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
- // IJavaElement inputElement= getInputJavaElement();
+ uninstallOverrideIndicator();
+ IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput());
+ final IJavaElement inputElement= getInputJavaElement();
- // if (model == null || inputElement == null)
- // return;
+ if (model == null || inputElement == null)
+ return;
- // CompilationUnit ast=
- // PHPeclipsePlugin.getDefault().getASTProvider().getAST(inputElement,
- // true, null);
- // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
- // inputElement, ast);
+// fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null);
+//
+// if (provideAST) {
+// Job job= new Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) { //$NON-NLS-1$
+// /*
+// * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+// * @since 3.0
+// */
+// protected IStatus run(IProgressMonitor monitor) {
+// CompilationUnit ast= JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true, null);
+// if (fOverrideIndicatorManager != null) // editor might have been closed in the meanwhile
+// fOverrideIndicatorManager.reconciled(ast, true, monitor);
+// return Status.OK_STATUS;
+// }
+// };
+// job.setPriority(Job.DECORATE);
+// job.setSystem(true);
+// job.schedule();
+// }
}
- /**
+ /**
* Tells whether override indicators are shown.
*
* @return <code>true</code> if the override indicators are shown
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
synchronizeOutlinePage(element);
setSelection(element, false);
- // updateStatusLine();
+ updateStatusLine();
}
private boolean isJavaOutlinePageActive() {