Author: scabanovich
Date: 2011-05-24 11:33:03 -0400 (Tue, 24 May 2011)
New Revision: 31445
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java
Log:
JBIDE-8983
https://issues.jboss.org/browse/JBIDE-8985
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -12,9 +12,12 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBeanMember;
@@ -37,20 +40,30 @@
return (BeanMemberDefinition)definition;
}
- protected void setMember(IMember member) {
+ protected void setMember(IJavaElement member) {
try {
- String returnType = member instanceof IField ? ((IField)member).getTypeSignature()
- : member instanceof IMethod ? ((IMethod)member).getReturnType() : null;
+ String returnType = null;
+ IMember currentMember = null;
+ if (member instanceof IField) {
+ returnType = ((IField)member).getTypeSignature();
+ currentMember = (IMember)member;
+ } else if (member instanceof IMethod) {
+ returnType = ((IMethod)member).getReturnType();
+ currentMember = (IMember)member;
+ } else if (member instanceof ILocalVariable) {
+ returnType = ((ILocalVariable)member).getTypeSignature();
+ currentMember = ((ILocalVariable)member).getDeclaringMember();
+ }
if(returnType != null) {
- ParametedType p =
getCDIProject().getNature().getTypeFactory().getParametedType(member, returnType);
+ ParametedType p =
getCDIProject().getNature().getTypeFactory().getParametedType(currentMember, returnType);
if(p != null) {
int offset = -1;
int length = 0;
String content = getDefinition().getTypeDefinition().getContent();
if(content != null) {
- ISourceRange sr = member.getSourceRange();
- ISourceRange nr = member.getNameRange();
+ ISourceRange sr = ((ISourceReference)member).getSourceRange();
+ ISourceRange nr = ((ISourceReference)member).getNameRange();
if(sr != null && nr != null && sr.getOffset() < nr.getOffset()
&& nr.getOffset() < content.length()) {
String start = content.substring(sr.getOffset(), nr.getOffset());
int off = -1;
@@ -105,16 +118,25 @@
return super.getResource();
}
+ protected ISourceReference getSourceReference() {
+ return getSourceMember();
+ }
+
+ protected ISourceRange getSourceRange() {
+ ISourceRange result = null;
+ try {
+ result = getSourceReference().getSourceRange();
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ return result;
+ }
+
public int getLength() {
if(definition.getOriginalDefinition() != null) {
return definition.getOriginalDefinition().getLength();
}
- ISourceRange r = null;
- try {
- getSourceMember().getSourceRange();
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
- }
+ ISourceRange r = getSourceRange();
return r == null ? 0 : r.getLength();
}
@@ -122,16 +144,11 @@
if(definition.getOriginalDefinition() != null) {
return definition.getOriginalDefinition().getStartPosition();
}
- ISourceRange r = null;
- try {
- getSourceMember().getSourceRange();
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
- }
+ ISourceRange r = getSourceRange();
return r == null ? 0 : r.getOffset();
}
public boolean isNullable() {
- return typeDeclaration==null?false:!typeDeclaration.isPrimitive();
+ return typeDeclaration == null ? false : !typeDeclaration.isPrimitive();
}
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -318,40 +318,19 @@
}
}
- boolean isParameter = false;// injectionPoint instanceof InjectionPointParameter;
boolean isNew = false;
Set<IQualifierDeclaration> qs = injectionPoint.getQualifierDeclarations();
- List<IType> qs2 = null;
- if(isParameter) {
- qs2 = new ArrayList<IType>();
- Set<IQualifier> qs_ =
((InjectionPointParameter)injectionPoint).getQualifiers();
- for (IQualifier q: qs_) {
- IType t = q.getSourceType();
- if(t != null) {
- if(CDIConstants.NEW_QUALIFIER_TYPE_NAME.equals(t.getFullyQualifiedName())) {
- isNew = true;
- } else {
- qs2.add(t);
- }
- }
- }
- } else {
- for (IQualifierDeclaration d: qs) {
- if(CDIConstants.NEW_QUALIFIER_TYPE_NAME.equals(d.getTypeName())) {
- isNew = true;
- break;
- }
- }
+ for (IQualifierDeclaration d: qs) {
+ if(CDIConstants.NEW_QUALIFIER_TYPE_NAME.equals(d.getTypeName())) {
+ isNew = true;
+ break;
+ }
}
if(isBuiltIn(type.getType())) {
Set<IBean> rslt = null;
- if(isParameter) {
- rslt = getBeans(attemptToResolveAmbiguousDependency, type, qs2.toArray(new
IType[0]));
- } else {
- rslt = getBeans(attemptToResolveAmbiguousDependency, type, qs.toArray(new
IQualifierDeclaration[0]));
- }
+ rslt = getBeans(attemptToResolveAmbiguousDependency, type, qs.toArray(new
IQualifierDeclaration[0]));
if(rslt.isEmpty()) {
BuiltInBean builtInBean = new BuiltInBean(type);
builtInBean.setParent(this);
@@ -396,14 +375,8 @@
continue;
}
Set<IQualifierDeclaration> qsb = b.getQualifierDeclarations(true);
- if(isParameter) {
- if(areMatchingQualifiers(qsb, qs2.toArray(new IType[0]))) {
- result.add(b);
- }
- } else {
- if(areMatchingQualifiers(qsb, qs)) {
- result.add(b);
- }
+ if(areMatchingQualifiers(qsb, qs)) {
+ result.add(b);
}
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
@@ -901,6 +874,10 @@
for (IClassBean b: classBeans.values()) {
Set<IInjectionPoint> ps = b.getInjectionPoints();
for (IInjectionPoint p: ps) {
+ if(p.getType() == null && p instanceof IInjectionPointField) {
+ System.out.println("shit");
+ continue;
+ }
if(p instanceof IInjectionPointField) {
IParametedType eventType = getEventType(p.getType());
if(eventType != null &&
((ParametedType)eventType).isAssignableTo((ParametedType)paramType, true)) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/Parameter.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -3,44 +3,55 @@
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.ISourceReference;
import org.jboss.tools.cdi.core.IBeanMethod;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IParameter;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.internal.core.impl.definition.ParameterDefinition;
-import org.jboss.tools.common.text.ITextSourceReference;
-public class Parameter extends AbstractBeanElement implements IParameter {
- ParameterDefinition definition;
+public class Parameter extends BeanMember implements IParameter {
BeanMethod beanMethod;
public Parameter() {}
+ public ParameterDefinition getDefinition() {
+ return (ParameterDefinition)definition;
+ }
+
public void setBeanMethod(BeanMethod beanMethod) {
this.beanMethod = beanMethod;
setParent(beanMethod);
}
public void setDefinition(ParameterDefinition definition) {
+ if(beanMethod.getMethod().getElementName().equals("obs")) {
+ System.out.println("!!");
+ }
super.setDefinition(definition);
this.definition = definition;
}
+ public void setLocalVariable(ILocalVariable v) {
+ setMember(v);
+ }
+
public String getName() {
- return definition.getName();
+ return getDefinition().getName();
}
public IParametedType getMemberType() {
- return definition.getType();
+ return getDefinition().getType();
}
public IParametedType getType() {
- if(definition.getOverridenType() != null) {
- return definition.getOverridenType();
+ if(getDefinition().getOverridenType() != null) {
+ return getDefinition().getOverridenType();
}
- return definition.getType();
+ return getDefinition().getType();
}
public IClassBean getClassBean() {
@@ -48,40 +59,17 @@
}
public IMember getSourceMember() {
- return definition.getMethodDefinition().getMethod();
+ return getDefinition().getMethodDefinition().getMethod();
}
- public int getLength() {
- ITextSourceReference p = definition.getPosition();
- return p == null ? 0 : p.getLength();
+ protected ISourceReference getSourceReference() {
+ return getDefinition().getVariable();
}
- public int getStartPosition() {
- ITextSourceReference p = definition.getPosition();
- return p == null ? 0 : p.getStartPosition();
- }
-
public Set<String> getAnnotationTypes() {
- return definition.getAnnotationTypes();
+ return getDefinition().getAnnotationTypes();
}
- public String getValue(String annotationTypeName) {
- String text = definition.getAnnotationText(annotationTypeName);
- if(text != null) {
- int i = text.indexOf('(');
- int j = text.lastIndexOf(')');
- if(i >= 0 && j > i) {
- String values = text.substring(i + 1, j).trim();
- if(values.startsWith("\"") &&
values.endsWith("\"")) {
- return values.substring(1, values.length() - 1);
- }
- //TODO improve
- return values;
- }
- }
- return null;
- }
-
/*
* (non-Javadoc)
* @see org.jboss.tools.cdi.core.IParameter#getBeanMethod()
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -362,7 +362,6 @@
packages = workingCopy.packages;
packageDefinitions = workingCopy.packageDefinitions;
beanXMLs = workingCopy.beanXMLs;
- dependencies = workingCopy.dependencies;
Set<IProcessAnnotatedTypeFeature> fs =
project.getExtensionManager().getProcessAnnotatedTypeFeature();
if(fs != null && !fs.isEmpty()) {
@@ -377,6 +376,9 @@
e.applyWorkingCopy();
}
+ //extensions may add to dependencies while they change
+ dependencies = workingCopy.dependencies;
+
project.getDelegate().update();
workingCopy = null;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -16,13 +16,10 @@
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IInterceptorBinding;
@@ -30,11 +27,7 @@
import org.jboss.tools.cdi.core.IRootDefinitionContext;
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
-import org.jboss.tools.cdi.internal.core.impl.AnnotationLiteral;
import org.jboss.tools.cdi.internal.core.impl.ClassBean;
-import org.jboss.tools.cdi.internal.core.impl.ParametedType;
-import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
/**
*
@@ -66,7 +59,6 @@
protected void init(IType contextType, IRootDefinitionContext context, int flags) throws
CoreException {
super.init(contextType, context, flags);
isConstructor = method.isConstructor();
- //TODO process parameters for disposers and observers
loadParamDefinitions(contextType, context, flags);
}
@@ -76,85 +68,31 @@
void loadParamDefinitions(IType contextType, IRootDefinitionContext context, int flags)
throws CoreException {
if(method == null) return;
+ ILocalVariable[] ps = method.getParameters();
+
boolean loadAll = (flags & FLAG_ALL_MEMBERS) > 0;
boolean parametersAreInjectionPoints = parametersAreInjectionPoints();
- String[] parameterNames = method.getParameterNames();
- if(parameterNames == null || parameterNames.length == 0) return;
+
+ if(ps.length == 0) return;
if(contextType == null || contextType.isBinary()) return;
- String content = typeDefinition.getContent();
- if(content == null) return;
- ISourceRange range = method.getSourceRange();
- ISourceRange nameRange = method.getNameRange();
- if(nameRange != null) range = nameRange;
- int paramStart = content.indexOf('(', range.getOffset());
- if(paramStart < 0) return;
- int declEnd = content.indexOf('{', paramStart);
- if(declEnd < 0) return;
- int paramEnd = content.lastIndexOf(')', declEnd);
- if(paramEnd < paramStart) paramEnd = declEnd;
- String paramsString = content.substring(paramStart + 1, paramEnd);
- if(!parametersAreInjectionPoints && paramsString.indexOf("@Observes")
>= 0) {
- parametersAreInjectionPoints = true;
- }
- if(!loadAll && !parametersAreInjectionPoints &&
paramsString.indexOf('@') < 0) return;
- String[] params = getParams(paramsString);
- String[] ps = method.getParameterTypes();
- int start = paramStart + 1;
- for (int i = 0; i < params.length; i++) {
- if(ps.length <= i) {
- // CDICorePlugin.getDefault().logError(new IllegalArgumentException("Cannot
parse method parameters for " + paramsString));
- // The source code may be broken. Just ignore such errors.
- break;
- }
- if(!loadAll && !parametersAreInjectionPoints &&
params[i].indexOf('@') < 0) {
- start += params[i].length() + 1;
- continue; //do not need parameters without annotation
- }
-
+ ParameterDefinition[] ds = new ParameterDefinition[ps.length];
+ for (int i = 0; i < ps.length; i++) {
ParameterDefinition pd = new ParameterDefinition();
-
- ParametedType type = context.getProject().getTypeFactory().getParametedType(method,
ps[i]);
-
- pd.methodDefinition = this;
- pd.name = parameterNames[i];
+ pd.setMethodDefinition(this);
pd.index = i;
- pd.type = type;
-
- String p = params[i].trim();
- int pi = params[i].indexOf(p);
-
- ValueInfo v = new CheckingValueInfo(method);
- v.setValue(params[i]);
- v.valueStartPosition = start + pi;
- v.valueLength = p.length();
- v.setResource((IFile)resource);
- pd.setPosition(v);
-
- String[] tokens = getParamTokens(p);
- for (String q: tokens) {
- if(!q.startsWith("@")) continue;
- int valueStartPosition = start + params[i].indexOf(q);
- int valueLength = q.length();
- int s = q.indexOf('(');
- if(s >= 0) q = q.substring(0, s).trim();
- String annotationType = EclipseJavaUtil.resolveType(contextType,
q.substring(1).trim());
- IType t = context.getProject().getType(annotationType);
- if(t != null) {
- String source = content.substring(valueStartPosition, valueStartPosition +
valueLength);
- IMemberValuePair[] pairs = ParameterDefinition.getMemberValues(source);
- AnnotationLiteral ja = new AnnotationLiteral(method.getResource(),
valueStartPosition, valueLength, null, IMemberValuePair.K_UNKNOWN, t);
- if(pairs != null && pairs.length > 0) for (IMemberValuePair pair: pairs)
{
- ja.addMemberValuePair(pair.getMemberName(), pair.getValue(), pair.getValueKind());
- }
- pd.addAnnotation(ja, context);
- }
+ pd.setLocalVariable(ps[i], context, flags);
+ if(pd.isAnnotationPresent(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME)) {
+ parametersAreInjectionPoints = true;
}
-
- parameters.add(pd);
-
- start += params[i].length() + 1;
+ ds[i] = pd;
}
+ for (int i = 0; i < ps.length; i++) {
+ if(!loadAll && !parametersAreInjectionPoints &&
ds[i].getAnnotations().isEmpty()) {
+ continue; //do not need parameters without annotation
+ }
+ parameters.add(ds[i]);
+ }
}
@Override
@@ -207,120 +145,4 @@
return annotationsByType.get(CDIConstants.POST_CONSTRUCTOR_TYPE_NAME);
}
- static String[] getParams(String paramsString) {
- List<String> result = new ArrayList<String>();
- int i = 0;
- int c1 = 0;
- int c2 = 0;
- char quote = '\0';
- StringBuffer sb = new StringBuffer();
- while(i < paramsString.length()) {
- char c = paramsString.charAt(i);
- if(c == ',' && c1 == 0 && c2 == 0 && quote ==
'\0') {
- if(sb.toString().trim().length() > 0) {
- result.add(sb.toString());
- }
- sb.setLength(0);
- i++;
- continue;
- } else if(c == '(' && quote == '\0') {
- c1++;
- } else if(c == ')' && quote == '\0') {
- c1--;
- } else if(c == '<' && quote == '\0') {
- c2++;
- } else if(c == '>' && quote == '\0') {
- c2--;
- } else if((c == '\'' || c == '"') && quote ==
'\0') {
- quote = c;
- } else if(quote == c) {
- quote = '\0';
- }
- sb.append(c);
- i++;
- }
- if(sb.length() > 0) {
- result.add(sb.toString());
- }
- return result.toArray(new String[0]);
- }
-
- static String[] getParamTokens(String paramsString) {
- List<String> result = new ArrayList<String>();
- int i = 0;
- int c1 = 0;
- int c2 = 0;
- char quote = '\0';
- StringBuffer sb = new StringBuffer();
- while(i < paramsString.length()) {
- char c = paramsString.charAt(i);
- boolean ws = Character.isWhitespace(c);
- if(ws && c1 == 0 && c2 == 0 && quote == '\0') {
- String t = sb.toString().trim();
- if(t.length() > 0) {
- result.add(t);
- }
- sb.setLength(0);
- i++;
- continue;
- } else if(c == '(' && quote == '\0') {
- c1++;
- } else if(c == ')' && quote == '\0') {
- c1--;
- } else if(c == '<' && quote == '\0') {
- c2++;
- } else if(c == '>' && quote == '\0') {
- c2--;
- } else if((c == '\'' || c == '"') && quote ==
'\0') {
- quote = c;
- } else if(quote == c) {
- quote = '\0';
- }
- sb.append(c);
- i++;
- }
- if(sb.length() > 0) {
- result.add(sb.toString());
- }
- return result.toArray(new String[0]);
- }
-
- class CheckingValueInfo extends ValueInfo {
- IMethod m;
- CheckingValueInfo(IMethod m) {
- this.m = m;
- }
-
- void check() {
- ISourceRange r = null;
- try {
- r = m.getSourceRange();
- } catch (JavaModelException e) {
- System.out.println("Method is obsolete: " + m);
- }
- if(r == null) {
- valueStartPosition = 0;
- valueLength = 0;
- } else {
- if(valueStartPosition + valueLength > r.getOffset() + r.getLength()) {
- System.out.println("Method is modified: " + m);
- valueStartPosition = 0;
- valueLength = 0;
- }
- }
-
- }
-
- public int getStartPosition() {
- check();
- return valueStartPosition;
- }
-
- public int getLength() {
- check();
- return valueLength;
- }
-
- }
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java 2011-05-24
15:15:11 UTC (rev 31444)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParameterDefinition.java 2011-05-24
15:33:03 UTC (rev 31445)
@@ -12,26 +12,43 @@
import java.util.Set;
-import org.eclipse.jdt.core.IMemberValuePair;
-import org.eclipse.jdt.internal.core.MemberValuePair;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.cdi.core.IRootDefinitionContext;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.cdi.internal.core.impl.TypeDeclaration;
import org.jboss.tools.common.text.ITextSourceReference;
-public class ParameterDefinition extends AbstractMemberDefinition {
+public class ParameterDefinition extends BeanMemberDefinition {
protected MethodDefinition methodDefinition;
- protected String name;
+ ILocalVariable variable;
protected ParametedType type;
protected TypeDeclaration overridenType;
protected int index;
- protected ITextSourceReference position = null;
-
public ParameterDefinition() {}
+ public void setMethodDefinition(MethodDefinition methodDefinition) {
+ this.methodDefinition = methodDefinition;
+ typeDefinition = methodDefinition.getTypeDefinition();
+ }
+
+ public void setLocalVariable(ILocalVariable v, IRootDefinitionContext context, int
flags) {
+ variable = v;
+ super.setAnnotatable(v, v.getDeclaringMember().getDeclaringType(), context, flags);
+ }
+
+ @Override
+ protected void init(IType contextType, IRootDefinitionContext context, int flags) throws
CoreException {
+ super.init(contextType, context, flags);
+ type =
context.getProject().getTypeFactory().getParametedType(variable.getDeclaringMember(),
variable.getTypeSignature());
+ }
+
public String getName() {
- return name;
+ return variable.getElementName();
}
public ParametedType getType() {
@@ -50,45 +67,14 @@
return methodDefinition;
}
- private static IMemberValuePair[] EMPTY_PAIRS = new IMemberValuePair[0];
-
- static IMemberValuePair[] getMemberValues(String source) {
- int p1 = source.indexOf('(');
- int p2 = source.indexOf(')');
- if(p1 >= 0 && p2 > p1) {
- String params = source.substring(p1 + 1, p2).trim();
- if(params.length() > 0) {
- if(params.startsWith("{") && params.endsWith("}")) {
- //TODO
- } else if(params.endsWith(".class")) {
- params = params.substring(0, params.length() - 6);
- IMemberValuePair pair = new MemberValuePair("value", params,
IMemberValuePair.K_CLASS);
- return new IMemberValuePair[]{pair};
- } else if(params.startsWith("\"") &&
params.endsWith("\"")) {
- params = params.substring(1, params.length() - 1);
- IMemberValuePair pair = new MemberValuePair("value", params,
IMemberValuePair.K_STRING);
- return new IMemberValuePair[]{pair};
- } else {
- //TODO
- }
- }
- }
-
- return EMPTY_PAIRS;
- }
-
public Set<String> getAnnotationTypes() {
return annotationsByType.keySet();
}
- public void setPosition(ITextSourceReference position) {
- this.position = position;
+ public ILocalVariable getVariable() {
+ return variable;
}
- public ITextSourceReference getPosition() {
- return position;
- }
-
public String getAnnotationText(String annotationTypeName) {
ITextSourceReference pos = getAnnotationPosition(annotationTypeName);
if(pos == null) return null;