/*
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.eclipse.codeassist.proposals;
import groovyjarjarasm.asm.Opcodes;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.eclipse.codeassist.ProposalUtils;
import org.eclipse.jdt.core.ICompilationUnit;
public class GroovyCategoryMethodProposal extends GroovyMethodProposal {
public GroovyCategoryMethodProposal(MethodNode method) {
super(method, "Groovy");
}
@Override
protected int getModifiers() {
return getMethod().getModifiers() & ~Opcodes.ACC_STATIC; // category methods are defined as static, but should not appear as such when a proposal
}
@Override
protected char[] createMethodSignature() {
return ProposalUtils.createMethodSignature(getMethod(), 1);
}
@Override
protected char[][] createAllParameterNames(ICompilationUnit unit) {
return removeFirst(super.createAllParameterNames(unit));
}
@Override
protected char[][] getParameterTypeNames(Parameter[] parameters) {
return removeFirst(super.getParameterTypeNames(parameters));
}
private char[][] removeFirst(char[][] array) {
if (array.length > 0) {
char[][] newArray = new char[array.length-1][];
System.arraycopy(array, 1, newArray, 0, array.length-1);
return newArray;
} else {
// shouldn't happen
return array;
}
}
}