001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 BEA Systems, Inc.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * tyeung@bea.com - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.apt.core.internal.env;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.jdt.apt.core.internal.AptPlugin;
014: import org.eclipse.jdt.apt.core.internal.env.MessagerImpl.Severity;
015: import org.eclipse.jdt.apt.core.util.EclipseMessager;
016: import org.eclipse.jdt.core.compiler.CategorizedProblem;
017: import org.eclipse.jdt.core.compiler.IProblem;
018:
019: class APTProblem extends CategorizedProblem implements IProblem {
020: private static final String[] NO_ARGS = new String[0];
021: private final Severity _severity;
022: private int _startingOffset;
023: private int _endingOffset;
024: private int _line;
025: private IFile _resource;
026: private final String _message;
027:
028: // May be null
029: private final String[] _arguments;
030:
031: APTProblem(final String msg, final Severity severity,
032: final IFile file, final int startingOffset,
033: final int endingOffset, final int line,
034: final String[] arguments) {
035: _message = msg;
036: _severity = severity;
037: _startingOffset = startingOffset;
038: _endingOffset = endingOffset;
039: _line = line;
040: _resource = file;
041: _arguments = arguments;
042: }
043:
044: public int getID() {
045: // If we have arguments, then we're quick-fixable
046: if (_arguments != null) {
047: return EclipseMessager.APT_QUICK_FIX_PROBLEM_ID;
048: } else {
049: return EclipseMessager.APT_PROBLEM_ID;
050: }
051: }
052:
053: public String[] getArguments() {
054: return _arguments == null ? NO_ARGS : (String[]) _arguments
055: .clone();
056: }
057:
058: public String getMessage() {
059: return _message;
060: }
061:
062: public char[] getOriginatingFileName() {
063: return _resource.getName().toCharArray();
064: }
065:
066: public int getSourceStart() {
067: return _startingOffset;
068: }
069:
070: public int getSourceEnd() {
071: return _endingOffset;
072: }
073:
074: public int getSourceLineNumber() {
075: return _line;
076: }
077:
078: public void setSourceStart(int sourceStart) {
079: _startingOffset = sourceStart;
080: }
081:
082: public void setSourceEnd(int sourceEnd) {
083: _endingOffset = sourceEnd;
084: }
085:
086: public void setSourceLineNumber(int lineNumber) {
087: _line = lineNumber;
088: }
089:
090: public boolean isError() {
091: return _severity == Severity.ERROR;
092: }
093:
094: public boolean isWarning() {
095: return _severity == Severity.WARNING;
096: }
097:
098: public String toString() {
099: return _message == null ? "<null message>" : _message; //$NON-NLS-1$
100: }
101:
102: @Override
103: public int getCategoryID() {
104: // TODO Auto-generated method stub
105: return 0;
106: }
107:
108: @Override
109: public String getMarkerType() {
110: return AptPlugin.APT_COMPILATION_PROBLEM_MARKER;
111: }
112: }
|