List of usage examples for org.aspectj.asm IProgramElement getExtraInfo
public ExtraInformation getExtraInfo();
From source file:org.eclipse.ajdt.core.javaelements.AdviceElement.java
License:Open Source License
protected Object createElementInfo() { try {//from w w w . j av a2s .c o m IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); AdviceElementInfo info = new AdviceElementInfo(); info.setAJExtraInfo(ipe.getExtraInfo()); info.setName(name.toCharArray()); info.setAJKind(IProgramElement.Kind.ADVICE); info.setAJModifiers(ipe.getModifiers()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); return info; } catch (Exception e) { // can fail for any of a number of reasons. // return null so that we can try again later. return null; } }
From source file:org.eclipse.ajdt.core.javaelements.AspectElement.java
License:Open Source License
protected Object createElementInfo() { AspectElementInfo info = new AspectElementInfo(); info.setAJKind(IProgramElement.Kind.ASPECT); info.setHandle(this); info.setSourceRangeStart(0);//from w ww .j av a2 s .c o m IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); if (ipe != null && ipe != IHierarchy.NO_STRUCTURE) { info.setAJExtraInfo(ipe.getExtraInfo()); info.setAJModifiers(ipe.getModifiers()); info.setFlags(getProgramElementModifiers(ipe)); info.setAJAccessibility(ipe.getAccessibility()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // info.setPrivileged(???); not setting this yet } return info; }
From source file:org.eclipse.ajdt.core.javaelements.IntertypeElement.java
License:Open Source License
protected Object createElementInfo() { IntertypeElementInfo info = new IntertypeElementInfo(); IProject project = this.getJavaProject().getProject(); IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForProject(project) .javaElementToProgramElement(this); if (ipe != IHierarchy.NO_STRUCTURE) { // this way of creating the element info does not contain proper source locations for the name and target type info.setAJExtraInfo(ipe.getExtraInfo()); info.setName(name.toCharArray()); info.setAJKind(ipe.getKind());//from www.ja va 2 s .c om info.setAJModifiers(ipe.getModifiers()); info.setFlags(ipe.getRawModifiers()); info.setDeclaredModifiers(info.getModifiers()); info.setAJAccessibility(ipe.getAccessibility()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); // This is wrong info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // also wrong info.setConstructor(info.getAJKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); char[][] argumentNames = CoreUtils.listStringsToCharArrays(ipe.getParameterNames()); char[][] argumentTypeNames = CoreUtils.listCharsToCharArrays(ipe.getParameterTypes()); if (argumentNames.length == 0 && argumentTypeNames.length > 0) { // argument names not found. likely coming from binary class file w/p source attachment // generate argument names argumentNames = new char[argumentTypeNames.length][]; for (int i = 0; i < argumentNames.length; i++) { argumentNames[i] = ("arg" + i).toCharArray(); } } info.setArgumentNames(argumentNames); info.setArgumentTypeNames(argumentTypeNames); info.setReturnType(ipe.getCorrespondingType(false).toCharArray()); info.setQualifiedReturnType(ipe.getCorrespondingType(true).toCharArray()); info.setTypeParameters(createTypeParameters(project)); if (argumentNames != null && argumentNames.length > 0) { ILocalVariable[] arguments = new ILocalVariable[argumentNames.length]; for (int i = 0; i < argumentNames.length; i++) { arguments[i] = new LocalVariable(this, String.valueOf(argumentNames[i]), // sloc is not correct, but it is close enough sourceLocation.getOffset(), sourceLocation.getOffset() + 1, sourceLocation.getOffset(), sourceLocation.getOffset() + 1, String.valueOf(argumentTypeNames[i]), new Annotation[0], Flags.AccDefault, true); } info.setArguments(arguments); } } else { // no successful build yet, we don't know the contents info.setName(name.toCharArray()); info.setAJKind(IProgramElement.Kind.ERROR); info.setAJModifiers(Collections.<Modifiers>emptyList()); } return info; }
From source file:org.eclipse.ajdt.core.javaelements.MockSourceMethod.java
License:Open Source License
protected Object createElementInfo() { if (elementInfo != null) { return elementInfo; }/* w w w . jav a 2 s . c o m*/ try { IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); elementInfo = new MethodElementInfo(); ISourceLocation sourceLocation = ipe.getSourceLocation(); elementInfo.setSourceRangeStart(sourceLocation.getOffset()); elementInfo.setNameSourceStart(sourceLocation.getOffset()); elementInfo.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); elementInfo.setAJExtraInfo(ipe.getExtraInfo()); elementInfo.setName(name.toCharArray()); elementInfo.setAJKind(IProgramElement.Kind.METHOD); elementInfo.setAJModifiers(ipe.getModifiers()); elementInfo.setAJAccessibility(ipe.getAccessibility()); return elementInfo; } catch (Exception e) { // can fail for any of a number of reasons. // return null so that we can try again later. return null; } }
From source file:org.eclipse.ajdt.internal.ui.markers.UpdateAJMarkers.java
License:Open Source License
/** * Get the marker type that should be used for the given relationship * /*from w w w . j a v a 2s . co m*/ * @param relationship * @param target * @return */ private String getMarkerTypeForRelationship(IRelationship relationship, String target) { String name = relationship.getName(); boolean runtimeTest = relationship.hasRuntimeTest(); String markerType; if (name.equals(AsmRelationshipProvider.ADVISED_BY)) { IProgramElement advice = model.getProgramElement(target); AdviceKind ak; if (advice.getExtraInfo() != null) { ak = AdviceKind.stringToKind(advice.getExtraInfo().getExtraAdviceInformation()); } else { ak = null; } if (runtimeTest) { if (ak == null) { markerType = IAJModelMarker.DYNAMIC_ADVICE_MARKER; } else if (ak == AdviceKind.Before) { markerType = IAJModelMarker.DYNAMIC_BEFORE_ADVICE_MARKER; } else if (ak == AdviceKind.After || ak == AdviceKind.AfterReturning || ak == AdviceKind.AfterThrowing) { markerType = IAJModelMarker.DYNAMIC_AFTER_ADVICE_MARKER; } else if (ak == AdviceKind.Around) { markerType = IAJModelMarker.DYNAMIC_AROUND_ADVICE_MARKER; } else { markerType = IAJModelMarker.DYNAMIC_ADVICE_MARKER; } } else { // no runtime test if (ak == null) { markerType = IAJModelMarker.ADVICE_MARKER; } else if (ak == AdviceKind.Before) { markerType = IAJModelMarker.BEFORE_ADVICE_MARKER; } else if (ak == AdviceKind.After || ak == AdviceKind.AfterReturning || ak == AdviceKind.AfterThrowing) { markerType = IAJModelMarker.AFTER_ADVICE_MARKER; } else if (ak == AdviceKind.Around) { markerType = IAJModelMarker.AROUND_ADVICE_MARKER; } else { markerType = IAJModelMarker.ADVICE_MARKER; } } } else if (name.equals(AsmRelationshipProvider.ADVISES)) { IProgramElement advice = model.getProgramElement(relationship.getSourceHandle()); AdviceKind ak; if (advice.getExtraInfo() != null) { ak = AdviceKind.stringToKind(advice.getExtraInfo().getExtraAdviceInformation()); } else { ak = null; // hmmm...sometmes ExtradviceInformtion is null. // try to get the advice kind by the name if (advice.getName().startsWith("before")) { ak = AdviceKind.Before; } else if (advice.getName().startsWith("after")) { ak = AdviceKind.After; } else if (advice.getName().startsWith("around")) { ak = AdviceKind.Around; } } if (runtimeTest) { if (ak == null) { markerType = IAJModelMarker.SOURCE_DYNAMIC_ADVICE_MARKER; } else if (ak == AdviceKind.Before) { markerType = IAJModelMarker.SOURCE_DYNAMIC_BEFORE_ADVICE_MARKER; } else if (ak == AdviceKind.After || ak == AdviceKind.AfterReturning || ak == AdviceKind.AfterThrowing) { markerType = IAJModelMarker.SOURCE_DYNAMIC_AFTER_ADVICE_MARKER; } else if (ak == AdviceKind.Around) { markerType = IAJModelMarker.SOURCE_DYNAMIC_AROUND_ADVICE_MARKER; } else { markerType = IAJModelMarker.SOURCE_DYNAMIC_ADVICE_MARKER; } } else { // no runtime test if (ak == null) { markerType = IAJModelMarker.SOURCE_ADVICE_MARKER; } else if (ak == AdviceKind.Before) { markerType = IAJModelMarker.SOURCE_BEFORE_ADVICE_MARKER; } else if (ak == AdviceKind.After || ak == AdviceKind.AfterReturning || ak == AdviceKind.AfterThrowing) { markerType = IAJModelMarker.SOURCE_AFTER_ADVICE_MARKER; } else if (ak == AdviceKind.Around) { markerType = IAJModelMarker.SOURCE_AROUND_ADVICE_MARKER; } else { markerType = IAJModelMarker.SOURCE_ADVICE_MARKER; } } } else if (name.equals(AsmRelationshipProvider.ANNOTATED_BY) || name.equals(AsmRelationshipProvider.SOFTENED_BY) || name.equals(AsmRelationshipProvider.INTER_TYPE_DECLARED_BY)) { // note that we ignore MATCHES_DECLARE because that is taken care of // by error and warning markers markerType = IAJModelMarker.ITD_MARKER; } else if (name.equals(AsmRelationshipProvider.ANNOTATES) || name.equals(AsmRelationshipProvider.INTER_TYPE_DECLARES) || name.equals(AsmRelationshipProvider.SOFTENS) || name.equals(AsmRelationshipProvider.MATCHED_BY)) { markerType = IAJModelMarker.SOURCE_ITD_MARKER; } else { markerType = null; } return markerType; }