diff options
author | Jeff Johnston | 2018-07-17 15:05:23 +0000 |
---|---|---|
committer | Kalyan Prasad Tatavarthi | 2018-07-25 11:57:52 +0000 |
commit | 9c1dbd0eadb50f05609507382707df879c4b4630 (patch) | |
tree | 8ff72a23f8deda7e3941ef95fe56b6c6e46e4396 | |
parent | 8339650573161d2c730896aa809969d2a9499629 (diff) | |
download | eclipse.jdt.ui-9c1dbd0eadb50f05609507382707df879c4b4630.tar.gz eclipse.jdt.ui-9c1dbd0eadb50f05609507382707df879c4b4630.tar.xz eclipse.jdt.ui-9c1dbd0eadb50f05609507382707df879c4b4630.zip |
Bug 537088 - Refactor IProblemLocation and ProblemLocationI20180725-2000
- create new IProblemLocationCore class in jdt.core.manipulation
based on IProblemLocation
- create new ProblemLocationCore class in jdt.core.manipulation
that implements IProblemLocation
- have ProblemLocation in jdt.ui extend ProblemLocationCore and
as well implement IProblemLocation
Change-Id: Id1ce30ff5bf689d9be3c767a8bf062df294d19bf
Signed-off-by: Jeff Johnston <jjohnstn@redhat.com>
4 files changed, 243 insertions, 123 deletions
diff --git a/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF index 6370d569d7..670ef14e11 100644 --- a/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF @@ -33,6 +33,7 @@ Export-Package: org.eclipse.jdt.core.manipulation, org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui", org.eclipse.jdt.internal.corext.refactoring.util;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui", org.eclipse.jdt.internal.corext.template.java;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui", - org.eclipse.jdt.internal.corext.util;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui,org.eclipse.jdt.junit" + org.eclipse.jdt.internal.corext.util;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui,org.eclipse.jdt.junit", + org.eclipse.jdt.internal.ui.text.correction;x-friends:="org.eclipse.jdt.ui" Import-Package: com.ibm.icu.text Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/IProblemLocationCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/IProblemLocationCore.java new file mode 100644 index 0000000000..205fb184b6 --- /dev/null +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/IProblemLocationCore.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Red Hat Inc. - copy to jdt.core.manipulation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.text.correction; + +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.CompilationUnit; + + +/** + * Problem information for quick fix and quick assist processors. + * <p> + * Note: this interface is not intended to be implemented. + * </p> + * + * @since 3.0 + * + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + */ +public interface IProblemLocationCore { + + /** + * Returns the start offset of the problem. + * + * @return the start offset of the problem + */ + int getOffset(); + + /** + * Returns the length of the problem. + * + * @return the length of the problem + */ + int getLength(); + + /** + * Returns the marker type of this problem. + * + * @return The marker type of the problem. + * @since 3.2 + */ + String getMarkerType(); + + /** + * Returns the id of problem. Note that problem ids are defined per problem marker type. + * See {@link org.eclipse.jdt.core.compiler.IProblem} for id definitions for problems of type + * <code>org.eclipse.jdt.core.problem</code> and <code>org.eclipse.jdt.core.task</code>. + * + * @return The id of the problem. + */ + int getProblemId(); + + /** + * Returns the original arguments recorded into the problem. + * + * @return String[] Returns the problem arguments. + */ + String[] getProblemArguments(); + + /** + * Returns if the problem has error severity. + * + * @return <code>true</code> if the problem has error severity + */ + boolean isError(); + + /** + * Convenience method to evaluate the AST node covering this problem. + * + * @param astRoot The root node of the current AST + * @return Returns the node that covers the location of the problem + */ + ASTNode getCoveringNode(CompilationUnit astRoot); + + /** + * Convenience method to evaluate the AST node covered by this problem. + * + * @param astRoot The root node of the current AST + * @return Returns the node that is covered by the location of the problem + */ + ASTNode getCoveredNode(CompilationUnit astRoot); + +} diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java new file mode 100644 index 0000000000..97d98ca4a3 --- /dev/null +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Red Hat Inc. - copied and modified in jdt.core.manipulation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.text.correction; + +import org.eclipse.jdt.core.IJavaModelMarker; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.NodeFinder; + +/** + * + */ +public class ProblemLocationCore implements IProblemLocationCore { + + private final int fId; + private final String[] fArguments; + private final int fOffset; + private final int fLength; + private final boolean fIsError; + private final String fMarkerType; + + public ProblemLocationCore(int offset, int length, int id, String[] arguments, boolean isError, String markerType) { + fId= id; + fArguments= arguments; + fOffset= offset; + fLength= length; + fIsError= isError; + fMarkerType= markerType; + } + + public ProblemLocationCore(IProblem problem) { + fId= problem.getID(); + fArguments= problem.getArguments(); + fOffset= problem.getSourceStart(); + fLength= problem.getSourceEnd() - fOffset + 1; + fIsError= problem.isError(); + fMarkerType= problem instanceof CategorizedProblem ? ((CategorizedProblem) problem).getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; + } + + + @Override + public int getProblemId() { + return fId; + } + + @Override + public String[] getProblemArguments() { + return fArguments; + } + + @Override + public int getLength() { + return fLength; + } + + @Override + public int getOffset() { + return fOffset; + } + + @Override + public boolean isError() { + return fIsError; + } + + @Override + public String getMarkerType() { + return fMarkerType; + } + + @Override + public ASTNode getCoveringNode(CompilationUnit astRoot) { + NodeFinder finder= new NodeFinder(astRoot, fOffset, fLength); + return finder.getCoveringNode(); + } + + @Override + public ASTNode getCoveredNode(CompilationUnit astRoot) { + NodeFinder finder= new NodeFinder(astRoot, fOffset, fLength); + return finder.getCoveredNode(); + } + + @Override + public String toString() { + StringBuilder buf= new StringBuilder(); + buf.append("Id: ").append(getErrorCode(fId)).append('\n'); //$NON-NLS-1$ + buf.append('[').append(fOffset).append(", ").append(fLength).append(']').append('\n'); //$NON-NLS-1$ + String[] arg= fArguments; + for (int i= 0; i < arg.length; i++) { + buf.append(arg[i]); + buf.append('\n'); + } + return buf.toString(); + } + + private String getErrorCode(int code) { + StringBuilder buf= new StringBuilder(); + + if ((code & IProblem.TypeRelated) != 0) { + buf.append("TypeRelated + "); //$NON-NLS-1$ + } + if ((code & IProblem.FieldRelated) != 0) { + buf.append("FieldRelated + "); //$NON-NLS-1$ + } + if ((code & IProblem.ConstructorRelated) != 0) { + buf.append("ConstructorRelated + "); //$NON-NLS-1$ + } + if ((code & IProblem.MethodRelated) != 0) { + buf.append("MethodRelated + "); //$NON-NLS-1$ + } + if ((code & IProblem.ImportRelated) != 0) { + buf.append("ImportRelated + "); //$NON-NLS-1$ + } + if ((code & IProblem.Internal) != 0) { + buf.append("Internal + "); //$NON-NLS-1$ + } + if ((code & IProblem.Syntax) != 0) { + buf.append("Syntax + "); //$NON-NLS-1$ + } + if ((code & IProblem.Javadoc) != 0) { + buf.append("Javadoc + "); //$NON-NLS-1$ + } + buf.append(code & IProblem.IgnoreCategoriesMask); + + return buf.toString(); + } + + +} diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ProblemLocation.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ProblemLocation.java index 99520c058c..a1310e91be 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ProblemLocation.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ProblemLocation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,15 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Red Hat Inc. - modified to extend ProblemLocationCore *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.correction; import org.eclipse.jdt.core.IJavaModelMarker; -import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.ui.text.java.IProblemLocation; @@ -25,131 +22,21 @@ import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation; /** * */ -public class ProblemLocation implements IProblemLocation { - - private final int fId; - private final String[] fArguments; - private final int fOffset; - private final int fLength; - private final boolean fIsError; - private final String fMarkerType; +public class ProblemLocation extends ProblemLocationCore implements IProblemLocation { public ProblemLocation(int offset, int length, IJavaAnnotation annotation) { - fId= annotation.getId(); - String[] arguments= annotation.getArguments(); - fArguments= arguments != null ? arguments : new String[0]; - fOffset= offset; - fLength= length; - fIsError= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()); - - String markerType= annotation.getMarkerType(); - fMarkerType= markerType != null ? markerType : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; + super(offset, length, annotation.getId(), + annotation.getArguments() != null ? annotation.getArguments() : new String[0], + JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()), + annotation.getMarkerType() != null ? annotation.getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); } public ProblemLocation(int offset, int length, int id, String[] arguments, boolean isError, String markerType) { - fId= id; - fArguments= arguments; - fOffset= offset; - fLength= length; - fIsError= isError; - fMarkerType= markerType; + super(offset, length, id, arguments, isError, markerType); } public ProblemLocation(IProblem problem) { - fId= problem.getID(); - fArguments= problem.getArguments(); - fOffset= problem.getSourceStart(); - fLength= problem.getSourceEnd() - fOffset + 1; - fIsError= problem.isError(); - fMarkerType= problem instanceof CategorizedProblem ? ((CategorizedProblem) problem).getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; - } - - - @Override - public int getProblemId() { - return fId; - } - - @Override - public String[] getProblemArguments() { - return fArguments; - } - - @Override - public int getLength() { - return fLength; - } - - @Override - public int getOffset() { - return fOffset; - } - - @Override - public boolean isError() { - return fIsError; - } - - @Override - public String getMarkerType() { - return fMarkerType; - } - - @Override - public ASTNode getCoveringNode(CompilationUnit astRoot) { - NodeFinder finder= new NodeFinder(astRoot, fOffset, fLength); - return finder.getCoveringNode(); - } - - @Override - public ASTNode getCoveredNode(CompilationUnit astRoot) { - NodeFinder finder= new NodeFinder(astRoot, fOffset, fLength); - return finder.getCoveredNode(); - } - - @Override - public String toString() { - StringBuilder buf= new StringBuilder(); - buf.append("Id: ").append(getErrorCode(fId)).append('\n'); //$NON-NLS-1$ - buf.append('[').append(fOffset).append(", ").append(fLength).append(']').append('\n'); //$NON-NLS-1$ - String[] arg= fArguments; - for (int i= 0; i < arg.length; i++) { - buf.append(arg[i]); - buf.append('\n'); - } - return buf.toString(); - } - - private String getErrorCode(int code) { - StringBuilder buf= new StringBuilder(); - - if ((code & IProblem.TypeRelated) != 0) { - buf.append("TypeRelated + "); //$NON-NLS-1$ - } - if ((code & IProblem.FieldRelated) != 0) { - buf.append("FieldRelated + "); //$NON-NLS-1$ - } - if ((code & IProblem.ConstructorRelated) != 0) { - buf.append("ConstructorRelated + "); //$NON-NLS-1$ - } - if ((code & IProblem.MethodRelated) != 0) { - buf.append("MethodRelated + "); //$NON-NLS-1$ - } - if ((code & IProblem.ImportRelated) != 0) { - buf.append("ImportRelated + "); //$NON-NLS-1$ - } - if ((code & IProblem.Internal) != 0) { - buf.append("Internal + "); //$NON-NLS-1$ - } - if ((code & IProblem.Syntax) != 0) { - buf.append("Syntax + "); //$NON-NLS-1$ - } - if ((code & IProblem.Javadoc) != 0) { - buf.append("Javadoc + "); //$NON-NLS-1$ - } - buf.append(code & IProblem.IgnoreCategoriesMask); - - return buf.toString(); + super(problem); } |