本文整理汇总了Java中org.emftext.language.java.members.Method类的典型用法代码示例。如果您正苦于以下问题:Java Method类的具体用法?Java Method怎么用?Java Method使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Method类属于org.emftext.language.java.members包,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caseClass
import org.emftext.language.java.members.Method; //导入依赖的package包/类
@Override
public List<Reference> caseClass(Class classObject) {
ArrayList<Reference> references = Lists.newArrayList();
for (Member member : classObject.getMembers()) {
if (member instanceof Field || member instanceof Method || member instanceof Constructor) {
references.add(new Reference(classObject, member, ReferenceType.Declares));
}
references.addAll(parentSwitch.doSwitch(member));
}
TypeReference extendsReference = classObject.getExtends();
if (extendsReference != null) {
references.add(new Reference(classObject, extendsReference.getTarget(), ReferenceType.SuperType));
}
for (TypeReference implementsReference : classObject.getImplements()) {
references.add(new Reference(classObject, implementsReference.getTarget(), ReferenceType.SuperType));
}
references.add(new Reference(classObject));
return references;
}
示例2: caseMethod
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Reference collection for all type of methods (interface + class).
*
* Return types are referenced by the method. Parameters are not, as no nested dependencies
* are considered (e.g. changed method with changed parameter inside does not make sense on
* the granularity level currently inspected).
*
* {@inheritDoc}
*/
@Override
public List<Reference> caseMethod(Method method) {
ArrayList<Reference> references = Lists.newArrayList();
if (extendedMode) {
for (Parameter parameter : method.getParameters()) {
references.addAll(parentSwitch.doSwitch(parameter));
}
Type type = method.getTypeReference().getTarget();
references.add(new Reference(method, type, ReferenceType.Typed));
Import importDecl = JaMoPPElementUtil.checkForImport(method, type);
if (importDecl != null) {
references.add(new Reference(method, importDecl, ReferenceType.Import));
}
}
references.add(new Reference(method));
return references;
}
示例3: refactorFullyAutomated
import org.emftext.language.java.members.Method; //导入依赖的package包/类
@Override
protected List<Resource> refactorFullyAutomated(VariationPoint variationPoint, Map<String, Object> refactoringOptions) {
MemberContainer vpLocation = (MemberContainer) ((JaMoPPJavaSoftwareElement) variationPoint.getLocation())
.getJamoppElement();
for (Variant variant : variationPoint.getVariants()) {
if (variant.getLeading()) {
continue;
}
for (SoftwareElement se : variant.getImplementingElements()) {
Method currentMethod = (Method) ((JaMoPPJavaSoftwareElement) se).getJamoppElement();
if (!RefactoringUtil.hasMethodWithEqualNameAndParameters(vpLocation, currentMethod)) {
vpLocation.getMembers().add(clone(currentMethod));
}
}
}
return Lists.newArrayList(vpLocation.eResource());
}
示例4: canBeAppliedTo
import org.emftext.language.java.members.Method; //导入依赖的package包/类
@Override
public Diagnostic canBeAppliedTo(VariationPoint variationPoint) {
Commentable jamoppElement = ((JaMoPPJavaSoftwareElement) variationPoint.getLocation()).getJamoppElement();
boolean correctLocation = jamoppElement instanceof MemberContainer;
boolean allImplementingElementsAreMethods = RefactoringUtil.allImplementingElementsOfType(variationPoint,
Method.class);
boolean correctInput = correctLocation && allImplementingElementsAreMethods;
String error = "If with Static Configuration Class Method: ";
if (!correctInput) {
return new BasicDiagnostic(Diagnostic.ERROR, null, 0, error + "Wrong Input", null);
}
if (RefactoringUtil.hasConflictingMethods(variationPoint)) {
return new BasicDiagnostic(Diagnostic.ERROR, null, 0, error + "Has Conflicting Methods", null);
}
return new BasicDiagnostic(Diagnostic.OK, null, 0, "OK", null);
}
示例5: testDoDiff
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Test method to detect changes in the method declarations.
*
* @throws Exception
* Identifies a failed diffing.
*/
@Test
public void testDoDiff() throws Exception {
TestUtil.setUp();
File testFileA = new File(BASE_PATH + "a/ClassA.java");
File testFileB = new File(BASE_PATH + "b/ClassA.java");
ResourceSet rsA = TestUtil.loadResourceSet(Sets.newHashSet(testFileA));
ResourceSet rsB = TestUtil.loadResourceSet(Sets.newHashSet(testFileB));
JaMoPPDiffer differ = new JaMoPPDiffer();
Comparison comparison = differ.doDiff(rsA, rsB, TestUtil.getDiffOptions());
EList<Diff> differences = comparison.getDifferences();
assertThat("Wrong number of differences detected", differences.size(), is(1));
assertThat("Wrong change type", differences.get(0), instanceOf(MethodChange.class));
MethodChange methodChange = ((MethodChange) differences.get(0));
assertThat("Wrong DifferenceKind", methodChange.getKind(), is(DifferenceKind.ADD));
Method method = methodChange.getChangedMethod();
assertThat("Wrong method", method.getName(), is("newMethod"));
}
示例6: testRemoveCommentableSoftwareElementReferenceWithLeadingAndTrailingLineBreak
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Tests the removeCommentableSoftwareElementReference method for a reference with a leading and
* trailing line break.
*
* @throws Exception
* In case of an error during loading the test model.
*/
@Test
public void testRemoveCommentableSoftwareElementReferenceWithLeadingAndTrailingLineBreak() throws Exception {
CompilationUnit cu = loadTestCompilationUnit("commentableSoftwareElements");
Modifier m = cu.getClassifiers().get(0).getMethods().get(0).getModifiers().get(0);
CommentableSoftwareElement cse = softwareFactory.eINSTANCE.createCommentableSoftwareElement();
cse.setCompilationUnit(cu);
cse.setType(Method.class);
cse.setId("UNIQUE_ID_50");
String comment = getHiddenTokenText(m);
assertThat(
comment,
equalTo("\n \n /* SPLEVO_REF UNIQUE_ID_50 */\n /**\n * This method does nothing. \n */\n "));
RefactoringUtil.removeCommentableSoftwareElementReference(cse);
assertThat(getHiddenTokenText(m), equalTo("\n \n /**\n * This method does nothing. \n */\n "));
}
示例7: testRemoveCommentableSoftwareElementReferenceWithLeadingLineBreak
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Tests the removeCommentableSoftwareElementReference method for a reference with a leading
* line break.
*
* @throws Exception
* In case of an error during loading the test model.
*/
@Test
public void testRemoveCommentableSoftwareElementReferenceWithLeadingLineBreak() throws Exception {
CompilationUnit cu = loadTestCompilationUnit("commentableSoftwareElements");
Modifier m = cu.getClassifiers().get(0).getMethods().get(1).getModifiers().get(0);
CommentableSoftwareElement cse = softwareFactory.eINSTANCE.createCommentableSoftwareElement();
cse.setCompilationUnit(cu);
cse.setType(Method.class);
cse.setId("UNIQUE_ID_100");
String comment = getHiddenTokenText(m);
assertThat(comment, equalTo("\n \n /* SPLEVO_REF UNIQUE_ID_100 */"));
RefactoringUtil.removeCommentableSoftwareElementReference(cse);
assertThat(getHiddenTokenText(m), equalTo("\n \n "));
}
示例8: hasConflictingMethods
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Checks whether a variation point has methods with equal names but different return types.
*
* @param variationPoint
* The {@link VariationPoint}.
* @return <code>true</code> if conflicting elements are found; <code>false</code> otherwise.
*/
public static boolean hasConflictingMethods(VariationPoint variationPoint) {
List<Method> methods = new LinkedList<Method>();
for (Variant variant : variationPoint.getVariants()) {
methods.addAll(getImplementingElements(variant, Method.class));
}
TypeReference retType = null;
for (Method method : methods) {
if (retType == null) {
retType = method.getTypeReference();
continue;
}
if (!EcoreUtil.equals(method.getTypeReference(), retType)) {
return true;
}
}
return false;
}
示例9: testMultiLineMethodLocation
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Test that a method specified on more than one line is located as expected.
*
* @throws Exception
* An error during parsing or locating.
*/
@Test
public void testMultiLineMethodLocation() throws Exception {
Method method = exampleClass.getMethods().get(0);
JaMoPPSoftwareElement softwareElement = softwareFactory.eINSTANCE.createJaMoPPSoftwareElement();
softwareElement.setJamoppElement(method);
SourceLocation location = softwareElement.getSourceLocation();
assertThat("Wrong start line", location.getStartLine(), is(6));
assertThat("Wrong start position", location.getStartPosition(), is(61));
assertThat("Wrong end position", location.getEndPosition(), is(121));
}
示例10: testSetTypeForMethod
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Tests the automatic conversion during setting a type. Types that are derived from statements
* and are not member elements are converted to their base type (statement). A method is a
* statement and a member.
*/
@Test
public void testSetTypeForMethod() {
subject.setType(Method.class);
assertEquals(Method.class, subject.getType());
}
示例11: testResolveMethodReference
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* Tests the resolution of the referenced element by its ID can type.
*/
@Test
public void testResolveMethodReference() {
subject.setCompilationUnit(compilationUnit);
subject.setId("ID_Method");
subject.setType(Method.class);
EObject expected = compilationUnit.getClassifiers().get(0).getMethods().get(1);
EObject actual = subject.getWrappedElement();
assertEquals(expected, actual);
}
示例12: setChangedMethod
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setChangedMethod(Method newChangedMethod) {
Method oldChangedMethod = changedMethod;
changedMethod = newChangedMethod;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, JaMoPPDiffPackage.METHOD_CHANGE__CHANGED_METHOD,
oldChangedMethod, changedMethod));
}
示例13: setChangedElement
import org.emftext.language.java.members.Method; //导入依赖的package包/类
@Override
public void setChangedElement(EObject newChangedElement) {
if(newChangedElement == null) {
setChangedMethod(null);
} else if(newChangedElement instanceof Method) {
setChangedMethod((Method) newChangedElement);
} else {
throw new IllegalArgumentException("Tried to set invalid class type: " + newChangedElement.getClass().getSimpleName());
}
}
示例14: eSet
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case JaMoPPDiffPackage.METHOD_CHANGE__CHANGED_METHOD:
setChangedMethod((Method) newValue);
return;
}
super.eSet(featureID, newValue);
}
示例15: eUnset
import org.emftext.language.java.members.Method; //导入依赖的package包/类
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case JaMoPPDiffPackage.METHOD_CHANGE__CHANGED_METHOD:
setChangedMethod((Method) null);
return;
}
super.eUnset(featureID);
}