blob: e1e21565cd958c6b8b9c7687ceb462809e96b409 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* <copyright>
*
* Copyright (c) 2005-2006 Markus Voelter 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:
* Markus Voelter - Initial API and implementation
*
* </copyright>
*/
package org.eclipse.m2t.common.recipe.astChecks.checks;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.m2t.common.recipe.core.AtomicCheck;
import org.eclipse.m2t.common.recipe.core.EvaluationStop;
public class JavaClassIsAbstractCheckEvaluator extends EclipseResourceCheckEvaluator {
private IType foundType = null;
public void evaluate(AtomicCheck check) {
String projectName = check.getParameterString("projectName");
String className = check.getParameterString("className");
IWorkspace workspace = refreshWorkspace(check);
IProject project = workspace.getRoot().getProject(projectName);
if (project == null) {
check.fail("Project not found");
}
try {
IJavaProject javaProject = JavaCore.create(project);
IType type = javaProject.findType(className);
if (type != null) {
if ( type.isClass() ) {
if ( Flags.isAbstract(type.getFlags()) ) {
check.ok();
} else {
check.fail(check.getShortDescription());
}
} else {
check.fail("type "+type.getElementName()+" is not a class!");
}
check.ok();
} else {
check.fail(check.getShortDescription());
}
} catch (EvaluationStop stop) {
throw stop;
} catch (JavaModelException e) {
check.fail(e.getMessage());
}
}
public IType getFoundType() {
return foundType;
}
}
|