| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2008, 2009 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.pde.api.tools.internal.builder; |
| 12 | |
| 13 | import org.eclipse.core.runtime.CoreException; |
| 14 | import org.eclipse.jdt.core.IType; |
| 15 | import org.eclipse.jface.text.BadLocationException; |
| 16 | import org.eclipse.jface.text.IDocument; |
| 17 | import org.eclipse.jface.text.Position; |
| 18 | import org.eclipse.pde.api.tools.internal.provisional.builder.IReference; |
| 19 | import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; |
| 20 | import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblemTypes; |
| 21 | |
| 22 | /** |
| 23 | * Detects when a type illegally extends another type. |
| 24 | * |
| 25 | * @since 1.1 |
| 26 | */ |
| 27 | public class IllegalInstantiateProblemDetector extends AbstractIllegalTypeReference { |
| 28 | |
| 29 | |
| 30 | /* (non-Javadoc) |
| 31 | * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiProblemDetector#getReferenceKinds() |
| 32 | */ |
| 33 | public int getReferenceKinds() { |
| 34 | return IReference.REF_INSTANTIATE; |
| 35 | } |
| 36 | |
| 37 | /* (non-Javadoc) |
| 38 | * @see org.eclipse.pde.api.tools.internal.search.AbstractIllegalTypeReference#getSourceRange(org.eclipse.jdt.core.IType, org.eclipse.jface.text.IDocument, org.eclipse.pde.api.tools.internal.provisional.model.IReference) |
| 39 | */ |
| 40 | protected Position getSourceRange(IType type, IDocument document, IReference reference) throws CoreException, BadLocationException { |
| 41 | String name = getSimpleTypeName(reference.getResolvedReference()); |
| 42 | Position pos = getMethodNameRange(true, name, document, reference); |
| 43 | if(pos == null) { |
| 44 | return defaultSourcePosition(type, reference); |
| 45 | } |
| 46 | return pos; |
| 47 | } |
| 48 | |
| 49 | /* (non-Javadoc) |
| 50 | * @see org.eclipse.pde.api.tools.internal.search.AbstractIllegalTypeReference#getProblemKind() |
| 51 | */ |
| 52 | protected int getProblemKind() { |
| 53 | return IApiProblem.ILLEGAL_INSTANTIATE; |
| 54 | } |
| 55 | |
| 56 | /* (non-Javadoc) |
| 57 | * @see org.eclipse.pde.api.tools.internal.search.AbstractIllegalTypeReference#getSeverityKey() |
| 58 | */ |
| 59 | protected String getSeverityKey() { |
| 60 | return IApiProblemTypes.ILLEGAL_INSTANTIATE; |
| 61 | } |
| 62 | |
| 63 | } |